-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathenum.go
More file actions
35 lines (29 loc) · 741 Bytes
/
enum.go
File metadata and controls
35 lines (29 loc) · 741 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// SPDX-FileCopyrightText: Copyright 2015-2025 go-swagger maintainers
// SPDX-License-Identifier: Apache-2.0
package codescan
import (
"go/ast"
"strconv"
"strings"
"github.com/go-openapi/spec"
)
func getEnumBasicLitValue(basicLit *ast.BasicLit) any {
switch basicLit.Kind.String() {
case "INT":
if result, err := strconv.ParseInt(basicLit.Value, 10, 64); err == nil {
return result
}
case "FLOAT":
if result, err := strconv.ParseFloat(basicLit.Value, 64); err == nil {
return result
}
default:
return strings.Trim(basicLit.Value, "\"")
}
return nil
}
const extEnumDesc = "x-go-enum-desc"
func getEnumDesc(extensions spec.Extensions) (desc string) {
desc, _ = extensions.GetString(extEnumDesc)
return desc
}