Skip to content

Commit cc62e3a

Browse files
committed
fix(schemaregistry): add support for format to validation
1 parent 8071cac commit cc62e3a

4 files changed

Lines changed: 238 additions & 17 deletions

File tree

package-lock.json

Lines changed: 41 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

schemaregistry/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"@types/simple-oauth2": "^5.0.7",
4545
"@types/validator": "^13.12.0",
4646
"ajv": "^8.17.1",
47+
"ajv-formats": "^3.0.1",
4748
"async-mutex": "^0.5.0",
4849
"avsc": "^5.7.7",
4950
"axios": "^1.12.0",

schemaregistry/serde/json.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
import Ajv, {ErrorObject} from "ajv";
1414
import Ajv2019 from "ajv/dist/2019";
1515
import Ajv2020 from "ajv/dist/2020";
16+
import addFormats from "ajv-formats";
1617
import * as draft6MetaSchema from 'ajv/dist/refs/json-schema-draft-06.json'
1718
import * as draft7MetaSchema from 'ajv/dist/refs/json-schema-draft-07.json'
1819
import {
@@ -272,13 +273,15 @@ async function toValidateFunction(
272273
if (spec === 'http://json-schema.org/draft/2020-12/schema'
273274
|| spec === 'https://json-schema.org/draft/2020-12/schema') {
274275
const ajv2020 = new Ajv2020({ ...conf as JsonSerdeConfig, allErrors: true })
276+
addFormats(ajv2020)
275277
ajv2020.addKeyword("confluent:tags")
276278
deps.forEach((schema, name) => {
277279
ajv2020.addSchema(JSON.parse(schema), name)
278280
})
279281
fn = ajv2020.compile(json)
280282
} else {
281283
const ajv = new Ajv2019({ ...conf as JsonSerdeConfig, allErrors: true })
284+
addFormats(ajv)
282285
ajv.addKeyword("confluent:tags")
283286
ajv.addMetaSchema(draft6MetaSchema)
284287
ajv.addMetaSchema(draft7MetaSchema)
@@ -504,6 +507,3 @@ function disjoint(tags1: Set<string>, tags2: Set<string>): boolean {
504507
}
505508
return true
506509
}
507-
508-
509-

0 commit comments

Comments
 (0)