Skip to content

Commit

Permalink
Set schema location
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-tay committed Dec 24, 2023
1 parent db1a14c commit 96b3207
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 2 additions & 4 deletions src/main/java/com/networknt/schema/JsonSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,8 @@ private void updateThisAsSubschema(URI originalUri) {
} catch (URISyntaxException ex) {
throw new JsonSchemaException("Unable to create URI without fragment from " + this.currentUri + ": " + ex.getMessage());
}
this.parentSchema = new JsonSchema(this.validationContext, this.schemaLocation, this.evaluationPath, currentUriWithoutFragment, this.schemaNode, this.parentSchema, super.suppressSubSchemaRetrieval); // TODO: Should this be delegated to the factory?

JsonNodePath path = UriReference.get(fragment);
this.schemaLocation = path;
this.parentSchema = new JsonSchema(this.validationContext, UriReference.get(currentUriWithoutFragment.toString()), this.evaluationPath, currentUriWithoutFragment, this.schemaNode, this.parentSchema, super.suppressSubSchemaRetrieval); // TODO: Should this be delegated to the factory?
this.schemaLocation = UriReference.get(originalUri.toString());
this.schemaNode = fragmentSchemaNode;
this.currentUri = combineCurrentUriWithIds(this.currentUri, fragmentSchemaNode);
}
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/networknt/schema/JsonSchemaFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,13 @@ public JsonSchema getSchema(final URI schemaUri, final SchemaValidatorsConfig co
JsonNodePath evaluationPath = new JsonNodePath(config.getPathType());
JsonSchema jsonSchema;
if (idMatchesSourceUri(jsonMetaSchema, schemaNode, schemaUri)) {
String schemaLocationValue = schemaUri.toString();
if(!schemaLocationValue.contains("#")) {
schemaLocationValue = schemaLocationValue + "#";
}
JsonNodePath schemaLocation = UriReference.get(schemaLocationValue);
ValidationContext validationContext = new ValidationContext(this.uriFactory, this.urnFactory, jsonMetaSchema, this, config);
jsonSchema = doCreate(validationContext, UriReference.DOCUMENT, evaluationPath, mappedUri, schemaNode, null, true /* retrieved via id, resolving will not change anything */);
jsonSchema = doCreate(validationContext, schemaLocation, evaluationPath, mappedUri, schemaNode, null, true /* retrieved via id, resolving will not change anything */);
} else {
final ValidationContext validationContext = createValidationContext(schemaNode);
validationContext.setConfig(config);
Expand Down

0 comments on commit 96b3207

Please sign in to comment.