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] REF_AS_PARENT_IN_ALLOF=true no longer works for allOf combined with properties #16389

Closed
4 tasks done
jpraet opened this issue Aug 24, 2023 · 7 comments
Closed
4 tasks done

Comments

@jpraet
Copy link
Contributor

jpraet commented Aug 24, 2023

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
Description

For test.yaml openapi example below, I expect the generated code to use inheritance for all 3 cases.

But, from 6.5.0 onwards, Y no longer extends B in the generated code.

Y is combination of an allOf and object properties.

    Y:
      description: allOf without embedded properties
      allOf:
        - $ref: '#/components/schemas/B'
      type: object
      properties:
        y:
          type: string

When the object properties are embedded inside the allOf (example X) it works.
Or when adding x-parent: true (example Z) it also works.

openapi-generator version

Works in 6.4.0, fails in 6.5.0, 6.6.0 and 7.0.0-beta

OpenAPI declaration file content or url

test.yaml:

openapi: 3.0.3
info:
  version: 1.0.0
  title: test
paths: {}
components:
  schemas:
    A:
      type: object
      properties:
        a:
          type: string
    B:
      type: object
      properties:
        b:
          type: string
    C:
      type: object
      properties:
        c:
          type: string
      x-parent: true
    X:
      description: allOf with embedded properties
      allOf:
        - $ref: '#/components/schemas/A'
        - type: object
          properties:
            x:
              type: string
    Y:
      description: allOf without embedded properties
      allOf:
        - $ref: '#/components/schemas/B'
      type: object
      properties:
        y:
          type: string
    Z:
      description: allOf without embedded properties (x-parent)
      allOf:
        - $ref: '#/components/schemas/C'
      type: object
      properties:
        z:
          type: string
Steps to reproduce
java -jar openapi-generator-cli-6.5.0.jar generate -g jaxrs-spec -i test.yaml -o output/ --openapi-normalizer REF_AS_PARENT_IN_ALLOF=true
@wing328
Copy link
Member

wing328 commented Aug 24, 2023

can you please try enabling REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true as well in openapi-normalizer?

ref: https://github.com/OpenAPITools/openapi-generator/blob/master/docs/customization.md#openapi-normalizer

@jpraet
Copy link
Contributor Author

jpraet commented Aug 24, 2023

Yes, with REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true it does generate inheritance in the model.

But in that case I notice additional unused *AllOf.java classes being generated. Can that be avoided?
I only see those in 6.5.0 and 6.6.0. With 7.0.0-beta these *AllOf.java classes are not generated.

@wing328
Copy link
Member

wing328 commented Aug 24, 2023

can you try the latest master as well? snapshot version can be found in the project's readme.

@jpraet
Copy link
Contributor Author

jpraet commented Aug 24, 2023

openapi-generator-cli-7.0.0-20230824.100806-306 behaves same as 7.0.0-beta in this regard.

To clarify: the behavior of 7.0.0 not generating these *AllOf.java that are not used anyway seems fine to me,
I'm just asking if there is an easy way to get rid of them in 6.6.0.

@wing328
Copy link
Member

wing328 commented Aug 30, 2023

I'm just asking if there is an easy way to get rid of them in 6.6.0.

Nope. You can delete those files manually post code generation.

v7.0.0 has been released. Please consider using the latest stable version instead.

@wing328 wing328 closed this as completed Aug 30, 2023
@mikepictor
Copy link

Just a note that I am experiencing this bug in 7.7.0. For context, I am generating kotlin classes, maybe that has an impact.

    Question:
      type: object
      required:
        - mandatory
      abstract: true
      properties:
        mandatory:
          type: boolean
          example: true
          default: true
    SingleAnswerQuestion:
      allOf:
        - $ref: '#/components/schemas/Question'
        - type: object
.... other properties

I get a Question object and a SingleAnswerQuestion object, but one does not extend the other.

@wing328
Copy link
Member

wing328 commented Jul 24, 2024

@mikepictor did you enable the rule in the normalizer?

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

No branches or pull requests

3 participants