Skip to content

Report an error when the discriminator property is not defined in 'oneOf' the schema types? #344

Closed

Description

Should we report an error when the discriminator property is not defined in 'oneOf' the schema types? in the below example, pet2 doesn't have the expected discriminator property.

responses:
'200':
description: pet response
content:
application/json:
schema:
oneOf:
- "$ref": '#/components/schemas/pet1'
- "$ref": '#/components/schemas/pet2'
discriminator:
propertyName: petType
components:
schemas:
pet1:
type: object
required:
- id
properties:
id:
type: integer
format: int64
petType:
type: string
pet2:
type: object
required:
- id
properties:
id:
type: integer
format: int64

Activity

  1. changed the title [-]Should we report an error when the discriminator property is not defined in 'oneOf' the schema types?[/-] [+]Report an error when the discriminator property is not defined in 'oneOf' the schema types?[/+] on Nov 8, 2018
  2. PerthCharern commented on Nov 8, 2018

    @PerthCharern
    Contributor

    From the spec, we might be able to be even stricter:

    https://github.com/OAI/OpenAPI-Specification/blob/master/versions/3.0.0.md#composition-and-inheritance-polymorphism

    "... As such, the discriminator field MUST be a required field. There are are two ways to define the value of a discriminator for an inheriting instance."

    Would you like to send out a PR? :)

  3. senthilkumarmohan commented on Nov 9, 2018

    @senthilkumarmohan
    ContributorAuthor

    Thanks for your response. I am working on it - will submit a PR soon.

  4. senthilkumarmohan commented on Nov 15, 2018

    @senthilkumarmohan
    ContributorAuthor

    PerthCharern, i have submitted a PR for this. Please can you review?

  5. added a commit that references this issue on Nov 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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