Skip to content

Commit 51f6901

Browse files
author
Keith Broughton
committed
Handle empty tags
1 parent 00cb70b commit 51f6901

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { getServices } from './getServices';
2+
3+
describe('getServices', () => {
4+
it('should create a unnamed service if tags are empty', () => {
5+
const services = getServices({
6+
openapi: '3',
7+
info: { title: 'x', version: '1' },
8+
paths: {
9+
'/api/trips': {
10+
get: { tags: [], responses: { 200: { description: 'X' }, default: { description: 'default' } } },
11+
},
12+
},
13+
});
14+
15+
expect(services).toHaveLength(1);
16+
expect(services[0].name).toEqual('Unnamed');
17+
});
18+
});

src/openApi/v3/parser/getServices.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ export function getServices(openApi: OpenApi): Service[] {
2828
case 'patch':
2929
// Each method contains an OpenAPI operation, we parse the operation
3030
const op = path[method]!;
31-
const tags = op.tags?.filter(unique) || ['Service'];
31+
const uniqueTags = op.tags?.filter(unique);
32+
const tags = uniqueTags?.length ? uniqueTags : ['Unnamed'];
3233
tags.forEach(tag => {
3334
const operation = getOperation(openApi, url, method, tag, op, pathParams);
3435

0 commit comments

Comments
 (0)