OpenAPITools / OpenAPITools/openapi-generator
[BUG][csharp-netcore] Ignoring `EnumMember.Value` when converting an enum query parameter to string
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
The EnumMember.Value (e.g. [EnumMember(Value = "opened")] Opened = 2) is not considered during enum to string conversion.
- False conversion (current):
State = State.Openedis converted toOpened - Expected conversion:
State = State.Openedis converted toopened
openapi-generator version
5.2.0
OpenAPI declaration file content or url
type: string
enum:
- all
- opened
- closed
Generation Details
openapi-generator-cli generate -g csharp-netcore --additional-properties=targetFramework=net5.0 --additional-properties=packageName=My.Namespace -o out -i PATH\TO\openapi.yaml
The generated code looks like the following:
[JsonConverter(typeof (StringEnumConverter))]
public enum State
{
[EnumMember(Value = "all")] All = 1,
[EnumMember(Value = "opened")] Opened = 2,
[EnumMember(Value = "closed")] Closed = 3,
}
Steps to reproduce
- Just generate the client and perform a query with an enum as a query parameter.
- The query parameter will have a capitalized first letter even if
EnumMember.Value = "opened"
Related issues/PRs
Suggest a fix
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 the csharp-netcore generator using the reported openapi-generator-cli command and inspect how generated enum query parameters are converted to strings. Reproduce the request with the generated State enum and verify that the query value uses EnumMember.Value, such as "opened", rather than the C# member name "Opened".
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
- 35/100