Skip to content

Commit

Permalink
Fix logic to filter groups
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge committed Feb 27, 2025
1 parent 6c28dce commit c0f52b1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion integrations/openapi/src/parser/spec.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('#divideOpenAPISpecSchema', () => {
it('respects the tags', async () => {
const schema = await dereferenceOpenAPISpec(rawSpec);
// Change the order of tags
schema.tags = [{ name: 'store' }, { name: 'pet' }];
schema.tags = [{ name: 'store' }, { name: 'pet' }, { name: 'unknown' }];
const groups = divideOpenAPISpecSchema(schema);
expect(groups).toHaveLength(2);
expect(groups[0].id).toBe('store');
Expand Down
10 changes: 6 additions & 4 deletions integrations/openapi/src/parser/spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,13 @@ export function divideOpenAPISpecSchema(schema: OpenAPIV3.Document): OpenAPIGrou

// If the schema has tags, use this order to sort the groups.
if (schema.tags) {
return schema.tags.map((tag) => {
return schema.tags.reduce<OpenAPIGroup[]>((tagGroups, tag) => {
const group = groups.find((group) => group.id === tag.name);
assert(group, `Group not found for tag ${tag.name}`);
return group;
});
if (group) {
tagGroups.push(group);
}
return tagGroups;
}, []);
}

return groups;
Expand Down

0 comments on commit c0f52b1

Please sign in to comment.