OpenAPITools / OpenAPITools/openapi-generator
[BUG] dart generator creates invalid code
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
The attached example demonstrates the problem.
It contains two classes (Obj1 and Obj2).
Both have the same mode property.
In the class Obj1 this results in the property
Set<Obj1ModeEnum> mode;
while in the class Obj2 the property looks like this:
Set<ModeEnum> mode;
Here I would expect Set<Obj2ModeEnum> mode;.
In the file obj1.dart the associated type is
class Obj2ModeEnum {
/// Instantiate a new enum with the provided [value].
const Obj2ModeEnum._(this.value);
...
Here I would expect Obj1ModeEnum.
In the file obj2.dart the corresponding type is correct (but duplicate, since it's in obj1.dart already):
class Obj2ModeEnum {
/// Instantiate a new enum with the provided [value].
const Obj2ModeEnum._(this.value);
...
openapi-generator version
openapi-generator-cli 7.6.0
commit : ab7d0cb
built : -999999999-01-01T00:00:00+18:00
source : https://github.com/openapitools/openapi-generator
docs : https://openapi-generator.tech/
OpenAPI declaration file content or url
{
"openapi": "3.0.1",
"info": {
"title": "api_test",
"version": "1.0.0"
},
"paths": {},
"components": {
"schemas": {
"Obj1": {
"type": "object",
"properties": {
"mode": {
"uniqueItems": true,
"type": "array",
"items": {
"type": "string",
"enum": [
"mode1",
"mode2",
"mode3"
]
}
}
}
},
"Obj2": {
"type": "object",
"properties": {
"mode": {
"uniqueItems": true,
"type": "array",
"items": {
"type": "string",
"enum": [
"mode1",
"mode2",
"mode3"
]
}
}
}
}
}
}
}
Generation Details
I'm using the following command:
openapi-generator generate -g dart -i spapi.json -o "$(pwd)/spapi" --additional-properties=pubName=spapi
Steps to reproduce
Use provided sample json and command.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Run the supplied OpenAPI declaration with the documented dart generator command and inspect the generated obj1.dart and obj2.dart files. Trace how the generator names inline enum types for both classes. Done means each class uses its own correctly named enum and the generated Dart code contains no duplicate or invalid references.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- dart, java
- Domain
- devtools, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100