OpenAPITools / OpenAPITools/openapi-generator
[BUG][C#] Not possible to generate nullable enum in an API model
Nobody has claimed this yet.
- 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)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I am implementing a REST API for an international standard on dairy data. The standard is expressed in JSON Schema and we use the Open API Generator to generate the model.
Unfortunately - no matter what I do, I can't get the generator to generate a nullable enum on the model. I have tried adding the "nullable": true property, adding null to the list of enum values, changed the type on the property to an array with null included as a type and finally I tried changing the reference to the type on the parent to be "oneOf" and adding null. Nothing works.
According to other definitions and bugs I've seen, it should be enough that the enum is not required in the specs to make it nullable.
Under the assumption that it should be possible to generate a nullable enum, I would like to know how it is done and if it is not possible, then I think it is a bug.
openapi-generator version
5.1.0
OpenAPI declaration file content or url
Generation Details
PowerShell command:
npx openapi-generator-cli generate -i exampleUrlScheme.json -g aspnetcore -o c:\temp\generated
Steps to reproduce
Clone the above GIT repo, navigate to the folder where the exampleUrlScheme.json file resides and run the above command.
Try also the changes I mentioned in the description on any enum type.
I expect a nullable enum on enum types that are not required or at least when the type in any of the above mentioned ways is defined as nullable.
Related issues/PRs
I found a couple of open issues that might be related to this bug:
#4816
#9022
Suggest a fix
Sorry - my Java is very rusty!
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 aspnetcore generator command against exampleUrlScheme.json from the linked ICAR repository, then inspect the generated model for an enum that should be nullable. Compare the result with the expected nullable enum behavior and review related issues #4816 and #9022 before determining the needed change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100