swagger-api / swagger-api/swagger-codegen

[CSharp] Bug Generating code for nullable Enum parameter does not compile

Open
#10,589 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When generating C# client from Open Api 3 schema where operation parameter is nullable enum with default value:

          {
            "name": "size",
            "in": "query",
            "schema": {
              "default": "Original",
              "$ref": "#/components/schemas/PhotoFileSize"
            },
            "x-position": 3
          }

....


  "components": {
    "schemas": {

      "PhotoFileSize": {
        "type": "string",
        "description": "",
        "x-enumNames": [
          "Original",
          "Avatar"
        ],
        "enum": [
          "Original",
          "Avatar"
        ]
      }
  }
}

The generated code does not set default value for the query parameter correctly and it does not define the enum parameter type nullable.

Expected result:
The parameter should be typed:
PhotoFileSize? size = null

Swagger-codegen version

swagger-codegen-cli-3.0.23

Swagger declaration file content or url
Command line used for generation

swagger-codegen-cli-3.0.23

Steps to reproduce
Related issues/PRs
Suggest a fix/enhancement

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

Run swagger-codegen-cli-3.0.23 with the OpenAPI 3 schema shown in the report, focusing on the nullable enum query parameter with default value "Original". Compare the generated C# signature with the expected PhotoFileSize? size = null result; done when the generated parameter is nullable, preserves the default value, and compiles.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.