Skip to content

Commit 500f15c

Browse files
Keith Broughtonmoretalk
authored andcommitted
Handle empty tags
(cherry picked from commit 51f6901)
1 parent 608a567 commit 500f15c

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export function getServices(openApi: OpenApi): Service[] {
3030
case 'patch':
3131
// Each method contains an OpenAPI operation, we parse the operation
3232
const op = path[method]!;
33-
34-
let tags = op.tags?.filter(unique) || ['Service'];
33+
const uniqueTags = op.tags?.filter(unique);
34+
let tags = uniqueTags?.length ? uniqueTags : ['Unnamed'];
3535

3636
//Remove Tags that are not in the x-tagGroups Extension
3737
if (tagGroups) {

0 commit comments

Comments
 (0)