Skip to content

Commit 9ae8cdb

Browse files
fairkingManweill
authored andcommitted
Wrong property type generated on binary #209
1 parent 71674b7 commit 9ae8cdb

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

src/utils.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ export function getGenericsClassNames(definitionClassName: string): string {
4141
const TClassName = definitionClassName.slice(splitIndex + 1, -1)
4242
if (isDefinedGenericTypes(interfaceClassName)) {
4343
str = interfaceClassName === 'IDictionary' || interfaceClassName === 'Dictionary'
44-
? `${interfaceClassName}<object>`
45-
: `${interfaceClassName}<${refClassName(TClassName)}>`
44+
? `${interfaceClassName}<object>`
45+
: `${interfaceClassName}<${refClassName(TClassName)}>`
4646

4747
} else {
4848
str = trimString(RemoveSpecialCharacters(definitionClassName), '_', 'right')
@@ -81,40 +81,47 @@ export function validRefTypeName(str: string) {
8181
return reg.test(str)
8282
}
8383

84-
export function isBaseType(s: string) {
84+
export function isBaseType(s: string): boolean {
8585
return ['boolean', 'number', 'string', 'Date', 'any'].includes(s)
8686
}
8787

88-
export function toBaseType(s: string, format?: string) {
88+
export function toBaseType(s: string, format?: string): string {
8989
if (s === undefined || s === null || s.length === 0) {
9090
return 'any | null'
9191
}
92+
93+
const s_lower = s.toLowerCase()
94+
const format_lower = format?.toLowerCase()
95+
9296
let result = ''
93-
switch (s) {
97+
switch (s_lower) {
9498
case 'boolean':
9599
case 'bool':
96-
case 'Boolean':
97100
result = 'boolean'
98101
break
99102
case 'array':
100103
result = '[]'
101104
break
102-
case 'Int64':
103-
case 'Int32':
105+
case 'int64':
106+
case 'int32':
104107
case 'int':
105108
case 'integer':
106109
case 'number':
107-
result = format === 'int64' || format === 'Int64' || format === 'long' ? 'string' : 'number'
110+
result = format_lower === 'int64' || format_lower === 'long' ? 'string' : 'number'
108111
break
109-
case 'Guid':
110-
case 'String':
111-
case 'string':
112112
case 'uuid':
113-
switch (format) {
113+
case 'guid':
114+
result = 'string'
115+
break
116+
case 'string':
117+
switch (format_lower) {
114118
case 'date':
115119
case 'date-time':
116120
result = 'Date'
117121
break
122+
case 'binary':
123+
result = 'any'
124+
break
118125
default:
119126
result = 'string'
120127
}
@@ -161,7 +168,7 @@ export function trimString(str: string, char: string, type: string) {
161168
return str.replace(/^\s+|\s+$/g, '')
162169
}
163170

164-
/**
171+
/**
165172
* 泛型类名提取数组
166173
* A<B<C>> => [A,B,C]
167174
**/
@@ -300,4 +307,4 @@ export function getValidationModel(propName: string, prop: IDefinitionProperty,
300307
hasValidationRules = true
301308
}
302309
return hasValidationRules ? validationModel : null
303-
}
310+
}

0 commit comments

Comments
 (0)