Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG][JAVA][SPRING] missing JsonValue import if allOf used as inline-scheme composition #11323

Closed
souwa opened this issue Jan 15, 2022 · 3 comments · Fixed by #11653
Closed

Comments

@souwa
Copy link

souwa commented Jan 15, 2022

Description

When using allOf as a composition inline-scheme without inheritance/discriminator the import import com.fasterxml.jackson.annotation.JsonValue for the Enum method @JsonValue public String getValue() is not added to the imports of the generated class.

This happens when the inline model doesn't have enums, but the parent does.

Also, the syntax that was used is the only workaround that prevents the generation of the redundant additional ParentTitle+AllOf class (see Java generation of 'extra' class with allOf Workaraound):

    Address:
      type: object
      properties:
        locationType:
          type: string
          enum:
            - VILLAGE
            - SMALL_TOWN
            - BIG_CITY
      allOf:
        - $ref: '#/components/schemas/BasicAddress'

    BasicAddress:
      type: object
      properties:
        street:
          type: string
        housenumber:
          type: string
        zip:
          type: string
        city:
          type: string
        country:
          type: string

The result includes the following imports from Jackson,

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;

but not the JsonValue-Import: although the method is generated

    @JsonValue
    public String getValue() {
      return value;
    }
openapi-generator version

openapi-generator v. 5.3.1 ( for java spring)

Related issues/PRs

If the generation of the additional unnecessary ParentTitle+AllOf class is fixed then I believe that will fix this problem as well.
Opt-in solution to remove unnecessary model for inline schema composition

Suggest a fix

For the solution, this method postProcessModelProperty (SpringCodegen) might probably be adapted at the point where Jackson imports are added and the model will be checked if it is or has enums or not.

kthoms pushed a commit to kthoms/openapi-generator that referenced this issue Feb 18, 2022
A CodegenModel's hasEnum property is set in addVars:
  cm.hasEnums = true;
This state was cleared afterwards again.

As one of its results the import for @JsonValue was not added for the model class in the Spring code generator, where 'model.hasEnums' was evaluated to false where it should be true.
wing328 pushed a commit that referenced this issue Feb 21, 2022
A CodegenModel's hasEnum property is set in addVars:
  cm.hasEnums = true;
This state was cleared afterwards again.

As one of its results the import for @JsonValue was not added for the model class in the Spring code generator, where 'model.hasEnums' was evaluated to false where it should be true.
@wing328
Copy link
Member

wing328 commented Feb 21, 2022

The issue has been fixed by #11653 by @kthoms.

Please pull the latest master to give it another try.

@wing328 wing328 closed this as completed Feb 21, 2022
@souwa
Copy link
Author

souwa commented May 20, 2022

@kthoms, @wing328 Thank you:)!

@efriandika
Copy link

Does the api spec you provide follow OpenAPI inheritance / polymorphism standard? Although this spec does not provide "unecessary *allOf files", But I don't think this follow the standard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants