Skip to content

Commit

Permalink
增加验证类型合法性方法
Browse files Browse the repository at this point in the history
  • Loading branch information
Manweill committed Jan 26, 2024
1 parent c0d71c7 commit 51b2639
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/requestCodegen/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ export function requestCodegen(paths: IPaths, isV3: boolean, options: ISwaggerOp
options.methodNameMode === 'operationId'
? reqProps.operationId
: options.methodNameMode === 'shortOperationId'
? trimSuffix(reqProps.operationId, reqProps.tags?.[0])
: typeof options.methodNameMode === 'function'
? options.methodNameMode(reqProps)
: methodName
? trimSuffix(reqProps.operationId, reqProps.tags?.[0])
: typeof options.methodNameMode === 'function'
? options.methodNameMode(reqProps)
: methodName
if (!methodName) {
// console.warn('method Name is null:', path);
continue
Expand Down
8 changes: 7 additions & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function refClassName(s: string, format?: string): string {
: toBaseType(trimString(RemoveSpecialCharacters(propType), '_', 'right'), format)

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

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

const reg = new RegExp("^[a-zA-Z_][a-zA-Z0-9_]*$", 'g');

export function validRefTypeName(str: string) {
return reg.test(str)
}

export function isBaseType(s: string) {
return ['boolean', 'number', 'string', 'Date', 'any'].includes(s)
}
Expand Down

0 comments on commit 51b2639

Please # to comment.