Skip to content
This repository has been archived by the owner on Feb 5, 2025. It is now read-only.

Commit

Permalink
Fixed #48
Browse files Browse the repository at this point in the history
  • Loading branch information
Jessewb786 committed Jan 28, 2025
1 parent 063c489 commit 7a4ffe2
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 1 deletion.
49 changes: 49 additions & 0 deletions src/test/openapi-files/ref-example-with-versioned-message.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
openapi: '3.0.0'
info:
title: Test Service
version: 1.1.0

paths:
/v1/users:
get:
operationId: users
summary: List all users
responses:
200:
description: A list of users
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/UserSignup'
/v2/users:
get:
operationId: users2
summary: List all users
x-eventcatalog-message-version: 2.0.0
description: |
Returns a list of all users.
This operation is **deprecated**.
responses:
200:
description: A list of users
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/UserSignup'
components:
schemas:
UserSignup:
$ref: 'ref-example-signup-message.yml'

Date:
type: string
format: date

DateWithExample:
$ref: '#/components/schemas/Date'
description: Date schema extended with a `default` value... Or not?
default: 2000-01-01
54 changes: 54 additions & 0 deletions src/test/plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,60 @@ describe('OpenAPI EventCatalog Plugin', () => {
);
});

it('messages that do not have an `x-eventcatalog-message-version` header defined take the version of the service', async () => {
const { getQuery } = utils(catalogDir);

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

const command = await getQuery('users');

const dir = await fs.readdir(join(catalogDir, 'queries'));

console.log(dir);

const file = await fs.readFile(join(catalogDir, 'queries', 'users', 'index.md'));
expect(file).toBeDefined();

expect(command).toEqual(
expect.objectContaining({
id: 'users',
version: '1.1.0',
name: 'users',
summary: 'List all users',
badges: [{ content: 'GET', textColor: 'blue', backgroundColor: 'blue' }],
})
);
});

it('messages that do have an `x-eventcatalog-message-version` header defined take it as the version', async () => {
const { getQuery } = utils(catalogDir);

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

const command = await getQuery('users2');

const dir = await fs.readdir(join(catalogDir, 'queries'));

console.log(dir);

const file = await fs.readFile(join(catalogDir, 'queries', 'users2', 'index.md'));
expect(file).toBeDefined();

expect(command).toEqual(
expect.objectContaining({
id: 'users2',
version: '2.0.0',
name: 'users2',
summary: 'List all users',
badges: [{ content: 'GET', textColor: 'blue', backgroundColor: 'blue' }],
})
);
});

describe('OpenAPI eventcatalog extensions', () => {
it('messages marked as "events" using the custom `x-eventcatalog-message-type` header in an OpenAPI are documented in EventCatalog as events ', async () => {
const { getEvent } = utils(catalogDir);
Expand Down
2 changes: 1 addition & 1 deletion 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 7a4ffe2

Please sign in to comment.