@@ -39,7 +39,15 @@ const rootSchema = `
3939 }
4040}
4141`
42-
42+ const rootSchema2020_12 = `
43+ {
44+ "$schema": "https://json-schema.org/draft/2020-12/schema",
45+ "type": "object",
46+ "properties": {
47+ "otherField": { "$ref": "DemoSchema" }
48+ }
49+ }
50+ `
4351const demoSchema = `
4452{
4553 "type": "object",
@@ -154,7 +162,10 @@ describe('JsonSerializer', () => {
154162 cacheCapacity : 1000
155163 }
156164 let client = SchemaRegistryClient . newClient ( conf )
157- let ser = new JsonSerializer ( client , SerdeType . VALUE , { autoRegisterSchemas : true } )
165+ let ser = new JsonSerializer ( client , SerdeType . VALUE , {
166+ autoRegisterSchemas : true ,
167+ validate : true
168+ } )
158169 let obj = {
159170 intField : 123 ,
160171 doubleField : 45.67 ,
@@ -205,7 +216,10 @@ describe('JsonSerializer', () => {
205216 cacheCapacity : 1000
206217 }
207218 let client = SchemaRegistryClient . newClient ( conf )
208- let ser = new JsonSerializer ( client , SerdeType . VALUE , { autoRegisterSchemas : true } )
219+ let ser = new JsonSerializer ( client , SerdeType . VALUE , {
220+ autoRegisterSchemas : true ,
221+ validate : true
222+ } )
209223
210224 let obj = {
211225 intField : 123 ,
@@ -226,7 +240,10 @@ describe('JsonSerializer', () => {
226240 cacheCapacity : 1000
227241 }
228242 let client = SchemaRegistryClient . newClient ( conf )
229- let ser = new JsonSerializer ( client , SerdeType . VALUE , { useLatestVersion : true } )
243+ let ser = new JsonSerializer ( client , SerdeType . VALUE , {
244+ useLatestVersion : true ,
245+ validate : true
246+ } )
230247
231248 let info : SchemaInfo = {
232249 schemaType : 'JSON' ,
@@ -258,6 +275,47 @@ describe('JsonSerializer', () => {
258275 let obj2 = await deser . deserialize ( topic , bytes )
259276 expect ( obj2 ) . toEqual ( obj )
260277 } )
278+ it ( 'serialize reference 2020_12' , async ( ) => {
279+ let conf : ClientConfig = {
280+ baseURLs : [ baseURL ] ,
281+ cacheCapacity : 1000
282+ }
283+ let client = SchemaRegistryClient . newClient ( conf )
284+ let ser = new JsonSerializer ( client , SerdeType . VALUE , {
285+ useLatestVersion : true ,
286+ validate : true
287+ } )
288+
289+ let info : SchemaInfo = {
290+ schemaType : 'JSON' ,
291+ schema : demoSchema2020_12
292+ }
293+ await client . register ( 'demo-value' , info , false )
294+
295+ info = {
296+ schemaType : 'JSON' ,
297+ schema : rootSchema2020_12 ,
298+ references : [ {
299+ name : 'DemoSchema' ,
300+ subject : 'demo-value' ,
301+ version : 1
302+ } ]
303+ }
304+ await client . register ( subject , info , false )
305+
306+ let obj = {
307+ intField : 123 ,
308+ doubleField : 45.67 ,
309+ stringField : 'hi' ,
310+ boolField : true ,
311+ bytesField : Buffer . from ( [ 0 , 0 , 0 , 1 ] ) . toString ( 'base64' )
312+ }
313+ let bytes = await ser . serialize ( topic , obj )
314+
315+ let deser = new JsonDeserializer ( client , SerdeType . VALUE , { } )
316+ let obj2 = await deser . deserialize ( topic , bytes )
317+ expect ( obj2 ) . toEqual ( obj )
318+ } )
261319 it ( 'basic failing validation' , async ( ) => {
262320 let conf : ClientConfig = {
263321 baseURLs : [ baseURL ] ,
0 commit comments