From c0f52b1622f5802381cf6baafc08ddf46eaea671 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Berg=C3=A9?= Date: Thu, 27 Feb 2025 16:49:16 +0100 Subject: [PATCH] Fix logic to filter groups --- integrations/openapi/src/parser/spec.test.ts | 2 +- integrations/openapi/src/parser/spec.ts | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/integrations/openapi/src/parser/spec.test.ts b/integrations/openapi/src/parser/spec.test.ts index 793621a92..9fa449154 100644 --- a/integrations/openapi/src/parser/spec.test.ts +++ b/integrations/openapi/src/parser/spec.test.ts @@ -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'); diff --git a/integrations/openapi/src/parser/spec.ts b/integrations/openapi/src/parser/spec.ts index 5a604c654..bd03faedf 100644 --- a/integrations/openapi/src/parser/spec.ts +++ b/integrations/openapi/src/parser/spec.ts @@ -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((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;