Skip to content

.Net OpenApi - Nullable Enum parameter generated as string type #61935

@steint23

Description

@steint23

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

A nullable enum query parameter is produced as straight string type in the OpenApi schema, the $ref statement is missing:

"parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "type": "string",
              "default": null
            }
          }
        ],

... if the enum parameter is not nullable, the OpenApi schema has a proper $ref statement to link the asscociated enum component:

"parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/MyStatus"
            }
          }
        ],

Expected Behavior

A nullable enum query parameter should be presented by default with a $ref statement to link the asscociated enum component:

"parameters": [
          {
            "name": "status",
            "in": "query",
            "schema": {
              "$ref": "#/components/schemas/MyStatus",
              "default": null
            }
          }
        ],

Steps To Reproduce

  • Brand new .NET 9 Web API from template, with OpenAPI enabled.

  • Define the enum:

[JsonConverter(typeof(JsonStringEnumConverter<MyStatus>))]
public enum MyStatus
{
    MyStatus1,
    MyStatus2,
    MyStatus3
}
  • Update WeatherForecastController Get method signature to include a nullable enum query parameter:
        public IEnumerable<WeatherForecast> Get([FromQuery] MyStatus? status = null) { ...
  • Launch app
  • Look at /openapi/v1.json
  • Observe status parameter of GetWeatherForecast operation

Exceptions (if any)

No response

.NET Version

9.0.103

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions