From 88e211db1b362a3aaf17b9799f48edf6ee924edc Mon Sep 17 00:00:00 2001 From: Steve Hu Date: Tue, 26 May 2026 16:23:15 -0400 Subject: [PATCH 1/2] fixes #1246 Coercion bug --- .../com/networknt/schema/dialect/Dialect.java | 8 ++-- .../com/networknt/schema/Issue1246Test.java | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 src/test/java/com/networknt/schema/Issue1246Test.java diff --git a/src/main/java/com/networknt/schema/dialect/Dialect.java b/src/main/java/com/networknt/schema/dialect/Dialect.java index 6af636e91..30b871137 100644 --- a/src/main/java/com/networknt/schema/dialect/Dialect.java +++ b/src/main/java/com/networknt/schema/dialect/Dialect.java @@ -414,10 +414,10 @@ public String readDynamicAnchor(JsonNode schemaNode) { return null; } - private static String readText(JsonNode node, String field) { - JsonNode fieldNode = node.get(field); - return fieldNode == null ? null : fieldNode.asString(); - } + private static String readText(JsonNode node, String field) { + JsonNode fieldNode = node.get(field); + return fieldNode != null && fieldNode.isString() ? fieldNode.asString() : null; + } public String getId() { return this.id; diff --git a/src/test/java/com/networknt/schema/Issue1246Test.java b/src/test/java/com/networknt/schema/Issue1246Test.java new file mode 100644 index 000000000..13615fa85 --- /dev/null +++ b/src/test/java/com/networknt/schema/Issue1246Test.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2026 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.networknt.schema; + +import static org.junit.jupiter.api.Assertions.assertTrue; + +import org.junit.jupiter.api.Test; + +class Issue1246Test { + @Test + void draft4SchemaIdResolutionIgnoresNonTextIdPropertySchemas() { + String schemaData = "{\n" + + " \"id\": \"https://www.example.org/schema#\",\n" + + " \"$schema\": \"http://json-schema.org/draft-04/schema#\",\n" + + " \"type\": \"object\",\n" + + " \"properties\": {\n" + + " \"title\": {\n" + + " \"$ref\": \"http://json-schema.org/draft-04/schema#/properties/title\"\n" + + " }\n" + + " }\n" + + "}"; + Schema schema = SchemaRegistry.withDefaultDialect(SpecificationVersion.DRAFT_4) + .getSchema(schemaData); + + assertTrue(schema.validate("{\"title\":\"Sample API\"}", InputFormat.JSON).isEmpty()); + } +} From fb130347854afad750186c004c9190e67230d41a Mon Sep 17 00:00:00 2001 From: Steve Hu Date: Wed, 27 May 2026 19:16:09 -0400 Subject: [PATCH 2/2] fixes #1247 refactor based on recommendation from justin --- src/main/java/com/networknt/schema/dialect/Dialect.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/networknt/schema/dialect/Dialect.java b/src/main/java/com/networknt/schema/dialect/Dialect.java index 30b871137..52df32525 100644 --- a/src/main/java/com/networknt/schema/dialect/Dialect.java +++ b/src/main/java/com/networknt/schema/dialect/Dialect.java @@ -416,7 +416,7 @@ public String readDynamicAnchor(JsonNode schemaNode) { private static String readText(JsonNode node, String field) { JsonNode fieldNode = node.get(field); - return fieldNode != null && fieldNode.isString() ? fieldNode.asString() : null; + return fieldNode == null ? null : fieldNode.stringValue(null); } public String getId() {