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] OpenAPIGenerator v7.0.1 and v6.6.0 is unable to generate a child class's constructor that could be constructed successfully with v6.0.1 #16797

Closed
4 of 6 tasks
JiyangWuUSB opened this issue Oct 11, 2023 · 6 comments

Comments

@JiyangWuUSB
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?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

OpenAPIGenerator v7.0.1 and v6.6.0 is unable to generate a child class's constructor that could be constructed successfully with v6.0.1
We were using this .yaml snippet to define a response type:

ListTimesheetsResponse:
  description: The response for listing timesheets
  allOf:
    - $ref: '#/components/schemas/SuccessPagingResponseV1'
    - type: object
      description: |
        The list of timesheets
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/Timesheet'

using v7.0.1 and v6.6.0 generated code as such:

@Generated(value = "org.openapitools.codegen.languages.SpringCodegen", date = "2023-10-11T21:11:03.837084888Z[Etc/UTC]")
public class ListTimesheetsResponse extends SuccessPagingResponseV1 {

  @Valid
  private List<@Valid Timesheet> data;

  public ListTimesheetsResponse() {
    super();
  }

  /**
   * Constructor with only required parameters
   */
  public ListTimesheetsResponse(String responseType, Boolean success) {
    super(pageInfo, responseType, success);
  }

As shown in the code, the pageInfo variable used in the constructor is neither defined nor passed in as a parameter anywhere.

While using v6.0.1 generates the valid code.

openapi-generator version

v7.0.1 and v6.6.0

OpenAPI declaration file content or url

included in description

This is the definition of the parent class for reference:

SuccessPagingResponseV1:
  description: |
    Another base success response
  allOf:
    - $ref: '#/components/schemas/SuccessResponseV1'
  properties:
    pageInfo:
      description: Information on the page of data contained in the response.
      $ref: '#/components/schemas/ResponsePagingInfoV1'
  required:
    - pageInfo
Generation Details
Steps to reproduce

Set up the repository and simply run mvn clean install, such error would be prompted:
[ERROR] /Users/tegee/talech/git/microservices/ts_service/target/generated-sources/src/main/java/com/talech/platform/microservicecommons/controller/dto/ListTimesheetsResponse.java:[46,10] error: pageInfo has private access in SuccessPagingResponseV1

Related issues/PRs
Suggest a fix
@dabdirb
Copy link
Contributor

dabdirb commented Oct 12, 2023

same issue as #15796

@JiyangWuUSB
Copy link
Author

same issue as #15796

Hi @dabdirb, thank you for your response! I checked out the issue you mentioned and in your PR checklist it says the PR was included in your 7.0.0 milestone (https://github.com/OpenAPITools/openapi-generator/pulls?q=is%3Amerged+is%3Apr+milestone%3A7.0.0+15827+), but I tested with both v7.0.0 and v7.0.1 and the issue is still happening. Could you provide some insight on what else I could check out for a resolution?

@dabdirb
Copy link
Contributor

dabdirb commented Oct 19, 2023

@JiyangWuUSB i did not create PR to fix this issue.
to work around it, you can use lombok, with these parameters.
java -jar openapi-generator-cli.jar generate -g spring -i petstore.json --additional-properties=generatedConstructorWithRequiredArgs=false,additionalModelTypeAnnotations="@lombok.NoArgsConstructor;@lombok.RequiredArgsConstructor;@lombok.AllArgsConstructor"

to fix this issue, can you provide a minimized yaml file ?

@JiyangWuUSB
Copy link
Author

Hi @dabdirb, thank you for your response! Regarding the workaround using lombok, how should we include the parameters in our pom file if we are calling the generator via the maven plugin?

Also regarding the "minimized yaml file", could you briefly elaborate on what else is needed beside the snippets included in the issue description?

P.S: this is what our current pom looks like:

  <plugin>
  <groupId>org.openapitools</groupId>
  <artifactId>openapi-generator-maven-plugin</artifactId>
  <version>${openapi-generator-maven-plugin.version}</version>
  <executions>
  <execution>
  <phase>generate-sources</phase>
  <id>generate</id>
  <goals>
  <goal>generate</goal>
  </goals>
  <configuration>
  <generateApis>true</generateApis>
  <generateApiDocumentation>true</generateApiDocumentation>
  <generateApiTests>false</generateApiTests>
  <generateSupportingFiles>false</generateSupportingFiles>
  <generateModels>true</generateModels>
  <generateModelTests>false</generateModelTests>
  <generateModelDocumentation>true</generateModelDocumentation>
  <apiPackage>PKG</apiPackage>
  <modelPackage>PKG</modelPackage>
  <inputSpec>${assembledYamlFile.location}</inputSpec>
  <generatorName>spring</generatorName>
  <output>${project.build.directory}/generated-sources</output>
   
  <configOptions>
  <useTags>true</useTags>
  <interfaceOnly>true</interfaceOnly>
  <reactive>false</reactive>
  <useOptional>false</useOptional>
  <serviceInterface>true</serviceInterface>
  <serviceImplementation>false</serviceImplementation>
  <useBeanValidation>true</useBeanValidation>
  <performBeanValidation>true</performBeanValidation>
  </configOptions>
  </configuration>
  </execution>
  </executions>
  </plugin>

@dabdirb
Copy link
Contributor

dabdirb commented Nov 1, 2023

If you want someone to fix this issue, we have to reproduce your issue first.
The basic material should be a openapi yaml/json and command/parameters to generate your code.
If you have read the doc, https://openapi-generator.tech/docs/generators, you should find the correct parameter location.

<configOptions>
      <additionalModelTypeAnnotations></additionalModelTypeAnnotations>
</configOptions>

@JiyangWuUSB
Copy link
Author

Thx @dabdirb , here is the minimized_yaml that can be used to reproduce the issue:

openapi: 3.0.1
info:
  title: OpenAPI definition
  version: v0
servers:
  - url: /
  - url: '{protocolAndBaseURL}'
    variables:
      protocolAndBaseURL:
        default: 'https://localhost'

components:
  schemas:
  
    Object1:
      type: object
      properties:
        responseType:
          type: string
        requestId:
          type: string
        success:
          type: boolean
          default: true
      required:
        - responseType
        - requestId
        - success
      discriminator:
        propertyName: responseType

    Object2:
      allOf:
        - $ref: '#/components/schemas/Object1'
        - type: object

    Type1:
      type: object
      properties:
        pageSize:
          minimum: 1
          type: integer
          format: int32
        rowCount:
          minimum: 0
          type: integer
          format: int32
      required:
        - pageSize
        - rowCount

    Object3:
      allOf:
        - $ref: '#/components/schemas/Object2'
      properties:
        pageInfo:
          $ref: '#/components/schemas/Type1'
      required:
        - pageInfo

    Object4:
      allOf:
        - $ref: '#/components/schemas/Object3'
        - type: object
          properties:
            data:
              type: string

We have been using the maven plugin version with properties set as in the previous comment, version 7.0.1, 7.0.0 and 6.6.0 were all tested and all three versions prompted this error after setting up the repo and running mvn clean install:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project: Compilation failure
[ERROR] Object4.java:[40,10] error: pageInfo has private access in Object3

dabdirb added a commit to dabdirb/openapi-generator that referenced this issue Nov 3, 2023
@wing328 wing328 closed this as completed in 64f2cad Jan 5, 2024
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.

2 participants