Skip to content

Commit

Permalink
feat: 添加响应类型包装器
Browse files Browse the repository at this point in the history
  • Loading branch information
WangMingHua111 authored and Manweill committed Feb 4, 2024
1 parent 51b2639 commit cab5017
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/baseInterfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions src/templates/template.ts
Original file line number Diff line number Diff line change
@@ -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]"
Expand Down Expand Up @@ -201,9 +201,9 @@ export function requestTemplate(name: string, requestSchema: IRequestSchema, opt
pathReplace = '',
parsedParameters = <any>{},
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
Expand All @@ -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}
Expand Down

0 comments on commit cab5017

Please sign in to comment.