swagger-api / swagger-api/swagger-codegen
NullPointerException running swagger-codegen-cli for model with nullable integer enum property in schema definition
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
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
- install swagger-codegen-ui 3.0.54
- 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the provided swagger-codegen-cli Java command against the NetBox 3.7 OpenAPI schema and reproduce the NullPointerException for the nullable integer enum. Trace the integer enum handling in the code-generation path, comparing it with nullable string enum handling. Done means Java client generation completes while preserving the nullable enum value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100