Redocly/redoc

Nullable support in `oneOf` operator

Open

#1303 opened on Jun 17, 2020

View on GitHub
 (3 comments) (1 reaction) (0 assignees)TypeScript (21,877 stars) (2,272 forks)batch import
Type: Enhancementhelp wanted

Description

This is feature request.

Currently, redoc@2.0.0-rc.30 can show nullable: true field(s) on properties like below: image This is great !!

I have API requests/responses that uses oneOf operator, and some of schemas used in oneOf is nullable: true like below:

   Foo:
      oneOf:
        - $ref: "#/components/schemas/Foo1"
        - $ref: "#/components/schemas/Foo2"
    Foo1:
      type: object
      properties: ...
    Foo2:
      type: object
      nullable: true
      properties: ...

I think this is valid schema definition to express object could be null, according to OpenAPI 3.0 specs.

OpenAPI 3.0 does not have an explicit null type as in JSON Schema, but you can use nullable: true to specify that the value may be null. https://swagger.io/docs/specification/data-models/data-types/#null

So, it would be great if ReDoc can render such objects as nullable.

UI Suggestions

image

Example OpenAPI file

openapi: "3.0.0"
info:
  version: "1.2.3"
  title: "My API"
paths:
  /foo:
    post:
      operationId: postFoo
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Foo"
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Foo"
  /bar:
    post:
      operationId: postBar
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/Foo2"
      responses:
        "200":
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Foo2"

components:
  schemas:
    Foo:
      oneOf:
        - $ref: "#/components/schemas/Foo1"
        - $ref: "#/components/schemas/Foo2"
    Foo1:
      type: object
      properties:
        foo1:
          type: string
          nullable: true
        bar:
          type: object
          nullable: true
          properties:
            x:
              type: int
            y:
              type: int
    Foo2:
      type: object
      nullable: true
      properties:
        bar:
          type: string
          nullable: true

Contributor guide