WEB-25335 JSON Schema: "not" type is not validated

This commit is contained in:
irengrig
2017-02-09 16:41:11 +01:00
parent 3a56e5b8ed
commit 6de604aaa0
2 changed files with 48 additions and 32 deletions
@@ -188,39 +188,36 @@ class JsonBySchemaObjectAnnotator implements Annotator {
final JsonSchemaType type = getType(value);
if (type == null) {
typeError(value);
return;
} else {
JsonSchemaType schemaType = matchSchemaType(schema, type);
if (schemaType == null && schema.hasSpecifiedType()) {
typeError(value);
}
else if (JsonSchemaType._boolean.equals(type)) {
checkForEnum(value, schema);
}
else if (JsonSchemaType._number.equals(type) || JsonSchemaType._integer.equals(type)) {
checkNumber(value, schema, schemaType);
checkForEnum(value, schema);
}
else if (JsonSchemaType._string.equals(type)) {
checkString(value, schema);
checkForEnum(value, schema);
}
else if (JsonSchemaType._array.equals(type)) {
checkArray(value, schema);
checkForEnum(value, schema);
}
else if (JsonSchemaType._object.equals(type)) {
checkObject(value, schema, validatedProperties);
checkForEnum(value, schema);
}
}
JsonSchemaType schemaType = matchSchemaType(schema, type);
if (schemaType == null && schema.hasSpecifiedType()) {
typeError(value);
return;
}
if (JsonSchemaType._boolean.equals(type)) {
checkForEnum(value, schema);
return;
}
if (JsonSchemaType._number.equals(type) || JsonSchemaType._integer.equals(type)) {
checkNumber(value, schema, schemaType);
checkForEnum(value, schema);
return;
}
if (JsonSchemaType._string.equals(type)) {
checkString(value, schema);
checkForEnum(value, schema);
return;
}
if (JsonSchemaType._array.equals(type)) {
checkArray(value, schema);
checkForEnum(value, schema);
return;
}
if (JsonSchemaType._object.equals(type)) {
checkObject(value, schema, validatedProperties);
checkForEnum(value, schema);
return;
}
if (JsonSchemaType._null.equals(type)) {
return;
if (schema.getNot() != null) {
final BySchemaChecker checker = new BySchemaChecker();
checker.checkByScheme(value, schema.getNot(), new HashSet<>());
if (checker.isCorrect()) error("Validates against 'not' schema", value);
}
}
@@ -439,6 +439,25 @@ public class JsonSchemaHighlightingTest extends DaemonAnalyzerTestCase {
testImpl(schema, text);
}
public void testNotSchema() throws Exception {
final String schema = "{\"properties\": {\n" +
" \"not_type\": { \"not\": { \"type\": \"string\" } }\n" +
" }}";
testImpl(schema, "{\"not_type\": <warning descr=\"Validates against 'not' schema\">\"wrong\"</warning>}");
}
public void testNotSchemaCombinedWithNormal() throws Exception {
final String schema = "{\"properties\": {\n" +
" \"not_type\": {\n" +
" \"pattern\": \"^[a-z]*[0-5]*$\",\n" +
" \"not\": { \"pattern\": \"^[a-z]{1}[0-5]$\" }\n" +
" }\n" +
" }}";
testImpl(schema, "{\"not_type\": \"va4\"}");
testImpl(schema, "{\"not_type\": <warning descr=\"Validates against 'not' schema\">\"a4\"</warning>}");
testImpl(schema, "{\"not_type\": <warning descr=\"String is violating the pattern: '^[a-z]*[0-5]*$'\">\"4a4\"</warning>}");
}
public static String rootObjectRedefinedSchema() {
return "{\n" +
" \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n" +