swagger-axios-codegen
Advanced tools
Comparing version
@@ -1,3 +0,3 @@ | ||
## 0.2.4 | ||
## 0.2.5 | ||
- 使用 `Promise` 代替 `AxiosPromise`。如果接口调用成功,默认返回response.data | ||
- 修改README.md |
@@ -30,9 +30,10 @@ "use strict"; | ||
} | ||
// 是个枚举 | ||
else if (v.enum) { | ||
// 是枚举 并且是字符串类型 | ||
else if (v.enum && v.type === 'string') { | ||
isEnum = true; | ||
propType = v.type === 'string' ? | ||
v.enum.map(item => `'${item}'='${item}'`).join(',') : | ||
v.enum.map(item => `'${item}'=${item}`).join(','); | ||
propType = v.enum.map(item => `'${item}'='${item}'`).join(','); | ||
} | ||
else if (v.enum) { | ||
propType = v.type === 'string' ? v.enum.map(item => `'${item}'`).join('|') : v.enum.join('|'); | ||
} | ||
// 基本类型 | ||
@@ -39,0 +40,0 @@ else { |
@@ -7,2 +7,3 @@ "use strict"; | ||
const camelcase_1 = __importDefault(require("camelcase")); | ||
const pascalcase_1 = __importDefault(require("pascalcase")); | ||
const utils_1 = require("./utils"); | ||
@@ -78,6 +79,9 @@ const methodNameChange = { get: 'GET', post: 'POST', put: 'PUT', delete: 'DELETE' }; | ||
if (v.parameters) { | ||
// 获取到接口的参数 | ||
parsedParameters = getRequestParameters(v.parameters); | ||
let methodParamsName = `I${methodName}Params`; | ||
//参数类型的名字 | ||
let methodParamsName = `I${pascalcase_1.default(methodName)}Params`; | ||
// 如果存在该参数类型的名字,则在参数类型的名字后面+1 | ||
if (RequestMethodInputs[methodParamsName]) { | ||
methodParamsName = `I${methodName}Params` + RequestMethodInputs[methodParamsName].length; | ||
methodParamsName = `I${pascalcase_1.default(methodName)}Params` + RequestMethodInputs[methodParamsName].length; | ||
} | ||
@@ -87,3 +91,3 @@ else { | ||
} | ||
RequestMethodInputs[`I${methodName}Params`].push(`export interface ${methodParamsName}{ | ||
RequestMethodInputs[`I${pascalcase_1.default(methodName)}Params`].push(`export interface ${methodParamsName}{ | ||
${parsedParameters.requestParameters} | ||
@@ -103,6 +107,4 @@ }`); | ||
* ${v.summary || ''} | ||
* @param {IRequestOptions} [options] Override http request option. | ||
* @throws {RequiredError} | ||
*/ | ||
${options.useStaticMethod ? 'static' : ''} ${camelcase_1.default(methodName)}(${parameters}options:IRequestOptions={}):AxiosPromise<${responseType}> { | ||
${options.useStaticMethod ? 'static' : ''} ${camelcase_1.default(methodName)}(${parameters}options:IRequestOptions={}):Promise<${responseType}> { | ||
@@ -133,3 +135,9 @@ ${handleNullParameters} | ||
return axios(configs); | ||
return new Promise((resolve, reject) => { | ||
axios(configs).then(res => { | ||
resolve(res.data); | ||
}).catch(err => { | ||
reject(err); | ||
}); | ||
}); | ||
} | ||
@@ -136,0 +144,0 @@ `; |
{ | ||
"name": "swagger-axios-codegen", | ||
"version": "0.2.4", | ||
"version": "0.2.5", | ||
"main": "./dist/index", | ||
@@ -5,0 +5,0 @@ "typings": "./dist/", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
24964
1.81%553
1.65%0
-100%