Skip to content

Commit

Permalink
Fix json pointer with number in fragment (#1077)
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-tay authored Jul 1, 2024
1 parent 46da4db commit 92bef22
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/main/java/com/networknt/schema/utils/JsonNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static <T extends JsonNode> T get(JsonNode node, JsonNodePath path) {
@SuppressWarnings("unchecked")
public static <T extends JsonNode> 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());
Expand Down
13 changes: 13 additions & 0 deletions src/test/java/com/networknt/schema/oas/OpenApi30Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 92bef22

Please sign in to comment.