Skip to content

Commit

Permalink
Merge pull request #37 from event-catalog/added-support-for-independe…
Browse files Browse the repository at this point in the history
…nt-message-versioning-on-openapi

feat(plugin): now supports x-eventcatalog-message-version
  • Loading branch information
boyney123 authored Feb 6, 2025
2 parents d61e5ed + f7b8f68 commit 97cc279
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .changeset/late-spiders-serve.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@eventcatalog/generator-openapi": patch
---

feat(plugin): now supports x-eventcatalog-message-version
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ All plugins require a license key. You can get a license key from [EventCatalog
- [Mapping commands, events and queries using the `x-eventcatalog-message-type` extension](./examples/generator-asyncapi/mapping-commands-events-queries/)
- [Independent Message Versioning using the `x-eventcatalog-message-version` extension](./examples/generator-asyncapi/independent-message-versioning/)
- [Message Ownership using the `x-eventcatalog-role` extension to control which service owns a message](./examples/generator-asyncapi/message-ownership/)
- EventCatalog will parse all messages, sometimes this leads to duplicated messages being created.
- The `x-eventcatalog-role` extension can be used to control which service owns a message.
- This is useful when you have multiple AsyncAPI files that define the same message.
- EventCatalog will parse all messages, sometimes this leads to duplicated messages being created.
- The `x-eventcatalog-role` extension can be used to control which service owns a message.
- This is useful when you have multiple AsyncAPI files that define the same message.

**EventBridge Integrations**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ paths:
x-eventcatalog-message-type: query # This is a query operation
x-eventcatalog-message-name: List Pets # Name used in EventCatalog
x-eventcatalog-message-id: list-pets # ID value used in EventCatalog
x-eventcatalog-message-version: 5.0.0
parameters:
- name: limit
in: query
Expand Down
21 changes: 15 additions & 6 deletions packages/generator-openapi/src/test/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ describe('OpenAPI EventCatalog Plugin', () => {

expect(service.receives).toHaveLength(4);
expect(service.receives).toEqual([
{ id: 'list-pets', version: '1.0.0' },
{ id: 'list-pets', version: '5.0.0' },
{ id: 'createPets', version: '1.0.0' },
{ id: 'showPetById', version: '1.0.0' },
{ id: 'petAdopted', version: '1.0.0' },
Expand Down Expand Up @@ -528,7 +528,7 @@ describe('OpenAPI EventCatalog Plugin', () => {
expect(service.receives).toHaveLength(5);
expect(service.receives).toEqual([
{ id: 'userloggedin', version: '1.0.0' },
{ id: 'list-pets', version: '1.0.0' },
{ id: 'list-pets', version: '5.0.0' },
{ id: 'createPets', version: '1.0.0' },
{ id: 'showPetById', version: '1.0.0' },
{ id: 'petAdopted', version: '1.0.0' },
Expand All @@ -546,7 +546,7 @@ describe('OpenAPI EventCatalog Plugin', () => {
name: 'Random Name',
markdown: 'Here is my original markdown, please do not override this!',
receives: [
{ id: 'list-pets', version: '1.0.0' },
{ id: 'list-pets', version: '5.0.0' },
{ id: 'createPets', version: '1.0.0' },
],
},
Expand All @@ -559,7 +559,7 @@ describe('OpenAPI EventCatalog Plugin', () => {
expect(service.receives).toHaveLength(4);

expect(service.receives).toEqual([
{ id: 'list-pets', version: '1.0.0' },
{ id: 'list-pets', version: '5.0.0' },
{ id: 'createPets', version: '1.0.0' },
{ id: 'showPetById', version: '1.0.0' },
{ id: 'petAdopted', version: '1.0.0' },
Expand Down Expand Up @@ -601,7 +601,7 @@ describe('OpenAPI EventCatalog Plugin', () => {
expect(command).toEqual(
expect.objectContaining({
id: 'list-pets',
version: '1.0.0',
version: '5.0.0',
name: 'List Pets',
summary: 'List all pets',
badges: [
Expand Down Expand Up @@ -686,7 +686,7 @@ describe('OpenAPI EventCatalog Plugin', () => {
expect.objectContaining({
id: 'list-pets',
name: 'List Pets',
version: '1.0.0',
version: '5.0.0',
summary: 'List all pets',
})
);
Expand All @@ -699,6 +699,15 @@ describe('OpenAPI EventCatalog Plugin', () => {
const event = await getQuery('list-pets');
expect(event.id).toEqual('list-pets');
});

it('when messages have the `x-eventcatalog-message-version` extension defined, this value is used for the message version', async () => {
const { getQuery } = utils(catalogDir);

await plugin(config, { services: [{ path: join(openAPIExamples, 'petstore.yml'), id: 'swagger-petstore' }] });

const event = await getQuery('list-pets');
expect(event.version).toEqual('5.0.0');
});
});

it('when the message already exists in EventCatalog but the versions do not match, the existing message is versioned', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/generator-openapi/src/utils/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const buildMessage = async (pathToFile: string, document: OpenAPI.Documen

return {
id: extensions['x-eventcatalog-message-id'] || uniqueIdentifier,
version: document.info.version,
version: extensions['x-eventcatalog-message-version'] || document.info.version,
name: extensions['x-eventcatalog-message-name'] || uniqueIdentifier,
summary: getSummary(operation),
markdown: defaultMarkdown(operation, requestBodiesAndResponses),
Expand Down

0 comments on commit 97cc279

Please sign in to comment.