Skip to content

Commit

Permalink
fix: python sdk types
Browse files Browse the repository at this point in the history
  • Loading branch information
BigJk committed Feb 10, 2024
1 parent a39dce3 commit 5c4b0d3
Show file tree
Hide file tree
Showing 2 changed files with 348 additions and 334 deletions.
19 changes: 15 additions & 4 deletions cmd/sdk_gen/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const pythonAPIHeader = `import requests
#
# Requires the requests library to be installed.
# python -m pip install requests
#
# For the structure of "snd types" check the following files in the root of the repository:
# data_source.go, entry.go, generator.go, settings.go, template.go
class SndAPI:
Expand Down Expand Up @@ -45,9 +48,13 @@ class SndAPI:
`

func pythonArgType(argType string) string {
slice := strings.HasSuffix(argType, "[]")
if strings.HasPrefix(argType, "map") {
return "dict"
}

slice := strings.HasPrefix(argType, "[]")
if slice {
argType = argType[:len(argType)-2]
argType = strings.TrimPrefix(argType, "[]")
}

typeName := ""
Expand All @@ -60,10 +67,14 @@ func pythonArgType(argType string) string {
typeName = "float"
case "bool":
typeName = "bool"
case "interface{}":
case "interface {}":
typeName = "dict"
default:
typeName = strings.Replace(argType, "snd.", "", -1)
if strings.HasPrefix(argType, "snd.") {
typeName = fmt.Sprintf("dict [snd type %s]", strcase.ToSnake(strings.Replace(argType, "snd.", "", -1)))
} else {
typeName = argType
}
}

if slice {
Expand Down
Loading

0 comments on commit 5c4b0d3

Please sign in to comment.