Skip to content

Commit f9b467d

Browse files
authored
Merge pull request #191 from networknt/issue190
Issue190
2 parents 1a839b3 + dbdfe90 commit f9b467d

File tree

2 files changed

+130
-73
lines changed

2 files changed

+130
-73
lines changed

src/main/java/com/networknt/schema/OneOfValidator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,10 @@ public Set<ValidationMessage> validate(JsonNode node, JsonNode rootNode, String
141141

142142
// validate that only a single element has been received in the oneOf node
143143
// validation should not continue, as it contradicts the oneOf requirement of only one
144-
if(node.isObject() && node.size()>1) {
145-
errors = Collections.singleton(buildValidationMessage(at, ""));
146-
return Collections.unmodifiableSet(errors);
147-
}
144+
// if(node.isObject() && node.size()>1) {
145+
// errors = Collections.singleton(buildValidationMessage(at, ""));
146+
// return Collections.unmodifiableSet(errors);
147+
// }
148148

149149
for (ShortcutValidator validator : schemas) {
150150
if (!validator.allConstantsMatch(node)) {

src/test/resources/tests/oneOf.json

Lines changed: 126 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -68,110 +68,167 @@
6868
{
6969
"description": "oneOf with objects and type pattern",
7070
"schema": {
71-
"oneOf": [
72-
{
73-
"type": "object",
74-
"required": [
75-
"type"
76-
],
77-
"properties": {
78-
"type": {
79-
"enum": [
80-
"TYPE_1"
81-
]
82-
}
83-
}
84-
},
85-
{
86-
"type": "object",
87-
"required": [
88-
"type"
89-
],
90-
"properties": {
91-
"type": {
92-
"enum": [
93-
"TYPE_2"
94-
]
95-
}
96-
}
97-
}
98-
99-
]
100-
},
71+
"oneOf": [
72+
{
73+
"type": "object",
74+
"required": [
75+
"type"
76+
],
77+
"properties": {
78+
"type": {
79+
"enum": [
80+
"TYPE_1"
81+
]
82+
}
83+
}
84+
},
85+
{
86+
"type": "object",
87+
"required": [
88+
"type"
89+
],
90+
"properties": {
91+
"type": {
92+
"enum": [
93+
"TYPE_2"
94+
]
95+
}
96+
}
97+
}
98+
99+
]
100+
},
101101
"tests": [
102102
{
103103
"description": "first oneOf valid",
104104
"data": {
105-
"type": "TYPE_1"
106-
},
105+
"type": "TYPE_1"
106+
},
107107
"valid": true
108108
},
109109
{
110110
"description": "second oneOf valid",
111111
"data": {
112-
"type": "TYPE_2"
113-
},
112+
"type": "TYPE_2"
113+
},
114114
"valid": true
115115
},
116116
{
117117
"description": "neither oneOf valid",
118118
"data": {
119-
"type": "INVALID_TYPE"
120-
},
119+
"type": "INVALID_TYPE"
120+
},
121+
"valid": false
122+
}
123+
]
124+
},
125+
{
126+
"description": "oneOf with objects and type pattern",
127+
"schema": {
128+
"oneOf": [
129+
{
130+
"type": "object",
131+
"properties": {
132+
"color": {
133+
"type": "string"
134+
},
135+
"id": {
136+
"type": "string"
137+
}
138+
}
139+
},
140+
{
141+
"type": "object",
142+
"required": [
143+
"type"
144+
],
145+
"properties": {
146+
"type": {
147+
"enum": [
148+
"TYPE_2"
149+
]
150+
}
151+
}
152+
}
153+
154+
]
155+
},
156+
"tests": [
157+
{
158+
"description": "first oneOf valid",
159+
"data": {
160+
"color": "black",
161+
"id": "abc"
162+
},
163+
"valid": true
164+
},
165+
{
166+
"description": "second oneOf valid",
167+
"data": {
168+
"type": "TYPE_2"
169+
},
170+
"valid": true
171+
},
172+
{
173+
"description": "neither oneOf valid",
174+
"data": {
175+
"type": "INVALID_TYPE"
176+
},
121177
"valid": false
122178
}
123179
]
124180
},
125181
{
126182
"description": "oneOf with objects and regex pattern",
127183
"schema": {
128-
"oneOf": [
129-
{
130-
"type": "object",
131-
"required": [
132-
"type"
133-
],
134-
"properties": {
135-
"type": {
136-
"type": "string",
137-
"pattern": "^TYPE_1$"
138-
}
139-
}
140-
},
141-
{
142-
"type": "object",
143-
"required": [
144-
"type"
145-
],
146-
"properties": {
147-
"type": {
148-
"type": "string",
149-
"pattern": "^TYPE_2$"
150-
}
151-
}
152-
}
153-
]
154-
},
184+
"oneOf": [
185+
{
186+
"type": "object",
187+
188+
"required": [
189+
"type"
190+
],
191+
"properties": {
192+
"type": {
193+
"type": "string",
194+
"pattern": "^TYPE_1$"
195+
}
196+
}
197+
},
198+
{
199+
"type": "object",
200+
"required": [
201+
"type"
202+
],
203+
"properties": {
204+
"type": {
205+
"type": "string",
206+
"pattern": "^TYPE_2$"
207+
}
208+
}
209+
}
210+
]
211+
},
155212
"tests": [
156213
{
157214
"description": "first oneOf valid",
158215
"data": {
159-
"type": "TYPE_1"
160-
},
216+
"type": "TYPE_1"
217+
},
161218
"valid": true
162219
},
163220
{
164221
"description": "second oneOf valid",
165222
"data": {
166-
"type": "TYPE_2"
167-
},
223+
"type": "TYPE_2"
224+
},
168225
"valid": true
169226
},
170227
{
171228
"description": "neither oneOf valid",
172229
"data": {
173-
"type": "INVALID_TYPE"
174-
},
230+
"type": "INVALID_TYPE"
231+
},
175232
"valid": false
176233
}
177234
]

0 commit comments

Comments
 (0)