Skip to content

Commit 40ef68f

Browse files
committed
- Cleanup of generation without tags
1 parent 5a8457f commit 40ef68f

File tree

6 files changed

+55
-12
lines changed

6 files changed

+55
-12
lines changed

src/openApi/v2/interfaces/OpenApiOperation.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export interface OpenApiOperation {
1616
produces?: string[];
1717
parameters?: OpenApiParameter[];
1818
responses: OpenApiResponses;
19-
schemes: ('http' | 'https' | 'ws' | 'wss')[];
19+
schemes?: ('http' | 'https' | 'ws' | 'wss')[];
2020
deprecated?: boolean;
2121
security?: OpenApiSecurityRequirement[];
2222
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
swagger: '2.0',
7+
info: {
8+
title: 'x',
9+
version: '1',
10+
},
11+
paths: {
12+
'/api/trips': {
13+
get: {
14+
tags: [],
15+
responses: {
16+
200: {
17+
description: 'x',
18+
},
19+
default: {
20+
description: 'default',
21+
},
22+
},
23+
},
24+
},
25+
},
26+
});
27+
28+
expect(services).toHaveLength(1);
29+
expect(services[0].name).toEqual('');
30+
});
31+
});

src/openApi/v2/parser/getServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ 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 tags = op.tags?.length ? op.tags.filter(unique) : [''];
3232
tags.forEach(tag => {
3333
const operation = getOperation(openApi, url, method, tag, op, pathParams);
3434

src/openApi/v3/parser/getServices.spec.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,29 @@ import { getServices } from './getServices';
33
describe('getServices', () => {
44
it('should create a unnamed service if tags are empty', () => {
55
const services = getServices({
6-
openapi: '3',
7-
info: { title: 'x', version: '1' },
6+
openapi: '3.0.0',
7+
info: {
8+
title: 'x',
9+
version: '1',
10+
},
811
paths: {
912
'/api/trips': {
10-
get: { tags: [], responses: { 200: { description: 'X' }, default: { description: 'default' } } },
13+
get: {
14+
tags: [],
15+
responses: {
16+
200: {
17+
description: 'x',
18+
},
19+
default: {
20+
description: 'default',
21+
},
22+
},
23+
},
1124
},
1225
},
1326
});
1427

1528
expect(services).toHaveLength(1);
16-
expect(services[0].name).toEqual('Unnamed');
29+
expect(services[0].name).toEqual('');
1730
});
1831
});

src/openApi/v3/parser/getServices.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ 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 uniqueTags = op.tags?.filter(unique);
32-
const tags = uniqueTags?.length ? uniqueTags : ['Unnamed'];
31+
const tags = op.tags?.length ? op.tags.filter(unique) : [''];
3332
tags.forEach(tag => {
3433
const operation = getOperation(openApi, url, method, tag, op, pathParams);
3534

test/__snapshots__/index.spec.ts.snap

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ function base64(str: string): string {
272272
function getQueryString(params: Record<string, any>): string {
273273
const searchParams = new URLSearchParams();
274274

275-
const process = (key:string, value: any) => {
275+
const process = (key: string, value: any) => {
276276
if (isDefined(value)) {
277277
if (Array.isArray(value)) {
278278
value.forEach(v => {
@@ -326,7 +326,7 @@ function getFormData(options: ApiRequestOptions): FormData | undefined {
326326
.filter(([_, value]) => isDefined(value))
327327
.forEach(([key, value]) => {
328328
if (Array.isArray(value)) {
329-
value.forEach(v => append(key, v));
329+
value.forEach(v => process(key, v));
330330
} else {
331331
process(key, value);
332332
}
@@ -3121,7 +3121,7 @@ function base64(str: string): string {
31213121
function getQueryString(params: Record<string, any>): string {
31223122
const searchParams = new URLSearchParams();
31233123

3124-
const process = (key:string, value: any) => {
3124+
const process = (key: string, value: any) => {
31253125
if (isDefined(value)) {
31263126
if (Array.isArray(value)) {
31273127
value.forEach(v => {
@@ -3175,7 +3175,7 @@ function getFormData(options: ApiRequestOptions): FormData | undefined {
31753175
.filter(([_, value]) => isDefined(value))
31763176
.forEach(([key, value]) => {
31773177
if (Array.isArray(value)) {
3178-
value.forEach(v => append(key, v));
3178+
value.forEach(v => process(key, v));
31793179
} else {
31803180
process(key, value);
31813181
}

0 commit comments

Comments
 (0)