Skip to content

Throw when registering over a schema with a different $id - #146

Open
MohitSAGAR11 wants to merge 1 commit into
hyperjump-io:mainfrom
MohitSAGAR11:fix-register-schema-overwrite
Open

MohitSAGAR11 wants to merge 1 commit into
hyperjump-io:mainfrom
MohitSAGAR11:fix-register-schema-overwrite

Conversation

@MohitSAGAR11

Copy link
Copy Markdown
Contributor

Fixes #142

registerSchema stores a schema at its retrieval URI, but it only checked the schema's $id for an existing entry. Registering a schema with a different $id at the same retrieval URI silently replaced the old one.

Changes

  • registerSchema checks the retrieval URI it's about to write to. It still checks the $id too, so registering a schema whose $id is already registered keeps throwing as before.
  • addSchema is meant to replace schemas, so it now unregisters the retrieval URI as well as the $id. Without this, calling addSchema twice at the same retrieval URI with different $ids would start throwing.
  • Fixed a missing closing quote in the error message.

Tests

Added to lib/schema.spec.ts:

  • duplicate registered schema with a different $id: the case from the issue. Fails without the fix.
  • registered schema with an $id that is already registered: the existing $id check still throws.
  • addSchema replaces a schema with a different $id: addSchema still replaces.

npm test, type-check and lint pass, except the multipleOf suite cases that #140 fixes.

@MohitSAGAR11

Copy link
Copy Markdown
Contributor Author

The 9 CI failures are the 1.5e-8 is not multiple of 1e-8 suite case added in json-schema-org/JSON-Schema-Test-Suite#1254. main fails it too, and #140 fixes it. I will rebase this once #140 is merged.

@SHUBHANSHU602 SHUBHANSHU602 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.

Job 128628431168 in hyperjump-io/json-schema
The job failed because 9 tests across different schema drafts all hit the same multipleOf validation error.

Each failing test checks that 1.5e-8 is not a multiple of 1e-8. The validator returned true, but the test expected false (expected true to equal false). This points to a shared issue in handling very small numbers—likely in the multipleOf validation logic—rather than nine separate draft-specific failures.

@MohitSAGAR11

Copy link
Copy Markdown
Contributor Author

Thanks for looking. That case is fixed in #140, since main fails it too (see my comment above). I'll rebase this PR once #140 is merged.

registerSchema stores a schema at its retrieval URI, but only checked its $id for an existing schema. Registering a schema with a different $id at the same retrieval URI replaced the old one instead of throwing. Check the retrieval URI too, and keep the $id check.

addSchema replaces schemas, so it now unregisters the retrieval URI as well as the $id.

Fixes hyperjump-io#142
@MohitSAGAR11
MohitSAGAR11 force-pushed the fix-register-schema-overwrite branch from 17acf91 to 48e94f2 Compare November 12, 2026 05:38
@MohitSAGAR11

Copy link
Copy Markdown
Contributor Author

Rebased onto main now that #140 is merged. CI is green.

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.

registerSchema silently replaces a schema when the $id is different

2 participants