Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: update getTags() function to handle webhooks #833

Merged
merged 4 commits into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion packages/oas/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,6 @@ export default class Oas {
/**
* Return an array of all tag names that exist on this API definition.
*
* Note: This method right now does **not** factor in webhooks that have tags.
*
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.0.0.md#oasObject}
* @see {@link https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#openapi-object}
Expand All @@ -758,6 +757,20 @@ export default class Oas {
});
});

Object.entries(this.getWebhooks()).forEach(([path, webhooks]) => {
darrenyong marked this conversation as resolved.
Show resolved Hide resolved
Object.values(webhooks).forEach(webhook => {
const tags = webhook.getTags();
if (setIfMissing && !tags.length) {
allTags.add(path);
return;
}

tags.forEach(tag => {
allTags.add(tag.name);
});
});
});

return Array.from(allTags);
}

Expand Down
4 changes: 3 additions & 1 deletion packages/oas/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ describe('#operation()', () => {
responses: {
200: expect.any(Object),
},
tags: expect.any(Array),
});
});

Expand Down Expand Up @@ -1613,8 +1614,9 @@ describe('#getWebhooks()', () => {
});

describe('#getTags()', () => {
it('should all tags that are present in a definition', () => {
it('should return all tags that are present in a definition', () => {
expect(petstore.getTags()).toStrictEqual(['pet', 'store', 'user']);
expect(webhooks.getTags()).toStrictEqual(['Webhooks']);
});

describe('setIfMissing option', () => {
Expand Down