Skip to content

Commit

Permalink
fix bug: enums of explicit type conversion (#1556)
Browse files Browse the repository at this point in the history
Signed-off-by: sdghchj <sdghchj@qq.com>
  • Loading branch information
sdghchj committed Apr 17, 2023
1 parent 01d20cc commit c14cc8e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 2 additions & 3 deletions package.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,19 +158,18 @@ func (pkg *PackageDefinitions) evaluateConstValue(file *ast.File, iota int, expr
if name == "uintptr" {
name = "uint"
}
value, _ := pkg.evaluateConstValue(file, iota, arg, globalEvaluator, recursiveStack)
if IsGolangPrimitiveType(name) {
value, _ := pkg.evaluateConstValue(file, iota, arg, globalEvaluator, recursiveStack)
value = EvaluateDataConversion(value, name)
return value, nil
} else if name == "len" {
value, _ := pkg.evaluateConstValue(file, iota, arg, globalEvaluator, recursiveStack)
return reflect.ValueOf(value).Len(), nil
}
typeDef := globalEvaluator.FindTypeSpec(name, file)
if typeDef == nil {
return nil, nil
}
return arg, valueExpr.Fun
return value, valueExpr.Fun
} else if selector, ok := valueExpr.Fun.(*ast.SelectorExpr); ok {
typeDef := globalEvaluator.FindTypeSpec(fullTypeName(selector.X.(*ast.Ident).Name, selector.Sel.Name), file)
if typeDef == nil {
Expand Down
15 changes: 10 additions & 5 deletions testdata/enums/expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,8 @@
1,
2,
4,
8
8,
3
],
"type": "integer",
"x-enum-comments": {
Expand All @@ -131,7 +132,8 @@
"Mask1",
"Mask2",
"Mask3",
"Mask4"
"Mask4",
"Mask5"
],
"name": "mask",
"in": "formData"
Expand Down Expand Up @@ -197,7 +199,8 @@
1,
2,
4,
8
8,
3
],
"type": "integer"
},
Expand Down Expand Up @@ -268,7 +271,8 @@
1,
2,
4,
8
8,
3
],
"x-enum-comments": {
"Mask1": "Mask1",
Expand All @@ -280,7 +284,8 @@
"Mask1",
"Mask2",
"Mask3",
"Mask4"
"Mask4",
"Mask5"
]
},
"types.Person": {
Expand Down
1 change: 1 addition & 0 deletions testdata/enums/types/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
Mask2 /* Mask2 */
Mask3 // Mask3
Mask4 // Mask4
Mask5 = Mask(A + B)
)

type Type string
Expand Down

0 comments on commit c14cc8e

Please sign in to comment.