diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaAnnotatorChecker.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaAnnotatorChecker.java index 5ac11f746eaf..5cb99f70401f 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaAnnotatorChecker.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaAnnotatorChecker.java @@ -279,7 +279,7 @@ class JsonSchemaAnnotatorChecker { } final JsonPointerPosition step = JsonPointerPosition.createSingleProperty(name); - final Pair pair = doSingleStep(step, schema, true); + final Pair pair = doSingleStep(step, schema, true, false); if (ThreeState.NO.equals(pair.getFirst()) && !set.contains(name)) { error(JsonBundle.message("json.schema.annotation.not.allowed.property", name), property.getDelegate(), JsonValidationError.FixableIssueKind.ProhibitedProperty, diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaVariantsTreeBuilder.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaVariantsTreeBuilder.java index 89c394d9bdef..4628d0741b04 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaVariantsTreeBuilder.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaVariantsTreeBuilder.java @@ -59,7 +59,7 @@ public class JsonSchemaVariantsTreeBuilder { node.nothingChild(); continue; } - final Pair pair = doSingleStep(step, node.getSchema(), acceptAdditional); + final Pair pair = doSingleStep(step, node.getSchema(), acceptAdditional, true); if (ThreeState.NO.equals(pair.getFirst())) node.nothingChild(); else if (ThreeState.YES.equals(pair.getFirst())) node.anyChild(); else { @@ -112,10 +112,11 @@ public class JsonSchemaVariantsTreeBuilder { @NotNull public static Pair doSingleStep(@NotNull JsonPointerPosition step, @NotNull JsonSchemaObject parent, - boolean acceptAdditionalPropertiesSchemas) { + boolean acceptAdditionalPropertiesSchemas, + boolean processAllBranches) { final String name = step.getFirstName(); if (name != null) { - return propertyStep(name, parent, acceptAdditionalPropertiesSchemas); + return propertyStep(name, parent, acceptAdditionalPropertiesSchemas, processAllBranches); } else { final int index = step.getFirstIndex(); assert index >= 0; @@ -383,7 +384,8 @@ public class JsonSchemaVariantsTreeBuilder { @NotNull private static Pair propertyStep(@NotNull String name, @NotNull JsonSchemaObject parent, - boolean acceptAdditionalPropertiesSchemas) { + boolean acceptAdditionalPropertiesSchemas, + boolean processAllBranches) { final JsonSchemaObject child = parent.getProperties().get(name); if (child != null) { return Pair.create(ThreeState.UNSURE, child); @@ -398,7 +400,7 @@ public class JsonSchemaVariantsTreeBuilder { } List ifThenElseList = parent.getIfThenElse(); - if (ifThenElseList != null) { + if (ifThenElseList != null && processAllBranches) { for (IfThenElse ifThenElse : ifThenElseList) { // resolve inside V7 if-then-else conditionals JsonSchemaObject childObject; diff --git a/json/tests/test/com/jetbrains/jsonSchema/JsonSchemaHighlightingTest.java b/json/tests/test/com/jetbrains/jsonSchema/JsonSchemaHighlightingTest.java index 83ef97873906..1b9d02522146 100644 --- a/json/tests/test/com/jetbrains/jsonSchema/JsonSchemaHighlightingTest.java +++ b/json/tests/test/com/jetbrains/jsonSchema/JsonSchemaHighlightingTest.java @@ -1086,4 +1086,28 @@ public class JsonSchemaHighlightingTest extends JsonSchemaHighlightingTestBase { " }\n" + " }}", "{ \"myPropertyXxx\": \"a\" }"); } + + public void testIfThenElseFlat() throws Exception { + @Language("JSON") String schemaText = FileUtil.loadFile(new File(getTestDataPath() + "/ifThenElseFlatSchema.json")); + doTest(schemaText, "{\n" + + " \"street_address\": \"24 Sussex Drive\",\n" + + " \"country\": \"Canada\",\n" + + " \"postal_code\": \"K1M 1M4\" \n" + + "}"); + doTest(schemaText, "{\n" + + " \"street_address\": \"24 Sussex Drive\",\n" + + " \"country\": \"Canada\",\n" + + " \"postal_code\": \"1K1M1M4\" \n" + + "}"); + doTest(schemaText, "{\n" + + " \"street_address\": \"24 Madison Cube Garden NYC\",\n" + + " \"country\": \"United States of America\",\n" + + " \"postal_code\": \"11222-1111-1111\"\n" + + "}"); + doTest(schemaText, "{\n" + + " \"street_address\": \"24 Madison Cube Garden NYC\",\n" + + " \"country\": \"United States of America\",\n" + + " \"postal_code\": \"1-1111-1111\"\n" + + "}"); + } } diff --git a/json/tests/testData/jsonSchema/highlighting/ifThenElseFlatSchema.json b/json/tests/testData/jsonSchema/highlighting/ifThenElseFlatSchema.json new file mode 100644 index 000000000000..b98146e02ea5 --- /dev/null +++ b/json/tests/testData/jsonSchema/highlighting/ifThenElseFlatSchema.json @@ -0,0 +1,20 @@ +{ + "type": "object", + "properties": { + "street_address": { + "type": "string" + }, + "country": { + "enum": ["United States of America", "Canada"] + } + }, + "if": { + "properties": { "country": { "const": "United States of America" } } + }, + "then": { + "properties": { "postal_code": { "pattern": "[0-9]{5}(-[0-9]{4})?" } } + }, + "else": { + "properties": { "postal_code": { "pattern": "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]" } } + } +}