Skip to content

Commit b4820f4

Browse files
committed
fix: do not alias simple type variables like int, int64 as valid values
1 parent 90270d9 commit b4820f4

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

cmd/requestgen/field.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ func parseValidValuesTag(tags *structtag.Tags, fieldName string, argKind types.B
102102
logrus.Debugf("%s found valid values: %v", fieldName, validValueList)
103103

104104
switch argKind {
105-
case types.Int, types.Int64, types.Int32:
105+
case types.Int, types.Int64, types.Int32, types.Uint, types.Uint32, types.Uint64:
106106
var slice []int
107107
for _, s := range validValueList {
108108
i, err := strconv.Atoi(s)

cmd/requestgen/main.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,16 @@ func (g *Generator) stringTypesCollectorWalker(typeName string, file *File) func
463463
return false
464464
}
465465

466+
// if the raw type is already basic types, skip
467+
if isBasicType(typeValue.Type) {
468+
return false
469+
}
470+
466471
fullQualifiedTypeName := typeValue.Type.String()
467472
for _, n := range decl.Names {
468473
g.simpleTypeValueNames[fullQualifiedTypeName] = append(g.simpleTypeValueNames[fullQualifiedTypeName], Literal(n.String()))
469474
}
470-
log.Debugf("simpleTypeValueNames %s = %+v", fullQualifiedTypeName, g.simpleTypeValueNames[fullQualifiedTypeName])
475+
log.Debugf("simpleTypeValueNames %s = %+v typeValue = %+v", fullQualifiedTypeName, g.simpleTypeValueNames[fullQualifiedTypeName], typeValue)
471476

472477
if isTypeString(typeValue.Type) {
473478
for _, v := range decl.Values {

cmd/requestgen/typeutils.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ func getBasicKind(a types.Type) types.BasicKind {
8080
return 0
8181
}
8282

83+
func isBasicType(a types.Type) bool {
84+
_, ok := a.(*types.Basic)
85+
return ok
86+
}
87+
8388
func isTypeInt(a types.Type) bool {
8489
a = getUnderlyingType(a)
8590
basic, ok := a.(*types.Basic)

0 commit comments

Comments
 (0)