Skip to content

Commit 92bef22

Browse files
authored
Fix json pointer with number in fragment (#1077)
1 parent 46da4db commit 92bef22

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/main/java/com/networknt/schema/utils/JsonNodes.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static <T extends JsonNode> T get(JsonNode node, JsonNodePath path) {
6767
@SuppressWarnings("unchecked")
6868
public static <T extends JsonNode> T get(JsonNode node, Object propertyOrIndex) {
6969
JsonNode value = null;
70-
if (propertyOrIndex instanceof Number) {
70+
if (propertyOrIndex instanceof Number && node.isArray()) {
7171
value = node.get(((Number) propertyOrIndex).intValue());
7272
} else {
7373
value = node.get(propertyOrIndex.toString());

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package com.networknt.schema.oas;
1717

1818
import static org.junit.jupiter.api.Assertions.assertEquals;
19+
import static org.junit.jupiter.api.Assertions.assertNotNull;
1920

2021
import java.util.List;
2122
import java.util.Set;
@@ -64,4 +65,16 @@ void validateMetaSchema() {
6465
assertEquals("required", list.get(1).getType());
6566
assertEquals("bark", list.get(1).getProperty());
6667
}
68+
69+
/**
70+
* Tests that schema location with number in fragment can resolve.
71+
*/
72+
@Test
73+
void jsonPointerWithNumberInFragment() {
74+
JsonSchemaFactory factory = JsonSchemaFactory.getInstance(VersionFlag.V7, builder -> builder
75+
.metaSchema(OpenApi30.getInstance()).defaultMetaSchemaIri(OpenApi30.getInstance().getIri()));
76+
JsonSchema schema = factory.getSchema(SchemaLocation.of(
77+
"classpath:schema/oas/3.0/petstore.yaml#/paths/~1pet/post/responses/200/content/application~1json/schema"));
78+
assertNotNull(schema);
79+
}
6780
}

0 commit comments

Comments
 (0)