Skip to content

When null is specified in anyOf/oneOf, nothing is displayed. #1152

@dsuket

Description

@dsuket

Describe the bug

  anyOf:
    - type: string
    - type: 'null'

As in the above OpenAPI Spec, when you use type: "null" as one of the options in anyOf/oneOf, nothing is shown when the tab is opened. As a result, users of the API reference can't tell what they are supposed to enter.

Expected behavior

Image

Just like string or boolean, it would be better to display null as well.

Also, for the tab labels, instead of using names like MOD1 or MOD2, it would be clearer and more helpful to show the type names such as string, boolean, and null.
In fact, when an object is specified using $ref, the object name is displayed.

Current behavior

  anyOf:
    - type: string
    - type: integer
    - type: boolean
    - type: 'null'

When this definition is used, nothing is displayed when the fourth tab is selected.

Image

Possible solution

Schema/index.tsx#L125
You just need to add null to this array.

Also, you can use type instead of MOD here. Schema/index.tsx#L116

    const label = anyOneSchema.title || anyOneSchema.type;

Steps to reproduce

  1. Define type: 'null' in anyOf in the OpenAPI Spec.
  2. Generate the API reference.
  3. Open the relevant API reference and select the anyOf tab.
  4. A tab opens, but nothing is displayed.

Screenshots

Context

This is necessary to comply with OpenAPI 3.1.

As discussed here: #1017 , rendering now works correctly when null is included in a type array.
However, there are still issues with anyOf and oneOf.
#950 (comment)

Your Environment

  • Version used: v4.4.0
  • Environment name and version (e.g. Chrome 59, node.js 5.4, python 3.7.3):
  • Operating System and version (desktop or mobile): both
  • Link to your project:

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions