最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

json - Validate multiple schemas inside a yaml file in java - Stack Overflow

programmeradmin2浏览0评论

I have a yaml file that contains 43 schemas that are referencing each other. Something like Customer, Address, City... How must I tell the validator to use all of them and not only one of them? Because at the moment it finds problems in the root object of the json but all other child objects are ignored. I tried to give the .everit.json.schema.SchemaLoader a map of schemas but the final result was a EmptySchema object which does no validation at all.

final File openAPIFile = new File("src/test/resources", pTransformation.getOpenApiSwaggerFile());
LOGGER.info(openAPIFile.getAbsolutePath());
final SwaggerParseResult result = new OpenAPIV3Parser().readLocation(openAPIFile.getAbsolutePath(), null, null);
final OpenAPI openAPI = result.getOpenAPI();

// Convert OpenAPI schema to JSON Schema
final JSONObject jsonSchema = new JSONObject(openAPI.getComponents().getSchemas().get(getTransformation().getSwaggerTitle()));

// Load the JSON file to be validated
final InputStream jsonStream = new FileInputStream(inputFile);
final JSONObject jsonObject = new JSONObject(new JSONTokener(jsonStream));

// Validate the JSON file against the schema
final Schema schema = SchemaLoader.load(jsonSchema);
schema.validate(jsonObject);
发布评论

评论列表(0)

  1. 暂无评论