diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaObject.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaObject.java index 51424d00baff..a1108f217e64 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaObject.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaObject.java @@ -41,10 +41,10 @@ public class JsonSchemaObject { private Integer myMinLength; private String myPattern; - private Boolean myAdditionalPropertiesAllowed = true; + private Boolean myAdditionalPropertiesAllowed; private JsonSchemaObject myAdditionalPropertiesSchema; - private Boolean myAdditionalItemsAllowed = true; + private Boolean myAdditionalItemsAllowed; private JsonSchemaObject myAdditionalItemsSchema; private JsonSchemaObject myItemsSchema; @@ -53,7 +53,7 @@ public class JsonSchemaObject { private Integer myMaxItems; private Integer myMinItems; - private boolean myUniqueItems; + private Boolean myUniqueItems; private Integer myMaxProperties; private Integer myMinProperties; @@ -152,7 +152,7 @@ public class JsonSchemaObject { myItemsSchemaList = copyList(myItemsSchemaList, other.myItemsSchemaList); if (other.myMaxItems != null) myMaxItems = other.myMaxItems; if (other.myMinItems != null) myMinItems = other.myMinItems; - if (other.myUniqueItems) myUniqueItems = other.myUniqueItems; + if (other.myUniqueItems != null) myUniqueItems = other.myUniqueItems; if (other.myMaxProperties != null) myMaxProperties = other.myMaxProperties; if (other.myMinProperties != null) myMinProperties = other.myMinProperties; myRequired = copyList(myRequired, other.myRequired); @@ -277,7 +277,7 @@ public class JsonSchemaObject { } public Boolean getAdditionalPropertiesAllowed() { - return myAdditionalPropertiesAllowed; + return myAdditionalPropertiesAllowed == null || myAdditionalPropertiesAllowed; } public void setAdditionalPropertiesAllowed(Boolean additionalPropertiesAllowed) { @@ -293,7 +293,7 @@ public class JsonSchemaObject { } public Boolean getAdditionalItemsAllowed() { - return myAdditionalItemsAllowed; + return myAdditionalItemsAllowed == null || myAdditionalItemsAllowed; } public void setAdditionalItemsAllowed(Boolean additionalItemsAllowed) { @@ -341,7 +341,7 @@ public class JsonSchemaObject { } public boolean isUniqueItems() { - return myUniqueItems; + return Boolean.TRUE.equals(myUniqueItems); } public void setUniqueItems(boolean uniqueItems) { diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaReader.java b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaReader.java index 0cab5b21eace..07dfd8d0e52a 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaReader.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonSchemaReader.java @@ -138,6 +138,7 @@ public class JsonSchemaReader { Set objects, @Nullable JsonSchemaExportedDefinitions definitions) { final ArrayDeque queue = new ArrayDeque<>(); + queue.add(root); queue.addAll(objects); int control = 10000; diff --git a/json/tests/test/com/jetbrains/jsonSchema/JsonSchemaHighlightingTest.java b/json/tests/test/com/jetbrains/jsonSchema/JsonSchemaHighlightingTest.java index c4728bb9ac18..4c5dc44a8ac3 100644 --- a/json/tests/test/com/jetbrains/jsonSchema/JsonSchemaHighlightingTest.java +++ b/json/tests/test/com/jetbrains/jsonSchema/JsonSchemaHighlightingTest.java @@ -360,6 +360,33 @@ public class JsonSchemaHighlightingTest extends DaemonAnalyzerTestCase { "}"); } + public void testRootObjectRedefinedAdditionalPropertiesForbidden() throws Exception { + testImpl(rootObjectRedefinedSchema(), "{\"a\": true," + + "\"r1\": \"allowed!\"}"); + } + + public static String rootObjectRedefinedSchema() { + return "{\n" + + " \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n" + + " \"type\": \"object\",\n" + + " \"$ref\" : \"#/definitions/root\",\n" + + " \"definitions\": {\n" + + " \"root\" : {\n" + + " \"type\": \"object\",\n" + + " \"additionalProperties\": false,\n" + + " \"properties\": {\n" + + " \"r1\": {\n" + + " \"type\": \"string\"\n" + + " },\n" + + " \"r2\": {\n" + + " \"type\": \"string\"\n" + + " }\n" + + " }\n" + + " }\n" + + " }\n" + + "}\n"; + } + static String schema(final String s) { return "{\"type\": \"object\", \"properties\": {\"prop\": " + s + "}}"; } diff --git a/json/tests/test/com/jetbrains/jsonSchema/impl/JsonBySchemaCompletionTest.java b/json/tests/test/com/jetbrains/jsonSchema/impl/JsonBySchemaCompletionTest.java index 17c1a4965959..6df614bad1a3 100644 --- a/json/tests/test/com/jetbrains/jsonSchema/impl/JsonBySchemaCompletionTest.java +++ b/json/tests/test/com/jetbrains/jsonSchema/impl/JsonBySchemaCompletionTest.java @@ -5,6 +5,7 @@ import com.intellij.codeInsight.lookup.LookupElement; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.testFramework.EditorTestUtil; +import com.jetbrains.jsonSchema.JsonSchemaHighlightingTest; import org.jetbrains.annotations.NotNull; import org.junit.Assert; @@ -127,6 +128,11 @@ public class JsonBySchemaCompletionTest extends CompletionTestCase { testImpl(schema, "{\"Cyan\": }", "\"em\"", "\"test\""); } + public void testRootObjectRedefined() throws Exception { + testImpl(JsonSchemaHighlightingTest.rootObjectRedefinedSchema(), "{}", + "\"r1\"", "\"r2\""); + } + @NotNull private static String parcelShopSchema() { return "{\n" +