swagger-api / swagger-api/swagger-codegen-generators
Generator fails on null enum choice
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 299
- Forks
- 439
- PR merge metrics
- No merged PRs in 30d
Description
When running the generator on a schema that contains a null enum option, we get an exception:
Exception: Cannot invoke "java.lang.Integer.toString()" because "i" is null
at io.swagger.codegen.v3.DefaultGenerator.processOperation(DefaultGenerator.java:989)
at io.swagger.codegen.v3.DefaultGenerator.processPaths(DefaultGenerator.java:889)
at io.swagger.codegen.v3.DefaultGenerator.generateApis(DefaultGenerator.java:484)
at io.swagger.codegen.v3.DefaultGenerator.generate(DefaultGenerator.java:796)
at io.swagger.codegen.v3.cli.cmd.Generate.run(Generate.java:388)
at java.base/java.lang.Thread.run(Unknown Source)
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Integer.toString()" because "i" is null
at io.swagger.codegen.v3.generators.DefaultCodegenConfig.processPropertySchemaTypes(DefaultCodegenConfig.java:1666)
at io.swagger.codegen.v3.generators.DefaultCodegenConfig.fromProperty(DefaultCodegenConfig.java:1587)
at io.swagger.codegen.v3.generators.DefaultCodegenConfig.fromParameter(DefaultCodegenConfig.java:2530)
at io.swagger.codegen.v3.generators.DefaultCodegenConfig.fromOperation(DefaultCodegenConfig.java:2237)
at io.swagger.codegen.v3.DefaultGenerator.processOperation(DefaultGenerator.java:965)
... 5 more
This occurs on enums like:
...
schema:
type: string
nullable: true
enum:
- ''
- AWS
- AZURE
- GCP
- KUBE
- null
- OCI
- github
- gitlab
...
The suggested resolution is adding a null check in the problematic function:
DefaultCodegenConfig.java:processPropertySchemaTypes:1663
for(Integer i : _enum) {
String stringifiedEnum = null;
if (i != null) {
stringifiedEnum = i.toString();
}
codegenProperty._enum.add(stringifiedEnum);
}
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 in DefaultCodegenConfig.java at processPropertySchemaTypes around line 1663, then follow the stack trace through fromProperty and fromParameter. Reproduce generation with the schema containing a null enum value; done means the generator completes without the null-related exception and preserves the enum choices in the generated result.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100