OpenAPITools / OpenAPITools/openapi-generator

[REQ] Add support for conditional generator option Use Global Import for both Model and Operation

Open
#8,295 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature
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 useGlobalImport is 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 calling getSchemaType() or getTypeDeclaration() methods in order to calculate baseType or dataType model's properties;

  • When the useGlobalImport is 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's importMapping when calling getSchemaType() or getTypeDeclaration() methods in order to calculate baseType or dataType model'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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.