swagger-axios-codegen
Advanced tools
Comparing version 0.11.5 to 0.11.6
### 0.11.5 | ||
### 0.11.6 | ||
- feat: support for "shortOperationId", with tag suffix removed (#108) | ||
### 0.11.4 | ||
- feat; `options.sharedServiceOptions` | ||
@@ -5,0 +9,0 @@ |
export interface ISwaggerOptions { | ||
serviceNameSuffix?: string; | ||
enumNamePrefix?: string; | ||
methodNameMode?: 'operationId' | 'path'; | ||
methodNameMode?: 'operationId' | 'path' | 'shortOperationId'; | ||
outputDir?: string; | ||
@@ -6,0 +6,0 @@ fileName?: string; |
@@ -77,3 +77,3 @@ "use strict"; | ||
let apiSource = ''; | ||
let serviceHeaderSource = options.useCustomerRequestInstance ? serviceHeader_1.customerServiceHeader(options) : serviceHeader_1.serviceHeader(options); | ||
let serviceHeaderSource = options.useCustomerRequestInstance ? serviceHeader_1.customerServiceHeader(options, swaggerSource.basePath) : serviceHeader_1.serviceHeader(options, swaggerSource.basePath); | ||
if (options.sharedServiceOptions) { | ||
@@ -84,6 +84,5 @@ writeFile(options.outputDir || '', 'serviceOptions.ts' || '', format(serviceHeaderSource, options)); | ||
else { | ||
apiSource += serviceHeader_1.serviceHeader(options); | ||
apiSource += serviceHeaderSource; | ||
} | ||
apiSource += serviceHeader_1.definitionHeader(options.extendDefinitionFile); | ||
apiSource += `const basePath = '${utils_1.trimString(swaggerSource.basePath, '/', 'right')}'`; | ||
// 判断是否是openApi3.0或者swagger3.0 | ||
@@ -90,0 +89,0 @@ const isV3 = utils_1.isOpenApi3(params.openApi || swaggerSource.openapi || swaggerSource.swagger); |
@@ -14,3 +14,3 @@ "use strict"; | ||
function requestCodegen(paths, isV3, options) { | ||
var _a, _b, _c, _d; | ||
var _a, _b, _c, _d, _e; | ||
const requestClasses = {}; | ||
@@ -21,3 +21,4 @@ if (!!paths) | ||
for (const [method, reqProps] of Object.entries(request)) { | ||
methodName = options.methodNameMode === 'operationId' ? reqProps.operationId : methodName; | ||
methodName = options.methodNameMode === 'operationId' ? reqProps.operationId : | ||
options.methodNameMode === 'shortOperationId' ? trimSuffix(reqProps.operationId, (_a = reqProps.tags) === null || _a === void 0 ? void 0 : _a[0]) : methodName; | ||
if (!methodName) { | ||
@@ -45,3 +46,3 @@ // console.warn('method Name is null:', path); | ||
}; | ||
const multipartDataProperties = (_b = (_a = reqProps) === null || _a === void 0 ? void 0 : _a.requestBody) === null || _b === void 0 ? void 0 : _b.content['multipart/form-data']; | ||
const multipartDataProperties = (_c = (_b = reqProps) === null || _b === void 0 ? void 0 : _b.requestBody) === null || _c === void 0 ? void 0 : _c.content['multipart/form-data']; | ||
if (reqProps.parameters || multipartDataProperties) { | ||
@@ -65,3 +66,3 @@ // 获取到接口的参数 | ||
// 合并imports | ||
if (((_c = parsedRequestBody.imports) === null || _c === void 0 ? void 0 : _c.length) >= 0) { | ||
if (((_d = parsedRequestBody.imports) === null || _d === void 0 ? void 0 : _d.length) >= 0) { | ||
// console.log("requestBody ", parsedRequestBody); | ||
@@ -75,3 +76,3 @@ imports.push(...parsedRequestBody.imports); | ||
parameters = | ||
((_d = parsedParameters.requestParameters) === null || _d === void 0 ? void 0 : _d.length) > 0 | ||
((_e = parsedParameters.requestParameters) === null || _e === void 0 ? void 0 : _e.length) > 0 | ||
? `params: { | ||
@@ -118,2 +119,6 @@ ${parsedParameters.requestParameters} | ||
exports.requestCodegen = requestCodegen; | ||
function trimSuffix(value, suffix) { | ||
var _a; | ||
return ((_a = value) === null || _a === void 0 ? void 0 : _a.endsWith(suffix)) ? value.slice(0, -suffix.length) : value; | ||
} | ||
//# sourceMappingURL=index.js.map |
import { ISwaggerOptions } from "../baseInterfaces"; | ||
export declare function serviceHeader(options: ISwaggerOptions): string; | ||
export declare function customerServiceHeader(options: ISwaggerOptions): string; | ||
export declare function serviceHeader(options: ISwaggerOptions, basePath: string): string; | ||
export declare function customerServiceHeader(options: ISwaggerOptions, basePath: string): string; | ||
export declare function definitionHeader(fileDir: string | undefined): string; |
@@ -13,3 +13,4 @@ "use strict"; | ||
const genericTypeDefinitionTemplate_1 = require("./genericTypeDefinitionTemplate"); | ||
function serviceHeader(options) { | ||
const utils_1 = require("../utils"); | ||
function serviceHeader(options, basePath) { | ||
const classTransformerImport = options.useClassTransformer | ||
@@ -23,2 +24,3 @@ ? `import { Expose, Transform, Type, plainToClass } from 'class-transformer'; | ||
const basePath = '${utils_1.trimString(basePath, '/', 'right')}' | ||
${classTransformerImport} | ||
@@ -49,3 +51,3 @@ | ||
exports.serviceHeader = serviceHeader; | ||
function customerServiceHeader(options) { | ||
function customerServiceHeader(options, basePath) { | ||
return `/** Generate by swagger-axios-codegen */ | ||
@@ -83,2 +85,4 @@ // tslint:disable | ||
const basePath = '${basePath}' | ||
// Add options interface | ||
@@ -116,2 +120,3 @@ export interface ServiceOptions { | ||
export function getConfigs(method: string, contentType: string, url: string,options: any):IRequestConfig { | ||
url = basePath + url | ||
const configs: IRequestConfig = { ...options, method, url }; | ||
@@ -118,0 +123,0 @@ configs.headers = { |
@@ -152,3 +152,3 @@ "use strict"; | ||
return new Promise((resolve, reject) => { | ||
let url = basePath+'${path}' | ||
let url = '${path}' | ||
${pathReplace} | ||
@@ -155,0 +155,0 @@ const configs:IRequestConfig = getConfigs('${method}', '${contentType}', url, options) |
{ | ||
"name": "swagger-axios-codegen", | ||
"version": "0.11.5", | ||
"version": "0.11.6", | ||
"main": "./dist/index", | ||
@@ -41,2 +41,2 @@ "typings": "./dist/", | ||
} | ||
} | ||
} |
@@ -27,2 +27,4 @@ # swagger-axios-codegen | ||
## [Contributing](./CONTRIBUTING.md) | ||
## Get Started | ||
@@ -29,0 +31,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
275
6
262803
153
3976
1