Merge pull request #929 from keithbro/handle-empty-tags

Handle empty tags
This commit is contained in:
Ferdi Koomen 2022-01-24 18:31:55 +01:00 committed by GitHub
commit 5a8457fee8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -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');
});
});

View File

@ -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);