Skip to content

Commit

Permalink
Merge pull request #201 from evanshortiss/apicurio-compat-register
Browse files Browse the repository at this point in the history
fix apicurio compatibility with register function
  • Loading branch information
Nevon authored Apr 5, 2022
2 parents 68c9fd5 + 5230831 commit 05a3613
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/SchemaRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
}
}

Expand All @@ -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)
Expand Down

0 comments on commit 05a3613

Please sign in to comment.