openapi: 3.1.0 info: title: anyOf / oneOf example description: Demonstrate the valid use of anyOf and oneOf version: 1.0.0 paths: /animals/{id}: get: summary: Find animal by ID description: Returns a single animal operationId: getAnimalByID parameters: - name: id in: path description: ID of animal to get schema: type: string required: true example: "10" responses: "200": description: successful operation content: "application/json": schema: oneOf: - $ref: "#/components/schemas/Cat" - $ref: "#/components/schemas/Dog" discriminator: propertyName: petType mapping: dog: "#/components/schemas/Dog" cat: "#/components/schemas/Cat" "201": description: bad discriminator shouldn't crash content: "application/json": schema: discriminator: propertyName: petType mapping: dog: "#/components/schemas/Dog" cat: "#/components/schemas/Cat" "400": description: Invalid ID supplied content: {} "404": description: animal not found content: {} components: schemas: Dog: type: object required: - name - owner - bark properties: petType: const: dog # "dog" is a value for the petType property (the discriminator value) name: type: string owner: type: string bark: type: string Cat: type: object required: - name - owner - meow properties: petType: const: cat # "cat" is a value for the petType property (the discriminator value) name: type: string owner: type: string meow: type: string