Open hofR opened 3 years ago
If anyOf with type array is used in a response, the generated code uses wrong imports:
anyOf
type
import { Array<ImageDTO> } from '../model/models'; import { Array<ImageFileDTO> } from '../model/models';
5.1.0
Defining the following schema in a response:
schema
"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:
Correctly only ImageDTO and ImageFileDTO should be imported.
ImageDTO
ImageFileDTO
Here is a full example Gist
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
Wrapping the anyOf in a schema which is used as response does not lead to this issue.
Looks like a similar issue is reported here for typescript-axios: https://github.com/OpenAPITools/openapi-generator/issues/9163#issuecomment-821881644
Description
If
anyOf
withtype
array is used in a response, the generated code uses wrong imports:openapi-generator version
5.1.0
OpenAPI declaration file content or url
Defining the following
schema
in a response:leads to the following import statements, which try to import the array type:
Correctly only
ImageDTO
andImageFileDTO
should be imported.Here is a full example Gist
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.