Skip to content

fix: json schema 403 error #1457

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public SpecVersion.VersionFlag getSchemaVersion() {
/**
* Set the version of the json schema specifications (default is V7)
*
* @param version May be V4, V6, V7 or V201909
* @param version May be V4, V6, V7, V201909 or V202012
*/
public void setSchemaVersion(SpecVersion.VersionFlag version) {
if (version != jsonSchemaVersion) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import com.fasterxml.jackson.databind.node.JsonNodeType;
import com.fasterxml.jackson.databind.node.NullNode;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.SchemaValidatorsConfig;
import com.networknt.schema.ValidationMessage;
import com.networknt.schema.uri.URITranslator;
import io.burt.jmespath.Expression;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
Expand Down Expand Up @@ -257,7 +259,10 @@ private static JsonSchema createJsonSchema(String schema) {
String filePath = schema.substring(CLASSPATH.length());
try (InputStream schemaStream = ValidationAspect.class.getResourceAsStream(filePath)) {

jsonSchema = ValidationConfig.get().getFactory().getSchema(schemaStream);
SchemaValidatorsConfig config = new SchemaValidatorsConfig();
config.addUriTranslator(URITranslator.prefix("https://json-schema.org", "resource:"));

jsonSchema = ValidationConfig.get().getFactory().getSchema(schemaStream, config);
} catch (Exception e) {
throw new IllegalArgumentException(
"'" + schema + "' is invalid, verify '" + filePath + "' is in your classpath");
Expand All @@ -270,13 +275,13 @@ private static JsonSchema createJsonSchema(String schema) {
}

private static void validateSchema(String schema, JsonSchema jsonSchema) {
String version = ValidationConfig.get().getSchemaVersion().toString();
String schemaId = ValidationConfig.get().getSchemaVersion().getId().replace("https://json-schema.org", "");
try {
validate(jsonSchema.getSchemaNode(),
getJsonSchema("classpath:/schemas/meta_schema_" + version));
getJsonSchema(CLASSPATH + schemaId));
} catch (ValidationException ve) {
throw new IllegalArgumentException(
"The schema " + schema + " is not valid, it does not respect the specification " + version, ve);
"The schema " + schema + " is not valid, it does not respect the specification " + schemaId, ve);
}
}

Expand Down
56 changes: 0 additions & 56 deletions powertools-validation/src/main/resources/schemas/meta/applicator

This file was deleted.

17 changes: 0 additions & 17 deletions powertools-validation/src/main/resources/schemas/meta/content

This file was deleted.

57 changes: 0 additions & 57 deletions powertools-validation/src/main/resources/schemas/meta/core

This file was deleted.

14 changes: 0 additions & 14 deletions powertools-validation/src/main/resources/schemas/meta/format

This file was deleted.

37 changes: 0 additions & 37 deletions powertools-validation/src/main/resources/schemas/meta/meta-data

This file was deleted.

98 changes: 0 additions & 98 deletions powertools-validation/src/main/resources/schemas/meta/validation

This file was deleted.

This file was deleted.

Loading