diff --git a/src/main/java/com/networknt/schema/utils/JsonNodes.java b/src/main/java/com/networknt/schema/utils/JsonNodes.java index f1f8947cd..3bfd9aa6d 100644 --- a/src/main/java/com/networknt/schema/utils/JsonNodes.java +++ b/src/main/java/com/networknt/schema/utils/JsonNodes.java @@ -67,7 +67,7 @@ public static T get(JsonNode node, JsonNodePath path) { @SuppressWarnings("unchecked") public static T get(JsonNode node, Object propertyOrIndex) { JsonNode value = null; - if (propertyOrIndex instanceof Number) { + if (propertyOrIndex instanceof Number && node.isArray()) { value = node.get(((Number) propertyOrIndex).intValue()); } else { value = node.get(propertyOrIndex.toString()); diff --git a/src/test/java/com/networknt/schema/oas/OpenApi30Test.java b/src/test/java/com/networknt/schema/oas/OpenApi30Test.java index 43256d271..e00abb492 100644 --- a/src/test/java/com/networknt/schema/oas/OpenApi30Test.java +++ b/src/test/java/com/networknt/schema/oas/OpenApi30Test.java @@ -16,6 +16,7 @@ package com.networknt.schema.oas; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import java.util.List; import java.util.Set; @@ -64,4 +65,16 @@ void validateMetaSchema() { assertEquals("required", list.get(1).getType()); assertEquals("bark", list.get(1).getProperty()); } + + /** + * Tests that schema location with number in fragment can resolve. + */ + @Test + 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")); + assertNotNull(schema); + } }