[json schema] improve the highlighting range and provide a typo quick fix for disallowed property inspection

GitOrigin-RevId: 11380194fc21750f07fde230dae6ad5b37362384
This commit is contained in:
Anton Lobov
2024-08-21 14:44:42 +02:00
committed by intellij-monorepo-bot
parent c30a950b9d
commit ef0cd49c7c
18 changed files with 146 additions and 50 deletions

View File

@@ -55,6 +55,7 @@ action.ConsoleView.ShowAsJsonAction.text=Show as JSON
#json schema
json.schema.add.schema.chooser.title=Select JSON Schema File
json.schema.annotation.not.allowed.property=Property ''{0}'' is not allowed
json.schema.annotation.not.allowed.property.possibly.typo=Property ''{0}'' is not allowed. A typo?
json.schema.conflicting.mappings=Warning: conflicting mappings. <a href="#">Show details</a>
json.schema.file.selector.title=Schema file or URL:
json.schema.version.selector.title=Schema version:
@@ -104,6 +105,7 @@ sorry.this.fix.is.not.available.in.batch.mode=Sorry, this fix is not available i
replace.with.allowed.value=Replace with allowed value
json.schema=JSON Schema
remove.prohibited.property=Remove prohibited property
fix.property.name.spelling=Adjust spelling to ''{0}''
add.missing.0=Add missing {0}
add.missing.properties=Add missing properties
intention.add.not.required.properties.text=Fill in all properties from JSON schema

View File

@@ -8,6 +8,7 @@ import com.intellij.openapi.util.NlsSafe;
import com.jetbrains.jsonSchema.extension.JsonErrorPriority;
import com.jetbrains.jsonSchema.extension.JsonLikeSyntaxAdapter;
import com.jetbrains.jsonSchema.impl.fixes.AddMissingPropertyFix;
import com.jetbrains.jsonSchema.impl.fixes.FixPropertyNameTypoFix;
import com.jetbrains.jsonSchema.impl.fixes.RemoveProhibitedPropertyFix;
import com.jetbrains.jsonSchema.impl.fixes.SuggestEnumValuesFix;
import org.jetbrains.annotations.NotNull;
@@ -16,6 +17,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
public final class JsonValidationError {
@@ -113,9 +115,11 @@ public final class JsonValidationError {
public static final class ProhibitedPropertyIssueData implements IssueData {
public final @NlsSafe String propertyName;
public final List<@NlsSafe String> typoCandidates;
public ProhibitedPropertyIssueData(@NlsSafe String propertyName) {
public ProhibitedPropertyIssueData(@NlsSafe String propertyName, List<@NlsSafe String> typoCandidates) {
this.propertyName = propertyName;
this.typoCandidates = typoCandidates;
}
}
@@ -156,10 +160,22 @@ public final class JsonValidationError {
case MissingOneOfProperty, MissingAnyOfProperty ->
((MissingOneOfPropsIssueData)myIssueData).myExclusiveOptions.stream().map(d -> new AddMissingPropertyFix(d, quickFixAdapter))
.toArray(LocalQuickFix[]::new);
case ProhibitedProperty ->
new RemoveProhibitedPropertyFix[]{new RemoveProhibitedPropertyFix((ProhibitedPropertyIssueData)myIssueData, quickFixAdapter)};
case ProhibitedProperty -> getProhibitedPropertyFixes(quickFixAdapter);
case NonEnumValue -> new SuggestEnumValuesFix[]{new SuggestEnumValuesFix(quickFixAdapter)};
default -> LocalQuickFix.EMPTY_ARRAY;
};
}
private LocalQuickFix @NotNull [] getProhibitedPropertyFixes(@NotNull JsonLikeSyntaxAdapter quickFixAdapter) {
ProhibitedPropertyIssueData data = (ProhibitedPropertyIssueData)myIssueData;
if (data.typoCandidates.isEmpty()) {
return new RemoveProhibitedPropertyFix[]{new RemoveProhibitedPropertyFix(data, quickFixAdapter)};
}
ArrayList<LocalQuickFix> allFixes = new ArrayList<>();
for (@NlsSafe String candidate : data.typoCandidates) {
allFixes.add(new FixPropertyNameTypoFix(candidate, quickFixAdapter));
}
allFixes.add(new RemoveProhibitedPropertyFix(data, quickFixAdapter));
return allFixes.toArray(LocalQuickFix[]::new);
}
}

View File

@@ -0,0 +1,41 @@
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.jetbrains.jsonSchema.impl.fixes;
import com.intellij.json.JsonBundle;
import com.intellij.modcommand.ModPsiUpdater;
import com.intellij.modcommand.PsiUpdateModCommandQuickFix;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.jetbrains.jsonSchema.extension.JsonLikePsiWalker;
import com.jetbrains.jsonSchema.extension.JsonLikeSyntaxAdapter;
import com.jetbrains.jsonSchema.extension.adapters.JsonPropertyAdapter;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
public class FixPropertyNameTypoFix extends PsiUpdateModCommandQuickFix {
private final String myAltName;
private final JsonLikeSyntaxAdapter myQuickFixAdapter;
public FixPropertyNameTypoFix(String altName,
JsonLikeSyntaxAdapter quickFixAdapter) {
myAltName = altName;
myQuickFixAdapter = quickFixAdapter;
}
@Override
public @Nls(capitalization = Nls.Capitalization.Sentence) @NotNull String getFamilyName() {
return JsonBundle.message("fix.property.name.spelling", myAltName);
}
@Override
protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
JsonLikePsiWalker walker = JsonLikePsiWalker.getWalker(element);
if (walker == null) return;
JsonPropertyAdapter parentProperty = walker.getParentPropertyAdapter(element);
if (parentProperty == null) return;
PsiElement newProperty = walker.getSyntaxAdapter(project).createProperty(myAltName, "foo", project);
parentProperty.getNameValueAdapter().getDelegate().replace(
walker.getParentPropertyAdapter(newProperty).getNameValueAdapter().getDelegate()
);
}
}

