Bug Report Checklist
Description
We use <modelNameSuffix>TO</modelNameSuffix> to distinct all our generated models from our internal models and prevent name collissions. In our Spec, we define our Ids as follows (in an extra file id.json):
"ExampleId": {
"description": "The example Id.",
"type": "string",
"format": "uuid",
"example": "53b1f9fe-44e1-11f0-1122-336652440000"
}
The spec then references these id types:
"ExampleWrapper": {
"type": "object",
"required": ["id", "name"],
"properties": {
"id": {
"$ref": "id.json#/components/schemas/ExampleId"
},
"name": {
"type": "string"
}
}
}
To prevent OpenAPI-Generator from generating ExampleId-classes, we define a mapping configuration via <configurationFile>configuration.json</configurationFile>:
{
"importMappings": {
"ExampleId": "com.example.model.id.ExampleId"
}
}
The referenced class ExampleId already exists of course.
All of this worked in 5.3.1 an lead to sources like this:
package com.example.api.generated.model;
[...]
import com.example.model.id.ExampleId;
[...]
public class ExampleWrapperTO {
[...]
private @Valid ExampleId id;
private @Valid String name;
[...]
}
With 5.4.0 this is generated:
package com.example.api.generated.model;
[...]
import com.example.api.generated.model.ExampleIdTO;
[...]
public class ExampleWrapperTO {
[...]
private @Valid ExampleIdTO id;
private @Valid String name;
[...]
Note: a ExampleIdTO is not generated! (we don't want it to, just a note)
I tracked the changed behaviour to 33bce99#r65722393 but as the PR says, this change is intended. Was it really, given the example above? Or was using modelNamePrefix/modelNameSuffix out of scope for that PR?
Workaround
If i change our configuration.json to the following, valid sources are generated:
{
"typeMappings": {
"ExampleIdTO": "ExampleId",
},
"importMappings": {
"ExampleId": "com.example.model.id.ExampleId",
"ExampleIdTO": "com.example.model.id.ExampleId",
}
}
But this seems very redundant and partly wrong to me. If i leave out any of the three definitions, it stops working:
- leave out
typeMappings.ExampleIdTO: ExampleWrapperTO uses ExampleIdTO instead of ExampleId
- leave out
importMappings.ExampleId: ExampleWrapperTO uses UUID instead of ExampleId
- leave out
importMappings.ExampleIdTO: ExampleWrapperTO imports com.example.api.generated.model.ExampleIdTO (which doesn't exist), but not com.example.model.id.ExampleId, but uses private @Valid ExampleId id, which cannot be found
openapi-generator version
5.4.0 (worked in 5.3.1)
OpenAPI declaration file content or url
see above
Generation Details
openapi-generator-maven-plugin:5.4.0
with config:
<configuration>
<inputSpec>${project.basedir}/src/main/resources/META-INF/openapi.json</inputSpec>
<configurationFile>${project.basedir}/src/main/openapi/generator/configuration.json</configurationFile>
<apiPackage>com.example.api.generated</apiPackage>
<modelPackage>com.example.api.generated.model</modelPackage>
<modelNameSuffix>TO</modelNameSuffix>
<generatorName>jaxrs-spec</generatorName>
<!-- <library>quarkus</library> would generate unnecessary Dockerfile etc. -->
<configOptions>
<interfaceOnly>true</interfaceOnly>
<returnResponse>false</returnResponse>
<sourceFolder>java</sourceFolder>
<useSwaggerAnnotations>false</useSwaggerAnnotations>
<generatePom>false</generatePom>
<dateLibrary>java8</dateLibrary>
</configOptions>
</configuration>
Steps to reproduce
Related issues/PRs
#11217
Suggest a fix
Revert #11217 or some of its contents?
Bug Report Checklist
Description
We use
<modelNameSuffix>TO</modelNameSuffix>to distinct all our generated models from our internal models and prevent name collissions. In our Spec, we define our Ids as follows (in an extra fileid.json):The spec then references these id types:
To prevent OpenAPI-Generator from generating
ExampleId-classes, we define a mapping configuration via<configurationFile>configuration.json</configurationFile>:The referenced class
ExampleIdalready exists of course.All of this worked in
5.3.1an lead to sources like this:With
5.4.0this is generated:Note: a
ExampleIdTOis not generated! (we don't want it to, just a note)I tracked the changed behaviour to 33bce99#r65722393 but as the PR says, this change is intended. Was it really, given the example above? Or was using
modelNamePrefix/modelNameSuffixout of scope for that PR?Workaround
If i change our
configuration.jsonto the following, valid sources are generated:But this seems very redundant and partly wrong to me. If i leave out any of the three definitions, it stops working:
typeMappings.ExampleIdTO:ExampleWrapperTOusesExampleIdTOinstead ofExampleIdimportMappings.ExampleId:ExampleWrapperTOusesUUIDinstead ofExampleIdimportMappings.ExampleIdTO:ExampleWrapperTOimportscom.example.api.generated.model.ExampleIdTO(which doesn't exist), but notcom.example.model.id.ExampleId, but usesprivate @Valid ExampleId id, which cannot be foundopenapi-generator version
5.4.0 (worked in 5.3.1)
OpenAPI declaration file content or url
see above
Generation Details
openapi-generator-maven-plugin:5.4.0with config:
Steps to reproduce
Related issues/PRs
#11217
Suggest a fix
Revert #11217 or some of its contents?