From b684353c8ca7a418cdff537518928bf56f56e3d0 Mon Sep 17 00:00:00 2001 From: irengrig Date: Tue, 20 Sep 2016 16:39:01 +0200 Subject: [PATCH] WEB-23376 Stylelint: correct schema used for the completion and highlighting (all rules listed; only a few of them have type specification) WEB-23373 Stylelint: correct name of the property used in the package.json + additional test for complex schema definition usage --- .../extension/schema/JsonSchemaFileIndex.java | 2 +- .../jsonSchema/impl/JsonSchemaReadTest.java | 22 ++++++++++++ .../testData/jsonSchema/arrayItemsSchema.json | 34 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 json/tests/testData/jsonSchema/arrayItemsSchema.json diff --git a/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaFileIndex.java b/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaFileIndex.java index 4f58ea936a24..2e8ad4da882b 100644 --- a/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaFileIndex.java +++ b/json/src/com/jetbrains/jsonSchema/extension/schema/JsonSchemaFileIndex.java @@ -35,7 +35,7 @@ import java.util.Map; */ public class JsonSchemaFileIndex extends FileBasedIndexExtension { public static final ID PROPERTIES_INDEX = ID.create("json.schema.properties.index"); - public static final int VERSION = 7; + public static final int VERSION = 8; private IntInlineKeyDescriptor myKeyDescriptor = new IntInlineKeyDescriptor(); @NotNull diff --git a/json/tests/test/com/jetbrains/jsonSchema/impl/JsonSchemaReadTest.java b/json/tests/test/com/jetbrains/jsonSchema/impl/JsonSchemaReadTest.java index 73a6313a45db..604248c8625b 100644 --- a/json/tests/test/com/jetbrains/jsonSchema/impl/JsonSchemaReadTest.java +++ b/json/tests/test/com/jetbrains/jsonSchema/impl/JsonSchemaReadTest.java @@ -9,6 +9,7 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.List; +import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; @@ -66,6 +67,27 @@ public class JsonSchemaReadTest { Assert.assertTrue(read.getDefinitions().get("common").getProperties().containsKey("id")); } + @Test + public void testArrayItemsSchema() throws Exception { + final File file = new File(PlatformTestUtil.getCommunityPath(), "json/tests/testData/jsonSchema/arrayItemsSchema.json"); + Assert.assertTrue(file.exists()); + final JsonSchemaReader reader = new JsonSchemaReader(null); + final JsonSchemaObject read = reader.read(new FileReader(file), null); + final Map properties = read.getProperties(); + Assert.assertEquals(1, properties.size()); + final JsonSchemaObject object = properties.get("color-hex-case"); + final List oneOf = object.getOneOf(); + Assert.assertEquals(2, oneOf.size()); + final JsonSchemaObject second = oneOf.get(1); + final List list = second.getItemsSchemaList(); + Assert.assertEquals(2, list.size()); + final JsonSchemaObject firstItem = list.get(0); + final List anEnum = firstItem.getEnum(); + Assert.assertEquals(2, anEnum.size()); + Assert.assertTrue(anEnum.contains("\"lower\"")); + Assert.assertTrue(anEnum.contains("\"upper\"")); + } + @Test public void testReadSchemaWithWrongRequired() throws Exception { testSchemaReadNotHung(new File(PlatformTestUtil.getCommunityPath(), "json/tests/testData/jsonSchema/WithWrongRequired.json")); diff --git a/json/tests/testData/jsonSchema/arrayItemsSchema.json b/json/tests/testData/jsonSchema/arrayItemsSchema.json new file mode 100644 index 000000000000..2df386682413 --- /dev/null +++ b/json/tests/testData/jsonSchema/arrayItemsSchema.json @@ -0,0 +1,34 @@ +{ + "definitions": { + "lowerUpper": {"type": "string", "enum": ["lower","upper"]}, + "secondaryOption": { + "type": "object", + "properties": { + "message": { + "type": "string" + } + } + } + }, + "properties": { + "color-hex-case": { + "description": "Specify lowercase or uppercase for hex colors.", + "oneOf": [ + { + "$ref": "#/definitions/lowerUpper" + }, + { + "type": "array", + "items": [ + { + "$ref": "#/definitions/lowerUpper" + }, + { + "$ref": "#/definitions/secondaryOption" + } + ] + } + ] + } + } +} \ No newline at end of file