You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/oas.md
+51Lines changed: 51 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -3245,6 +3245,57 @@ components:
3245
3245
- packSize
3246
3246
```
3247
3247
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
0 commit comments