Skip to content

Instantly share code, notes, and snippets.

@martin-mfg
Created September 11, 2023 19:45
Show Gist options
  • Save martin-mfg/b93d8c5639a823da0970dace1847d727 to your computer and use it in GitHub Desktop.
Save martin-mfg/b93d8c5639a823da0970dace1847d727 to your computer and use it in GitHub Desktop.
openapi: 3.0.3
info:
title: example of a parent schema with discriminator property that is an enum
version: "2.0"
paths:
"/pet/{petId}":
get:
summary: Find pet by id
operationId: getBetById
parameters:
- name: petId
in: path
required: true
schema:
type: string
responses:
'200':
description: OK - The request has succeeded.
content:
application/json:
schema:
type: array
items:
"$ref": "#/components/schemas/Pet"
components:
schemas:
Pet:
type: object
required:
- petType
properties:
myType:
type: string
enum: [ Cat, Dog, Lizard ]
discriminator:
propertyName: myType
mapping:
dog: Dog
Cat:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
# all other properties specific to a `Cat`
properties:
name:
type: string
Dog:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
# all other properties specific to a `Dog`
properties:
bark:
type: string
Lizard:
allOf:
- $ref: '#/components/schemas/Pet'
- type: object
# all other properties specific to a `Lizard`
properties:
lovesRocks:
type: boolean
House:
type: object
properties:
myType:
type: string
discriminator:
propertyName: myType
School:
allOf:
- $ref: '#/components/schemas/House'
- type: object
properties:
students:
type: integer
Tower:
allOf:
- $ref: '#/components/schemas/House'
- type: object
properties:
height:
type: number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment