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

NullPointerException running swagger-codegen-cli for model with nullable integer enum property in schema definition #12371

Open
jenskreidler opened this issue Apr 17, 2024 · 0 comments

Comments

@jenskreidler
Copy link

Description

As a user I want to generate JAVA client data types with swagger-codegen-cli using a valid OpenAPI 3 document.

When Swagger CodeGen encounters components schemas (models) with a nullable enum property of type integer, the generation fails unexpectedly with a NullPointerException (invoking java.lang.Integer.toString() on a null object, but that is intentionally because the property is nullable).
Removing the potential null value in the enum's schema elements list within the yaml source will sanitize the issue (see yaml snippet below).

Swagger-codegen version

Tested using swagger-code-gen 3.0.54

Swagger declaration file content or url

Issue can be verified using the Yaml OpenAPI 3 schema file of Netbox 3.7 under https://demo.netbox.dev/api/schema/

Command line used for generation

shell:
java -DmaxYamlCodePoints=40000000 -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i https://demo.netbox.dev/api/schema/ -l java -o ~/tmp/swagger-netbox

Steps to reproduce
  1. install swagger-codegen-ui 3.0.54
  2. run java generation of Netbox 3.7 OpenAPI3:
    • java -DmaxYamlCodePoints=40000000 -jar modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate -i https://demo.netbox.dev/api/schema/ -l java -o /tmp/swagger-netbox
Related issues/PRs
Suggest a fix/enhancement

The fix should respect a possible null integer enum value as specified with an appropriate OpenAPI3 schema property part (like it does with nullable string enums):

        speed:
          enum:
          - 1200
          - 2400
          - 4800
          - 9600
          - 19200
          - 38400
          - 57600
          - 115200
          - null // <-- THIS IS THE CLASHING ELEMENT (removing it will sanitize generation run)
          type: integer // <-- switching this to string will also sanitize the issue, null enum valie is OK, generation runs well
          description: |-
            * `1200` - 1200 bps
            * `2400` - 2400 bps
            * `4800` - 4800 bps
            * `9600` - 9600 bps
            * `19200` - 19.2 kbps
            * `38400` - 38.4 kbps
            * `57600` - 57.6 kbps
            * `115200` - 115.2 kbps
          x-spec-enum-id: ab6d9635c131a378
          nullable: true
@jenskreidler jenskreidler changed the title NullPointerException running swagger-codegen-ci for model with nullable integer enum property in schema definition NullPointerException running swagger-codegen-cli for model with nullable integer enum property in schema definition Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant