fix lying swagger spec response type

This commit is contained in:
2024-11-27 13:52:15 -05:00
parent 521e376455
commit 8ba2caa16d
5 changed files with 8714 additions and 2186 deletions

File diff suppressed because it is too large Load Diff

View File

@ -30,33 +30,49 @@ var ParseFunctionsMap = map[string]interface{}{
type FunctionParamInfo struct {
FunctionName string
Params []string
Params []FunctionParam
}
type FunctionParam struct {
Name string
Type string
}
const tmplFuncParams = `
// List of functions in eiaapi package
// with slice of arg types as strings
var FunctionParams = map[string][]string{
type FunctionParam struct {
Name string
Type string
}
var FunctionParams = map[string][]FunctionParam{
{{- range .}}
"{{ .FunctionName }}": {
{{- range .Params }}
{{ . | printf "\"%s\"" }},
{
Name: {{ .Name | printf "\"%s\"" }},
Type: {{ .Type | printf "\"%s\"" }},
},
{{- end }}
},
{{- end}}
}
func GetFuncParamType(funcName string, idx int) string {
func GetFuncParamType(funcName string, idx int) *FunctionParam {
var param FunctionParam
funcParams, exists := FunctionParams[funcName]
if !exists {
return ""
return nil
}
if idx < len(funcParams) {
return funcParams[idx]
param = funcParams[idx]
}
return ""
return &param
}
`
@ -88,7 +104,7 @@ func main() {
// Load up params for all functions
if funcDecl.Name.IsExported() {
paramTypes := make([]string, 0)
paramTypes := make([]FunctionParam, 0)
if funcDecl.Type.Params != nil {
for _, param := range funcDecl.Type.Params.List {
// Convert the type expression to a string representation
@ -98,8 +114,11 @@ func main() {
continue
}
// Append the type once for each name in the parameter
for range param.Names {
paramTypes = append(paramTypes, typeStr)
for _, name := range param.Names {
paramTypes = append(paramTypes, FunctionParam{
Name: name.Name,
Type: typeStr,
})
}
}
}