diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonBySchemaObjectAnnotator.java b/json/src/com/jetbrains/jsonSchema/impl/JsonBySchemaObjectAnnotator.java index 22723c4b4498..597534aa7cf6 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonBySchemaObjectAnnotator.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonBySchemaObjectAnnotator.java @@ -356,14 +356,26 @@ public class JsonBySchemaObjectAnnotator implements Annotator { private void checkForEnum(PsiElement value, JsonSchemaObject schema) { //enum values + pattern -> don't check enum values if (schema.getEnum() == null || schema.getPattern() != null) return; - final String text = value.getText(); + final String text = StringUtil.notNullize(value.getText()); final List objects = schema.getEnum(); for (Object object : objects) { - if (object.toString().equalsIgnoreCase(text)) return; + if (myWalker.onlyDoubleQuotesForStringLiterals()) { + if (object.toString().equalsIgnoreCase(text)) return; + } else { + if (equalsIgnoreQuotesAndCase(object.toString(), text)) return; + } } error("Value should be one of: [" + StringUtil.join(objects, o -> o.toString(), ", ") + "]", value); } + private static boolean equalsIgnoreQuotesAndCase(@NotNull final String s1, @NotNull final String s2) { + final boolean quoted1 = StringUtil.isQuotedString(s1); + final boolean quoted2 = StringUtil.isQuotedString(s2); + if (quoted1 != quoted2) return false; + if (!quoted1) return s1.equalsIgnoreCase(s2); + return StringUtil.unquoteString(s1).equalsIgnoreCase(StringUtil.unquoteString(s2)); + } + private void checkArray(JsonValueAdapter value, JsonSchemaObject schema) { final JsonArrayValueAdapter asArray = value.getAsArray(); if (asArray == null) return; diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonLikePsiWalker.java b/json/src/com/jetbrains/jsonSchema/impl/JsonLikePsiWalker.java index 36e516bc7c3d..7aebd2b1a8df 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonLikePsiWalker.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonLikePsiWalker.java @@ -32,6 +32,7 @@ public interface JsonLikePsiWalker { PsiElement goUpToCheckable(@NotNull final PsiElement element); List findPosition(@NotNull final PsiElement element, boolean isName, boolean forceLastTransition); boolean isNameQuoted(); + boolean onlyDoubleQuotesForStringLiterals(); boolean hasPropertiesBehindAndNoComma(@NotNull PsiElement element); Set getPropertyNamesOfParentObject(@NotNull PsiElement element); @Nullable JsonPropertyAdapter getParentPropertyAdapter(@NotNull PsiElement element); diff --git a/json/src/com/jetbrains/jsonSchema/impl/JsonOriginalPsiWalker.java b/json/src/com/jetbrains/jsonSchema/impl/JsonOriginalPsiWalker.java index 66c12fe4d211..6278d281c7ab 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/JsonOriginalPsiWalker.java +++ b/json/src/com/jetbrains/jsonSchema/impl/JsonOriginalPsiWalker.java @@ -121,6 +121,11 @@ public class JsonOriginalPsiWalker implements JsonLikePsiWalker { return true; } + @Override + public boolean onlyDoubleQuotesForStringLiterals() { + return true; + } + @Override public boolean hasPropertiesBehindAndNoComma(@NotNull PsiElement element) { PsiElement current = element instanceof JsonProperty ? element : PsiTreeUtil.getParentOfType(element, JsonProperty.class);