Skip to content

Commit 8fc6913

Browse files
authored
Fix evaluationPath and schemaLocation in getSubSchema for number in fragment (#1081)
1 parent 3234d02 commit 8fc6913

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/main/java/com/networknt/schema/JsonSchema.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ public JsonSchema getSubSchema(JsonNodePath fragment) {
369369
Object segment = fragment.getElement(x);
370370
JsonNode subSchemaNode = getNode(parentNode, segment);
371371
if (subSchemaNode != null) {
372-
if (segment instanceof Number) {
372+
if (segment instanceof Number && parentNode.isArray()) {
373373
int index = ((Number) segment).intValue();
374374
schemaLocation = schemaLocation.append(index);
375375
evaluationPath = evaluationPath.append(index);

src/test/java/com/networknt/schema/oas/OpenApi30Test.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
import com.networknt.schema.InputFormat;
2929
import com.networknt.schema.JsonSchema;
3030
import com.networknt.schema.JsonSchemaFactory;
31+
import com.networknt.schema.PathType;
3132
import com.networknt.schema.SchemaLocation;
33+
import com.networknt.schema.SchemaValidatorsConfig;
3234
import com.networknt.schema.SpecVersion.VersionFlag;
3335
import com.networknt.schema.ValidationMessage;
3436

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

0 commit comments

Comments
 (0)