View File

@@ -8,6 +8,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.jetbrains.jsonSchema.extension.JsonLikePsiWalker;
import com.jetbrains.jsonSchema.extension.JsonLikeSyntaxAdapter;
import com.jetbrains.jsonSchema.extension.adapters.JsonPropertyAdapter;
import com.jetbrains.jsonSchema.impl.JsonValidationError;
import org.jetbrains.annotations.Nls;
import org.jetbrains.annotations.NotNull;
@@ -38,7 +39,8 @@ public final class RemoveProhibitedPropertyFix extends PsiUpdateModCommandQuickF
protected void applyFix(@NotNull Project project, @NotNull PsiElement element, @NotNull ModPsiUpdater updater) {
JsonLikePsiWalker walker = JsonLikePsiWalker.getWalker(element);
if (walker == null) return;
assert myData.propertyName.equals(Objects.requireNonNull(walker.getParentPropertyAdapter(element)).getName());
myQuickFixAdapter.removeProperty(element);
JsonPropertyAdapter parentProperty = walker.getParentPropertyAdapter(element);
assert myData.propertyName.equals(Objects.requireNonNull(parentProperty).getName());
myQuickFixAdapter.removeProperty(parentProperty.getDelegate());
}
}

View File

@@ -3,12 +3,14 @@ package com.jetbrains.jsonSchema.impl.validations;
import com.intellij.json.JsonBundle;
import com.intellij.json.pointer.JsonPointerPosition;
import com.intellij.openapi.util.NlsSafe;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.ThreeState;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.text.EditDistance;
import com.jetbrains.jsonSchema.extension.JsonErrorPriority;
import com.jetbrains.jsonSchema.extension.JsonSchemaValidation;
import com.jetbrains.jsonSchema.extension.JsonValidationHost;
@@ -16,6 +18,7 @@ import com.jetbrains.jsonSchema.extension.adapters.JsonObjectValueAdapter;
import com.jetbrains.jsonSchema.extension.adapters.JsonPropertyAdapter;
import com.jetbrains.jsonSchema.extension.adapters.JsonValueAdapter;
import com.jetbrains.jsonSchema.impl.*;
import kotlin.collections.CollectionsKt;
import one.util.streamex.StreamEx;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -38,6 +41,8 @@ public final class ObjectValidation implements JsonSchemaValidation {
return checkObject(propValue, schema, consumer, options);
}
private static final int MIN_LENGTH_TO_FIX_TYPOS = 3;
private static boolean checkObject(@NotNull JsonValueAdapter value,
@NotNull JsonSchemaObject schema,
JsonValidationHost consumer,
@@ -52,8 +57,8 @@ public final class ObjectValidation implements JsonSchemaValidation {
for (JsonPropertyAdapter property : propertyList) {
final String name = StringUtil.notNullize(property.getName());
JsonSchemaObject propertyNamesSchema = schema.getPropertyNamesSchema();
JsonValueAdapter nameValueAdapter = property.getNameValueAdapter();
if (propertyNamesSchema != null) {
JsonValueAdapter nameValueAdapter = property.getNameValueAdapter();
if (nameValueAdapter != null) {
JsonValidationHost checker = consumer.checkByMatchResult(nameValueAdapter, consumer.resolve(propertyNamesSchema,
nameValueAdapter), options);
@@ -68,9 +73,21 @@ public final class ObjectValidation implements JsonSchemaValidation {
final JsonPointerPosition step = JsonPointerPosition.createSingleProperty(name);
final Pair<ThreeState, JsonSchemaObject> pair = doSingleStep(step, schema);
if (ThreeState.NO.equals(pair.getFirst()) && !set.contains(name)) {
consumer.error(JsonBundle.message("json.schema.annotation.not.allowed.property", name), property.getDelegate(),
Iterator<String> propertyNamesIterator = schema.getPropertyNames();
List<@NlsSafe String> typoCandidates = CollectionsKt.filter(
iteratorToList(propertyNamesIterator),
s -> EditDistance.optimalAlignment(s, name, false, 1) <= 1
);
consumer.error(JsonBundle.message(
name.length() < MIN_LENGTH_TO_FIX_TYPOS || typoCandidates.isEmpty() ?
"json.schema.annotation.not.allowed.property" :
"json.schema.annotation.not.allowed.property.possibly.typo", name),
nameValueAdapter != null ? nameValueAdapter.getDelegate() : property.getDelegate(),
JsonValidationError.FixableIssueKind.ProhibitedProperty,
new JsonValidationError.ProhibitedPropertyIssueData(name), JsonErrorPriority.LOW_PRIORITY);
new JsonValidationError.ProhibitedPropertyIssueData(
name,
name.length() >= MIN_LENGTH_TO_FIX_TYPOS ? typoCandidates : Collections.emptyList()
), JsonErrorPriority.LOW_PRIORITY);
isValid = false;
if (options.shouldStopValidationAfterAnyErrorFound()) return false;
}
@@ -143,6 +160,22 @@ public final class ObjectValidation implements JsonSchemaValidation {
return checkUnevaluatedPropertiesSchemaViolation(consumer, schema, object, options);
}
private static @NotNull ArrayList<@NlsSafe String> iteratorToList(Iterator<String> propertyNamesIterator) {
return Collections.list(
new Enumeration<>() {
@Override
public boolean hasMoreElements() {
return propertyNamesIterator.hasNext();
}
@Override
public String nextElement() {
return propertyNamesIterator.next();
}
}
);
}
private static boolean checkUnevaluatedPropertiesSchemaViolation(@NotNull JsonValidationHost consumer,
@NotNull JsonSchemaObject schemaNode,
@NotNull JsonObjectValueAdapter inspectedObject,
@@ -195,7 +228,8 @@ public final class ObjectValidation implements JsonSchemaValidation {
if (defaultValue == null) {
if (Registry.is("json.schema.object.v2")) {
defaultValue = schema.getExampleByName(req);
} else {
}
else {
var example = schema.getExample();
defaultValue = example == null ? null : example.get(req);
}
@@ -287,7 +321,8 @@ public final class ObjectValidation implements JsonSchemaValidation {
var existingProperties = ContainerUtil.map(objectValueAdapter.getPropertyList(), JsonPropertyAdapter::getName);
Iterable<String> iter = (() -> schema.getPropertyNames());
var missingProperties = StreamSupport.stream(iter.spliterator(), false).filter(it -> !existingProperties.contains(it)).collect(Collectors.toSet());
var missingProperties =
StreamSupport.stream(iter.spliterator(), false).filter(it -> !existingProperties.contains(it)).collect(Collectors.toSet());
var missingPropertiesData = createMissingPropertiesData(schema, missingProperties, validationHost, objectValueAdapter);
validationHost.error(
JsonBundle.message("schema.validation.missing.not.required.property.or.properties", missingPropertiesData.getMessage(false)),

View File

@@ -191,7 +191,7 @@ public class JsonSchemaHighlightingTest extends JsonSchemaHighlightingTestBase {
public void testAdditionalPropertiesDisabled() {
@Language("JSON") final String schema = "{\"type\": \"object\", \"properties\": {\"prop\": {}}, \"additionalProperties\": false}";
// not sure abt inner object
doTest(schema, "{\"prop\": {}, <warning descr=\"Property 'someStuff' is not allowed\">\"someStuff\": 20</warning>}");
doTest(schema, "{\"prop\": {}, <warning descr=\"Property 'someStuff' is not allowed\">\"someStuff\"</warning>: 20}");
}
public void testAdditionalPropertiesSchema() {
@@ -268,7 +268,7 @@ public class JsonSchemaHighlightingTest extends JsonSchemaHighlightingTestBase {
"\"innerType\":{}, \"innerValue\":{}" +
"}, \"additionalProperties\": false" +
"}}");
doTest(schema, "{\"prop\": [{\"innerType\":{}, <warning descr=\"Property 'alien' is not allowed\">\"alien\":{}</warning>}]}");
doTest(schema, "{\"prop\": [{\"innerType\":{}, <warning descr=\"Property 'alien' is not allowed\">\"alien\"</warning>:{}}]}");
}
public void testObjectDeeperInArray() {
@@ -279,7 +279,7 @@ public class JsonSchemaHighlightingTest extends JsonSchemaHighlightingTestBase {
"}, \"additionalProperties\": false" +
"}}");
doTest(schema,
"{\"prop\": [{\"innerType\":{\"only\": true, <warning descr=\"Property 'hidden' is not allowed\">\"hidden\": false</warning>}}]}");
"{\"prop\": [{\"innerType\":{\"only\": true, <warning descr=\"Property 'hidden' is not allowed\">\"hidden\"</warning>: false}}]}");
}
public void testInnerObjectPropValueInArray() {
@@ -292,7 +292,7 @@ public class JsonSchemaHighlightingTest extends JsonSchemaHighlightingTestBase {
@Language("JSON") final String schema = "{\"allOf\": [{\"type\": \"object\", \"properties\": {\"first\": {}}}," +
" {\"properties\": {\"second\": {\"enum\": [33,44]}}}], \"additionalProperties\": false}";
doTest(schema, "{\"first\": {}, \"second\": <warning descr=\"Value should be one of: 33, 44\">null</warning>}");
doTest(schema, "{\"first\": {}, \"second\": 44, <warning descr=\"Property 'other' is not allowed\">\"other\": 15</warning>}");
doTest(schema, "{\"first\": {}, \"second\": 44, <warning descr=\"Property 'other' is not allowed\">\"other\"</warning>: 15}");
doTest(schema, "{\"first\": {}, \"second\": <warning descr=\"Value should be one of: 33, 44\">12</warning>}");
}
@@ -302,7 +302,7 @@ public class JsonSchemaHighlightingTest extends JsonSchemaHighlightingTestBase {
@Language("JSON") final String schema = "{\"properties\": {\"prop\": {\"oneOf\": [" + subSchema1 + ", " + subSchema2 + "]}}}";
//doTest(schema, "{\"prop\": [{\"kilo\": 20}]}");
//doTest(schema, "{\"prop\": 5}");
doTest(schema, "{\"prop\": [{<warning descr=\"Property 'foxtrot' is not allowed\">\"foxtrot\": 15</warning>, \"kilo\": 20}]}");
doTest(schema, "{\"prop\": [{<warning descr=\"Property 'foxtrot' is not allowed\">\"foxtrot\"</warning>: 15, \"kilo\": 20}]}");
}
public void testIntegerTypeWithMinMax() throws Exception {
@@ -454,7 +454,7 @@ public class JsonSchemaHighlightingTest extends JsonSchemaHighlightingTestBase {
}
public void testRootObjectRedefinedAdditionalPropertiesForbidden() {
doTest(rootObjectRedefinedSchema(), "{<warning descr=\"Property 'a' is not allowed\">\"a\": true</warning>," +
doTest(rootObjectRedefinedSchema(), "{<warning descr=\"Property 'a' is not allowed\">\"a\"</warning>: true," +
"\"r1\": \"allowed!\"}");
}
@@ -1204,14 +1204,14 @@ public class JsonSchemaHighlightingTest extends JsonSchemaHighlightingTestBase {
"subject": {
"discriminator": "first",
"first": false,
<warning descr="Property 'second' is not allowed">"second": false</warning>
<warning descr="Property 'second' is not allowed">"second"</warning>: false
}
}""");
doTest(schemaText, """
{
"subject": {
"discriminator": "second",
<warning descr="Property 'first' is not allowed">"first": false</warning>,
<warning descr="Property 'first' is not allowed">"first"</warning>: false,
"second": false
}
}""");

View File

@@ -75,10 +75,10 @@ public class JsonSchemaQuickFixTest extends JsonSchemaQuickFixTestBase {
"additionalProperties": false
}""";
String fixName = "Remove prohibited property 'b'";
doTest(schema, "{\"a\": 5, <warning><caret>\"b\": 6</warning>, \"c\": 7}", fixName, "{\"a\": 5,\n \"c\": 7}");
doTest(schema, "{\"a\": 5, \"c\": 7, <warning><caret>\"b\": 6</warning>}", fixName, "{\"a\": 5, \"c\": 7}");
doTest(schema, "{<warning><caret>\"b\": 6</warning>, \"a\": 5, \"c\": 7}", fixName, "{\n \"a\": 5, \"c\": 7}");
doTest(schema, "{<warning><caret>\"b\": 6</warning>}", fixName, "{}");
doTest(schema, "{\"a\": 5, <warning><caret>\"b\"</warning>: 6, \"c\": 7}", fixName, "{\"a\": 5,\n \"c\": 7}");
doTest(schema, "{\"a\": 5, \"c\": 7, <warning><caret>\"b\"</warning>: 6}", fixName, "{\"a\": 5, \"c\": 7}");
doTest(schema, "{<warning><caret>\"b\"</warning>: 6, \"a\": 5, \"c\": 7}", fixName, "{\n \"a\": 5, \"c\": 7}");
doTest(schema, "{<warning><caret>\"b\"</warning>: 6}", fixName, "{}");
}
public void testRemoveProhibitedPropertyInjection() {
@@ -98,7 +98,7 @@ public class JsonSchemaQuickFixTest extends JsonSchemaQuickFixTestBase {
doTest(schema, """
{"outer": "{\\"inner\\": \
{\\"x\\": 1, <warning descr="Property 'y' is not allowed"><caret>\\"</warning><warning descr="Property 'y' is not allowed">y</warning>\
<warning descr="Property 'y' is not allowed">\\"</warning><warning descr="Property 'y' is not allowed">: 2</warning>}}"}""",
<warning descr="Property 'y' is not allowed">\\"</warning>: 2}}"}""",
"Remove prohibited property 'y'", """
{"outer": "{\\"inner\\": {\\"x\\": 1}}"}""");
}

View File

@@ -424,7 +424,7 @@ internal class JsonSchema2020FeaturesTest : JsonSchemaVersionTestBase() {
{
"foo": {
"${dollar}ref": "...",
<warning descr="Property 'prohibitedAdditionalProperty' is not allowed">"prohibitedAdditionalProperty": 123</warning>
<warning descr="Property 'prohibitedAdditionalProperty' is not allowed">"prohibitedAdditionalProperty"</warning>: 123
}
}
""".trimIndent(),

View File

@@ -2,6 +2,6 @@
"anyOne": {
"a112": 9,
"b111": 9,
<warning descr="Property 'ccc' is not allowed">"ccc": true</warning>
<warning descr="Property 'ccc' is not allowed">"ccc"</warning>: true
}
}

View File

@@ -1,5 +1,5 @@
{
"about1": <warning descr="Value should be one of: \"var13\", \"var23\"">"var1"</warning>,
"b_111": true,
<warning descr="Property 'ccc' is not allowed">"ccc": 18</warning>
<warning descr="Property 'ccc' is not allowed">"ccc"</warning>: 18
}

View File

@@ -1,5 +1,5 @@
{
"a": <warning descr="Incompatible types.
Required: string. Actual: integer.">6</warning>,
<warning descr="Property 'b' is not allowed">"b": "a"</warning>
<warning descr="Property 'b' is not allowed">"b"</warning>: "a"
}

View File

@@ -1,12 +1,12 @@
{
"a": "a",
<warning descr="Property 'c' is not allowed">"c": 7</warning>,
"b": <warning descr="Incompatible types.
<warning descr="Property 'c' is not allowed">"c"</warning>: 7,
<warning descr="Property 'b' is not allowed">"b"</warning>: <warning descr="Incompatible types.
Required: string. Actual: integer.">5</warning>,
"x25": "q",
"x255": <warning descr="Incompatible types.
Required: string. Actual: integer.">7</warning>,
"0x256": <warning descr="Incompatible types.
Required: string. Actual: boolean.">true</warning>,
<warning descr="Property 'x025' is not allowed">"x025": "fail"</warning>
<warning descr="Property 'x025' is not allowed">"x025"</warning>: "fail"
}

View File

@@ -1,9 +1,9 @@
{
<warning descr="Property 'b' is not allowed">"b": 5</warning>,
<warning descr="Property 'b' is not allowed">"b"</warning>: 5,
"x25": "q",
"x255": <warning descr="Incompatible types.
Required: string. Actual: integer.">7</warning>,
"0x256": <warning descr="Incompatible types.
Required: string. Actual: boolean.">true</warning>,
<warning descr="Property 'x025' is not allowed">"x025": "fail"</warning>
<warning descr="Property 'x025' is not allowed">"x025"</warning>: "fail"
}

View File

@@ -1,10 +1,10 @@
{
"testProp": {
"testProp": {
<warning descr="Property 'alala' is not allowed">"alala": {
}</warning>
<warning descr="Property 'alala' is not allowed">"alala"</warning>: {
}
}
},
<warning descr="Property 'alala' is not allowed">"alala": {
}</warning>
<warning descr="Property 'alala' is not allowed">"alala"</warning>: {
}
}

View File

@@ -6,5 +6,5 @@
}
}
},
<warning descr="Property 'aaa' is not allowed">"aaa": 1</warning>
<warning descr="Property 'aaa' is not allowed">"aaa"</warning>: 1
}

View File

@@ -187,7 +187,7 @@ public class YamlByJsonSchemaHighlightingTest extends JsonSchemaHighlightingTest
public void testAdditionalPropertiesDisabled() {
@Language("JSON") final String schema = "{\"type\": \"object\", \"properties\": {\"prop\": {}}, \"additionalProperties\": false}";
// not sure abt inner object
doTest(schema, "prop:\n q: true\n<warning descr=\"Schema validation: Property 'someStuff' is not allowed\">someStuff: 20</warning>");
doTest(schema, "prop:\n q: true\n<warning descr=\"Schema validation: Property 'someStuff' is not allowed\">someStuff</warning>: 20");
}
public void testAdditionalPropertiesSchema() {
@@ -270,7 +270,7 @@ public class YamlByJsonSchemaHighlightingTest extends JsonSchemaHighlightingTest
"\"innerType\":{}, \"innerValue\":{}" +
"}, \"additionalProperties\": false" +
"}}");
doTest(schema, "prop:\n- innerType: aaa\n <warning descr=\"Schema validation: Property 'alien' is not allowed\">alien: bee</warning>");
doTest(schema, "prop:\n- innerType: aaa\n <warning descr=\"Schema validation: Property 'alien' is not allowed\">alien</warning>: bee");
}
public void testObjectDeeperInArray() {
@@ -281,7 +281,7 @@ public class YamlByJsonSchemaHighlightingTest extends JsonSchemaHighlightingTest
"}, \"additionalProperties\": false" +
"}}");
doTest(schema,
"prop:\n- innerType:\n only: true\n <warning descr=\"Schema validation: Property 'hidden' is not allowed\">hidden: false</warning>");
"prop:\n- innerType:\n only: true\n <warning descr=\"Schema validation: Property 'hidden' is not allowed\">hidden</warning>: false");
}
public void testInnerObjectPropValueInArray() {
@@ -294,7 +294,7 @@ public class YamlByJsonSchemaHighlightingTest extends JsonSchemaHighlightingTest
@Language("JSON") final String schema = "{\"allOf\": [{\"type\": \"object\", \"properties\": {\"first\": {}}}," +
" {\"properties\": {\"second\": {\"enum\": [33,44]}}}], \"additionalProperties\": false}";
// doTest(schema, "first: true\nsecond: <warning descr=\"Schema validation: Value should be one of: [33, 44]\">null</warning>");
doTest(schema, "first: true\nsecond: 44\n<warning descr=\"Schema validation: Property 'other' is not allowed\">other: 15</warning>");
doTest(schema, "first: true\nsecond: 44\n<warning descr=\"Schema validation: Property 'other' is not allowed\">other</warning>: 15");
doTest(schema, "first: true\nsecond: <warning descr=\"Schema validation: Value should be one of: 33, 44\">12</warning>");
}
@@ -302,7 +302,7 @@ public class YamlByJsonSchemaHighlightingTest extends JsonSchemaHighlightingTest
final String subSchema1 = "{\"enum\": [1,2,3,4,5]}";
final String subSchema2 = "{\"type\": \"array\", \"items\": {\"properties\": {\"kilo\": {}}, \"additionalProperties\": false}}";
@Language("JSON") final String schema = "{\"properties\": {\"prop\": {\"oneOf\": [" + subSchema1 + ", " + subSchema2 + "]}}}";
doTest(schema, "prop:\n - <warning descr=\"Schema validation: Property 'foxtrot' is not allowed\">foxtrot: 15</warning>\n kilo: 20");
doTest(schema, "prop:\n - <warning descr=\"Schema validation: Property 'foxtrot' is not allowed\">foxtrot</warning>: 15\n kilo: 20");
}
public void testPatternPropertiesHighlighting() {
@@ -392,7 +392,7 @@ public class YamlByJsonSchemaHighlightingTest extends JsonSchemaHighlightingTest
public void testRootObjectRedefinedAdditionalPropertiesForbidden() {
doTest(rootObjectRedefinedSchema(), "<warning descr=\"Schema validation: Property 'a' is not allowed\">a: true</warning>\n" +
doTest(rootObjectRedefinedSchema(), "<warning descr=\"Schema validation: Property 'a' is not allowed\">a</warning>: true\n" +
"r1: allowed!");
}

View File

@@ -53,7 +53,7 @@ public class YamlByJsonSchemaQuickFixTest extends JsonSchemaQuickFixTestBase {
"c": {}
},
"additionalProperties": false
}""", "a: 5\n<warning>b: 6<caret></warning>\nc: 7", "Remove prohibited property 'b'", "a: 5\n" +
}""", "a: 5\n<warning>b<caret></warning>: 6\nc: 7", "Remove prohibited property 'b'", "a: 5\n" +
"c: 7");
}

View File

@@ -218,7 +218,7 @@ public class YamlByYamlSchemaHighlightingTest extends JsonSchemaHighlightingTest
public void testAdditionalPropertiesDisabled() {
@Language("YAML") final String schema = "{\"type\": \"object\", \"properties\": {\"prop\": {}}, \"additionalProperties\": false}";
// not sure abt inner object
doTestYaml(schema, "prop:\n q: true\n<warning descr=\"Schema validation: Property 'someStuff' is not allowed\">someStuff: 20</warning>");
doTestYaml(schema, "prop:\n q: true\n<warning descr=\"Schema validation: Property 'someStuff' is not allowed\">someStuff</warning>: 20");
}
public void testAdditionalPropertiesSchema() {
@@ -301,7 +301,7 @@ public class YamlByYamlSchemaHighlightingTest extends JsonSchemaHighlightingTest
"\"innerType\":{}, \"innerValue\":{}" +
"}, \"additionalProperties\": false" +
"}}");
doTestYaml(schema, "prop:\n- innerType: aaa\n <warning descr=\"Schema validation: Property 'alien' is not allowed\">alien: bee</warning>");
doTestYaml(schema, "prop:\n- innerType: aaa\n <warning descr=\"Schema validation: Property 'alien' is not allowed\">alien</warning>: bee");
}
public void testObjectDeeperInArray() {
@@ -312,7 +312,7 @@ public class YamlByYamlSchemaHighlightingTest extends JsonSchemaHighlightingTest
"}, \"additionalProperties\": false" +
"}}");
doTestYaml(schema,
"prop:\n- innerType:\n only: true\n <warning descr=\"Schema validation: Property 'hidden' is not allowed\">hidden: false</warning>");
"prop:\n- innerType:\n only: true\n <warning descr=\"Schema validation: Property 'hidden' is not allowed\">hidden</warning>: false");
}
public void testInnerObjectPropValueInArray() {
@@ -325,7 +325,7 @@ public class YamlByYamlSchemaHighlightingTest extends JsonSchemaHighlightingTest
@Language("YAML") final String schema = "{\"allOf\": [{\"type\": \"object\", \"properties\": {\"first\": {}}}," +
" {\"properties\": {\"second\": {\"enum\": [33,44]}}}], \"additionalProperties\": false}";
// doTestYaml(schema, "first: true\nsecond: <warning descr=\"Schema validation: Value should be one of: [33, 44]\">null</warning>");
doTestYaml(schema, "first: true\nsecond: 44\n<warning descr=\"Schema validation: Property 'other' is not allowed\">other: 15</warning>");
doTestYaml(schema, "first: true\nsecond: 44\n<warning descr=\"Schema validation: Property 'other' is not allowed\">other</warning>: 15");
doTestYaml(schema, "first: true\nsecond: <warning descr=\"Schema validation: Value should be one of: 33, 44\">12</warning>");
}
@@ -333,7 +333,7 @@ public class YamlByYamlSchemaHighlightingTest extends JsonSchemaHighlightingTest
final String subSchema1 = "{\"enum\": [1,2,3,4,5]}";
final String subSchema2 = "{\"type\": \"array\", \"items\": {\"properties\": {\"kilo\": {}}, \"additionalProperties\": false}}";
@Language("YAML") final String schema = "{\"properties\": {\"prop\": {\"oneOf\": [" + subSchema1 + ", " + subSchema2 + "]}}}";
doTestYaml(schema, "prop:\n - <warning descr=\"Schema validation: Property 'foxtrot' is not allowed\">foxtrot: 15</warning>\n kilo: 20");
doTestYaml(schema, "prop:\n - <warning descr=\"Schema validation: Property 'foxtrot' is not allowed\">foxtrot</warning>: 15\n kilo: 20");
}
public void testPatternPropertiesHighlighting() {
@@ -423,7 +423,7 @@ public class YamlByYamlSchemaHighlightingTest extends JsonSchemaHighlightingTest
public void testRootObjectRedefinedAdditionalPropertiesForbidden() {
doTestYaml(rootObjectRedefinedSchema(), "<warning descr=\"Schema validation: Property 'a' is not allowed\">a: true</warning>\n" +
doTestYaml(rootObjectRedefinedSchema(), "<warning descr=\"Schema validation: Property 'a' is not allowed\">a</warning>: true\n" +
"r1: allowed!");
}