OpenAPITools / OpenAPITools/openapi-generator
[REQ] Add support for conditional generator option Use Global Import for both Model and Operation
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Is your feature request related to a problem? Please describe.
When using ImportMapping option in the Java language (and others), both the baseType and dataType properties of the CodegenModel will be mapped to a possible value existing in the DefaultCodegen's importMapping property.
This forces the creation of full inline types declaration everywhere in the generated java classes, and text files bigger than necessary.
Describe the solution you'd like
-
Introduce a new general option that could be called:
useGlobalImport; -
When the
useGlobalImportis set to true, then the generator just adds a value into the CodegenModel's object import set.
So, in this case NO mapping using importMapping will be done when callinggetSchemaType()orgetTypeDeclaration()methods in order to calculatebaseTypeordataTypemodel's properties; -
When the
useGlobalImportis set to false, then the generator won't add a value into the CodegenModel's object import set and will search for a match using the model'simportMappingwhen callinggetSchemaType()orgetTypeDeclaration()methods in order to calculatebaseTypeordataTypemodel's properties;
Describe alternatives you've considered
The alternative I'm considering is to change the signatures of generator's fromProperty, fromRequestBody, fromResponse, fromRequestBody, getSchemaType and getTypeDeclaration, passing a Set<String> importSet (can be used by both model and operation generation process).
Additional context
It is not clear to me, yet, the differences between getSchemaType and getTypeDeclaration and the reason of doing importMapping in both.
I've written my doubts here in the slack.
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
Start by tracing DefaultCodegen's importMapping through getSchemaType() and getTypeDeclaration(), then inspect how fromProperty(), fromRequestBody(), and fromResponse() build CodegenModel imports for models and operations. The change is complete when a conditional useGlobalImport option consistently controls whether values are added to the model import set or resolved through importMapping, with behavior covered for both generation paths.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100