-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoly.yml
More file actions
133 lines (121 loc) · 3.58 KB
/
poly.yml
File metadata and controls
133 lines (121 loc) · 3.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
openapi: 3.1.0
info:
title: Polymorphism Stress Test
version: 1.1.0
description: |
Extended contract for testing **oneOf**, **allOf**, and **anyOf** with and without discriminators.
paths:
/test/implicit:
post:
summary: No Discriminator (Validation by Structure)
description: |
- **oneOf**: Must match exactly one (SimpleText OR SimpleNumeric).
- **anyOf**: Can match one or both (AdminPermissions, EditorPermissions, or both).
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ImplicitContainer'
responses:
"200":
description: OK
/test/explicit:
post:
summary: With Discriminator (Validation by Label)
description: |
- **allOf**: Combines BaseUser and SystemMeta into a single requirement.
- **oneOf**: Uses `actionType` to switch between Email and SMS.
requestBody:
required: true
content:
application/json:
schema:
$ref: '#/components/schemas/ExplicitContainer'
responses:
"200":
description: OK
components:
schemas:
# --- NON-DISCRIMINATED SCHEMAS ---
ImplicitContainer:
type: object
properties:
# oneOf: Must satisfy EXACTLY ONE
payload:
oneOf:
- $ref: '#/components/schemas/SimpleText'
- $ref: '#/components/schemas/SimpleNumeric'
# anyOf: Must satisfy AT LEAST ONE (can be both)
userRoles:
anyOf:
- $ref: '#/components/schemas/AdminPermissions'
- $ref: '#/components/schemas/EditorPermissions'
user:
allOf:
- $ref: '#/components/schemas/BaseUser'
- $ref: '#/components/schemas/SystemMeta'
# --- DISCRIMINATED SCHEMAS ---
ExplicitContainer:
type: object
required: [user, action]
properties:
# allOf: Must satisfy BOTH (Inheritance pattern)
user:
allOf:
- $ref: '#/components/schemas/BaseUser'
- $ref: '#/components/schemas/SystemMeta'
action:
oneOf:
- $ref: '#/components/schemas/EmailAction'
- $ref: '#/components/schemas/SmsAction'
discriminator:
propertyName: actionType
mapping:
email: '#/components/schemas/EmailAction'
sms: '#/components/schemas/SmsAction'
# --- SHARED COMPONENTS ---
BaseUser:
type: object
required: [username]
properties:
username: { type: string }
SystemMeta:
type: object
required: [lastLogin]
properties:
lastLogin: { type: string, format: date-time }
SimpleText:
type: object
required: [content]
properties:
content: { type: string }
SimpleNumeric:
type: object
required: [value]
properties:
value: { type: integer }
# anyOf Components
AdminPermissions:
type: object
required: [canDelete]
properties:
canDelete: { type: boolean }
EditorPermissions:
type: object
required: [canEdit]
properties:
canEdit: { type: boolean }
# oneOf Components
EmailAction:
type: object
required: [actionType, emailAddress]
properties:
actionType: { type: string }
emailAddress: { type: string, format: email }
SmsAction:
type: object
required: [actionType, phoneNumber]
properties:
actionType: { type: string }
phoneNumber: { type: string }