@@ -73,7 +73,7 @@ export class JsonSerializer extends Serializer implements JsonSerde {
7373 throw new Error ( 'message is empty' )
7474 }
7575
76- const jsonSchema = generateSchema ( msg )
76+ const jsonSchema = JsonSerializer . messageToSchema ( msg )
7777 const schema : SchemaInfo = {
7878 schemaType : 'JSON' ,
7979 schema : JSON . stringify ( jsonSchema ) ,
@@ -92,14 +92,14 @@ export class JsonSerializer extends Serializer implements JsonSerde {
9292 }
9393
9494 async fieldTransform ( ctx : RuleContext , fieldTransform : FieldTransform , msg : any ) : Promise < any > {
95- const schema = this . toType ( ctx . target )
95+ const schema = await this . toType ( ctx . target )
9696 if ( typeof schema === 'boolean' ) {
9797 return msg
9898 }
9999 return await transform ( ctx , schema , '$' , msg , fieldTransform )
100100 }
101101
102- toType ( info : SchemaInfo ) : DereferencedJSONSchema {
102+ async toType ( info : SchemaInfo ) : Promise < DereferencedJSONSchema > {
103103 return toType ( this . client , this . conf as JsonDeserializerConfig , this , info , async ( client , info ) => {
104104 const deps = new Map < string , string > ( )
105105 await this . resolveReferences ( client , info , deps )
@@ -115,6 +115,10 @@ export class JsonSerializer extends Serializer implements JsonSerde {
115115 } ,
116116 )
117117 }
118+
119+ static messageToSchema ( msg : any ) : DereferencedJSONSchema {
120+ return generateSchema ( msg )
121+ }
118122}
119123
120124export type JsonDeserializerConfig = DeserializerConfig & JsonSerdeConfig
@@ -173,7 +177,7 @@ export class JsonDeserializer extends Deserializer implements JsonSerde {
173177 }
174178
175179 async fieldTransform ( ctx : RuleContext , fieldTransform : FieldTransform , msg : any ) : Promise < any > {
176- const schema = this . toType ( ctx . target )
180+ const schema = await this . toType ( ctx . target )
177181 return await transform ( ctx , schema , '$' , msg , fieldTransform )
178182 }
179183
@@ -211,14 +215,17 @@ async function toValidateFunction(
211215
212216 const json = JSON . parse ( info . schema )
213217 const spec = json . $schema
214- if ( spec === 'http://json-schema.org/draft/2020-12/schema' ) {
218+ if ( spec === 'http://json-schema.org/draft/2020-12/schema'
219+ || spec === 'https://json-schema.org/draft/2020-12/schema' ) {
215220 const ajv2020 = new Ajv2020 ( conf as JsonSerdeConfig )
221+ ajv2020 . addKeyword ( "confluent:tags" )
216222 deps . forEach ( ( schema , name ) => {
217223 ajv2020 . addSchema ( JSON . parse ( schema ) , name )
218224 } )
219225 fn = ajv2020 . compile ( json )
220226 } else {
221227 const ajv = new Ajv2019 ( conf as JsonSerdeConfig )
228+ ajv . addKeyword ( "confluent:tags" )
222229 ajv . addMetaSchema ( draft6MetaSchema )
223230 ajv . addMetaSchema ( draft7MetaSchema )
224231 deps . forEach ( ( schema , name ) => {
0 commit comments