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 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 httpMapper map[string]map[string]string = make(map[string]map[string]string)
var packageName string = "main"
@ -257,6 +258,8 @@ func main() {
loadConfig()
exceptionaltypemapper["[]byte"] = "string"
tstypemapper["time.Time"] = "Date"
tstypemapper["primitive.ObjectID"] = "string"
tstypemapper["time.Duration"] = "Date"

View File

@ -3,7 +3,6 @@ package main
import (
"bytes"
"fmt"
dc "go.digitalcircle.com.br/golib/base"
"io/ioutil"
"strings"
)
@ -110,5 +109,7 @@ func invoke(m string, path string, bodyo interface{}) (*json.Decoder, error) {
}
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)
dc.Err(err)
if err != nil {
panic(err)
}
cmd := exec.Command("/bin/sh", "-c", "go fmt "+f)
bs, err := cmd.Output()
//dc.Err(err)

View File

@ -3,8 +3,8 @@ package main
import (
"bytes"
"fmt"
dc "go.digitalcircle.com.br/golib/base"
"io/ioutil"
"log"
"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))
var ftype string
var ok bool
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 {
ftype = f.Type
}
if f.Array {
ftype = ftype + "[]"
} else if f.Map {
if f.Map {
fm, ok := tstypemapper[f.Mapkey]
if !ok {
fm = f.Mapkey
@ -155,5 +166,7 @@ async function InvokeOk(path: string, method: HTMLMethod, body?: any): Promise<b
b.WriteString("//#endregion\n")
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"`
Mapval string `yaml:"mapval"`
}
func (a *APIField) String() string {
if a.Array {
return "[]" + a.Type
} else {
return a.Type
}
}
type APIType struct {
Name string
Desc string `yaml:"desc"`