mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
Merge pull request #929 from keithbro/handle-empty-tags
Handle empty tags
This commit is contained in:
commit
5a8457fee8
18
src/openApi/v3/parser/getServices.spec.ts
Normal file
18
src/openApi/v3/parser/getServices.spec.ts
Normal 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');
|
||||
});
|
||||
});
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user