@@ -73,7 +73,7 @@ export class JsonSerializer extends Serializer implements JsonSerde {
73
73
throw new Error ( 'message is empty' )
74
74
}
75
75
76
- const jsonSchema = generateSchema ( msg )
76
+ const jsonSchema = JsonSerializer . messageToSchema ( msg )
77
77
const schema : SchemaInfo = {
78
78
schemaType : 'JSON' ,
79
79
schema : JSON . stringify ( jsonSchema ) ,
@@ -92,14 +92,14 @@ export class JsonSerializer extends Serializer implements JsonSerde {
92
92
}
93
93
94
94
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 )
96
96
if ( typeof schema === 'boolean' ) {
97
97
return msg
98
98
}
99
99
return await transform ( ctx , schema , '$' , msg , fieldTransform )
100
100
}
101
101
102
- toType ( info : SchemaInfo ) : DereferencedJSONSchema {
102
+ async toType ( info : SchemaInfo ) : Promise < DereferencedJSONSchema > {
103
103
return toType ( this . client , this . conf as JsonDeserializerConfig , this , info , async ( client , info ) => {
104
104
const deps = new Map < string , string > ( )
105
105
await this . resolveReferences ( client , info , deps )
@@ -115,6 +115,10 @@ export class JsonSerializer extends Serializer implements JsonSerde {
115
115
} ,
116
116
)
117
117
}
118
+
119
+ static messageToSchema ( msg : any ) : DereferencedJSONSchema {
120
+ return generateSchema ( msg )
121
+ }
118
122
}
119
123
120
124
export type JsonDeserializerConfig = DeserializerConfig & JsonSerdeConfig
@@ -173,7 +177,7 @@ export class JsonDeserializer extends Deserializer implements JsonSerde {
173
177
}
174
178
175
179
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 )
177
181
return await transform ( ctx , schema , '$' , msg , fieldTransform )
178
182
}
179
183
@@ -211,14 +215,17 @@ async function toValidateFunction(
211
215
212
216
const json = JSON . parse ( info . schema )
213
217
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' ) {
215
220
const ajv2020 = new Ajv2020 ( conf as JsonSerdeConfig )
221
+ ajv2020 . addKeyword ( "confluent:tags" )
216
222
deps . forEach ( ( schema , name ) => {
217
223
ajv2020 . addSchema ( JSON . parse ( schema ) , name )
218
224
} )
219
225
fn = ajv2020 . compile ( json )
220
226
} else {
221
227
const ajv = new Ajv2019 ( conf as JsonSerdeConfig )
228
+ ajv . addKeyword ( "confluent:tags" )
222
229
ajv . addMetaSchema ( draft6MetaSchema )
223
230
ajv . addMetaSchema ( draft7MetaSchema )
224
231
deps . forEach ( ( schema , name ) => {
0 commit comments