Skip to content

Commit 51b2639

Browse files
committed
增加验证类型合法性方法
1 parent c0d71c7 commit 51b2639

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

src/requestCodegen/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ export function requestCodegen(paths: IPaths, isV3: boolean, options: ISwaggerOp
2929
options.methodNameMode === 'operationId'
3030
? reqProps.operationId
3131
: options.methodNameMode === 'shortOperationId'
32-
? trimSuffix(reqProps.operationId, reqProps.tags?.[0])
33-
: typeof options.methodNameMode === 'function'
34-
? options.methodNameMode(reqProps)
35-
: methodName
32+
? trimSuffix(reqProps.operationId, reqProps.tags?.[0])
33+
: typeof options.methodNameMode === 'function'
34+
? options.methodNameMode(reqProps)
35+
: methodName
3636
if (!methodName) {
3737
// console.warn('method Name is null:', path);
3838
continue

src/utils.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export function refClassName(s: string, format?: string): string {
6666
: toBaseType(trimString(RemoveSpecialCharacters(propType), '_', 'right'), format)
6767

6868
// 如果是数字开头,则加上下划线
69-
if (!Number.isNaN(Number(result[0]))) result = '_' + result
69+
if (!Number.isNaN(Number(result[0]))) result = 'IRef' + result
7070
return result
7171
}
7272

@@ -75,6 +75,12 @@ export function RemoveSpecialCharacters(str: string) {
7575
return str?.replace(/[-`~!@#$%^&*()_+<>«»?:"{},.\/;'[\]]/g, '_')
7676
}
7777

78+
const reg = new RegExp("^[a-zA-Z_][a-zA-Z0-9_]*$", 'g');
79+
80+
export function validRefTypeName(str: string) {
81+
return reg.test(str)
82+
}
83+
7884
export function isBaseType(s: string) {
7985
return ['boolean', 'number', 'string', 'Date', 'any'].includes(s)
8086
}

0 commit comments

Comments
 (0)