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

Generator fails on null enum choice #1296

Open
Tavh opened this issue Jun 3, 2024 · 0 comments
Open

Generator fails on null enum choice #1296

Tavh opened this issue Jun 3, 2024 · 0 comments

Comments

@Tavh
Copy link

Tavh commented Jun 3, 2024

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);
}
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