1 /* 2 * Copyright (c) 2024 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.networknt.schema; 17 18 import static org.junit.jupiter.api.Assertions.assertEquals; 19 20 import java.io.IOException; 21 import java.io.InputStream; 22 import java.util.Set; 23 24 import org.junit.jupiter.api.Test; 25 26 import com.fasterxml.jackson.databind.JsonNode; 27 import com.networknt.schema.SpecVersion.VersionFlag; 28 import com.networknt.schema.serialization.JsonMapperFactory; 29 30 /** 31 * Tests for meta schema validating a schema. 32 */ 33 public class MetaSchemaValidationTest { 34 /** 35 * Validates a OpenAPI 3.1 schema using the OpenAPI 3.1 meta schema. 36 * 37 * @throws IOException the exception 38 */ 39 @Test oas31()40 void oas31() throws IOException { 41 try (InputStream input = MetaSchemaValidationTest.class.getResourceAsStream("/schema/oas/v31/petstore.json")) { 42 JsonNode inputData = JsonMapperFactory.getInstance().readTree(input); 43 SchemaValidatorsConfig config = new SchemaValidatorsConfig(); 44 config.setPathType(PathType.JSON_POINTER); 45 JsonSchema schema = JsonSchemaFactory 46 .getInstance(VersionFlag.V202012, 47 builder -> builder.schemaMappers(schemaMappers -> schemaMappers 48 .mapPrefix("https://spec.openapis.org/oas/3.1", "classpath:oas/v31") 49 .mapPrefix("https://json-schema.org", "classpath:"))) 50 .getSchema(SchemaLocation.of("https://spec.openapis.org/oas/3.1/schema-base/2022-10-07"), config); 51 Set<ValidationMessage> messages = schema.validate(inputData); 52 assertEquals(0, messages.size()); 53 } 54 } 55 } 56