mirror of
https://github.com/ferdikoomen/openapi-typescript-codegen.git
synced 2025-12-08 20:16:21 +00:00
- Cleanup of generation without tags
This commit is contained in:
parent
5a8457fee8
commit
40ef68fec4
@ -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[];
|
||||
}
|
||||
|
||||
31
src/openApi/v2/parser/getServices.spec.ts
Normal file
31
src/openApi/v2/parser/getServices.spec.ts
Normal file
@ -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('');
|
||||
});
|
||||
});
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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('');
|
||||
});
|
||||
});
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -272,7 +272,7 @@ function base64(str: string): string {
|
||||
function getQueryString(params: Record<string, any>): 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, any>): 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);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user