Skip to content

Fix: handle boolean-schema validation errors (register validation handler) - #112

Closed
Pravalika-Batchu wants to merge 85 commits into
hyperjump-io:mainfrom
Pravalika-Batchu:main
Closed

Pravalika-Batchu wants to merge 85 commits into
hyperjump-io:mainfrom
Pravalika-Batchu:main

Conversation

@Pravalika-Batchu

Copy link
Copy Markdown

Summary: Add an error handler for boolean-schema validation failures normalized under https://json-schema.org/validation so boolean schemas (e.g. properties: { foo: false }) produce user-friendly error messages.
Fixes: Closes #111
What I changed:
Added validation.js — emits errors for boolean schema failures (skips /additionalProperties to avoid duplicates).
Registered the handler in index.js.
Added a small repro check-boolean.mjs used during verification.
Why: Previously boolean-schema failures were normalized under https://json-schema.org/validation but no error handler was registered, so the library returned an empty errors array for these cases.
Verification:
Tests pass locally: npm test
Notes: This change avoids emitting duplicate messages for additionalProperties

jdesrosiers and others added 30 commits May 15, 2025 11:13
Done normalizing the OutputFormat
added options param in the main function
Keyword handlers: Added four new keywordHandlers
completed evaluatedKeywordsHandlers
arpitkuriyal and others added 20 commits August 19, 2025 22:57
Discriminator- more anyof cases
Bumps [actions/upload-pages-artifact](https://github.com/actions/upload-pages-artifact) from 3 to 4.
- [Release notes](https://github.com/actions/upload-pages-artifact/releases)
- [Commits](actions/upload-pages-artifact@v3...v4)

---
updated-dependencies:
- dependency-name: actions/upload-pages-artifact
  dependency-version: '4'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
…tions/upload-pages-artifact-4

Bump actions/upload-pages-artifact from 3 to 4
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 4 to 5.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](actions/setup-node@v4...v5)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-version: '5'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
* Updated README with installation notes

* Revised readme.md for project status 

Updated README to clarify project status.
Bumps [actions/checkout](https://github.com/actions/checkout) from 5 to 6.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](actions/checkout@v5...v6)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
After fixing some type errors in @hyperjump/json-schema, it exposed a
type issue in the plugin system. We aren't using the plugin system, so I
decided to just remove it for now instead of fix it. Something like it
can be added in again later if it turns out we need it.
Bumps [actions/setup-node](https://github.com/actions/setup-node) from 5 to 6.
- [Release notes](https://github.com/actions/setup-node/releases)
- [Commits](actions/setup-node@v5...v6)

---
updated-dependencies:
- dependency-name: actions/setup-node
  dependency-version: '6'
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
…95)

* fixed:format test failure

Signed-off-by: Diya <diyasrivastava2023@gmail.com>

* fix lint error

* removed repition in format test

* fixed repetition and lint errors

---------

Signed-off-by: Diya <diyasrivastava2023@gmail.com>
* fixed type error handler to handle allOf

Signed-off-by: Diya <diyasrivastava2023@gmail.com>

* Add more tests for schemas with mulitple types

* refactor code in type handler

Signed-off-by: Diya <diyasrivastava2023@gmail.com>

* implemented changes

* remove duplicate tests

* Removed new set creation from ALL_TYPES

---------

Signed-off-by: Diya <diyasrivastava2023@gmail.com>
Co-authored-by: Jason Desrosiers <jdesrosi@gmail.com>
fix: add validation error handler for boolean schemas

@jdesrosiers jdesrosiers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for working on this issue. Next time, keep in mind that unless the issue is trivial and obvious, there's should always be discussion before submitting a PR. It helps makes sure everyone understands the issue and what solution we're aiming for so we can minimize any wasted time from going down the wrong path.

The problem with this approach is that now there are two separate ways of handling a false schema. Currently, individual keywords like additionalProperties handle this case. The benefit of that approach is that you can get more customized and context appropriate messaging. The downside is that you end up repeating some of the logic in multiple error handlers.

Your solution takes a different approach where all false schema messaging is handled in one place. The benefit of that approach is that there isn't any duplication, but the downside is that the error message needs to be a little more generic.

I'm fine with either approach, but I like the latter better if we can come up with wording for the message that makes sense in all cases.

What's not ok is a mixture of both approaches. So, either we change additionalProperties so that it doesn't handle false schema messaging itself, or we add false schema handling similar to what additionalProperties does for every applicator keyword. I think changing additionalProperties is going to be the easiest solution.

if (normalizedErrors["https://json-schema.org/validation"]) {
for (const schemaLocation in normalizedErrors["https://json-schema.org/validation"]) {
// additionalProperties has its own specific error handler; avoid duplicate messages
if (schemaLocation.endsWith("/additionalProperties")) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This won't always work. Try this schema and you'll see what I mean,

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "properties": {
    "additionalProperties": false
  }
}

Here, "additionalProperties" is being used as a property name, not as a JSON Schema keyword.

Comment on lines +19 to +20
const value = normalizedErrors["https://json-schema.org/validation"][schemaLocation];
if (value === false) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This needs a better name. Try,

Suggested change
const value = normalizedErrors["https://json-schema.org/validation"][schemaLocation];
if (value === false) {
const isValid = normalizedErrors["https://json-schema.org/validation"][schemaLocation];
if (!isValid) {

const value = normalizedErrors["https://json-schema.org/validation"][schemaLocation];
if (value === false) {
errors.push({
message: localization.getNotErrorMessage(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is not the right error message. This is for the not keyword. I think you're going to need to create a new message for this case.

@Pravalika-Batchu

Copy link
Copy Markdown
Author

Hi Jason — thanks a lot for the review and for the helpful guidance.
Apologies for opening the PR without prior discussion — I’ll make sure to discuss non-trivial changes first going forward.

Summary of changes based on your feedback

Centralized false-schema handling in validation.js. This removes the brittle endsWith heuristic and instead relies on !isValid.

Removed the per-keyword false-schema message from additionalProperties.js to avoid mixing approaches.

Added a dedicated localization helper getBooleanSchemaErrorMessage() in localization.js, along with the boolean-schema-error entry in en-US.ftl.

Updated expectations in keyword-error-message.test.js.

Fixed lint issues and cleaned up code style (prefixed unused args, removed an unused import).

Ran lint and tests locally — everything is passing.

Design tradeoffs & alternatives

Current approach: Using a single centralized handler avoids duplicating logic across applicator keywords and keeps behavior consistent. The error message is intentionally generic:

“The instance is not allowed by the schema.”

Alternative: Handling false schemas on a per-keyword basis would allow more specific, contextual messages (for example, additionalProperties reporting which property is disallowed). The downside is that it would require adding similar logic across all relevant applicators, increasing code size and maintenance overhead.

Since mixing both approaches can lead to inconsistency, I removed the per-keyword handling from additionalProperties and kept everything aligned with the centralized approach.

@jdesrosiers jdesrosiers left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sounds like you have the right idea. However, I see that you pushed a bunch of commits, but nothing has actually changed. Have a look at the "Files changed" tab.

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.

Missing error message for Boolean schemas

4 participants