diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaObject.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaObject.java index 31b271f89d86..f0a6f31c5ef1 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaObject.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaObject.java @@ -102,8 +102,7 @@ public class JsonSchemaObject { // peer pointer is not merged! public void mergeValues(@NotNull JsonSchemaObject other) { // we do not copy id, schema - - myProperties.putAll(other.myProperties); + mergeProperties(this, other); myDefinitionsMap = copyMap(myDefinitionsMap, other.myDefinitionsMap); final Map map = copyMap(myPatternProperties == null ? null : myPatternProperties.mySchemasMap, other.myPatternProperties == null ? null : other.myPatternProperties.mySchemasMap); @@ -161,6 +160,20 @@ public class JsonSchemaObject { myShouldValidateAgainstJSType |= other.myShouldValidateAgainstJSType; } + private static void mergeProperties(@NotNull JsonSchemaObject thisObject, @NotNull JsonSchemaObject otherObject) { + for (Map.Entry prop: otherObject.myProperties.entrySet()) { + String key = prop.getKey(); + JsonSchemaObject otherProp = prop.getValue(); + if (!thisObject.myProperties.containsKey(key)) { + thisObject.myProperties.put(key, otherProp); + } + else { + JsonSchemaObject existingProp = thisObject.myProperties.get(key); + thisObject.myProperties.put(key, JsonSchemaVariantsTreeBuilder.merge(existingProp, otherProp, otherProp)); + } + } + } + public void shouldValidateAgainstJSType() { myShouldValidateAgainstJSType = true; } diff --git a/json/tests/test/com/jetbrains/jsonSchema/impl/JsonBySchemaCompletionTest.kt b/json/tests/test/com/jetbrains/jsonSchema/impl/JsonBySchemaCompletionTest.kt index d6f4acedbe2e..a182810b1979 100644 --- a/json/tests/test/com/jetbrains/jsonSchema/impl/JsonBySchemaCompletionTest.kt +++ b/json/tests/test/com/jetbrains/jsonSchema/impl/JsonBySchemaCompletionTest.kt @@ -281,7 +281,7 @@ class JsonBySchemaCompletionTest : JsonBySchemaCompletionBaseTest() { } @Throws(Exception::class) - private fun testImpl(schema: String, text: String, + private fun testImpl(@Language("JSON") schema: String, text: String, vararg variants: String) { testBySchema(schema, text, ".json", *variants) } @@ -352,4 +352,28 @@ class JsonBySchemaCompletionTest : JsonBySchemaCompletionBaseTest() { testImpl(ifThenElseSchema, """{"a": 5, "c": }""", "false", "true") Assert.assertEquals(2, myItems.size.toLong()) } + + @Throws(Exception::class) + fun testNestedPropsMerging() { + testImpl("""{ + "allOf": [ + { + "properties": { + "severity": { + "type": "string", + "enum": ["a", "b"] + } + } + }, + { + "properties": { + "severity": { + } + } + } + ] +}""","""{ + "severity": +}""", "\"a\"", "\"b\""); + } }