in powertools-validation/src/main/java/software/amazon/lambda/powertools/validation/ValidationUtils.java [231:266]
public static JsonSchema getJsonSchema(String schema, boolean validateSchema) {
JsonSchema jsonSchema = schemas.get(schema);
if (jsonSchema != null) {
return jsonSchema;
}
if (schema.startsWith(CLASSPATH)) {
String filePath = schema.substring(CLASSPATH.length());
try (InputStream schemaStream = ValidationAspect.class.getResourceAsStream(filePath)) {
if (schemaStream == null) {
throw new IllegalArgumentException("'" + schema + "' is invalid, verify '" + filePath + "' is in your classpath");
}
jsonSchema = ValidationConfig.get().getFactory().getSchema(schemaStream);
} catch (IOException e) {
throw new IllegalArgumentException("'" + schema + "' is invalid, verify '" + filePath + "' is in your classpath");
}
} else {
jsonSchema = ValidationConfig.get().getFactory().getSchema(schema);
}
if (validateSchema) {
String version = ValidationConfig.get().getSchemaVersion().toString();
try {
validate(jsonSchema.getSchemaNode(),
getJsonSchema("classpath:/schemas/meta_schema_" + version));
} catch (ValidationException ve) {
throw new IllegalArgumentException("The schema " + schema + " is not valid, it does not respect the specification " + version, ve);
}
}
schemas.put(schema, jsonSchema);
return jsonSchema;
}