File tree Expand file tree Collapse file tree 3 files changed +24
-2
lines changed
main/java/org/everit/json/schema/loader
java/org/everit/json/schema/loader
resources/org/everit/jsonvalidator Expand file tree Collapse file tree 3 files changed +24
-2
lines changed Original file line number Diff line number Diff line change @@ -224,8 +224,8 @@ private CombinedSchema.Builder buildAnyOfSchemaForMultipleTypes() {
224
224
JSONArray subtypeJsons = ls .schemaJson .getJSONArray ("type" );
225
225
Collection <Schema > subschemas = new ArrayList <>(subtypeJsons .length ());
226
226
for (int i = 0 ; i < subtypeJsons .length (); ++i ) {
227
- Object subtypeJson = subtypeJsons .get (i );
228
- Schema .Builder <?> schemaBuilder = loadForExplicitType (( String ) subtypeJson );
227
+ String subtypeJson = subtypeJsons .getString (i );
228
+ Schema .Builder <?> schemaBuilder = loadForExplicitType (subtypeJson );
229
229
subschemas .add (schemaBuilder .build ());
230
230
}
231
231
return CombinedSchema .anyOf (subschemas );
Original file line number Diff line number Diff line change @@ -138,6 +138,22 @@ public void multipleTypes() {
138
138
assertTrue (SchemaLoader .load (get ("multipleTypes" )) instanceof CombinedSchema );
139
139
}
140
140
141
+ @ Test
142
+ public void implicitAnyOfLoadsTypeProps () {
143
+ CombinedSchema schema = (CombinedSchema ) SchemaLoader .load (get ("multipleTypesWithProps" ));
144
+ StringSchema stringSchema = schema .getSubschemas ().stream ()
145
+ .filter (sub -> sub instanceof StringSchema )
146
+ .map (sub -> (StringSchema ) sub )
147
+ .findFirst ().orElseThrow (() -> new AssertionError ("no StringSchema" ));
148
+ NumberSchema numSchema = schema .getSubschemas ().stream ()
149
+ .filter (sub -> sub instanceof NumberSchema )
150
+ .map (sub -> (NumberSchema ) sub )
151
+ .findFirst ()
152
+ .orElseThrow (() -> new AssertionError ("no NumberSchema" ));
153
+ assertEquals (3 , stringSchema .getMinLength ().intValue ());
154
+ assertEquals (5 , numSchema .getMinimum ().intValue ());
155
+ }
156
+
141
157
@ Test
142
158
public void neverMatchingAnyOf () {
143
159
assertTrue (SchemaLoader .load (get ("anyOfNeverMatches" )) instanceof CombinedSchema );
@@ -297,4 +313,5 @@ public void withoutFragmentNoFragment() {
297
313
String actual = ReferenceLookup .withoutFragment ("http://example.com" ).toString ();
298
314
assertEquals ("http://example.com" , actual );
299
315
}
316
+
300
317
}
Original file line number Diff line number Diff line change 192
192
" boolean"
193
193
]
194
194
},
195
+ "multipleTypesWithProps" : {
196
+ "type" : [" number" , " string" ],
197
+ "minLength" : 3 ,
198
+ "minimum" : 5
199
+ },
195
200
"invalidType" : {
196
201
"type" : {}
197
202
},
You can’t perform that action at this time.
0 commit comments