Skip to content

Commit

Permalink
Fix evaluationPath and schemaLocation in getSubSchema for number in f…
Browse files Browse the repository at this point in the history
…ragment (#1081)
  • Loading branch information
justin-tay authored Jul 5, 2024
1 parent 3234d02 commit 8fc6913
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/networknt/schema/JsonSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ public JsonSchema getSubSchema(JsonNodePath fragment) {
Object segment = fragment.getElement(x);
JsonNode subSchemaNode = getNode(parentNode, segment);
if (subSchemaNode != null) {
if (segment instanceof Number) {
if (segment instanceof Number && parentNode.isArray()) {
int index = ((Number) segment).intValue();
schemaLocation = schemaLocation.append(index);
evaluationPath = evaluationPath.append(index);
Expand Down
7 changes: 6 additions & 1 deletion src/test/java/com/networknt/schema/oas/OpenApi30Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
import com.networknt.schema.InputFormat;
import com.networknt.schema.JsonSchema;
import com.networknt.schema.JsonSchemaFactory;
import com.networknt.schema.PathType;
import com.networknt.schema.SchemaLocation;
import com.networknt.schema.SchemaValidatorsConfig;
import com.networknt.schema.SpecVersion.VersionFlag;
import com.networknt.schema.ValidationMessage;

Expand Down Expand Up @@ -74,7 +76,10 @@ void jsonPointerWithNumberInFragment() {
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(VersionFlag.V7, builder -> builder
.metaSchema(OpenApi30.getInstance()).defaultMetaSchemaIri(OpenApi30.getInstance().getIri()));
JsonSchema schema = factory.getSchema(SchemaLocation.of(
"classpath:schema/oas/3.0/petstore.yaml#/paths/~1pet/post/responses/200/content/application~1json/schema"));
"classpath:schema/oas/3.0/petstore.yaml#/paths/~1pet/post/responses/200/content/application~1json/schema"),
SchemaValidatorsConfig.builder().pathType(PathType.JSON_PATH).build());
assertNotNull(schema);
assertEquals("$.paths['/pet'].post.responses['200'].content['application/json'].schema",
schema.getEvaluationPath().toString());
}
}

0 comments on commit 8fc6913

Please sign in to comment.