Skip to content

Commit 0a1200b

Browse files
authored
Use oneOf for enums when possible (GREsau#108)
1 parent dec8bcc commit 0a1200b

15 files changed

+305
-279
lines changed

schemars/tests/expected/deprecated-enum.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://json-schema.org/draft-07/schema#",
33
"title": "DeprecatedEnum",
44
"deprecated": true,
5-
"anyOf": [
5+
"oneOf": [
66
{
77
"type": "string",
88
"enum": [
@@ -24,13 +24,13 @@
2424
"foo"
2525
],
2626
"properties": {
27-
"foo": {
28-
"type": "integer",
29-
"format": "int32"
30-
},
3127
"deprecated_field": {
3228
"deprecated": true,
3329
"type": "boolean"
30+
},
31+
"foo": {
32+
"type": "integer",
33+
"format": "int32"
3434
}
3535
}
3636
}

schemars/tests/expected/doc_comments_enum.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "http://json-schema.org/draft-07/schema#",
33
"title": "This is the enum's title",
44
"description": "This is the enum's description.",
5-
"anyOf": [
5+
"oneOf": [
66
{
77
"type": "string",
88
"enum": [

schemars/tests/expected/enum-adjacent-tagged-duf.json

+38-38
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "http://json-schema.org/draft-07/schema#",
33
"title": "Adjacent",
4-
"anyOf": [
4+
"oneOf": [
55
{
66
"type": "object",
77
"required": [
@@ -24,17 +24,17 @@
2424
"t"
2525
],
2626
"properties": {
27-
"t": {
28-
"type": "string",
29-
"enum": [
30-
"StringMap"
31-
]
32-
},
3327
"c": {
3428
"type": "object",
3529
"additionalProperties": {
3630
"type": "string"
3731
}
32+
},
33+
"t": {
34+
"type": "string",
35+
"enum": [
36+
"StringMap"
37+
]
3838
}
3939
},
4040
"additionalProperties": false
@@ -46,14 +46,14 @@
4646
"t"
4747
],
4848
"properties": {
49+
"c": {
50+
"$ref": "#/definitions/UnitStruct"
51+
},
4952
"t": {
5053
"type": "string",
5154
"enum": [
5255
"UnitStructNewType"
5356
]
54-
},
55-
"c": {
56-
"$ref": "#/definitions/UnitStruct"
5757
}
5858
},
5959
"additionalProperties": false
@@ -65,14 +65,14 @@
6565
"t"
6666
],
6767
"properties": {
68+
"c": {
69+
"$ref": "#/definitions/Struct"
70+
},
6871
"t": {
6972
"type": "string",
7073
"enum": [
7174
"StructNewType"
7275
]
73-
},
74-
"c": {
75-
"$ref": "#/definitions/Struct"
7676
}
7777
},
7878
"additionalProperties": false
@@ -84,28 +84,28 @@
8484
"t"
8585
],
8686
"properties": {
87-
"t": {
88-
"type": "string",
89-
"enum": [
90-
"Struct"
91-
]
92-
},
9387
"c": {
9488
"type": "object",
9589
"required": [
9690
"bar",
9791
"foo"
9892
],
9993
"properties": {
94+
"bar": {
95+
"type": "boolean"
96+
},
10097
"foo": {
10198
"type": "integer",
10299
"format": "int32"
103-
},
104-
"bar": {
105-
"type": "boolean"
106100
}
107101
},
108102
"additionalProperties": false
103+
},
104+
"t": {
105+
"type": "string",
106+
"enum": [
107+
"Struct"
108+
]
109109
}
110110
},
111111
"additionalProperties": false
@@ -117,12 +117,6 @@
117117
"t"
118118
],
119119
"properties": {
120-
"t": {
121-
"type": "string",
122-
"enum": [
123-
"Tuple"
124-
]
125-
},
126120
"c": {
127121
"type": "array",
128122
"items": [
@@ -136,6 +130,12 @@
136130
],
137131
"maxItems": 2,
138132
"minItems": 2
133+
},
134+
"t": {
135+
"type": "string",
136+
"enum": [
137+
"Tuple"
138+
]
139139
}
140140
},
141141
"additionalProperties": false
@@ -162,39 +162,39 @@
162162
"t"
163163
],
164164
"properties": {
165+
"c": {
166+
"type": "integer",
167+
"format": "int32"
168+
},
165169
"t": {
166170
"type": "string",
167171
"enum": [
168172
"WithInt"
169173
]
170-
},
171-
"c": {
172-
"type": "integer",
173-
"format": "int32"
174174
}
175175
},
176176
"additionalProperties": false
177177
}
178178
],
179179
"definitions": {
180-
"UnitStruct": {
181-
"type": "null"
182-
},
183180
"Struct": {
184181
"type": "object",
185182
"required": [
186183
"bar",
187184
"foo"
188185
],
189186
"properties": {
187+
"bar": {
188+
"type": "boolean"
189+
},
190190
"foo": {
191191
"type": "integer",
192192
"format": "int32"
193-
},
194-
"bar": {
195-
"type": "boolean"
196193
}
197194
}
195+
},
196+
"UnitStruct": {
197+
"type": "null"
198198
}
199199
}
200200
}

0 commit comments

Comments
 (0)