openapi-generator-dart
openapi-generator-dart copied to clipboard
How to use Openapi Generator Dart with Dart 3 ?
Description of the bug
Could not generate project with dart 3
Steps to reproduce
Using Dart SDK version: 3.3.4 (stable) (Tue Apr 16 19:56:12 2024 +0000) on "macos_arm64" Run generate and pubspec.yaml as
environment:
sdk: '>=2.7.0 <3.0.0'
Expected behavior
Openapi-Generator-Dart should generate dart 3 project with pubspec env as
environment:
sdk: '>=3.0.0 <4.0.0'
Logs
No response
Screenshots
No response
Platform
macOS
Library version
5.0.2
Flutter version
3.19.6
Flutter channel
stable
Additional context
No response
It's not possible as https://github.com/OpenAPITools/openapi-generator generates only Dart 2 code. Both vanila and dio versions.
The only problem I faced with dart 3 was that mixins are defined as abstract classes which is not a valid code in dart 3. I run this bash script after codegen to fix it:
#!/bin/bash
MODEL_DIRECTORY="./lib/sdk/lib/src/model/"
for file in "$MODEL_DIRECTORY"/*; do
if [ -f "$file" ]; then
sed -i '' "s/abstract class _/mixin _/Ig" "$file"
echo "Moved to mixins in: $file"
fi
done