Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nullable enum does not populate nullable #2633

Closed
fairking opened this issue Apr 13, 2023 · 2 comments
Closed

Nullable enum does not populate nullable #2633

fairking opened this issue Apr 13, 2023 · 2 comments

Comments

@fairking
Copy link

fairking commented Apr 13, 2023

The following class:

public class BookingQueryForm
{
    public BookingStatusEnum? Status { get; set; }
}

populates the following schema:

"BookingQueryForm": {
        "required": [
        ],
        "type": "object",
        "properties": {
          "status": {
            "$ref": "#/components/schemas/BookingStatusEnum"
          }
        },
        "additionalProperties": false
      },
      "BookingStatusEnum": {
        "enum": [
          "Booked",
          "Waiting",
          "Cancelled"
        ],
        "type": "string"
      },

Please note that the status property is not nullable while it should be:

 "properties": {
          "status": {
            "$ref": "#/components/schemas/BookingStatusEnum",
            "nullable": true
          }
        },

Related issue: RicoSuter/NSwag#4397

@kjkrum
Copy link

kjkrum commented May 21, 2023

I noticed this while digging into a different problem with enum properties. It may have something to do with how enum nullability is defined in the OpenAPI spec. In languages like C#, nullability is a property of the reference. In OpenAPI, nullability of an enum is a matter of null being a member of the enum. You can use an ISchemaFilter to set Nullable and add OpenApiNull to the Enum property of enum schemas. I tried this and it didn't solve my other problem, but I haven't tried generating an NSwag client against the resulting schema.

@martincostello
Copy link
Collaborator

To make issue tracking a bit less overwhelming for the new maintainers (see #2778), I've created a new tracking issue to roll-up various nullability issues here: #2793.

We'll refer back to this issue from there and include it as part of resolving that issue, but I'm going to close this one to help prune the backlog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants