Skip to content

Commit 3ea3fa1

Browse files
authored
Use URITranslator to use local files instead of remote (#1457)
Remove local schema files, use the ones provided in the dependency Add support for 202012 Update tests
1 parent 1140fcf commit 3ea3fa1

File tree

13 files changed

+27
-819
lines changed

13 files changed

+27
-819
lines changed

powertools-validation/src/main/java/software/amazon/lambda/powertools/validation/ValidationConfig.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public SpecVersion.VersionFlag getSchemaVersion() {
4949
/**
5050
* Set the version of the json schema specifications (default is V7)
5151
*
52-
* @param version May be V4, V6, V7 or V201909
52+
* @param version May be V4, V6, V7, V201909 or V202012
5353
*/
5454
public void setSchemaVersion(SpecVersion.VersionFlag version) {
5555
if (version != jsonSchemaVersion) {

powertools-validation/src/main/java/software/amazon/lambda/powertools/validation/ValidationUtils.java

+9-4
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import com.fasterxml.jackson.databind.node.JsonNodeType;
2222
import com.fasterxml.jackson.databind.node.NullNode;
2323
import com.networknt.schema.JsonSchema;
24+
import com.networknt.schema.SchemaValidatorsConfig;
2425
import com.networknt.schema.ValidationMessage;
26+
import com.networknt.schema.uri.URITranslator;
2527
import io.burt.jmespath.Expression;
2628
import java.io.ByteArrayOutputStream;
2729
import java.io.InputStream;
@@ -257,7 +259,10 @@ private static JsonSchema createJsonSchema(String schema) {
257259
String filePath = schema.substring(CLASSPATH.length());
258260
try (InputStream schemaStream = ValidationAspect.class.getResourceAsStream(filePath)) {
259261

260-
jsonSchema = ValidationConfig.get().getFactory().getSchema(schemaStream);
262+
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
263+
config.addUriTranslator(URITranslator.prefix("https://json-schema.org", "resource:"));
264+
265+
jsonSchema = ValidationConfig.get().getFactory().getSchema(schemaStream, config);
261266
} catch (Exception e) {
262267
throw new IllegalArgumentException(
263268
"'" + schema + "' is invalid, verify '" + filePath + "' is in your classpath");
@@ -270,13 +275,13 @@ private static JsonSchema createJsonSchema(String schema) {
270275
}
271276

272277
private static void validateSchema(String schema, JsonSchema jsonSchema) {
273-
String version = ValidationConfig.get().getSchemaVersion().toString();
278+
String schemaId = ValidationConfig.get().getSchemaVersion().getId().replace("https://json-schema.org", "");
274279
try {
275280
validate(jsonSchema.getSchemaNode(),
276-
getJsonSchema("classpath:/schemas/meta_schema_" + version));
281+
getJsonSchema(CLASSPATH + schemaId));
277282
} catch (ValidationException ve) {
278283
throw new IllegalArgumentException(
279-
"The schema " + schema + " is not valid, it does not respect the specification " + version, ve);
284+
"The schema " + schema + " is not valid, it does not respect the specification " + schemaId, ve);
280285
}
281286
}
282287

powertools-validation/src/main/resources/schemas/meta/applicator

-56
This file was deleted.

powertools-validation/src/main/resources/schemas/meta/content

-17
This file was deleted.

powertools-validation/src/main/resources/schemas/meta/core

-57
This file was deleted.

powertools-validation/src/main/resources/schemas/meta/format

-14
This file was deleted.

powertools-validation/src/main/resources/schemas/meta/meta-data

-37
This file was deleted.

powertools-validation/src/main/resources/schemas/meta/validation

-98
This file was deleted.

powertools-validation/src/main/resources/schemas/meta_schema_V201909

-42
This file was deleted.

0 commit comments

Comments
 (0)