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] allOf object are not correctly generated with properties REF_AS_PARENT_IN_ALLOF=true and REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true #20005

Closed
4 tasks done
JelmerBouma1985 opened this issue Oct 31, 2024 · 6 comments · Fixed by #20083

Comments

@JelmerBouma1985
Copy link

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

Since release of 7.9.0 allOf objects don´t extend the parent anymore when normalizer REF_AS_PARENT_IN_ALLOF=true and REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true are used.

I expect the child object extends the parent object which works as expected until 7.9.0. Below generated code from 7.8.0:

public class Child1 extends Parent {
...
}

below code is generated code from 7.9.0

public class Child1 {
...
}
openapi-generator version

7.9.0

OpenAPI declaration file content or url

test.yaml

openapi: 3.0.0
info:
  title: 'AllOf does not work'
  description: 'Minimal yaml to showcase allOf does not work anymore'
  version: info
paths:
  /allOf:
    get:
      operationId: allOf
      responses:
        "200":
          description: oke
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Parent'
components:
  schemas:
    Parent:
      type: object
      properties:
        p1:
          type: integer
    Child1:
      properties:
        p2:
          type: string
      allOf:
        - $ref: '#/components/schemas/Parent'
Generation Details

I'm using the openapi-generator-maven-plugin

<plugin>
                <groupId>org.openapitools</groupId>
                <artifactId>openapi-generator-maven-plugin</artifactId>
                <version>7.9.0</version>
                <configuration>
                    <openapiNormalizer>REF_AS_PARENT_IN_ALLOF=true,REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true</openapiNormalizer>
                    <generatorName>spring</generatorName>
                    <configOptions>
                        <useSpringBoot3>true</useSpringBoot3>
                        <interfaceOnly>true</interfaceOnly>
                    </configOptions>
                </configuration>
                <executions>
                    <execution>
                        <id>allOf</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                        <configuration>
                            <inputSpec>${basedir}/src/main/resources/openapi/Showcase.yaml</inputSpec>
                            <generatorName>spring</generatorName>
                            <generateSupportingFiles>true</generateSupportingFiles>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
Steps to reproduce

java -jar openapi-generator-cli.jar generate -g spring -i test.yaml -o output/ --openapi-normalizer REF_AS_PARENT_IN_ALLOF=true,REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true

@wing328
Copy link
Member

wing328 commented Nov 1, 2024

thanks for reporting the issue. i will try to take a look over the weekend

@wing328
Copy link
Member

wing328 commented Nov 12, 2024

UPDATE: I've filed #20083 to fix the issue

@AlexanderEvstatiev
Copy link

AlexanderEvstatiev commented Dec 4, 2024

This issue is still present in 7.10.0. The latest version it works is 7.1.0. Please check again. Meanwhile 7.1.0 has another issue which creates conflicting setters when using the normalizer flags, so major version 7 is unusable for such examples at the moment.

@wing328
Copy link
Member

wing328 commented Dec 5, 2024

@AlexanderEvstatiev can you please share your spec (minimal) to reproduce the issue?

@JelmerBouma1985 does the fix (in v7.10.0) work for you?

@JelmerBouma1985
Copy link
Author

@JelmerBouma1985 does the fix (in v7.10.0) work for you?

@wing328 yes, v7.10.0 works like a charm 👍

@AlexanderEvstatiev
Copy link

AlexanderEvstatiev commented Dec 5, 2024

@wing328
These definitions are in a task-base.yaml schema

AbstractOperation:
  required:
    - code
  type: object
  properties:
    code:
      type: string
    comment:
      type: string
Response:
  allOf:
    - $ref: '#/components/schemas/AbstractOperation'
Action:
  allOf:
    - $ref: '#/components/schemas/AbstractOperation'

And are being referenced in the task-api.yaml like this:

content:
  application/json:
    schema:
      $ref: './task-base.yaml#/components/schemas/Action'

The last confirmed working version for these schemas was 4.3.1 if that helps.

java -jar openapi-generator-cli-7.10.0.jar generate --input-spec task-api.yaml --generator-name spring --output dma --openapi-normalizer REF_AS_PARENT_IN_ALLOF=true,REFACTOR_ALLOF_WITH_PROPERTIES_ONLY=true --additional-properties=containerDefaultToNull=true,useJakartaEe=true,skipDefaultInterface=true,hideGenerationTimestamp=true --artifact-id dma --api-package test --model-name-prefix Api --model-package test.model.api --type-mappings=URI=String --type-mappings=AnyType=Object --schema-mappings=...

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