swagger-axios-codegen
Advanced tools
Comparing version 0.11.14 to 0.11.15
## 0.11.15 | ||
- fix classTransform feature | ||
## 0.11.14 | ||
@@ -3,0 +7,0 @@ |
@@ -0,1 +1,2 @@ | ||
/** 生成器参数 */ | ||
export interface ICodegenOptions { | ||
@@ -8,3 +9,3 @@ serviceNameSuffix?: string; | ||
remoteUrl?: string; | ||
source?: any; | ||
source?: unknown; | ||
useCustomerRequestInstance?: boolean | undefined; | ||
@@ -29,3 +30,7 @@ serviceOptionsMode?: 'inFile' | 'shared'; | ||
format?: (s: string) => string; | ||
include?: Array<string | IInclude>; | ||
} | ||
export interface IInclude { | ||
[key: string]: string[]; | ||
} | ||
export declare const defaultOptions: ICodegenOptions; | ||
@@ -32,0 +37,0 @@ declare type IEnvConfig = { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.envConfig = exports.defaultOptions = void 0; | ||
exports.defaultOptions = { | ||
@@ -15,4 +16,3 @@ serviceNameSuffix: 'Service', | ||
multipleFileMode: false, | ||
serviceOptionsMode: 'inFile', | ||
openApiVersion: '2' | ||
serviceOptionsMode: 'inFile' | ||
}; | ||
@@ -19,0 +19,0 @@ exports.envConfig = { |
@@ -1,6 +0,6 @@ | ||
import { IPropDef } from "../types/CodegenInterfaces"; | ||
import { IPropDef } from "@/types/CodegenInterfaces"; | ||
/** 类模板 */ | ||
export declare function interfaceTemplate(name: string, props: IPropDef[], imports: string[]): string; | ||
export declare function interfaceTemplate(name: string, props: IPropDef[], imports: string[], strictNullChecks?: boolean): string; | ||
/** 类模板 */ | ||
export declare function classTemplate(name: string, props: IPropDef[], imports: string[]): string; | ||
export declare function classTemplate(name: string, props: IPropDef[], imports: string[], strictNullChecks: boolean, useClassTransformer: boolean, generateValidationModel: boolean): string; | ||
/** 类属性模板 */ | ||
@@ -7,0 +7,0 @@ export declare function classPropsTemplate(filedName: string, type: string, format: string, description: string, canNull: boolean, useClassTransformer: boolean, isType: boolean): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const envConfig_1 = require("../envConfig"); | ||
const baseType_1 = require("../utils/baseType"); | ||
const genericTypesUtils_1 = require("../utils/genericTypesUtils"); | ||
exports.classConstructorTemplate = exports.classTransformTemplate = exports.classValidationModelTemplate = exports.propValidationModelTemplate = exports.classPropsTemplate = exports.classTemplate = exports.interfaceTemplate = void 0; | ||
const baseTypeUtils_1 = require("@/utils/baseTypeUtils"); | ||
const genericTypesUtils_1 = require("@/utils/genericTypesUtils"); | ||
const baseTypes = ['string', 'number', 'object', 'boolean', 'any']; | ||
/** 类模板 */ | ||
function interfaceTemplate(name, props, imports) { | ||
const { strictNullChecks } = envConfig_1.envConfig.options; | ||
function interfaceTemplate(name, props, imports, strictNullChecks = true) { | ||
if (genericTypesUtils_1.isDefinedGenericTypes(name)) { | ||
@@ -24,3 +24,6 @@ // 已经定义过的interface不再生成 | ||
${props.map(p => classPropsTemplate(p.name, p.type, p.format, p.desc, !strictNullChecks, false, false)).join('')} | ||
${props.map(p => { | ||
var _a; | ||
return classPropsTemplate(p.name, p.type, p.format, p.desc, !strictNullChecks || !((_a = p.validationModel) === null || _a === void 0 ? void 0 : _a.required), false, false); | ||
}).join('')} | ||
} | ||
@@ -31,4 +34,3 @@ `; | ||
/** 类模板 */ | ||
function classTemplate(name, props, imports) { | ||
const { strictNullChecks, useClassTransformer, generateValidationModel } = envConfig_1.envConfig.options; | ||
function classTemplate(name, props, imports, strictNullChecks = true, useClassTransformer, generateValidationModel) { | ||
// 所有的引用 | ||
@@ -48,3 +50,6 @@ const mappedImports = imports.map(imp => { | ||
${props | ||
.map(p => classPropsTemplate(p.name, p.type, p.format, p.desc, !strictNullChecks, useClassTransformer, p.isEnum || p.isType)) | ||
.map(p => { | ||
var _a; | ||
return classPropsTemplate(p.name, p.type, p.format, p.desc, !strictNullChecks || !((_a = p.validationModel) === null || _a === void 0 ? void 0 : _a.required), useClassTransformer, p.isEnum || p.isType); | ||
}) | ||
.join('')} | ||
@@ -67,3 +72,3 @@ | ||
*/ | ||
type = baseType_1.toBaseType(type, format); | ||
type = baseTypeUtils_1.toBaseType(type); | ||
if (useClassTransformer) { | ||
@@ -112,3 +117,3 @@ const decorators = classTransformTemplate(type, format, isType); | ||
/* ignore interfaces */ | ||
if (baseType_1.isBaseType(nonArrayType) && !isType) { | ||
if (baseTypes.indexOf(nonArrayType) < 0 && !isType) { | ||
decorators.push(`@Type(() => ${nonArrayType})`); | ||
@@ -115,0 +120,0 @@ } |
/** 枚举 */ | ||
export declare function enumTemplate(name: string, enumString: string): string; | ||
export declare function typeTemplate(name: string, typeString: string): string; | ||
export declare function enumTemplate(name: string, enumString: string, prefix?: string): string; | ||
export declare function typeTemplate(name: string, typeString: string, prefix?: string): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.typeTemplate = exports.enumTemplate = void 0; | ||
/** 枚举 */ | ||
function enumTemplate(name, enumString) { | ||
function enumTemplate(name, enumString, prefix) { | ||
return ` | ||
@@ -12,3 +13,3 @@ export enum ${name}{ | ||
exports.enumTemplate = enumTemplate; | ||
function typeTemplate(name, typeString) { | ||
function typeTemplate(name, typeString, prefix) { | ||
return ` | ||
@@ -15,0 +16,0 @@ export type ${name} = ${typeString}; |
@@ -0,3 +1,5 @@ | ||
/**默认的服务头文件 */ | ||
export declare function defaultServiceHeader(basePath: string): string; | ||
/** 自定义请求客户端的服务头文件 */ | ||
export declare function customerReqClientServiceHeader(basePath: string): string; | ||
export declare function definitionHeader(fileDir: string | undefined): string; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.definitionHeader = exports.customerReqClientServiceHeader = exports.defaultServiceHeader = void 0; | ||
const fs = __importStar(require("fs")); | ||
const path = __importStar(require("path")); | ||
const stringUtils_1 = require("../utils/stringUtils"); | ||
const envConfig_1 = require("../envConfig"); | ||
const stringUtils_1 = require("@/utils/stringUtils"); | ||
const envConfig_1 = require("@/envConfig"); | ||
const genericTypeDefinitionTemplate_1 = require("./genericTypeDefinitionTemplate"); | ||
/**默认的服务头文件 */ | ||
function defaultServiceHeader(basePath) { | ||
@@ -19,3 +33,4 @@ // TODO: move to class template | ||
? `import { Expose, Transform, Type, plainToClass } from 'class-transformer'; | ||
` : ''; | ||
` | ||
: ''; | ||
return `/* eslint-disable */ | ||
@@ -52,2 +67,3 @@ /** Generate by swagger-axios-codegen */ | ||
exports.defaultServiceHeader = defaultServiceHeader; | ||
/** 自定义请求客户端的服务头文件 */ | ||
function customerReqClientServiceHeader(basePath) { | ||
@@ -137,3 +153,3 @@ return `/* eslint-disable */ | ||
let fileStr = '// empty '; | ||
if (!!fileDir) { | ||
if (fileDir) { | ||
console.log('extendDefinitionFile url : ', path.resolve(fileDir)); | ||
@@ -140,0 +156,0 @@ if (fs.existsSync(path.resolve(fileDir))) { |
@@ -73,3 +73,3 @@ "use strict"; | ||
type = utils_1.toBaseType(type, format); | ||
if (useClassTransformer) { | ||
if (useClassTransformer && format) { | ||
const decorators = classTransformTemplate(type, format, isType); | ||
@@ -76,0 +76,0 @@ return ` |
@@ -9,2 +9,3 @@ export interface ISwaggerSource { | ||
} | ||
/**Deprecated */ | ||
export interface IEnumDef { | ||
@@ -15,2 +16,3 @@ name: string; | ||
} | ||
/**Deprecated */ | ||
export interface IDefinitionEnum { | ||
@@ -21,5 +23,29 @@ name: string; | ||
} | ||
/**Deprecated */ | ||
export interface IDefinitionEnums { | ||
[key: string]: IDefinitionEnum; | ||
} | ||
/** | ||
* Enum描述定义 | ||
*/ | ||
export interface IEnumDefSpec { | ||
/**枚举的名字,不包括前缀 */ | ||
name: string; | ||
/**枚举的枚举项 */ | ||
props: INameValue[]; | ||
/**枚举的类型,int或者字符串等 */ | ||
type: string; | ||
} | ||
/** | ||
* Enum描述定义,有可能与IEnumDefSpec合并 | ||
*/ | ||
export interface IDefinitionEnumSpec { | ||
name: string; | ||
value?: IEnumDefSpec | null | undefined; | ||
content?: string | null | undefined; | ||
} | ||
/**枚举定义集合 */ | ||
export interface IDefinitionEnumSpecs { | ||
[key: string]: IDefinitionEnumSpec; | ||
} | ||
export interface IPropDef { | ||
@@ -34,5 +60,2 @@ name: string; | ||
} | ||
export interface IInclude { | ||
[key: string]: string[]; | ||
} | ||
export interface IClassDef { | ||
@@ -62,1 +85,5 @@ name: string; | ||
} | ||
export interface INameValue { | ||
name: string; | ||
value: any; | ||
} |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Map = exports.Dictionary = void 0; | ||
class Dictionary { | ||
@@ -4,0 +5,0 @@ } |
@@ -8,2 +8,3 @@ export interface ISwaggerSource { | ||
definitions: IDefinitions; | ||
components: IComponents; | ||
externalDocs: string; | ||
@@ -26,2 +27,3 @@ basePath?: string | undefined; | ||
parameters: IParameter[]; | ||
requestBody: IRequestBody; | ||
responses: { | ||
@@ -31,6 +33,6 @@ [key: string]: { | ||
schema: { | ||
'$ref': string; | ||
'type'?: string; | ||
'items'?: IParameterItems; | ||
'format'?: string; | ||
$ref: string; | ||
type?: string; | ||
items?: IParameterItems; | ||
format?: string; | ||
}; | ||
@@ -40,6 +42,6 @@ content: { | ||
schema: { | ||
'$ref': string; | ||
'type'?: string; | ||
'items'?: IParameterItems; | ||
'format'?: string; | ||
$ref: string; | ||
type?: string; | ||
items?: IParameterItems; | ||
format?: string; | ||
}; | ||
@@ -51,2 +53,9 @@ }; | ||
} | ||
export interface IRequestBody { | ||
content: { | ||
[key: string]: { | ||
schema: ISchema; | ||
}; | ||
}; | ||
} | ||
export declare type IParameterIn = 'path' | 'formData' | 'query' | 'body'; | ||
@@ -93,13 +102,20 @@ export interface IParameter { | ||
$ref: string; | ||
allOf: IDefinitionProperty[]; | ||
oneOf: IDefinitionProperty[]; | ||
items: IDefinitionProperty; | ||
description: string; | ||
} | ||
export interface IComponents { | ||
schemas: { | ||
[key: string]: IDefinition; | ||
}; | ||
} | ||
export interface ISchema { | ||
'$ref': string; | ||
'type'?: string; | ||
'items'?: IParameterItems; | ||
'format'?: string; | ||
'properties'?: { | ||
$ref: string; | ||
type?: string; | ||
items?: IParameterItems; | ||
format?: string; | ||
properties?: { | ||
[key: string]: IParameterItems; | ||
}; | ||
} |
@@ -7,5 +7,8 @@ export interface ISwaggerSource { | ||
securityDefinitions: string; | ||
/**一个包含多种纲要的元素,可重复使用组件 */ | ||
definitions: IDefinitions; | ||
/**一个包含多种纲要的元素,可重复使用组件 */ | ||
components: IComponents; | ||
externalDocs: string; | ||
/** 基本路径 */ | ||
basePath?: string | undefined; | ||
@@ -21,2 +24,3 @@ } | ||
tags: string[]; | ||
/**简要总结,描述此路径内包含的所有操作。 */ | ||
summary: string; | ||
@@ -27,3 +31,5 @@ description: string; | ||
produces: string[]; | ||
/** 请求参数 */ | ||
parameters: IParameter[]; | ||
/** 请求 */ | ||
requestBody: IRequestBody; | ||
@@ -33,15 +39,9 @@ responses: { | ||
description: string; | ||
schema: { | ||
'$ref': string; | ||
'type'?: string; | ||
'items'?: IParameterItems; | ||
'format'?: string; | ||
}; | ||
content: { | ||
[key: string]: { | ||
schema: { | ||
'$ref': string; | ||
'type'?: string; | ||
'items'?: IParameterItems; | ||
'format'?: string; | ||
$ref: string; | ||
type?: string; | ||
items?: IParameterItems; | ||
format?: string; | ||
}; | ||
@@ -56,3 +56,3 @@ }; | ||
[key: string]: { | ||
schema: ISchema; | ||
schema: IRequestBodySchema; | ||
}; | ||
@@ -62,2 +62,5 @@ }; | ||
export declare type IParameterIn = 'path' | 'formData' | 'query' | 'body'; | ||
export declare type IParameterRef = { | ||
$ref: string; | ||
}; | ||
export interface IParameter { | ||
@@ -72,2 +75,3 @@ in: IParameterIn; | ||
format: string; | ||
$ref: string; | ||
} | ||
@@ -79,2 +83,3 @@ export interface IParameterSchema { | ||
} | ||
/**参数项 */ | ||
export interface IParameterItems { | ||
@@ -111,14 +116,22 @@ type?: string; | ||
export interface IComponents { | ||
schemas: { | ||
schemas: IComponentsSchemas; | ||
requestBodies: { | ||
[key: string]: IDefinition; | ||
}; | ||
responses: { | ||
[key: string]: IDefinition; | ||
}; | ||
parameters: IParameter[]; | ||
} | ||
export interface ISchema { | ||
'$ref': string; | ||
'type'?: string; | ||
'items'?: IParameterItems; | ||
'format'?: string; | ||
'properties'?: { | ||
export interface IComponentsSchemas { | ||
[key: string]: IDefinition; | ||
} | ||
export interface IRequestBodySchema { | ||
$ref: string; | ||
type?: string; | ||
items?: IParameterItems; | ||
format?: string; | ||
properties?: { | ||
[key: string]: IParameterItems; | ||
}; | ||
} |
@@ -8,7 +8,10 @@ "use strict"; | ||
// 是否是接口类型 | ||
exports.isOpenApiGenerics = (s) => /^.+\[.+\]$/.test(s) || /^.+\«.+\»$/.test(s) || /^.+\<.+\>$/.test(s); | ||
exports.isGenerics = (s) => { | ||
const isOpenApiGenerics = (s) => /^.+\[.+\]$/.test(s) || /^.+\«.+\»$/.test(s) || /^.+\<.+\>$/.test(s); | ||
exports.isOpenApiGenerics = isOpenApiGenerics; | ||
const isGenerics = (s) => { | ||
return /^.+\<.+\>$/.test(s); | ||
}; | ||
exports.isDefinedGenericTypes = (x) => definedGenericTypes.some(i => i === x); | ||
exports.isGenerics = isGenerics; | ||
const isDefinedGenericTypes = (x) => definedGenericTypes.some(i => i === x); | ||
exports.isDefinedGenericTypes = isDefinedGenericTypes; | ||
function setDefinedGenericTypes(types = []) { | ||
@@ -18,3 +21,4 @@ definedGenericTypes.push(...UniversalGenericTypes, ...AbpGenericTypes, ...types); | ||
exports.setDefinedGenericTypes = setDefinedGenericTypes; | ||
exports.getDefinedGenericTypes = () => definedGenericTypes; | ||
const getDefinedGenericTypes = () => definedGenericTypes; | ||
exports.getDefinedGenericTypes = getDefinedGenericTypes; | ||
/** | ||
@@ -21,0 +25,0 @@ * 分解泛型接口 |
@@ -1,3 +0,4 @@ | ||
import { ICodegenOptions } from "../envConfig"; | ||
export declare function fileWrite(fileDir: string, name: string, data: any): void; | ||
export declare function fileFormat(text: string, options: ICodegenOptions): string; | ||
import { ICodegenOptions } from '@/envConfig'; | ||
/** 把内容写到文件 */ | ||
export declare function writeFile(fileDir: string, name: string, data: any): void; | ||
export declare function FileFormat(text: string, options: ICodegenOptions): string; |
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; | ||
result["default"] = mod; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
@@ -13,6 +25,8 @@ }; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.FileFormat = exports.writeFile = void 0; | ||
const fs = __importStar(require("fs")); | ||
const path = __importStar(require("path")); | ||
const prettier_1 = __importDefault(require("prettier")); | ||
function fileWrite(fileDir, name, data) { | ||
/** 把内容写到文件 */ | ||
function writeFile(fileDir, name, data) { | ||
if (!fs.existsSync(fileDir)) { | ||
@@ -25,4 +39,4 @@ fs.mkdirSync(fileDir); | ||
} | ||
exports.fileWrite = fileWrite; | ||
function fileFormat(text, options) { | ||
exports.writeFile = writeFile; | ||
function FileFormat(text, options) { | ||
if (options.format) { | ||
@@ -45,3 +59,3 @@ // console.log('use custom formatter') | ||
} | ||
exports.fileFormat = fileFormat; | ||
exports.FileFormat = FileFormat; | ||
//# sourceMappingURL=fileUtils.js.map |
@@ -11,5 +11,7 @@ export declare const isOpenApiGenerics: (s: string) => boolean; | ||
/** | ||
* 数组类名转泛型类名 | ||
* [A,B,C] => A<B<C>> | ||
* 分解泛型接口 | ||
* @param className | ||
*/ | ||
export declare function classNamesToGenerics(classNames: string[]): string; | ||
export declare function splitGenericsClassName(className: string): string[]; | ||
/** 使类型数组转换成泛型名称 */ | ||
export declare function combineGenericsType(classNameArray: string[]): string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const envConfig_1 = require("../envConfig"); | ||
exports.combineGenericsType = exports.splitGenericsClassName = exports.genericsToClassNames = exports.setDefinedGenericTypes = exports.isDefinedGenericTypes = exports.isGenerics = exports.isOpenApiGenerics = void 0; | ||
const envConfig_1 = require("@/envConfig"); | ||
const UniversalGenericTypes = ['IList', 'List']; | ||
const AbpGenericTypes = ['IListResult', 'ListResultDto', 'IPagedResult', 'PagedResultDto', 'Dictionary', 'IDictionary']; | ||
// 是否是接口类型 | ||
exports.isOpenApiGenerics = (s) => /^.+\[.+\]$/.test(s) || /^.+\«.+\»$/.test(s) || /^.+\<.+\>$/.test(s); | ||
exports.isGenerics = (s) => { | ||
// 所有的泛型定义最终都转为<>格式,例如List<Result> | ||
return /^.+\<.+\>$/.test(s); | ||
// 是否是泛型类型 | ||
const isOpenApiGenerics = (s) => /^.+\[.+\]$/.test(s) || /^.+\«.+\»$/.test(s) || /^.+\<.+\>$/.test(s); | ||
exports.isOpenApiGenerics = isOpenApiGenerics; | ||
const isGenerics = (s) => { | ||
return /^.+<.+>$/.test(s); | ||
}; | ||
exports.isDefinedGenericTypes = (x) => envConfig_1.envConfig.definedGenericTypes.some(i => i === x); | ||
exports.isGenerics = isGenerics; | ||
const isDefinedGenericTypes = (x) => envConfig_1.envConfig.definedGenericTypes.some((i) => i === x); | ||
exports.isDefinedGenericTypes = isDefinedGenericTypes; | ||
function setDefinedGenericTypes(types = []) { | ||
@@ -35,17 +38,24 @@ envConfig_1.envConfig.definedGenericTypes.push(...UniversalGenericTypes, ...AbpGenericTypes, ...types); | ||
/** | ||
* 数组类名转泛型类名 | ||
* [A,B,C] => A<B<C>> | ||
* 分解泛型接口 | ||
* @param className | ||
*/ | ||
function classNamesToGenerics(classNames) { | ||
const len = classNames.length; | ||
if (len > 1) { | ||
const end = new Array(len).join('>'); | ||
const name = classNames.join('<') + end; | ||
return name; | ||
function splitGenericsClassName(className) { | ||
if (/^.+\[.+\]$/.test(className)) { | ||
return className.split(/[\[\]]+/); | ||
} | ||
else if (len === 1) { | ||
return classNames[1]; | ||
else if (/^.+«.+»$/.test(className)) { | ||
return className.split(/[«»]+/); | ||
} | ||
else if (/^.+<.+>$/.test(className)) { | ||
return className.split(/[<>]+/); | ||
} | ||
return []; | ||
} | ||
exports.classNamesToGenerics = classNamesToGenerics; | ||
exports.splitGenericsClassName = splitGenericsClassName; | ||
/** 使类型数组转换成泛型名称 */ | ||
function combineGenericsType(classNameArray) { | ||
const [interfaceClassName, ...TClassName] = classNameArray; | ||
return `${interfaceClassName}<${combineGenericsType(TClassName)}>`; | ||
} | ||
exports.combineGenericsType = combineGenericsType; | ||
//# sourceMappingURL=genericTypesUtils.js.map |
@@ -5,2 +5,6 @@ declare const message: { | ||
}; | ||
export declare const LogMsg: { | ||
success: (msg: string | any) => void; | ||
error: (msg: any) => void; | ||
}; | ||
export default message; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LogMsg = void 0; | ||
const msgColor = { | ||
'success': '\x1b[32m', | ||
'error': '\x1b[91m' | ||
success: '\x1b[32m', | ||
error: '\x1b[91m' | ||
}; | ||
@@ -11,3 +12,7 @@ const message = { | ||
}; | ||
exports.LogMsg = { | ||
success: (msg) => console.log(msgColor.success + msg), | ||
error: (msg) => console.log(msgColor.error + msg) | ||
}; | ||
exports.default = message; | ||
//# sourceMappingURL=logTipsUtils.js.map |
@@ -1,3 +0,8 @@ | ||
import { IDefinitionClass, IDefinitionEnum } from "../types/CodegenInterfaces"; | ||
import { IDefinitionClass, IDefinitionEnum } from '@/types/CodegenInterfaces'; | ||
/** | ||
* 获取引用类型 | ||
* @param s | ||
*/ | ||
export declare function refClassName(s: string): string; | ||
/** | ||
* 查找深层引用 | ||
@@ -4,0 +9,0 @@ * @param imports 所有的应用 |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const genericTypesUtils_1 = require("./genericTypesUtils"); | ||
exports.findDeepRefs = exports.refClassName = void 0; | ||
const genericTypesUtils_1 = require("@/utils/genericTypesUtils"); | ||
const baseTypeUtils_1 = require("./baseTypeUtils"); | ||
const stringUtils_1 = require("./stringUtils"); | ||
const lodash_1 = __importDefault(require("lodash")); | ||
/** | ||
* 获取引用类型 | ||
* @param s | ||
*/ | ||
function refClassName(s) { | ||
let propType = s === null || s === void 0 ? void 0 : s.slice(s.lastIndexOf('/') + 1); | ||
return genericTypesUtils_1.isOpenApiGenerics(propType) | ||
? getGenericsClassName(propType) | ||
: baseTypeUtils_1.toBaseType(lodash_1.default.trimEnd(stringUtils_1.removeSpecialCharacters(propType), '_')); | ||
} | ||
exports.refClassName = refClassName; | ||
/** | ||
* 获取泛型类名 | ||
* A[B[C]] => A<B<C>>,* A<<B<<C>>>> => A<B<C>> | ||
*/ | ||
function getGenericsClassName(className) { | ||
const genericNames = genericTypesUtils_1.splitGenericsClassName(className); | ||
if (genericNames.length < 0) | ||
return ''; | ||
genericNames.filter(Boolean).map((item) => baseTypeUtils_1.toBaseType(lodash_1.default.trimEnd(stringUtils_1.removeSpecialCharacters(item), '_'))); | ||
return genericTypesUtils_1.combineGenericsType(genericNames); | ||
} | ||
/** | ||
* 查找深层引用 | ||
@@ -12,3 +41,3 @@ * @param imports 所有的应用 | ||
function findDeepRefs(imports, allDefinition, allEnums, currentImports = []) { | ||
let result = (currentImports !== null && currentImports !== void 0 ? currentImports : []); | ||
let result = currentImports !== null && currentImports !== void 0 ? currentImports : []; | ||
// if (imports.includes('AuthUserStationDto[]')) { | ||
@@ -24,5 +53,5 @@ // console.log('result init', imports, currentImports); | ||
let ref = null; | ||
ref = allDefinition.find(item => modelName === item.name); | ||
ref = allDefinition.find((item) => modelName === item.name); | ||
if (ref == null) | ||
ref = allDefinition.find(item => modelName.startsWith(item.name)); | ||
ref = allDefinition.find((item) => modelName.startsWith(item.name)); | ||
// if (modelNames.includes('AuthUserStationDto[]')) { | ||
@@ -40,3 +69,3 @@ // console.log('ref', JSON.stringify(ref)); | ||
if (ref.value.imports.length > 0) { | ||
let uniqueImports = []; | ||
const uniqueImports = []; | ||
for (const importItem of ref.value.imports) { | ||
@@ -47,7 +76,7 @@ if (result.includes(importItem) || uniqueImports.includes(importItem)) | ||
} | ||
let deepRefs = findDeepRefs(uniqueImports, allDefinition, allEnums, result); | ||
const deepRefs = findDeepRefs(uniqueImports, allDefinition, allEnums, result); | ||
// if (ref.value.imports.includes('MotorMonthlyCurrentItem') || ref.value.imports.includes('MotorMonthlyDto')) { | ||
// console.log('uniqueImports', deepRefs); | ||
// } | ||
if (!!deepRefs) { | ||
if (deepRefs) { | ||
result = deepRefs; | ||
@@ -58,3 +87,3 @@ } | ||
else { | ||
ref = allEnums.find(item => modelNames.some((modelName) => modelName.startsWith(item.name))); | ||
ref = allEnums.find((item) => modelNames.some((modelName) => modelName.startsWith(item.name))); | ||
if (ref) { | ||
@@ -61,0 +90,0 @@ result.push(ref.name); |
export declare function trimString(str: string, char: string, type: string): string; | ||
/** 移除特殊字符 */ | ||
export declare function RemoveSpecialCharacters(str: string): string; | ||
export declare function pascalcaseStr(str: string): string; | ||
export declare function removeSpecialCharacters(str: string): string; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const pascalcase_1 = __importDefault(require("pascalcase")); | ||
exports.removeSpecialCharacters = exports.trimString = void 0; | ||
function trimString(str, char, type) { | ||
str = (str !== null && str !== void 0 ? str : ''); | ||
str = str !== null && str !== void 0 ? str : ''; | ||
if (char) { | ||
@@ -22,11 +19,6 @@ if (type == 'left') { | ||
/** 移除特殊字符 */ | ||
function RemoveSpecialCharacters(str) { | ||
var _a; | ||
return (_a = str) === null || _a === void 0 ? void 0 : _a.replace(/[`~!@#$%^&*()_+<>«»?:"{},.\/;'[\]]/g, '_'); | ||
function removeSpecialCharacters(str) { | ||
return str === null || str === void 0 ? void 0 : str.replace(/[`~!@#$%^&*()_+<>«»?:"{},.\/;'[\]]/g, '_'); | ||
} | ||
exports.RemoveSpecialCharacters = RemoveSpecialCharacters; | ||
function pascalcaseStr(str) { | ||
return pascalcase_1.default(str); | ||
} | ||
exports.pascalcaseStr = pascalcaseStr; | ||
exports.removeSpecialCharacters = removeSpecialCharacters; | ||
//# sourceMappingURL=stringUtils.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function getValidationModel(propName, prop, required) { | ||
let validationModel = {}; | ||
let hasValidationRules = false; | ||
if (required && required.includes(propName)) { | ||
validationModel.required = true; | ||
hasValidationRules = true; | ||
} | ||
if (prop.maxLength) { | ||
validationModel.maxLength = prop.maxLength; | ||
hasValidationRules = true; | ||
} | ||
return hasValidationRules ? validationModel : null; | ||
} | ||
exports.getValidationModel = getValidationModel; | ||
//# sourceMappingURL=validationModelUtils.js.map |
{ | ||
"name": "swagger-axios-codegen", | ||
"version": "0.11.14", | ||
"version": "0.11.15", | ||
"main": "./dist/index", | ||
@@ -41,2 +41,2 @@ "typings": "./dist/", | ||
} | ||
} | ||
} |
@@ -181,11 +181,5 @@ # swagger-axios-codegen | ||
fliter by [multimatch](https://github.com/sindresorhus/multimatch) | ||
fliter by [multimatch](https://github.com/sindresorhus/multimatch) using 'include' setting | ||
```js | ||
let include = [ | ||
'*', | ||
// 'Products*', | ||
'!Products', | ||
{ 'User': ['*', '!history'] }, | ||
] | ||
codegen({ | ||
@@ -195,3 +189,8 @@ methodNameMode: 'path', | ||
outputDir: './swagger/services', | ||
include | ||
include: [ | ||
'*', | ||
// 'Products*', | ||
'!Products', | ||
{ 'User': ['*', '!history'] }, | ||
] | ||
}) | ||
@@ -202,3 +201,3 @@ ``` | ||
Eg. The service names are `MyApp.FirstModule.Products`, `MyApp.FirstModule.Customers`, `MyApp.SecondModule.Orders`: | ||
For example the service names are `MyApp.FirstModule.Products`, `MyApp.FirstModule.Customers`, `MyApp.SecondModule.Orders`: | ||
@@ -211,3 +210,3 @@ ```json | ||
"tags": [ | ||
"MyApp.MyModule.Products" | ||
"MyApp.FirstModule.Products" | ||
], | ||
@@ -223,3 +222,3 @@ "operationId": "Get", | ||
outputDir: './swagger/services', | ||
include: ['MyAppMyModule*'] // Only Products and Customers will be included | ||
include: ['MyAppFirstModule*'] // Only Products and Customers will be included. As you can see dots are escaped being contract names. | ||
}) | ||
@@ -226,0 +225,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
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
279790
165
4275
311