Skip to content

fixes #1174 TextNodes as schema seem to validate any value#1250

Merged
stevehu merged 7 commits into
masterfrom
issue1174
Jun 11, 2026
Merged

fixes #1174 TextNodes as schema seem to validate any value#1250
stevehu merged 7 commits into
masterfrom
issue1174

Conversation

@stevehu

@stevehu stevehu commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses issue #1174 by preventing non-schema JSON node types (notably TextNode) from being treated as valid JSON Schemas, which previously could result in “accept anything” behavior due to empty validator sets.

Changes:

  • Add validation in SchemaRegistry to reject schema root nodes that are neither an object nor (where supported) a boolean.
  • Add regression tests covering TextNode root schemas and boolean-schema support differences between Draft 4 and Draft 7.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/test/java/com/networknt/schema/Issue1174Test.java Adds regression tests for rejecting TextNode schemas and for boolean-schema behavior across drafts.
src/main/java/com/networknt/schema/SchemaRegistry.java Adds schema node null/type validation and draft-aware boolean-schema acceptance.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main/java/com/networknt/schema/SchemaRegistry.java

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment thread src/main/java/com/networknt/schema/SchemaRegistry.java
Comment thread src/test/java/com/networknt/schema/Issue1174Test.java

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Comment thread src/main/java/com/networknt/schema/SchemaRegistry.java Outdated
Comment thread src/main/java/com/networknt/schema/SchemaRegistry.java Outdated

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread src/main/java/com/networknt/schema/keyword/RefValidator.java

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread src/main/java/com/networknt/schema/SchemaRegistry.java

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Comment thread src/main/java/com/networknt/schema/keyword/RefValidator.java

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 8 out of 8 changed files in this pull request and generated no new comments.

@stevehu

stevehu commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Viewed spec.yaml:39-84
Ran command: curl -sL https://patch-diff.githubusercontent.com/raw/networknt/json-schema-validator/pull/1250.diff
Ran command: curl -sL https://patch-diff.githubusercontent.com/raw/networknt/json-schema-validator/pull/1250.diff | head -n 100

This is an excellent pull request for specification compliance and strictness. Here is my review of the changes in PR #1250:

1. Strict Schema Node Type Validation

The most significant change is the introduction of strict type validation for schema nodes (validateSchemaNodeType). Previously, the validator might have silently ignored or swallowed invalid JSON nodes that were mistakenly passed as schemas or sub-schemas (such as strings or arrays). Now, it strictly enforces that all schemas must be either a JSON object or a boolean.

This strictness is so effective that it actually caught several malformed schemas in your own test suite! For example:

  • In issue656.json, "frequency": "integer" was corrected to "frequency": {"type": "integer"}.
  • In UnknownMetaSchemaTest.java, the "required": ["data"] array was mistakenly nested inside the properties object. Because the new logic validates sub-schemas, it correctly realized that an array is not a valid JSON schema object and forced the test to be corrected.

2. Specification-Aware Boolean Schemas

The PR correctly implements boolean schema support based on the JSON Schema draft version. By introducing supportsBooleanSchema, it ensures that boolean schemas (true / false) are accepted in Draft 6 and newer, but correctly rejected in Draft 4 (which strictly required schemas to be objects).

3. Graceful Fragment Resolution

The overloaded loadSchema(schemaUri, validateLoadedSchema) method is a smart addition. It allows the registry to download a raw JSON document and resolve a specific fragment (e.g., url#/my-schema) without prematurely validating the root document as a schema. This correctly handles edge cases where a schema is embedded inside a larger, non-schema JSON payload.

Conclusion

This PR massively improves the robustness of the validator. It prevents users from writing silent bugs in their JSON schemas (like typing "id": "string" instead of {"type": "string"}) by failing fast and throwing a clear SchemaException. The code is clean, the fallback logic for dialect versions is correct, and the accompanying test fixes prove that the new validation is working exactly as intended.

Everything looks great and ready to merge!

@stevehu stevehu merged commit e5f6dc1 into master Jun 11, 2026
4 checks passed
@stevehu stevehu deleted the issue1174 branch June 11, 2026 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants