added []byte=>string mapping

master
Paulo Simão 2020-12-22 10:08:57 -03:00
parent 943bd7e769
commit 517aa43668
5 changed files with 38 additions and 10 deletions

View File

@ -14,6 +14,7 @@ var api API
//var httptestdir string //var httptestdir string
var tstypemapper map[string]string = make(map[string]string) var tstypemapper map[string]string = make(map[string]string)
var exceptionaltypemapper map[string]string = make(map[string]string)
var knownMethods map[string]bool = make(map[string]bool) var knownMethods map[string]bool = make(map[string]bool)
var httpMapper map[string]map[string]string = make(map[string]map[string]string) var httpMapper map[string]map[string]string = make(map[string]map[string]string)
var packageName string = "main" var packageName string = "main"
@ -257,6 +258,8 @@ func main() {
loadConfig() loadConfig()
exceptionaltypemapper["[]byte"] = "string"
tstypemapper["time.Time"] = "Date" tstypemapper["time.Time"] = "Date"
tstypemapper["primitive.ObjectID"] = "string" tstypemapper["primitive.ObjectID"] = "string"
tstypemapper["time.Duration"] = "Date" tstypemapper["time.Duration"] = "Date"

View File

@ -3,7 +3,6 @@ package main
import ( import (
"bytes" "bytes"
"fmt" "fmt"
dc "go.digitalcircle.com.br/golib/base"
"io/ioutil" "io/ioutil"
"strings" "strings"
) )
@ -110,5 +109,7 @@ func invoke(m string, path string, bodyo interface{}) (*json.Decoder, error) {
} }
err := ioutil.WriteFile(f, b.Bytes(), 0600) err := ioutil.WriteFile(f, b.Bytes(), 0600)
dc.Err(err) if err != nil {
panic(err)
}
} }

View File

@ -115,7 +115,9 @@ ret.Perms["%s_%s"]="%s"
} }
err := ioutil.WriteFile(f, b.Bytes(), 0600) err := ioutil.WriteFile(f, b.Bytes(), 0600)
dc.Err(err) if err != nil {
panic(err)
}
cmd := exec.Command("/bin/sh", "-c", "go fmt "+f) cmd := exec.Command("/bin/sh", "-c", "go fmt "+f)
bs, err := cmd.Output() bs, err := cmd.Output()
//dc.Err(err) //dc.Err(err)

View File

@ -3,8 +3,8 @@ package main
import ( import (
"bytes" "bytes"
"fmt" "fmt"
dc "go.digitalcircle.com.br/golib/base"
"io/ioutil" "io/ioutil"
"log"
"strings" "strings"
) )
@ -111,15 +111,26 @@ async function InvokeOk(path: string, method: HTMLMethod, body?: any): Promise<b
} }
b.WriteString(fmt.Sprintf("export interface %s {\n", k)) b.WriteString(fmt.Sprintf("export interface %s {\n", k))
var ftype string
var ok bool
for kf, f := range v.Fields { for kf, f := range v.Fields {
ftype, ok := tstypemapper[f.Type] ftype, ok = exceptionaltypemapper[f.String()]
if ok {
log.Printf("Mapped exceptional type: %s ==> %s", f.String(), ftype)
}
if !ok {
if f.Array {
ftype, ok = tstypemapper["[]"+f.Type]
} else {
ftype, ok = tstypemapper[f.Type]
}
}
if !ok { if !ok {
ftype = f.Type ftype = f.Type
} }
if f.Array { if f.Map {
ftype = ftype + "[]"
} else if f.Map {
fm, ok := tstypemapper[f.Mapkey] fm, ok := tstypemapper[f.Mapkey]
if !ok { if !ok {
fm = f.Mapkey fm = f.Mapkey
@ -155,5 +166,7 @@ async function InvokeOk(path: string, method: HTMLMethod, body?: any): Promise<b
b.WriteString("//#endregion\n") b.WriteString("//#endregion\n")
err := ioutil.WriteFile(f, b.Bytes(), 0600) err := ioutil.WriteFile(f, b.Bytes(), 0600)
dc.Err(err) if err != nil {
panic(err)
}
} }

View File

@ -15,6 +15,15 @@ type APIField struct {
Mapkey string `yaml:"mapkey"` Mapkey string `yaml:"mapkey"`
Mapval string `yaml:"mapval"` Mapval string `yaml:"mapval"`
} }
func (a *APIField) String() string {
if a.Array {
return "[]" + a.Type
} else {
return a.Type
}
}
type APIType struct { type APIType struct {
Name string Name string
Desc string `yaml:"desc"` Desc string `yaml:"desc"`