Skip to content

Commit 36b7d3f

Browse files
committed
minor cleanup of #62 and some more unittests
1 parent 881e03d commit 36b7d3f

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

core/src/main/java/org/everit/json/schema/loader/SchemaLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ private CombinedSchema.Builder buildAnyOfSchemaForMultipleTypes() {
224224
JSONArray subtypeJsons = ls.schemaJson.getJSONArray("type");
225225
Collection<Schema> subschemas = new ArrayList<>(subtypeJsons.length());
226226
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);
229229
subschemas.add(schemaBuilder.build());
230230
}
231231
return CombinedSchema.anyOf(subschemas);

core/src/test/java/org/everit/json/schema/loader/SchemaLoaderTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,22 @@ public void multipleTypes() {
138138
assertTrue(SchemaLoader.load(get("multipleTypes")) instanceof CombinedSchema);
139139
}
140140

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+
141157
@Test
142158
public void neverMatchingAnyOf() {
143159
assertTrue(SchemaLoader.load(get("anyOfNeverMatches")) instanceof CombinedSchema);
@@ -297,4 +313,5 @@ public void withoutFragmentNoFragment() {
297313
String actual = ReferenceLookup.withoutFragment("http://example.com").toString();
298314
assertEquals("http://example.com", actual);
299315
}
316+
300317
}

core/src/test/resources/org/everit/jsonvalidator/testschemas.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@
192192
"boolean"
193193
]
194194
},
195+
"multipleTypesWithProps" : {
196+
"type" : ["number", "string"],
197+
"minLength" : 3,
198+
"minimum" : 5
199+
},
195200
"invalidType": {
196201
"type": {}
197202
},

0 commit comments

Comments
 (0)