OpenAPITools / OpenAPITools/openapi-generator
[BUG] nullable schema is not allowed to contain `null`
Open
Nobody has claimed this yet.
Issue: Bug
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What's the version of OpenAPI Generator used? 5.0.0
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
Description
Generator crashes if nullable enum schema contains null value.
This is allowed by jsonschema and thus openapi spec.
openapi-generator version
5.0.0 branch, 4th Feb 2020
OpenAPI declaration file content or url
rating:
type: string
nullable: true
enum:
- null
- Gibberish
Command line used for generation
openapi-generator-cli generate --input-spec openapi.yaml --enable-post-process-file --generator-name elm --config openapi-generator.yml --output openapi-client
Steps to reproduce
There's an error:
Exception in thread "main" java.lang.RuntimeException: Could not process model 'rating'.Please make sure that your schema is correct!
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:473)
at org.openapitools.codegen.DefaultGenerator.generate(DefaultGenerator.java:938)
at org.openapitools.codegen.cmd.Generate.run(Generate.java:423)
at org.openapitools.codegen.OpenAPIGenerator.main(OpenAPIGenerator.java:61)
Caused by: java.lang.NullPointerException
at org.openapitools.codegen.DefaultCodegen.postProcessModelsEnum(DefaultCodegen.java:490)
at org.openapitools.codegen.languages.ElmClientCodegen.postProcessModels(ElmClientCodegen.java:321)
at org.openapitools.codegen.DefaultGenerator.processModels(DefaultGenerator.java:1214)
at org.openapitools.codegen.DefaultGenerator.generateModels(DefaultGenerator.java:468)
... 3 more
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
Reproduce the nullable enum case with the shown openapi-generator command, then inspect DefaultCodegen.java at postProcessModelsEnum and ElmClientCodegen.java at postProcessModels. Confirm that generation no longer crashes for an enum containing null and that the generated Elm client represents the nullable value correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- elm, java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100