OpenAPITools / OpenAPITools/openapi-generator
[BUG] nullable innerEnum not generated in aspnetcore template
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Description
When an innerEnum is defined and that enum is nullable, the enum class itself will not be defined.
Ex: public MyEnumEnum? MyEnum { get; set; } where the MyEnumEnum class is never defined. This results in code that will not compile.
In the spec below, my_enum evaluates to complexType string? (seen in model debugging).
In the template, {{>enumClass}} is only run when complexType is false. https://github.com/OpenAPITools/openapi-generator/blob/c2472b03b63fa61a3d7e5b086f36c1bd48d0ee4c/modules/openapi-generator/src/main/resources/aspnetcore/3.0/model.mustache#L52-L63
I don't know why it is only generated when complexType is false, and I'm not sure what might / will break if that condition is removed.
openapi-generator version
7.7.0
OpenAPI declaration file content or url
openapi: "3.0.0"
info:
version: 1.0.0
title: Swagger Petstore
servers: []
paths: {}
components:
schemas:
Pet:
type: object
properties:
my_enum:
type: string
nullable: true
enum:
- "value1"
Generation Details
generate --generator-name aspnetcore -i spec.yml \
--additional-properties nullableReferenceTypes=true
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)
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 with modules/openapi-generator/src/main/resources/aspnetcore/3.0/model.mustache, especially lines 52-63, and reproduce the issue using the supplied spec and generation command with the aspnetcore generator. Compare the generated output for the nullable enum and verify that the enum class is defined and the generated C# code compiles.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100