swagger-axios-codegen
Advanced tools
Comparing version 0.5.3 to 0.5.4
## 0.5.4 | ||
Support typescript strict mode [issue 23](https://github.com/Manweill/swagger-axios-codegen/issues/23) | ||
## 0.5.3 | ||
@@ -3,0 +7,0 @@ |
@@ -12,2 +12,3 @@ export interface ISwaggerOptions { | ||
include?: Array<string | IInclude>; | ||
format?: (s: string) => string; | ||
} | ||
@@ -14,0 +15,0 @@ export interface IPropDef { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=baseInterfaces.js.map |
@@ -1,2 +0,2 @@ | ||
import { IDefinitionProperties } from "../saggerInterfaces"; | ||
import { IDefinitionProperties } from "../swaggerInterfaces"; | ||
import { IClassDef } from "../baseInterfaces"; | ||
@@ -3,0 +3,0 @@ /** |
@@ -19,3 +19,3 @@ "use strict"; | ||
let model = { name: className, props: [], imports: [] }; | ||
const propertiesEntities = Object.entries(properties); | ||
const propertiesEntities = Object.entries(properties || {}); | ||
for (const [k, v] of propertiesEntities) { | ||
@@ -53,1 +53,2 @@ // console.log('props name', k) | ||
exports.createDefinitionClass = createDefinitionClass; | ||
//# sourceMappingURL=createDefinitionClass.js.map |
@@ -22,1 +22,2 @@ "use strict"; | ||
exports.createDefinitionEnum = createDefinitionEnum; | ||
//# sourceMappingURL=createDefinitionEnum.js.map |
@@ -1,2 +0,2 @@ | ||
import { IDefinitions } from '../saggerInterfaces'; | ||
import { IDefinitions } from '../swaggerInterfaces'; | ||
import { IDefinitionClasses, IDefinitionEnums } from '../baseInterfaces'; | ||
@@ -3,0 +3,0 @@ export declare function definitionsCodeGen(definitions: IDefinitions): { |
@@ -45,1 +45,2 @@ "use strict"; | ||
exports.definitionsCodeGen = definitionsCodeGen; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { IDefinitionProperty } from "../saggerInterfaces"; | ||
import { IDefinitionProperty } from "../swaggerInterfaces"; | ||
export declare function propTrueType(v: IDefinitionProperty): { | ||
@@ -3,0 +3,0 @@ propType: string; |
@@ -43,7 +43,7 @@ "use strict"; | ||
result.isEnum = true; | ||
result.propType = v.enum.map(item => `'${item}'='${item}'`).join(','); | ||
result.propType = getEnums(v.enum).map(item => `'${item}'='${item}'`).join(','); | ||
} | ||
else if (v.enum) { | ||
result.isType = true; | ||
result.propType = v.type === 'string' ? v.enum.map(item => `'${item}'`).join('|') : v.enum.join('|'); | ||
result.propType = v.type === 'string' ? getEnums(v.enum).map(item => `'${item}'`).join('|') : v.enum.join('|'); | ||
} | ||
@@ -57,1 +57,5 @@ // 基本类型 | ||
exports.propTrueType = propTrueType; | ||
function getEnums(enumObject) { | ||
return Object.prototype.toString.call(enumObject) === '[object Object]' ? Object.values(enumObject) : enumObject; | ||
} | ||
//# sourceMappingURL=propTrueType.js.map |
@@ -33,2 +33,3 @@ "use strict"; | ||
console.time('finish'); | ||
let err; | ||
let swaggerSource; | ||
@@ -68,3 +69,3 @@ if (params.remoteUrl) { | ||
const fileDir = path.join(options.outputDir || '', 'definitions'); | ||
writeFile(fileDir, item.name + '.ts', format(text)); | ||
writeFile(fileDir, item.name + '.ts', format(text, options)); | ||
}); | ||
@@ -74,3 +75,3 @@ Object.values(models).forEach(item => { | ||
const fileDir = path.join(options.outputDir || '', 'definitions'); | ||
writeFile(fileDir, item.name, format(text)); | ||
writeFile(fileDir, item.name, format(text, options)); | ||
}); | ||
@@ -139,3 +140,3 @@ } | ||
apiSource += reqSource + defSource; | ||
writeFile(options.outputDir || '', options.fileName || '', format(apiSource)); | ||
writeFile(options.outputDir || '', options.fileName || '', format(apiSource, options)); | ||
} | ||
@@ -166,6 +167,7 @@ else { | ||
}); | ||
writeFile(options.outputDir || '', options.fileName || '', format(apiSource)); | ||
writeFile(options.outputDir || '', options.fileName || '', format(apiSource, options)); | ||
} | ||
catch (error) { | ||
console.log('error', error); | ||
err = error; | ||
} | ||
@@ -177,2 +179,5 @@ } | ||
console.timeEnd('finish'); | ||
if (err) { | ||
throw err; | ||
} | ||
} | ||
@@ -188,3 +193,8 @@ exports.codegen = codegen; | ||
} | ||
function format(text) { | ||
function format(text, options) { | ||
if (options.format) { | ||
console.log('use custom formatter'); | ||
return options.format(text); | ||
} | ||
console.log('use default formatter'); | ||
return prettier_1.default.format(text, { | ||
@@ -200,1 +210,2 @@ "printWidth": 120, | ||
} | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { IParameter } from "../saggerInterfaces"; | ||
import { IParameter } from '../swaggerInterfaces'; | ||
/** | ||
@@ -3,0 +3,0 @@ * 生成参数 |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const utils_1 = require("../utils"); | ||
const camelcase = require("camelcase"); | ||
const camelcase_1 = __importDefault(require("camelcase")); | ||
/** | ||
@@ -43,3 +46,3 @@ * 生成参数 | ||
} | ||
const paramName = camelcase(p.name); | ||
const paramName = camelcase_1.default(p.name); | ||
requestParameters += ` | ||
@@ -69,1 +72,2 @@ /** ${p.description || ''} */ | ||
exports.getRequestParameters = getRequestParameters; | ||
//# sourceMappingURL=getRequestParameters.js.map |
@@ -1,2 +0,2 @@ | ||
import { IRequestMethod } from "../saggerInterfaces"; | ||
import { IRequestMethod } from "../swaggerInterfaces"; | ||
/** | ||
@@ -3,0 +3,0 @@ * 获取请求的返回类型 |
@@ -44,1 +44,2 @@ "use strict"; | ||
exports.getResponseType = getResponseType; | ||
//# sourceMappingURL=getResponseType.js.map |
@@ -1,2 +0,2 @@ | ||
import { IPaths } from '../saggerInterfaces'; | ||
import { IPaths } from '../swaggerInterfaces'; | ||
export interface IRequestClass { | ||
@@ -3,0 +3,0 @@ [key: string]: IRequestMethods[]; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -6,2 +9,3 @@ const utils_1 = require("../utils"); | ||
const getResponseType_1 = require("./getResponseType"); | ||
const camelcase_1 = __importDefault(require("camelcase")); | ||
function requestCodegen(paths) { | ||
@@ -13,3 +17,5 @@ const requestClasses = {}; | ||
// methodName = options.methodNameMode === 'operationId' ? reqProps.operationId : methodName | ||
const contentType = reqProps.consumes && reqProps.consumes.includes('multipart/form-data') ? 'multipart/form-data' : 'application/json'; | ||
const contentType = reqProps.consumes && reqProps.consumes.includes('multipart/form-data') | ||
? 'multipart/form-data' | ||
: 'application/json'; | ||
let formData = ''; | ||
@@ -20,3 +26,5 @@ let pathReplace = ''; | ||
continue; | ||
const className = reqProps.tags[0]; | ||
const className = camelcase_1.default(reqProps.tags[0], { pascalCase: true }); | ||
if (className === '') | ||
continue; | ||
// 是否存在 | ||
@@ -28,11 +36,12 @@ if (!requestClasses[className]) { | ||
let handleNullParameters = ''; | ||
let parsedParameters; | ||
let parsedParameters = {}; | ||
if (reqProps.parameters) { | ||
// 获取到接口的参数 | ||
parsedParameters = getRequestParameters_1.getRequestParameters(reqProps.parameters); | ||
parameters = parsedParameters.requestParameters.length > 0 | ||
? `params: { | ||
parameters = | ||
parsedParameters.requestParameters.length > 0 | ||
? `params: { | ||
${parsedParameters.requestParameters} | ||
} = <any>{},` | ||
: ''; | ||
: ''; | ||
formData = parsedParameters.requestFormData ? 'data = new FormData();\n' + parsedParameters.requestFormData : ''; | ||
@@ -44,3 +53,5 @@ pathReplace = parsedParameters.requestPathReplace; | ||
if (refResponseType) { | ||
parsedParameters.imports.push(responseType); | ||
let imports = parsedParameters.imports || []; | ||
imports.push(responseType); | ||
parsedParameters.imports = imports; | ||
} | ||
@@ -67,1 +78,2 @@ requestClasses[className].push({ | ||
exports.requestCodegen = requestCodegen; | ||
//# sourceMappingURL=index.js.map |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const camelcase = require("camelcase"); | ||
const camelcase_1 = __importDefault(require("camelcase")); | ||
/** 类模板 */ | ||
@@ -15,6 +18,4 @@ function classTemplate(name, props, imports) { | ||
constructor(data?:any){ | ||
if(data){ | ||
constructor(data: (undefined | any) = {}){ | ||
${props.map(p => classConstructorTemplate(p.name)).join('')} | ||
} | ||
} | ||
@@ -55,3 +56,3 @@ } | ||
*/ | ||
${options.useStaticMethod ? 'static' : ''} ${camelcase(name)}(${parameters}options:IRequestOptions={}):Promise<${responseType}> { | ||
${options.useStaticMethod ? 'static' : ''} ${camelcase_1.default(name)}(${parameters}options:IRequestOptions={}):Promise<${responseType}> { | ||
return new Promise((resolve, reject) => { | ||
@@ -166,1 +167,2 @@ const configs:IRequestConfig = {...options, method: "${method}" }; | ||
`; | ||
//# sourceMappingURL=template.js.map |
@@ -57,3 +57,3 @@ "use strict"; | ||
default: | ||
result = s; | ||
result = 'any'; | ||
break; | ||
@@ -108,1 +108,2 @@ } | ||
exports.findDeepRefs = findDeepRefs; | ||
//# sourceMappingURL=utils.js.map |
{ | ||
"name": "swagger-axios-codegen", | ||
"version": "0.5.3", | ||
"version": "0.5.4", | ||
"main": "./dist/index", | ||
@@ -5,0 +5,0 @@ "typings": "./dist/", |
# swagger-axios-codegen | ||
swagger client to use axios and typescript | ||
swagger client with axios and typescript | ||
[![NpmVersion](https://img.shields.io/npm/v/swagger-axios-codegen.svg)](https://www.npmjs.com/package/swagger-axios-codegen) | ||
[![npm](https://img.shields.io/npm/dt/swagger-axios-codegen.svg)](https://www.npmjs.com/package/swagger-axios-codegen) | ||
[![npm](https://img.shields.io/npm/dm/swagger-axios-codegen.svg)](https://www.npmjs.com/package/swagger-axios-codegen) | ||
[![Build Status](https://dev.azure.com/manweill/swagger-axios-codegen/_apis/build/status/Manweill.swagger-axios-codegen?branchName=master)](https://dev.azure.com/manweill/swagger-axios-codegen/_build/latest?definitionId=1&branchName=master) | ||
@@ -12,3 +12,3 @@ | ||
support other support similar to `axios` library, for example [Fly.js](https://github.com/wendux/fly), required setting `ISwaggerOptions.useCustomerRequestInstance = true` | ||
support other similar to `axios` library, for example [Fly.js](https://github.com/wendux/fly), required setting `ISwaggerOptions.useCustomerRequestInstance = true` | ||
@@ -15,0 +15,0 @@ ## [Example](./example) |
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
102447
55
1730
1