swagger-axios-codegen
Advanced tools
Comparing version 0.1.7 to 0.1.8
@@ -68,6 +68,3 @@ "use strict"; | ||
propsStr += ` | ||
/** | ||
* ${v.description} | ||
* @type {${propType}} | ||
*/ | ||
/** ${v.description || ''} */ | ||
${k}:${propType};\n | ||
@@ -74,0 +71,0 @@ `; |
@@ -5,2 +5,5 @@ import { IPaths, ISwaggerOptions } from './baseInterfaces'; | ||
} | ||
export interface IRequestMethodInput { | ||
[key: string]: string[]; | ||
} | ||
export declare function requestCodeGen(paths: IPaths, options: ISwaggerOptions): string; |
@@ -33,8 +33,11 @@ "use strict"; | ||
const paramName = camelcase_1.default(p.name); | ||
requestParameters += `${paramName}${p.required ? '' : '?'}:${propType},`; | ||
requestParameters += ` | ||
/** ${p.description || ''} */ | ||
${paramName}${p.required ? '' : '?'}:${propType}, | ||
`; | ||
// 如果参数是从formData 提交 | ||
if (p.in === 'formData') { | ||
requestFormData += ` | ||
if(parameters['${paramName}']){ | ||
data.append('${paramName}',parameters['${paramName}'],'${paramName}') | ||
if(params['${paramName}']){ | ||
data.append('${paramName}',params['${paramName}'],'${paramName}') | ||
}\n | ||
@@ -44,9 +47,9 @@ `; | ||
else if (p.in === 'path') { | ||
requestPathReplace += `url = url.replace('{${paramName}}',parameters['${paramName}']+'')\n`; | ||
requestPathReplace += `url = url.replace('{${paramName}}',params['${paramName}']+'')\n`; | ||
} | ||
else if (p.in === 'query') { | ||
queryParameters.push(`'${paramName}':parameters['${paramName}']`); | ||
queryParameters.push(`'${paramName}':params['${paramName}']`); | ||
} | ||
else if (p.in === 'body') { | ||
var body = p.schema ? `...parameters['${paramName}']` : `'${paramName}':parameters['${paramName}']`; | ||
var body = p.schema ? `...params['${paramName}']` : `'${paramName}':params['${paramName}']`; | ||
bodyParameters.push(body); | ||
@@ -59,2 +62,3 @@ } | ||
const RequestMethods = {}; | ||
const RequestMethodInputs = {}; | ||
for (const [path, request] of Object.entries(paths)) { | ||
@@ -77,3 +81,14 @@ let methodName = utils_1.getMethodName(path); | ||
parsedParameters = getRequestParameters(v.parameters); | ||
parameters = `parameters: {${parsedParameters.requestParameters}},`; | ||
let methodParamsName = `I${methodName}Params`; | ||
if (RequestMethodInputs[methodParamsName]) { | ||
methodParamsName = `I${methodName}Params` + RequestMethodInputs[methodParamsName].length; | ||
} | ||
else { | ||
RequestMethodInputs[methodParamsName] = []; | ||
} | ||
RequestMethodInputs[`I${methodName}Params`].push(` | ||
export interface ${methodParamsName}{ | ||
${parsedParameters.requestParameters} | ||
}`); | ||
parameters = `params: ${methodParamsName},`; | ||
formData = parsedParameters.requestFormData ? 'data = new FormData();\n' + parsedParameters.requestFormData : ''; | ||
@@ -89,3 +104,3 @@ pathReplace = parsedParameters.requestPathReplace; | ||
/** | ||
* | ||
* ${v.summary || ''} | ||
* @param {IRequestOptions} [options] Override http request option. | ||
@@ -127,4 +142,9 @@ * @throws {RequiredError} | ||
} | ||
Object.values(RequestMethodInputs).forEach(item => { | ||
item.forEach(text => { | ||
RequestClasses += text; | ||
}); | ||
}); | ||
return RequestClasses; | ||
} | ||
exports.requestCodeGen = requestCodeGen; |
{ | ||
"name": "swagger-axios-codegen", | ||
"version": "0.1.7", | ||
"version": "0.1.8", | ||
"main": "./dist/index", | ||
@@ -5,0 +5,0 @@ "typings": "./dist/", |
1132893
28627