[BUG][Dart] Generator creates a model class name that conflicts with a core lib class name (Type)
See original GitHub issueBug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue? Yes:
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What’s the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When generating Dart code, an OAS is using a reserved(ish) word (Type
) which the generator defines a class for which then conflicts and causes errors. (It’s not technically a reserved word of the language, it’s a class in the core library. Something that’s always available and you can’t import it with a namespace)
openapi-generator version
5.1.0 release on both dart-dio and dart-dio-next
OpenAPI declaration file content or url
https://cdn-prod.wdesk.com/endpoints-admin/1.342.0/openapi/platform-v1.yaml
Problem arises from line 813
Generation Details
I used the jar release for 5.1.0 with this command:
java -jar openapi-generator-cli.jar generate -i https://cdn-prod.wdesk.com/endpoints-admin/1.342.0/openapi/platform-v1.yaml -g dart-dio -o ./ --additional-properties="pubDescription=Workiva Platform API (Dart),pubName=wk,pubVersion=1.0.0"
Steps to reproduce
Generate Dart code with the above command.
Have Dart installed (2.12.2)
Then run
pub get
pub run build_runner build --delete-conflicting-outputs -o build
(then remove the build directory … you only need to run a build to do built_value code generation
Then either open in an IDE with the Dart plugin (VS Code, intelliJ) or just run dartanalyzer .
which will show the errors.
Related issues/PRs
Suggest a fix
I’m not actually sure what a good fix would be. I might actually prefer if generation failed when creating the code and suggested a way to work around it, possibly by using the [--reserved-words-mappings <reserved word mappings>...]
option ?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:14 (7 by maintainers)
Top GitHub Comments
Hi @kuhnroyal
I have an issue with imports in *_api.dart (generated by .templates/dart-dio/api.mustache), see details below:
.templates/dart-dio/api.mustache
*_api.dart
config.yaml
generator version is 5.1.0
.Could you have a look? or help me correct it?
Whatever works for you. You can also always use docker with the
cli-latest
tag: https://hub.docker.com/r/openapitools/openapi-generator