diff --git a/src/openApi/v3/parser/getServices.spec.ts b/src/openApi/v3/parser/getServices.spec.ts new file mode 100644 index 00000000..2530ddab --- /dev/null +++ b/src/openApi/v3/parser/getServices.spec.ts @@ -0,0 +1,18 @@ +import { getServices } from './getServices'; + +describe('getServices', () => { + it('should create a unnamed service if tags are empty', () => { + const services = getServices({ + openapi: '3', + info: { title: 'x', version: '1' }, + paths: { + '/api/trips': { + get: { tags: [], responses: { 200: { description: 'X' }, default: { description: 'default' } } }, + }, + }, + }); + + expect(services).toHaveLength(1); + expect(services[0].name).toEqual('Unnamed'); + }); +}); diff --git a/src/openApi/v3/parser/getServices.ts b/src/openApi/v3/parser/getServices.ts index 486608fd..f2375962 100644 --- a/src/openApi/v3/parser/getServices.ts +++ b/src/openApi/v3/parser/getServices.ts @@ -28,7 +28,8 @@ export function getServices(openApi: OpenApi): Service[] { case 'patch': // Each method contains an OpenAPI operation, we parse the operation const op = path[method]!; - const tags = op.tags?.filter(unique) || ['Service']; + const uniqueTags = op.tags?.filter(unique); + const tags = uniqueTags?.length ? uniqueTags : ['Unnamed']; tags.forEach(tag => { const operation = getOperation(openApi, url, method, tag, op, pathParams);