diff --git a/src/openApi/v2/interfaces/OpenApiOperation.d.ts b/src/openApi/v2/interfaces/OpenApiOperation.d.ts index b0b17022..aa811bd3 100644 --- a/src/openApi/v2/interfaces/OpenApiOperation.d.ts +++ b/src/openApi/v2/interfaces/OpenApiOperation.d.ts @@ -16,7 +16,7 @@ export interface OpenApiOperation { produces?: string[]; parameters?: OpenApiParameter[]; responses: OpenApiResponses; - schemes: ('http' | 'https' | 'ws' | 'wss')[]; + schemes?: ('http' | 'https' | 'ws' | 'wss')[]; deprecated?: boolean; security?: OpenApiSecurityRequirement[]; } diff --git a/src/openApi/v2/parser/getServices.spec.ts b/src/openApi/v2/parser/getServices.spec.ts new file mode 100644 index 00000000..75228719 --- /dev/null +++ b/src/openApi/v2/parser/getServices.spec.ts @@ -0,0 +1,31 @@ +import { getServices } from './getServices'; + +describe('getServices', () => { + it('should create a unnamed service if tags are empty', () => { + const services = getServices({ + swagger: '2.0', + 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(''); + }); +}); diff --git a/src/openApi/v2/parser/getServices.ts b/src/openApi/v2/parser/getServices.ts index 486608fd..e52f8496 100644 --- a/src/openApi/v2/parser/getServices.ts +++ b/src/openApi/v2/parser/getServices.ts @@ -28,7 +28,7 @@ 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 tags = op.tags?.length ? op.tags.filter(unique) : ['']; tags.forEach(tag => { const operation = getOperation(openApi, url, method, tag, op, pathParams); diff --git a/src/openApi/v3/parser/getServices.spec.ts b/src/openApi/v3/parser/getServices.spec.ts index 2530ddab..873970ad 100644 --- a/src/openApi/v3/parser/getServices.spec.ts +++ b/src/openApi/v3/parser/getServices.spec.ts @@ -3,16 +3,29 @@ 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' }, + openapi: '3.0.0', + info: { + title: 'x', + version: '1', + }, paths: { '/api/trips': { - get: { tags: [], responses: { 200: { description: 'X' }, default: { description: 'default' } } }, + get: { + tags: [], + responses: { + 200: { + description: 'x', + }, + default: { + description: 'default', + }, + }, + }, }, }, }); expect(services).toHaveLength(1); - expect(services[0].name).toEqual('Unnamed'); + expect(services[0].name).toEqual(''); }); }); diff --git a/src/openApi/v3/parser/getServices.ts b/src/openApi/v3/parser/getServices.ts index f2375962..e52f8496 100644 --- a/src/openApi/v3/parser/getServices.ts +++ b/src/openApi/v3/parser/getServices.ts @@ -28,8 +28,7 @@ export function getServices(openApi: OpenApi): Service[] { case 'patch': // Each method contains an OpenAPI operation, we parse the operation const op = path[method]!; - const uniqueTags = op.tags?.filter(unique); - const tags = uniqueTags?.length ? uniqueTags : ['Unnamed']; + const tags = op.tags?.length ? op.tags.filter(unique) : ['']; tags.forEach(tag => { const operation = getOperation(openApi, url, method, tag, op, pathParams); diff --git a/test/__snapshots__/index.spec.ts.snap b/test/__snapshots__/index.spec.ts.snap index 5feac141..0d3dc80f 100644 --- a/test/__snapshots__/index.spec.ts.snap +++ b/test/__snapshots__/index.spec.ts.snap @@ -272,7 +272,7 @@ function base64(str: string): string { function getQueryString(params: Record): string { const searchParams = new URLSearchParams(); - const process = (key:string, value: any) => { + const process = (key: string, value: any) => { if (isDefined(value)) { if (Array.isArray(value)) { value.forEach(v => { @@ -326,7 +326,7 @@ function getFormData(options: ApiRequestOptions): FormData | undefined { .filter(([_, value]) => isDefined(value)) .forEach(([key, value]) => { if (Array.isArray(value)) { - value.forEach(v => append(key, v)); + value.forEach(v => process(key, v)); } else { process(key, value); } @@ -3121,7 +3121,7 @@ function base64(str: string): string { function getQueryString(params: Record): string { const searchParams = new URLSearchParams(); - const process = (key:string, value: any) => { + const process = (key: string, value: any) => { if (isDefined(value)) { if (Array.isArray(value)) { value.forEach(v => { @@ -3175,7 +3175,7 @@ function getFormData(options: ApiRequestOptions): FormData | undefined { .filter(([_, value]) => isDefined(value)) .forEach(([key, value]) => { if (Array.isArray(value)) { - value.forEach(v => append(key, v)); + value.forEach(v => process(key, v)); } else { process(key, value); }