diff --git a/src/SchemaRegistry.ts b/src/SchemaRegistry.ts index bc7bb3e..c98a02a 100644 --- a/src/SchemaRegistry.ts +++ b/src/SchemaRegistry.ts @@ -112,7 +112,7 @@ export default class SchemaRegistry { const helper = helperTypeFromSchemaType(confluentSchema.type) const schemaInstance = schemaFromConfluentSchema(confluentSchema, this.options) helper.validate(schemaInstance) - + let isFirstTimeRegistration = false let subject: ConfluentSubject if (userOpts?.subject) { subject = { @@ -134,10 +134,8 @@ export default class SchemaRegistry { } catch (error) { if (error.status !== 404) { throw error - } - - if (compatibility) { - await this.api.Subject.updateConfig({ subject: subject.name, body: { compatibility } }) + } else { + isFirstTimeRegistration = true } } @@ -149,6 +147,10 @@ export default class SchemaRegistry { }, }) + if (compatibility && isFirstTimeRegistration) { + await this.api.Subject.updateConfig({ subject: subject.name, body: { compatibility } }) + } + const registeredSchema: RegisteredSchema = response.data() this.cache.setLatestRegistryId(subject.name, registeredSchema.id) this.cache.setSchema(registeredSchema.id, confluentSchema.type, schemaInstance)