mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-164185 JSON schema: allow $ref as a top-level reference to definition
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -138,6 +138,7 @@ public class JsonSchemaReader {
|
||||
Set<JsonSchemaObject> objects,
|
||||
@Nullable JsonSchemaExportedDefinitions definitions) {
|
||||
final ArrayDeque<JsonSchemaObject> queue = new ArrayDeque<>();
|
||||
queue.add(root);
|
||||
queue.addAll(objects);
|
||||
int control = 10000;
|
||||
|
||||
|
||||
@@ -360,6 +360,33 @@ public class JsonSchemaHighlightingTest extends DaemonAnalyzerTestCase {
|
||||
"}");
|
||||
}
|
||||
|
||||
public void testRootObjectRedefinedAdditionalPropertiesForbidden() throws Exception {
|
||||
testImpl(rootObjectRedefinedSchema(), "{<warning descr=\"Property 'a' is not allowed\">\"a\": true</warning>," +
|
||||
"\"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 + "}}";
|
||||
}
|
||||
|
||||
@@ -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\": <caret>}", "\"em\"", "\"test\"");
|
||||
}
|
||||
|
||||
public void testRootObjectRedefined() throws Exception {
|
||||
testImpl(JsonSchemaHighlightingTest.rootObjectRedefinedSchema(), "{<caret>}",
|
||||
"\"r1\"", "\"r2\"");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static String parcelShopSchema() {
|
||||
return "{\n" +
|
||||
|
||||
Reference in New Issue
Block a user