openapi-generator-dart icon indicating copy to clipboard operation
openapi-generator-dart copied to clipboard

How to use Openapi Generator Dart with Dart 3 ?

Open linh232323 opened this issue 1 year ago • 2 comments

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

linh232323 avatar Apr 24 '24 09:04 linh232323

It's not possible as https://github.com/OpenAPITools/openapi-generator generates only Dart 2 code. Both vanila and dio versions.

gawi151 avatar Aug 14 '24 11:08 gawi151

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

Vitaliy-Svinchyak avatar Aug 29 '24 10:08 Vitaliy-Svinchyak