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

Extend support for nullable reference types in responses #2650

Closed
yohny opened this issue May 10, 2023 · 2 comments
Closed

Extend support for nullable reference types in responses #2650

yohny opened this issue May 10, 2023 · 2 comments

Comments

@yohny
Copy link

yohny commented May 10, 2023

Currently when you have a method returning simple DTO like this:

[HttpGet()]
public SettingsDto Settings()
{
    // implementation details
}

it correctly produces OpenAPI specs like this:

 "/api/Settings": {
      "get": {
        "tags": [
          "Settings"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/plain": {
                "schema": {
                  "$ref": "#/components/schemas/Viacar.iDispo.Controllers.Shared.SettingsController+SettingsDto"
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Viacar.iDispo.Controllers.Shared.SettingsController+SettingsDto"
                }
              },
              "text/json": {
                "schema": {
                  "$ref": "#/components/schemas/Viacar.iDispo.Controllers.Shared.SettingsController+SettingsDto"
                }
              }
            }
          }
        }
      }
    },

however if you change the signature to return nullable DTO:

[HttpGet()]
public SettingsDto? Settings() // added ?
{
    // implementation details
}

one would expect that this is reflected in OpenAPI specs (given that SupportNonNullableReferenceTypes() was called when setting up swagger generation), resulting in nullable being added to the specs like so:

 "/api/Settings": {
      "get": {
        "tags": [
          "Settings"
        ],
        "responses": {
          "200": {
            "description": "Success",
            "content": {
              "text/plain": {
                "schema": {
                  "$ref": "#/components/schemas/Viacar.iDispo.Controllers.Shared.SettingsController+SettingsDto",
                  "nullable": true // should be added
                }
              },
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Viacar.iDispo.Controllers.Shared.SettingsController+SettingsDto",
                  "nullable": true // should be added
                }
              },
              "text/json": {
                "schema": {
                  "$ref": "#/components/schemas/Viacar.iDispo.Controllers.Shared.SettingsController+SettingsDto"
                  "nullable": true // should be added
                }
              }
            }
          }
        }
      }
    },

but thats not the case now.

@kpko
Copy link

kpko commented Jul 10, 2023

Hi, facing the same issue. Is there a hint what could cause this issue?

@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