Skip to content

Commit 27216de

Browse files
committed
Add back polymorphic example using allOf
1 parent d36a8ff commit 27216de

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/oas.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3245,6 +3245,57 @@ components:
32453245
- packSize
32463246
```
32473247

3248+
###### Models with Polymorphism Support using allOf and a Discriminator Object
3249+
3250+
It is also possible to describe polymorphic models using `allOf`. The following example uses `allOf` with a [Discriminator Object](#discriminator-object) to describe a polymorphic `Pet` model.
3251+
3252+
```yaml
3253+
components:
3254+
schemas:
3255+
Pet:
3256+
type: object
3257+
discriminator:
3258+
propertyName: petType
3259+
properties:
3260+
name:
3261+
type: string
3262+
petType:
3263+
type: string
3264+
required:
3265+
- name
3266+
- petType
3267+
Cat: # "Cat" will be used as the discriminating value
3268+
description: A representation of a cat
3269+
allOf:
3270+
- $ref: '#/components/schemas/Pet'
3271+
- type: object
3272+
properties:
3273+
huntingSkill:
3274+
type: string
3275+
description: The measured skill for hunting
3276+
enum:
3277+
- clueless
3278+
- lazy
3279+
- adventurous
3280+
- aggressive
3281+
required:
3282+
- huntingSkill
3283+
Dog: # "Dog" will be used as the discriminating value
3284+
description: A representation of a dog
3285+
allOf:
3286+
- $ref: '#/components/schemas/Pet'
3287+
- type: object
3288+
properties:
3289+
packSize:
3290+
type: integer
3291+
format: int32
3292+
description: the size of the pack the dog is from
3293+
default: 0
3294+
minimum: 0
3295+
required:
3296+
- packSize
3297+
```
3298+
32483299
###### Generic Data Structure Model
32493300

32503301
```JSON

0 commit comments

Comments
 (0)