diff --git a/.changeset/ten-knives-tell.md b/.changeset/ten-knives-tell.md new file mode 100644 index 0000000..4339c75 --- /dev/null +++ b/.changeset/ten-knives-tell.md @@ -0,0 +1,5 @@ +--- +"@eventcatalog/generator-asyncapi": patch +--- + +fix(plugin): owner and repo are now persisted between builds versions diff --git a/package.json b/package.json index 38eeb89..0988e07 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "dependencies": { "@asyncapi/avro-schema-parser": "^3.0.24", "@asyncapi/parser": "^3.3.0", - "@eventcatalog/sdk": "^1.4.1", + "@eventcatalog/sdk": "^1.4.4", "chalk": "^4", "fs-extra": "^11.2.0", "glob": "^11.0.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ec8f164..86ecc26 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -15,8 +15,8 @@ importers: specifier: ^3.3.0 version: 3.3.0 '@eventcatalog/sdk': - specifier: ^1.4.1 - version: 1.4.1 + specifier: ^1.4.4 + version: 1.4.4 chalk: specifier: ^4 version: 4.1.2 @@ -428,8 +428,8 @@ packages: cpu: [x64] os: [win32] - '@eventcatalog/sdk@1.4.1': - resolution: {integrity: sha512-319ubhnupxA6ylxHgH8GWMRCREvtFNhGmn4bUgmQecElReXcLI1PzvR/ajQ98jxFZeAzZSbn8eDppn7v2W+HOw==} + '@eventcatalog/sdk@1.4.4': + resolution: {integrity: sha512-N+DuPoLmaqGt8IaqTWfvdsL3B2t5oMCkNa5Yfs4wl6HFRMrd5AP586jXk684untD8g324ztN0fQAdlmnHtIxMg==} '@isaacs/cliui@8.0.2': resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} @@ -2310,7 +2310,7 @@ snapshots: '@esbuild/win32-x64@0.23.1': optional: true - '@eventcatalog/sdk@1.4.1': + '@eventcatalog/sdk@1.4.4': dependencies: '@changesets/cli': 2.27.9 fs-extra: 11.2.0 diff --git a/src/index.ts b/src/index.ts index 422c674..f54837a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -163,6 +163,9 @@ export default async (config: any, options: Props) => { let sends = []; let receives = []; + let owners = null; + let repository = null; + let serviceSpecifications = {}; let serviceSpecificationsFiles = []; let serviceMarkdown = generateMarkdownForService(document); @@ -352,6 +355,9 @@ export default async (config: any, options: Props) => { if (latestServiceInCatalog) { serviceMarkdown = latestServiceInCatalog.markdown; + owners = latestServiceInCatalog.owners || ([] as any); + repository = latestServiceInCatalog.repository || null; + // Found a service, and versions do not match, we need to version the one already there if (latestServiceInCatalog.version !== version) { await versionService(serviceId); @@ -386,6 +392,8 @@ export default async (config: any, options: Props) => { ...serviceSpecifications, asyncapiPath: fileName || 'asyncapi.yml', }, + ...(owners && { owners }), + ...(repository && { repository }), }, { override: true, diff --git a/src/test/plugin.test.ts b/src/test/plugin.test.ts index 7d37022..9bc4345 100644 --- a/src/test/plugin.test.ts +++ b/src/test/plugin.test.ts @@ -211,6 +211,53 @@ describe('AsyncAPI EventCatalog Plugin', () => { ); }); + it('when the AsyncAPI service is already defined in EventCatalog and the versions match, the owners and repo are persisted', async () => { + // Create a service with the same name and version as the AsyncAPI file for testing + const { writeService, getService } = utils(catalogDir); + + await writeService({ + id: 'account-service', + version: '1.0.0', + name: 'Random Name', + owners: ['dboyne'], + repository: { + language: 'typescript', + url: 'https://github.com/dboyne/eventcatalog', + }, + markdown: 'Here is my original markdown, please do not override this!', + }); + + await plugin(config, { services: [{ path: join(asyncAPIExamplesDir, 'simple.asyncapi.yml'), id: 'account-service' }] }); + + const service = await getService('account-service', '1.0.0'); + expect(service).toEqual( + expect.objectContaining({ + id: 'account-service', + name: 'Account Service', + version: '1.0.0', + summary: 'This service is in charge of processing user signups', + owners: ['dboyne'], + repository: { + language: 'typescript', + url: 'https://github.com/dboyne/eventcatalog', + }, + markdown: 'Here is my original markdown, please do not override this!', + badges: [ + { + content: 'Events', + textColor: 'blue', + backgroundColor: 'blue', + }, + { + content: 'Authentication', + textColor: 'blue', + backgroundColor: 'blue', + }, + ], + }) + ); + }); + it('when the AsyncAPI service is already defined in EventCatalog and the versions do not match, a new service is created and the old one is versioned', async () => { // Create a service with the same name and version as the AsyncAPI file for testing const { writeService, getService } = utils(catalogDir);