Skip to content

OAS 3.0: Rendering oneOf and anyOf #3490

@hkosova

Description

@hkosova

Version: 3.1.1

(This issue is specifically about model rendering, not example rendering or validation.)

OpenAPI 3.0 supports oneOf and anyOf in models. #3083 was supposed to cover "Render schema values with anyOf, oneOf, not", but it looks the rendering is not implemented yet.

On this image, ArrayOfStrOrInt is an array of oneof string or integer, and the blank item is CatOrDot which is anyOf Cat or Dog models. The full spec is below.

oneof anyof

openapi: 3.0.0
info:
  version: 0.0.0
  title: test
paths: {}
components:
  schemas:
    # Item type is displayed
    ArrayOfStr:
      type: array
      items:
        type: string

    # Item type is NOT displayed
    ArrayOfStrOrInt:
      type: array
      items:
        oneOf:
          - type: integer
          - type: string

    # Neither model name nor contents is displayed
    CatOrDog:
      anyOf:
        - $ref: '#/components/schemas/Cat'
        - $ref: '#/components/schemas/Dog'

    Pet:
      type: object
      properties:
        name:
          type: string
      required:
        - name
    Cat:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            huntingSkill:
              type: string
              description: The measured skill for hunting
              default: lazy
              enum:
              - clueless
              - lazy
              - adventurous
              - aggressive
    Dog:
      allOf:
        - $ref: '#/components/schemas/Pet'
        - type: object
          properties:
            packSize:
              type: integer
              format: int32
              description: the size of the pack the dog is from
              default: 0
              minimum: 0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions