question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Response types using Nullable/oneOf are invisible in swagger-ui (OpenApi3)

See original GitHub issue

This can be seen for example in NSwag.Sample.NETCore22 (unmodified):

Operation /pet/{petId}:

image

Definition:

    "/pet/{petId}": {
      "get": {
        "tags": [
          "Pet"
        ],
        "operationId": "Pet_FindById",
        "parameters": [
          {
            "name": "petId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "format": "int32"
            },
            "x-position": 1
          }
        ],
        "responses": {
          "200": {
            "description": "",
            "content": {
              "application/json": {
                "schema": {
                  "nullable": true,
                  "oneOf": [
                    {
                      "$ref": "#/components/schemas/Pet"
                    }
                  ]
                }
              }
            }
          },

The schemas for the other responses are visible because they are array types. But the problem exists for all single object return types.

The only workaround I found is

config.DefaultReferenceTypeNullHandling = ReferenceTypeNullHandling.NotNull; But that doesn’t seem to be a good solution…

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:31 (24 by maintainers)

github_iconTop GitHub Comments

3reactions
RicoSutercommented, Apr 2, 2019

But I think we still need to create an issue in Swagger UI - as this will be probably a problem for all these nullable + oneOfs (also between DTO schemas, etc.) - can you do that?

1reaction
RicoSutercommented, Apr 2, 2019

@handrews thanks for your fast answer!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to specify a property can be null or a reference with ...
Note: some swagger implementations use x-nullable (or some-such) to specify a property value can be null, however, $ref replaces the object with ......
Read more >
Describing Responses
In OpenAPI 3.0, you can use oneOf to specify alternate schemas for the response and document possible dependencies verbally in the response description...
Read more >
OpenAPI Specification - Version 3.0.3
The OpenAPI Specification defines a standard interface to RESTful APIs which allows both humans and computers to understand service capabilities without ...
Read more >
Data Types
OpenAPI defines the following basic types: string (this includes dates and files); number; integer; boolean; array ...
Read more >
Describing Parameters
In OpenAPI 3.0, parameters are defined in the parameters section of an operation or path. To describe a parameter, you specify its name...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found