Skip to content

oneOf with discriminator does not verify json correctly #1087

@seveneves

Description

@seveneves

Given this schema to highlight the problem

$id: resource:/schema/issueXXX
$defs:
  TypeA:
    type: object
    required:
      - kind
    properties:
      kind:
        type: string
  TypeB:
    type: object
    required:
      - kind
    properties:
      kind:
        type: string
oneOf:
  - $ref: "#/$defs/TypeA"
  - $ref: "#/$defs/TypeB"
discriminator:
  propertyName: kind
  mapping:
    A: "#/$defs/TypeA"
    B: "#/$defs/TypeB"

TypeA and TypeB are essentially the same with the difference that there is discriminator kind is registered with given mapping A and B.

Then following json cannot be validated

{"kind": "A"}

Validator provides this error

must be valid to one and only one schema, but 2 are valid with indexes '0, 1'

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