swagger-axios-codegen
Advanced tools
Comparing version 0.9.7 to 0.9.8
## 0.9.8 | ||
- add Universal Generic TypeDefinition | ||
- add | ||
`options.extendDefinitionFile` | ||
`options.extendGenericType` | ||
[example](./example/swagger.enumArray.json) | ||
## 0.9.7 | ||
- fix: enum member cannot have numeric value | ||
## 0.9.6 | ||
- fix issue #63. remove special characters of serviceName and fieldName | ||
## 0.9.5 | ||
- fix requestBody in openApi3 | ||
## 0.9.4 | ||
- fix #59 empty components in openApi v3.0 | ||
## 0.9.3 | ||
- fix request name | ||
## 0.9.2 | ||
@@ -3,0 +32,0 @@ |
@@ -20,3 +20,4 @@ export interface ISwaggerOptions { | ||
openApi?: string | undefined; | ||
extendFile?: string | undefined; | ||
extendDefinitionFile?: string | undefined; | ||
extendGenericType?: string[] | undefined; | ||
} | ||
@@ -23,0 +24,0 @@ export interface IPropDef { |
@@ -16,2 +16,5 @@ "use strict"; | ||
let className = utils_1.refClassName(k); | ||
// 如果已经转为泛型类型,则不需要重新定义 | ||
if (utils_1.isGenerics(className)) | ||
continue; | ||
let result = null; | ||
@@ -18,0 +21,0 @@ // is an enum definition,just in swagger openAPI v2 |
@@ -11,2 +11,6 @@ "use strict"; | ||
let className = utils_1.refClassName(k); | ||
// 如果已经转为泛型类型,则不需要重新定义 | ||
if (utils_1.isGenerics(className)) { | ||
continue; | ||
} | ||
let result = null; | ||
@@ -13,0 +17,0 @@ // is an enum definition,just in swagger openAPI v2 |
@@ -27,7 +27,8 @@ "use strict"; | ||
const pascalcase_1 = __importDefault(require("pascalcase")); | ||
const definitionCodegen_1 = require("./definitionCodegen"); | ||
const template_1 = require("./template"); | ||
const template_1 = require("./templates/template"); | ||
const serviceHeader_1 = require("./templates/serviceHeader"); | ||
const utils_1 = require("./utils"); | ||
const requestCodegen_1 = require("./requestCodegen"); | ||
const utils_1 = require("./utils"); | ||
const componentsCodegen_1 = require("./componentsCodegen"); | ||
const definitionCodegen_1 = require("./definitionCodegen"); | ||
const defaultOptions = { | ||
@@ -44,3 +45,4 @@ serviceNameSuffix: 'Service', | ||
strictNullChecks: true, | ||
useClassTransformer: false | ||
useClassTransformer: false, | ||
extendGenericType: [] | ||
}; | ||
@@ -52,2 +54,3 @@ function codegen(params) { | ||
let swaggerSource; | ||
utils_1.setDefinedGenericTypes(params.extendGenericType); | ||
// 获取接口定义文件 | ||
@@ -72,4 +75,4 @@ if (params.remoteUrl) { | ||
let apiSource = options.useCustomerRequestInstance | ||
? template_1.customerServiceHeader(options) | ||
: template_1.serviceHeader(options); | ||
? serviceHeader_1.customerServiceHeader(options) | ||
: serviceHeader_1.serviceHeader(options); | ||
// 判断是否是openApi3.0或者swagger3.0 | ||
@@ -76,0 +79,0 @@ const isV3 = utils_1.isOpenApi3(params.openApi || swaggerSource.openapi || swaggerSource.swagger); |
@@ -1,2 +0,2 @@ | ||
import { IRequestMethod } from '../swaggerInterfaces'; | ||
import { IRequestMethod } from "../swaggerInterfaces"; | ||
/** | ||
@@ -3,0 +3,0 @@ * 获取请求的返回类型 |
@@ -97,5 +97,2 @@ export interface ISwaggerSource { | ||
} | ||
export interface IDictionary<T> { | ||
[key: string]: T; | ||
} | ||
export interface ISchema { | ||
@@ -107,1 +104,13 @@ '$ref': string; | ||
} | ||
export interface IDictionary<TKey, TValue = any> { | ||
[key: string]: TValue; | ||
} | ||
export interface IDictionary<TKey, TValue = any> { | ||
[key: number]: TValue; | ||
} | ||
export declare class Dictionary<TKey, TValue> implements IDictionary<TKey, TValue> { | ||
[key: string]: TValue; | ||
} | ||
export declare class Map<TKey, TValue> implements IDictionary<TKey, TValue> { | ||
[key: string]: TValue; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class Dictionary { | ||
} | ||
exports.Dictionary = Dictionary; | ||
class Map { | ||
} | ||
exports.Map = Map; | ||
//# sourceMappingURL=swaggerInterfaces.js.map |
@@ -1,4 +0,6 @@ | ||
import { IDefinitionClass, IDefinitionEnum } from "./baseInterfaces"; | ||
export declare const GENERIC_SPLIT_KEY = "["; | ||
import { IDefinitionClass, IDefinitionEnum } from './baseInterfaces'; | ||
export declare const isOpenApiGenerics: (s: string) => boolean; | ||
export declare const isGenerics: (s: string) => boolean; | ||
export declare const isDefinedGenericTypes: (x: string) => boolean; | ||
export declare function setDefinedGenericTypes(types: string[]): void; | ||
/** | ||
@@ -8,6 +10,3 @@ * 分解泛型接口 | ||
*/ | ||
export declare function getGenericsClassNames(definitionClassName: string): { | ||
interfaceClassName: string; | ||
TClassName: string; | ||
}; | ||
export declare function getGenericsClassNames(definitionClassName: string): string; | ||
/** | ||
@@ -14,0 +13,0 @@ * 获取引用类型 |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.GENERIC_SPLIT_KEY = '['; | ||
let definedGenericTypes = []; | ||
const UniversalGenericTypes = ['IList', 'List']; | ||
const AbpGenericTypes = ['IListResult', 'ListResultDto', 'IPagedResult', 'PagedResultDto']; | ||
// 是否是接口类型 | ||
exports.isGenerics = (s) => (/^.+\[.+\]$/.test(s) || /^.+\«.+\»$/.test(s)); | ||
exports.isOpenApiGenerics = (s) => (/^.+\[.+\]$/.test(s) || /^.+\«.+\»$/.test(s) || /^.+\<.+\>$/.test(s)); | ||
exports.isGenerics = (s) => /^.+\<.+\>$/.test(s); | ||
exports.isDefinedGenericTypes = (x) => definedGenericTypes.some(i => i === x); | ||
function setDefinedGenericTypes(types) { | ||
definedGenericTypes.push(...UniversalGenericTypes, ...AbpGenericTypes, ...types); | ||
} | ||
exports.setDefinedGenericTypes = setDefinedGenericTypes; | ||
/** | ||
@@ -11,8 +19,28 @@ * 分解泛型接口 | ||
function getGenericsClassNames(definitionClassName) { | ||
const splitIndex = definitionClassName.indexOf(exports.GENERIC_SPLIT_KEY); | ||
// 泛型基类 PagedResultDto | ||
const interfaceClassName = definitionClassName.slice(0, splitIndex); | ||
// 泛型类型 T 的类型名称 | ||
const TClassName = definitionClassName.slice(splitIndex + 1, -1); | ||
return { interfaceClassName, TClassName }; | ||
let str = ''; | ||
let split_key = ''; | ||
if (/^.+\[.+\]$/.test(definitionClassName)) { | ||
split_key = '['; | ||
} | ||
else if (/^.+\«.+\»$/.test(definitionClassName)) { | ||
split_key = '«'; | ||
} | ||
else if (/^.+\<.+\>$/.test(definitionClassName)) { | ||
split_key = '<'; | ||
} | ||
if (split_key !== '') { | ||
const splitIndex = definitionClassName.indexOf(split_key); | ||
// 泛型基类 PagedResultDto | ||
const interfaceClassName = definitionClassName.slice(0, splitIndex); | ||
// 泛型类型 T 的类型名称 | ||
const TClassName = definitionClassName.slice(splitIndex + 1, -1); | ||
str = exports.isDefinedGenericTypes(interfaceClassName) | ||
? `${interfaceClassName}<${refClassName(TClassName)}>` | ||
: trimString(RemoveSpecialCharacters(definitionClassName), '_', 'right'); | ||
} | ||
else { | ||
console.log('str', definitionClassName); | ||
str = trimString(RemoveSpecialCharacters(definitionClassName), '_', 'right'); | ||
} | ||
return str; | ||
} | ||
@@ -27,11 +55,5 @@ exports.getGenericsClassNames = getGenericsClassNames; | ||
let propType = (_a = s) === null || _a === void 0 ? void 0 : _a.slice(s.lastIndexOf('/') + 1); | ||
if (exports.isGenerics(propType)) { | ||
const { interfaceClassName, TClassName } = getGenericsClassNames(propType); | ||
// return `${interfaceClassName}<${toBaseType(TClassName)}>` | ||
const str = trimString(RemoveSpecialCharacters(propType), '_', 'right'); | ||
return str; | ||
} | ||
else { | ||
return propType; | ||
} | ||
return exports.isOpenApiGenerics(propType) | ||
? getGenericsClassNames(propType) | ||
: trimString(toBaseType(RemoveSpecialCharacters(propType)), '_', 'right'); | ||
} | ||
@@ -38,0 +60,0 @@ exports.refClassName = refClassName; |
{ | ||
"name": "swagger-axios-codegen", | ||
"version": "0.9.7", | ||
"version": "0.9.8", | ||
"main": "./dist/index", | ||
@@ -31,3 +31,4 @@ "typings": "./dist/", | ||
"pascalcase": "^0.1.1", | ||
"prettier": "^1.15.2" | ||
"prettier": "^1.15.2", | ||
"structured-log": "^0.2.0" | ||
}, | ||
@@ -34,0 +35,0 @@ "devDependencies": { |
@@ -5,2 +5,3 @@ # swagger-axios-codegen | ||
![GitHub Workflow Status](https://img.shields.io/github/workflow/status/manweill/swagger-axios-codegen/NodeCI) | ||
[![NpmVersion](https://img.shields.io/npm/v/swagger-axios-codegen.svg)](https://www.npmjs.com/package/swagger-axios-codegen) | ||
@@ -52,3 +53,9 @@ [![npm](https://img.shields.io/npm/dm/swagger-axios-codegen.svg)](https://www.npmjs.com/package/swagger-axios-codegen) | ||
/** use class-transformer to transform the results */ | ||
useClassTransformer?: boolean | ||
useClassTransformer?: boolean, | ||
// force the specified swagger or openAPI version, | ||
openApi?: string | undefined, | ||
// extend file url. It will be inserted in front of the service method | ||
extendDefinitionFile?: string | undefined | ||
// mark generic type | ||
extendGenericType?: string[] | undefined | ||
} | ||
@@ -55,0 +62,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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
247357
136
3855
224
5
5
+ Addedstructured-log@^0.2.0
+ Addedstructured-log@0.2.0(transitive)