OpenAPITools / OpenAPITools/openapi-generator

[BUG][csharp-netcore] Ignoring `EnumMember.Value` when converting an enum query parameter to string

Open
#10,107 1 comment 1 reaction 0 assignees View on GitHub

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)?
  • 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.Opened is converted to Opened
  • Expected conversion: State = State.Opened is converted to opened
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.