Skip to content

AsyncAPI: Discriminator not valid #43

@ccarlile

Description

@ccarlile

When rendering an enum schema, AsyncAPI.toYaml returns something like this:

components:
  schemas:
    MyEvent:
      oneOf:
      - $ref: '#/components/schemas/MyEvent1'
      - $ref: '#/components/schemas/MyEvent2'
      - $ref: '#/components/schemas/MyEvent3'

      discriminator:
        propertyName: eventType
        mapping:
          MyEvent1: '#/components/schemas/MyEvent1'
          MyEvent2: '#/components/schemas/MyEvent2'
          MyEvent3: '#/components/schemas/MyEvent3'

AsyncAPI Studio says this is an error, and the spec says:

field type description
discriminator string Adds support for polymorphism. The discriminator is the schema property name that is used to differentiate between other schema that inherit this schema. The property name used MUST be defined at this schema and it MUST be in the required property list. When used, the value MUST be the name of this schema or any schema that inherits it. See Composition and Inheritance for more details.

Changing the outputted yaml to the following rendered as expected:

components:
  schemas:
    MyEvent:
      oneOf:
      - $ref: '#/components/schemas/MyEvent1'
      - $ref: '#/components/schemas/MyEvent2'
      - $ref: '#/components/schemas/MyEvent3'

      discriminator: eventType

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions