0

On my openapi yaml file I have a Layout schema, which has an attribute fields, which is an array of Field objects. My idea is to have a parent Field schema with common attributes, and some children schemas (TextInput, Select, Toggle, etc...) which inherit those and extend with their particular attributes.

So, this is what I'm trying:

Layout:
  type: object
  properties:
    fields:
      type: array
      items:
        $ref: '#/Field'
Field:
  type: object
  properties:
    name:
      type: string
      description: Field name.
    label:
      type: string
      description: Field label.
    description:
      type: string
      description: Short description explaining the purpose of the field.
    fieldType:
      type: string
      description: Field type.
  required:
    - name
    - label
  discriminator: fieldType
  mapping:
    text: '#/TextInput'
    select: '#/Select'
TextInput:
  allOf:
    - $ref: '#/Field'
    - type: object
      properties:
        placeholder:
          type: string
          description: Field placeholder. **Only for *text* fields.**
Select:
  allOf:
    - $ref: '#/Field'
    - type: object
      properties:
        options:
          type: array
          items:
            type: string
        multiple:
          type: boolean
          default: false

Compilation works fine, but when I expand the fields attribute I see:

Array ()
 Schema not provided

I would expect something like what happens here with the petType attribute in the 200 response: http://redocly.github.io/redoc/#operation/findPetsByStatus

Germán Medaglia
  • 182
  • 1
  • 1
  • 7

1 Answers1

0

Add title : ObjectName under child schemas then it will display Array(ObjectName) instead of Array().

Try this.
TextInput:
allOf:
- $ref: '#/Field'
- title : TextInput
- type: object
properties:
placeholder:
type: string
description: Field placeholder. Only for text fields.

See this for reference: https://redoc.ly/docs/resources/discriminator/