Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #1246 by preventing schema ID/anchor parsing from coercing non-string JSON nodes into text, which could incorrectly influence schema resource registration and $ref resolution (notably for Draft 4 where the ID keyword is id).
Changes:
- Added a regression test covering Draft 4 schema resolution involving a
$refinto the Draft 4 meta-schema. - Updated
Dialect.readText(...)to return a value only when the target field exists and is a JSON string (no coercion).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/test/java/com/networknt/schema/Issue1246Test.java |
Adds regression coverage to ensure Draft 4 $ref resolution is not impacted by non-text nodes encountered under id-named fields. |
src/main/java/com/networknt/schema/dialect/Dialect.java |
Tightens ID/anchor reading to ignore non-string values, avoiding unintended coercion effects. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| } | ||
| private static String readText(JsonNode node, String field) { | ||
| JsonNode fieldNode = node.get(field); | ||
| return fieldNode != null && fieldNode.isString() ? fieldNode.asString() : null; |
There was a problem hiding this comment.
Since the issue is that it shouldn't be coercing then these changes are confusing as asString() does coercing but isString() ensures it's a StringNode so the intent isn't clear.
More appropriate to use the following instead
private static String readText(JsonNode node, String field) {
JsonNode fieldNode = node.get(field);
return fieldNode == null ? null : fieldNode.stringValue(null);
}There was a problem hiding this comment.
Makes sense. I have made the code change based on your recommendation. Thanks a lot.
No description provided.