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] Compilation error of array field in oneOf field, value of complextype is empty #18274

Closed
5 of 6 tasks
fanqiewanzi opened this issue Apr 2, 2024 · 14 comments · Fixed by #18324
Closed
5 of 6 tasks

Comments

@fanqiewanzi
Copy link
Contributor

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

A compilation error occurs in the generated code when using the oneof field.

By checking the template, we found that the corresponding complextype is empty.

As you can see from the picture below, something was missing.

image

openapi-generator version

7.4.0 (7.3.0 also tried)

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: SDK API
  description: SDK API
  version: 1.0.0
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0.html
  
servers:
  - url: https://test.com:443

paths:
  /sdk/test:
    get:
      tags:
        - test
      summary: test
      description: test
      operationId: test
      responses:
        '200':
          $ref: '#/components/responses/TestResponse'

components:
  responses:
    TestResponse:
      description: test return
      content:
        application/json:
          schema:
            allOf:
            - type: object
              properties:
                data:
                  type: object
                  description: test
                  properties:
                    rule_config:
                      type: object
                      description: test
                      properties:
                        operator:
                          oneOf:
                          - type: array
                            items:
                              type: string
                          - type: string
                            example: 'gt'
                          description: test operator
Generation Details

Target Language: Java
Config.yaml:

additionalProperties:
  withAWSV4Signature: true
  library: okhttp-gson
  useBeanValidation: true
  useSingleRequestParameter: true
  apiPackage: com.sdk.v2018
  modelPackage: com.sdk.v2018.model
  artifactDescription:  SDK for Java
  artifactId: sdk2018
  artifactVersion: 1.0.0
  useOneOfInterfaces: true
Steps to reproduce
  1. generate sdk using openapi-generator-cli
  2. pack sdk code to jar using maven
Related issues/PRs
Suggest a fix

I guess there may be a problem with the template or a problem with complextype processing in the children of the oneOf filed.
the anyof filed probably has the same problem.

@wing328
Copy link
Member

wing328 commented Apr 2, 2024

library: okhttp-gson

can you try jersey2/jersey3 instead?

@fanqiewanzi
Copy link
Contributor Author

library: okhttp-gson

can you try jersey2/jersey3 instead?

Unfortunately it still doesn't work properly. The generated code does not import the List class. Even if I import it manually, there are still other errors in the code.

image

@wing328
Copy link
Member

wing328 commented Apr 3, 2024

are you trying the latest master? we merged a fix recently.

snapshot version can be found in project's readme

@fanqiewanzi
Copy link
Contributor Author

are you trying the latest master? we merged a fix recently.

snapshot version can be found in project's readme

i just tried the latest version which i downloaded from https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/7.5.0-SNAPSHOT/openapi-generator-cli-7.5.0-20240327.040016-66.jar
unluckly it still seems work incrorrectly, the generate result is as same as the version before 7.5.0.

Generator version: 7.5.0-SNAPSHOT

@wing328
Copy link
Member

wing328 commented Apr 3, 2024

can you please build the CLI jar based on the latest master?

snapshot version has not been published due to Travis CI running out of free open source credits.

@fanqiewanzi
Copy link
Contributor Author

can you please build the CLI jar based on the latest master?

snapshot version has not been published due to Travis CI running out of free open source credits.

I builded the CLI jar based on the latest master and tried again, unlucky I still got the same result. :(

@wing328
Copy link
Member

wing328 commented Apr 3, 2024

i tested with latest master:

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i /tmp/1.yaml -o /tmp/111/ --skip-validate-spec  -c /tmp/config.yaml

output compiles fine (after removing useBeanValidation: true in config.yaml which cause compilation error)

@fanqiewanzi
Copy link
Contributor Author

i tested with latest master:

java -jar modules/openapi-generator-cli/target/openapi-generator-cli.jar generate -g java -i /tmp/1.yaml -o /tmp/111/ --skip-validate-spec  -c /tmp/config.yaml

output compiles fine (after removing useBeanValidation: true in config.yaml which cause compilation error)

Can I take a look at your config file? It is weird that i tried again but still get the same result, I thought there was something wrong with packaging the latest CLI, but even I download the latest jar package from https://oss.sonatype.org/content/repositories/snapshots/org/openapitools/openapi-generator-cli/7.5.0-SNAPSHOT/openapi-generator-cli-7.5.0-20240403.034519-67.jar and use no more config file, I still get the same result which cause compilation error.

@wing328
Copy link
Member

wing328 commented Apr 3, 2024

this one works: java -jar ~/Downloads/openapi-generator-cli-7.5.0-20240403.034519-67.jar generate -i /tmp/2.yaml -o /tmp/new-test3/ -g java --library jersey2

can you please give it another try?

@wing328
Copy link
Member

wing328 commented Apr 3, 2024

FYI. I've filed #18281 to sync jersey2 and jersey3 templates.

@fanqiewanzi
Copy link
Contributor Author

Thank you, it works finally, but it doesn’t actually solve the problem fundamentally. Using the Jersey2 framework does not guarantee that other bugs will not exist. And if I change framework from okhttp-gson to jersey2, I have to adapt aws authentication template(which only available for okhttp-gson library).

@wing328
Copy link
Member

wing328 commented Apr 3, 2024

we can plot the same fix to java okhttp-gson. here is the PR that fixes the jersey2 templates to support array in oneOf

#18042

may I know if you've time to contribute a PR to apply the same fix in java okhttp-gson templates?

@fanqiewanzi
Copy link
Contributor Author

Thanks for your invitation. I'm not pretty sure whether I can handle this, i think it wont be easy to resolve this problem. I can give it a try if you are not in a hurry to fix this bug(because I have a job and I don't really know how to develop this project for now). :)

@wing328
Copy link
Member

wing328 commented Apr 8, 2024

just merged #18324 to provide array type support in anyOf, oneOf,

please give it a try with the snapshot version (which will be published soon as part of the CI workflow)

snapshot version can be found in the project's readme.

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