Skip to content

Commit 881e03d

Browse files
authored
Merge pull request #63 from halvorgb/pattern-not-set-for-multiple-types
Failing test case and attempted fix for issue 62
2 parents 13c2162 + 8cf5d95 commit 881e03d

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,13 +222,11 @@ public SchemaLoader(final SchemaLoaderBuilder builder) {
222222

223223
private CombinedSchema.Builder buildAnyOfSchemaForMultipleTypes() {
224224
JSONArray subtypeJsons = ls.schemaJson.getJSONArray("type");
225-
Map<String, Object> dummyJson = new HashMap<String, Object>();
226-
Collection<Schema> subschemas = new ArrayList<Schema>(subtypeJsons.length());
225+
Collection<Schema> subschemas = new ArrayList<>(subtypeJsons.length());
227226
for (int i = 0; i < subtypeJsons.length(); ++i) {
228227
Object subtypeJson = subtypeJsons.get(i);
229-
dummyJson.put("type", subtypeJson);
230-
JSONObject child = new JSONObject(dummyJson);
231-
subschemas.add(loadChild(child).build());
228+
Schema.Builder<?> schemaBuilder = loadForExplicitType((String) subtypeJson);
229+
subschemas.add(schemaBuilder.build());
232230
}
233231
return CombinedSchema.anyOf(subschemas);
234232
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-04/schema#",
3+
"type": "object",
4+
"properties": {
5+
"only_as_1": {
6+
"pattern": "^a+$",
7+
"type": ["string", "null"]
8+
}
9+
}
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"only_as_1": "bbb"
3+
}

0 commit comments

Comments
 (0)