upgrade go-zero

This commit is contained in:
MaxToby
2021-04-01 23:19:31 +08:00
parent de003dbcfa
commit 502888a23e
6 changed files with 47 additions and 45 deletions

View File

@ -3,8 +3,9 @@ package generate
import (
"bytes"
"encoding/json"
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
"reflect"
"github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway/descriptor"
)
var (
@ -19,6 +20,8 @@ var (
"[]int32": reflect.Slice,
"bool": reflect.Bool,
"struct": reflect.Struct,
"float32": reflect.Float32,
"float64": reflect.Float64,
}
)

View File

@ -4,8 +4,9 @@ import (
"bytes"
"encoding/json"
"fmt"
plugin2 "github.com/tal-tech/go-zero/tools/goctl/plugin"
"io/ioutil"
plugin2 "github.com/tal-tech/go-zero/tools/goctl/plugin"
)
func Do(filename string, in *plugin2.Plugin) error {
@ -19,12 +20,14 @@ func Do(filename string, in *plugin2.Plugin) error {
enc.SetIndent("", " ")
if err := enc.Encode(swagger); err != nil {
fmt.Println(err)
}
output := in.Dir + "/" + filename
err = ioutil.WriteFile(output, formatted.Bytes(), 0666)
if err != nil {
fmt.Println(err)
}
return err
}

View File

@ -3,13 +3,14 @@ package generate
import (
"bytes"
"fmt"
"github.com/tal-tech/go-zero/tools/goctl/api/spec"
plugin2 "github.com/tal-tech/go-zero/tools/goctl/plugin"
"net/http"
"reflect"
"strconv"
"strings"
"unsafe"
"github.com/tal-tech/go-zero/tools/goctl/api/spec"
plugin2 "github.com/tal-tech/go-zero/tools/goctl/plugin"
)
var (
@ -30,6 +31,7 @@ func applyGenerate(p *plugin2.Plugin) (*swaggerObject, error) {
title, _ := strconv.Unquote(p.Api.Info.Properties["title"])
version, _ := strconv.Unquote(p.Api.Info.Properties["version"])
desc, _ := strconv.Unquote(p.Api.Info.Properties["desc"])
s := swaggerObject{
Swagger: "2.0",
@ -40,8 +42,9 @@ func applyGenerate(p *plugin2.Plugin) (*swaggerObject, error) {
Definitions: make(swaggerDefinitionsObject),
StreamDefinitions: make(swaggerDefinitionsObject),
Info: swaggerInfoObject{
Title: title,
Version: version,
Title: title,
Version: version,
Description: desc,
},
}
@ -116,6 +119,11 @@ func renderServiceRoutes(service spec.Service, groups []spec.Group, paths swagge
}
}
}
if len(member.Comment) > 0 {
sp.Description = strings.TrimLeft(member.Comment, "//")
}
parameters = append(parameters, sp)
}
@ -169,18 +177,16 @@ func renderServiceRoutes(service spec.Service, groups []spec.Group, paths swagge
}
// set OperationID
if value := route.GetAnnotation("handler"); len(value) > 0 {
operationObject.OperationID = value
}
operationObject.OperationID = route.Handler
for _, param := range operationObject.Parameters {
if param.Schema != nil && param.Schema.Ref != "" {
requestResponseRefs[param.Schema.Ref] = struct{}{}
}
}
operationObject.Summary = route.JoinedDoc()
if len(route.AtDoc.Properties) > 0 {
operationObject.Summary, _ = strconv.Unquote(route.AtDoc.Properties["summary"])
operationObject.Description, _ = strconv.Unquote(route.AtDoc.Properties["description"])
}
@ -347,6 +353,10 @@ func primitiveSchema(kind reflect.Kind, t string) (ftype, format string, ok bool
return "boolean", "boolean", true
case reflect.String:
return "string", "", true
case reflect.Float32:
return "number", "float", true
case reflect.Float64:
return "number", "double", true
case reflect.Slice:
return strings.Replace(t, "[]", "", -1), "", true
default: