From cab501773987be3b56299a6dae9708dd54493492 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=98=8E=E5=8D=8E?= <735161977@qq.com> Date: Mon, 22 Jan 2024 13:00:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E5=93=8D=E5=BA=94?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E5=8C=85=E8=A3=85=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/baseInterfaces.ts | 2 ++ src/templates/template.ts | 10 +++++----- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/baseInterfaces.ts b/src/baseInterfaces.ts index e2c78d5..5102a8e 100644 --- a/src/baseInterfaces.ts +++ b/src/baseInterfaces.ts @@ -39,6 +39,8 @@ export interface ISwaggerOptions { sharedServiceOptions?: boolean | undefined /** use parameters in header or not*/ useHeaderParameters?: boolean + /** wrapper response type */ + responseTypeWrapper ?: (responseType: string)=> string } export interface IPropDef { diff --git a/src/templates/template.ts b/src/templates/template.ts index 5873018..409fe74 100644 --- a/src/templates/template.ts +++ b/src/templates/template.ts @@ -1,6 +1,6 @@ import camelcase from 'camelcase' -import { IPropDef, ISwaggerOptions } from '../baseInterfaces' -import { toBaseType, isDefinedGenericTypes, getDefinedGenericTypes } from '../utils' +import { IPropDef } from '../baseInterfaces' +import { isDefinedGenericTypes, toBaseType } from '../utils' const baseTypes = ['string', 'number', 'object', 'boolean', 'any'] const isAdditionalProperties = (x: string) => x === "[additionalProperties: string]" @@ -201,9 +201,9 @@ export function requestTemplate(name: string, requestSchema: IRequestSchema, opt pathReplace = '', parsedParameters = {}, formData = '', - requestBody = null + requestBody = null, } = requestSchema - const { useClassTransformer } = options + const { useClassTransformer, responseTypeWrapper } = options const { queryParameters = [], bodyParameter = [], headerParameters } = parsedParameters const nonArrayType = responseType.replace('[', '').replace(']', '') const isArrayType = responseType.indexOf('[') > 0 @@ -219,7 +219,7 @@ export function requestTemplate(name: string, requestSchema: IRequestSchema, opt */ ${options.useStaticMethod ? 'static' : ''} ${camelcase( name - )}(${parameters}options:IRequestOptions={}):Promise<${responseType}> { + )}(${parameters}options:IRequestOptions={}):Promise<${responseTypeWrapper ? responseTypeWrapper(responseType) : responseType}> { return new Promise((resolve, reject) => { let url = basePath+'${path}' ${pathReplace}