OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.29k stars 6.44k forks source link

[BUG][dart][dart-dio] Error generating Dart client-side code from OpenAPI API JSON #16243

Open edimmeduseljac opened 1 year ago

edimmeduseljac commented 1 year ago

Bug Report Checklist

Description

I am trying to generate the client-side code of an OpenAPI API using the openapi-generator-cli with the Dart-Dio generator. However, I am encountering errors during the generation process. The API JSON provided is just a small part of the whole API, and we have already successfully generated the API client code using the typescript-angular generator for Angular without any issues.

openapi-generator version

Should be 6.6.0

Contents of the openapitools.json file:

{
  "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "6.6.0"
  }
}
OpenAPI declaration file content or url

Link to OpenAPI declaration file

Generation Details

Script I am using for generation:

cd packages/apis

echo "Removing old files..."
rm -rf client_api

echo "Generating client api..."
openapi-generator-cli generate -i "../../scripts/api_snippet.json" -g dart-dio -o client_api

cd client_api

echo "Adding dependencies..."
flutter pub add build_runner
flutter pub add analyzer:0.39.14

echo "Cleaning up..."
flutter clean
flutter pub cache repair
flutter pub run build_runner clean

echo "Getting dependencies..."
flutter pub get

echo "Running build_runner..."
dart pub run build_runner build --delete-conflicting-outputs

I've also tried using the dart openapi generator, but this also did not work out. I think I would like to have it with dart-dio, since this seems to be the most liked option by the flutter community.

Logs after running command: Logs

Contents of the generated pubspec.yaml file: pubspect.yaml

Expected Outcome: I expect the Dart client-side code to be successfully generated without any syntax errors.

Actual Outcome: The generation process fails with syntax errors in the token_info.dart file.

Contents of the token_info.dart file: token_info.dart

Error when hovering over part 'token_info.g.dart:

Target of URI hasn't been generated: 'package:openapi/src/model/token_info.g.dart'.
Try running the generator that will generate the file referenced by the URI. dart([uri_has_not_been_generated](https://dart.dev/diagnostics/uri_has_not_been_generated))

TokenInfoBuilder is also underlined in red everywhere and shows the following error when hovering over:

Undefined class 'TokenInfoBuilder'.
Try changing the name to the name of an existing class, or creating a class with the name 'TokenInfoBuilder'. dart([undefined_class](https://dart.dev/diagnostics/undefined_class))
Steps to reproduce

Since this API client code generation is created as a package, I think there are no steps to reproduce this other than just using the shell script. You may have to install the openapi-generator-cli and flutter.

Related issues/PRs

This could be a similar issue

Suggest a fix

As a disclaimer, I must admit that I am more of a beginner when it comes to Flutter. If you have any questions or suggestions regarding the problem and the provided logs, please feel free to ask. I will do my best to address any queries and work towards finding a solution. Thank you for taking the time to review my problem and for any assistance you can provide!

maldag commented 2 months ago

Is there any progress on this? I was running into the same issue using openapi-generator 7.7.0.

The "....g.dart" files are not generated so the package won't build.