[Typescript] fix(schemaregistry): add support for format to validation#443
Conversation
There was a problem hiding this comment.
Pull request overview
Adds JSON Schema format validation support in the Schema Registry JSON serde so schemas with format annotations can be compiled/validated successfully.
Changes:
- Add
ajv-formatsdependency to the schemaregistry workspace. - Register standard format validators on both Ajv2019 and Ajv2020 instances used for message validation.
- Add Jest coverage for validating common formats (email, uri, date-time, ipv4, uuid).
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| schemaregistry/serde/json.ts | Hooks ajv-formats into the Ajv validators created for JSON schema validation. |
| schemaregistry/test/serde/json.spec.ts | Adds a new test that validates serialization behavior for schemas using format. |
| schemaregistry/package.json | Declares ajv-formats runtime dependency. |
| package-lock.json | Updates lockfile to include ajv-formats (and additional lockfile metadata changes). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const schemaWithFormats = ` | ||
| { | ||
| "type": "object", | ||
| "properties": { | ||
| "email": { | ||
| "type": "string", | ||
| "format": "email" |
There was a problem hiding this comment.
schemaWithFormats does not include a $schema declaration, so this test only exercises the non-2020-12 validation path in toValidateFunction. Since this PR adds addFormats in both Ajv2019 and Ajv2020 branches, add an additional test case (or extend this schema) that sets $schema to the 2020-12 URI to cover the Ajv2020 path as well.
74107ca to
cc62e3a
Compare
|
/sem-approve |
2 similar comments
|
/sem-approve |
|
/sem-approve |
|
/sem-approve |
Please prefix all TypeScript pull-requests with
[Typescript]What
Add support for format validation to json schema registry serde. without this, any schema containing format annotations seems to error.
Checklist
References
JIRA: No JIRA Ticket
Test & Review
Has been tested by adding unit tests with format annotations defined. Also have a patched version of this package in use in a local utility package in use at my company.
Open questions / Follow-ups