@@ -54,6 +54,11 @@ export interface SchemaRegistryAvroSerializerOptions {
5454 * Automatic schema registration is NOT recommended for production scenarios.
5555 */
5656 autoRegisterSchemas ?: boolean ;
57+ /**
58+ * The group name to be used when registering/looking up a schema. Must be specified
59+ * if you will be calling `serialize`.
60+ */
61+ groupName ?: string ;
5762}
5863
5964/**
@@ -66,21 +71,14 @@ export class SchemaRegistryAvroSerializer {
6671 *
6772 * @param client - Schema Registry where schemas are registered and obtained.
6873 * Usually this is a SchemaRegistryClient instance.
69- *
70- * @param groupName - The schema group to use when making requests to the
71- * registry.
7274 */
73- constructor (
74- client : SchemaRegistry ,
75- groupName : string ,
76- options ?: SchemaRegistryAvroSerializerOptions
77- ) {
75+ constructor ( client : SchemaRegistry , options ?: SchemaRegistryAvroSerializerOptions ) {
7876 this . registry = client ;
79- this . schemaGroup = groupName ;
77+ this . schemaGroup = options ?. groupName ;
8078 this . autoRegisterSchemas = options ?. autoRegisterSchemas ?? false ;
8179 }
8280
83- private readonly schemaGroup : string ;
81+ private readonly schemaGroup ? : string ;
8482 private readonly registry : SchemaRegistry ;
8583 private readonly autoRegisterSchemas : boolean ;
8684
@@ -190,6 +188,12 @@ export class SchemaRegistryAvroSerializer {
190188 throw new Error ( "Schema must have a name." ) ;
191189 }
192190
191+ if ( ! this . schemaGroup ) {
192+ throw new Error (
193+ "Schema group must have been specified in the constructor options when the client was created in order to serialize."
194+ ) ;
195+ }
196+
193197 const description : SchemaDescription = {
194198 groupName : this . schemaGroup ,
195199 name : avroType . name ,
0 commit comments