Closed Xiphoseer closed 2 weeks ago
https://github.com/search?q=repo%3AOpenAPITools%2Fopenapi-generator+%22String+toModelFilename%28%22&type=code shows a bunch of toModelFilename
overloads that delegate to model name mappings / toModelName
or schemaMappings
directly, so this issue applies to more generators than just Java.
Bug Report Checklist
Description
When I specify a schema mapping (aka
schemaMappings
map in a config.yaml), where the mapped value contains a java type with generic parameters (e.g.Wrapper<Thing>
), then the code generation aborts withat https://github.com/OpenAPITools/openapi-generator/blob/2abcb4f7f0aa67c126304e43602ae72a83f2dca7/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java#L491
openapi-generator version
At least since 7.4.0, still broken on master
OpenAPI declaration file content or url
https://gist.github.com/Xiphoseer/05c1b92d36ff3beef1e7e84fc476ccf9
Generation Details
DefaultCodegen
wheretoModelFilename
resolves schemaMappingsschemaMappings
Steps to reproduce
api.yaml
andconfig.yaml
in a directoryopenapi-generator-cli generate -c .\config.yaml
It's possible / likely this particular error only occurs on windows, Linux will let me create a file with
<
in the name just fine, but my understanding is that just hides the underlying issue.Related issues/PRs
None found
Suggest a fix
I'd suggest removing the entire loop marked as "HACK": https://github.com/OpenAPITools/openapi-generator/blob/2abcb4f7f0aa67c126304e43602ae72a83f2dca7/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultGenerator.java#L488-L493
It doesn't quite do what it's supposed to (skip generation of model templated files for models that are schema mapped), because
toModelFilename
for Java callstoModelName
which considersschemaMappings
and thus acts on the mapped model name and file, not the file it would generate without the schema mapping. Additionally, the function where this happens seems to ensure anyway (usingcontinue
after the loop) that the schema will not be imported for generation.This overload in
AbstractJavaCodegen
is what causes the issue, but it is a valid implementation since Java does require the class and file name to match: https://github.com/OpenAPITools/openapi-generator/blob/2abcb4f7f0aa67c126304e43602ae72a83f2dca7/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java#L930-L933The default implementation is not susceptible to this because it's stateless: https://github.com/OpenAPITools/openapi-generator/blob/2abcb4f7f0aa67c126304e43602ae72a83f2dca7/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java#L1637-L1639
So far I did not reason about the other generators.