Open PhilippParis opened 3 years ago
The problem here is that you describe this object by your own here https://gist.github.com/PhilippParis/28c40d590b4a9019cb8040b143e09884#file-openapi-yaml-L36
to work with alias do the following
$ref
them, but just use type: TypeAlias
At least this is how I configured alias for my project. Version of openapi-maven-plugin-generator is 4.3.1 Example:
/type-alias/{id}:
post:
parameters:
- name: id
in: path
required: true
schema:
type: TypeAlias <--
responses:
200:
description: OK
I've just tested this, and it also works in version 5.0.0 But without the definition of the alias type the yaml is an incomplete api specification and cannot be used by a third party..
I'll fix this
I think the issue is that "TypeAlias" is a String, It's impossible to generate in java such object that extends String. How looks the custom implementation provided?
The problem here is that in DefaultCodegen#fromParameter, the schema gets prematurely dereferenced - losing the schema name that is later used to handle the importMapping/typeMapping/languageSpecificPrimitives stuff through a call to DefaultCodegen#fromProperty.
In my projects, everything looks good when I either avoid the dereferencing in DefaultCodegen#fromParameter:
parameterSchema = unaliasSchema(parameterSchema, importMapping); // <-- this was Collections.emptySet()
or hand the original schema of the parameter into DefaultCodegen#fromProperty:
CodegenProperty codegenProperty = fromProperty(parameter.getName(),
parameter.getSchema() != null ? parameter.getSchema() : parameterSchema);
However, I have no clue why the unaliasSchema
was done without importMappings in the first place, so I'm not sure what breakage this might cause (at least all tests stay green).
Bug Report Checklist
Description
when using importMapping for alias types, the generated code does not use the importmapping in the api interface
Expected
Actual
openapi-generator version
5.0.0
OpenAPI declaration file content or url
https://gist.github.com/PhilippParis/28c40d590b4a9019cb8040b143e09884
Generation Details
Steps to reproduce
run openapi-generator 5.0.0 with specified generation details
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/3589