1 package com.networknt.schema; 2 3 import static org.junit.jupiter.api.Assertions.assertEquals; 4 5 import java.util.Set; 6 7 import org.junit.jupiter.api.Test; 8 9 import com.fasterxml.jackson.core.JsonProcessingException; 10 import com.fasterxml.jackson.databind.JsonNode; 11 import com.fasterxml.jackson.databind.ObjectMapper; 12 13 public class Issue824Test { 14 @Test validate()15 void validate() throws JsonProcessingException { 16 final JsonSchema v201909SpecSchema = JsonSchemaFactory 17 .builder(JsonSchemaFactory.getInstance(SpecVersion.VersionFlag.V201909)) 18 .schemaMappers(schemaMappers -> { 19 schemaMappers.mapPrefix("https://json-schema.org", "resource:"); 20 }).build() 21 .getSchema(SchemaLocation.of(JsonMetaSchema.getV201909().getIri())); 22 v201909SpecSchema.preloadJsonSchema(); 23 final JsonNode invalidSchema = new ObjectMapper().readTree( 24 "{"+ 25 " \"$schema\": \"https://json-schema.org/draft/2019-09/schema\","+ 26 " \"type\": \"cat\" "+ 27 "}"); 28 29 // Validate same JSON schema against v2019-09 spec schema twice 30 final Set<ValidationMessage> validationErrors1 = v201909SpecSchema.validate(invalidSchema); 31 final Set<ValidationMessage> validationErrors2 = v201909SpecSchema.validate(invalidSchema); 32 33 // Validation errors should be the same 34 assertEquals(validationErrors1, validationErrors2); 35 36 // Results 37 // 38 // 1.0.73 39 // [$.type: does not have a value in the enumeration [array, boolean, integer, 40 // null, number, object, string], $.type: should be valid to any of the schemas 41 // array] 42 // [$.type: does not have a value in the enumeration [array, boolean, integer, 43 // null, number, object, string], $.type: should be valid to any of the schemas 44 // array] 45 // 46 // 1.0.74 47 // [$.type: does not have a value in the enumeration [array, boolean, integer, 48 // null, number, object, string], $.type: string found, array expected] 49 // [$.type: does not have a value in the enumeration [array, boolean, integer, 50 // null, number, object, string], $.type: string found, array expected] 51 // 52 // 1.0.78 53 // [$.type: does not have a value in the enumeration [array, boolean, integer, 54 // null, number, object, string], $.type: should be valid to any of the schemas 55 // array] 56 // [$.type: does not have a value in the enumeration [array, boolean, integer, 57 // null, number, object, string], $.type: should be valid to any of the schemas 58 // array] 59 // 60 // >= 1.0.82 61 // [$.type: does not have a value in the enumeration [array, boolean, integer, 62 // null, number, object, string], $.type: string found, array expected] 63 // [$.type: does not have a value in the enumeration [array, boolean, integer, 64 // null, number, object, string], $.type: should be valid to any of the schemas 65 // array] 66 // 67 // ????? 68 } 69 } 70