OpenAPITools / OpenAPITools/openapi-generator
[BUG][typescript-angular] response with anyOf type array leads to wrong imports in generated code
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
If anyOf with type array is used in a response, the generated code uses wrong imports:
import { Array<ImageDTO> } from '../model/models';
import { Array<ImageFileDTO> } from '../model/models';
openapi-generator version
5.1.0
OpenAPI declaration file content or url
Defining the following schema in a response:
"schema": {
"title": "Get Content",
"anyOf": [
{
"type": "array",
"items": { "$ref": "#/components/schemas/ImageFile" }
},
{
"type": "array",
"items": { "$ref": "#/components/schemas/Image" }
}
]
}
leads to the following import statements, which try to import the array type:
import { Array<ImageDTO> } from '../model/models';
import { Array<ImageFileDTO> } from '../model/models';
Correctly only ImageDTO and ImageFileDTO should be imported.
Command line used for generation
java -jar openapi-generator-cli-5.1.0.jar generate -i openapi\minimal_openapi.json -g typescript-angular -o .\src\client --additional-properties=modelSuffix=DTO
Workaround
Wrapping the anyOf in a schema which is used as response does not lead to this issue.
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
Reproduce the issue with the provided OpenAPI schema and the typescript-angular generator command. Trace how response anyOf array schemas are converted into imports, then verify that generation imports only ImageDTO and ImageFileDTO rather than Array and Array.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- angular, openapi, typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100