Skip to content

Conversation

@srivastava-diya
Copy link
Contributor

Fix: Add support for format keyword across all JSON Schema dialects

This PR updates the formatter to handle the format keyword for every JSON Schema dialect that Hyperjump supports.

What was wrong

Recent updates in @hyperjump/json-schema changed the format keyword to have dialect-specific URIs (2020-12, 2019-09, draft-07, draft-06, draft-04).The formatter still relied on the old URI, which no longer exists.As a result, tests like format: email were failing.

What I changed

1. Added normalization support for all dialect format URIs

  • https://json-schema.org/keyword/draft-2020-12/format
  • https://json-schema.org/keyword/draft-2019-09/format
  • https://json-schema.org/keyword/draft-07/format
  • https://json-schema.org/keyword/draft-06/format
  • https://json-schema.org/keyword/draft-04/format

2. Updated error handler

The handler now checks for all dialect-specific format URIs, instead of assuming a single URI.

3. Added tests for all dialects

Added format: email tests for:

  • draft-2020-12
  • draft-2019-09
  • draft-07
  • draft-06
  • draft-04

All tests now pass.
This PR fixes #90

Result

Formatting errors for format: email now work consistently across all supported dialects.

@jdesrosiers Please let me know if you'd like any follow-ups or adjustments.

Copy link
Collaborator

@arpitkuriyal arpitkuriyal left a comment

Choose a reason for hiding this comment

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

Please ensure there are no linting errors in your PR by running npm run lint before creating a PR.
I guess, it’s not necessary to test every dialect, one test case is sufficient.

@srivastava-diya
Copy link
Contributor Author

Please ensure there are no linting errors in your PR by running npm run lint before creating a PR. I guess, it’s not necessary to test every dialect, one test case is sufficient.

sure @arpitkuriyal , i forgot to run lint test at the end , but i have fixed it now.

Copy link
Collaborator

@arpitkuriyal arpitkuriyal left a comment

Choose a reason for hiding this comment

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

The current tests contain a lot of repetition. If we still want to verify behavior across all dialects, we can replace the duplicated tests with a single parameterized test like this

const dialects = [
  { name: "draft-2020-12", schema: "https://json-schema.org/draft/2020-12/schema" },
  { name: "draft-2019-09", schema: "https://json-schema.org/draft/2019-09/schema" },
  { name: "draft-07",      schema: "http://json-schema.org/draft-07/schema" },
  { name: "draft-06",      schema: "http://json-schema.org/draft-06/schema" },
  { name: "draft-04",      schema: "http://json-schema.org/draft-04/schema" }
];

for (const { name, schema } of dialects) {
  test(`format: email (${name})`, async () => {
    registerSchema({
      $schema: schema,
      format: "email"
    }, schemaUri);

    const instance = "not-an-email";
    const output = {
      valid: false,
      errors: [
        {
          absoluteKeywordLocation: "https://example.com/main#/format",
          instanceLocation: "#"
        }
      ]
    };

    const result = await betterJsonSchemaErrors(output, schemaUri, instance);

    expect(result.errors).to.eql([
      {
        schemaLocation: "https://example.com/main#/format",
        instanceLocation: "#",
        message: localization.getFormatErrorMessage("email")
      }
    ]);
  });
}

@srivastava-diya
Copy link
Contributor Author

The current tests contain a lot of repetition. If we still want to verify behavior across all dialects, we can replace the duplicated tests with a single parameterized test like this

hey @arpitkuriyal i think i have addressed the situation, thanks a lot for the help.

Copy link
Collaborator

@arpitkuriyal arpitkuriyal left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Collaborator

@jdesrosiers jdesrosiers left a comment

Choose a reason for hiding this comment

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

Looks good! Vitest actually has special syntax for parameterized tests, but I don't see any reason why it would be preferable to use that over what you did here.

@jdesrosiers jdesrosiers merged commit 9380015 into hyperjump-io:main Nov 28, 2025
1 check passed
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.

PROPOSAL : Fixing format: email Test Failure

3 participants