Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support tags per operation #112

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 39 additions & 36 deletions generate/entities.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,45 @@ import (
)

var swaggerMapTypes = map[string]reflect.Kind{
"string": reflect.String,
"*string": reflect.String,
"int": reflect.Int,
"*int": reflect.Int,
"uint": reflect.Uint,
"*uint": reflect.Uint,
"int8": reflect.Int8,
"*int8": reflect.Int8,
"uint8": reflect.Uint8,
"*uint8": reflect.Uint8,
"int16": reflect.Int16,
"*int16": reflect.Int16,
"uint16": reflect.Uint16,
"*uint16": reflect.Uint16,
"int32": reflect.Int,
"*int32": reflect.Int,
"uint32": reflect.Int,
"*uint32": reflect.Int,
"uint64": reflect.Int64,
"*uint64": reflect.Int64,
"int64": reflect.Int64,
"*int64": reflect.Int64,
"[]string": reflect.Slice,
"[]int": reflect.Slice,
"[]int64": reflect.Slice,
"[]int32": reflect.Slice,
"[]uint32": reflect.Slice,
"[]uint64": reflect.Slice,
"bool": reflect.Bool,
"*bool": reflect.Bool,
"struct": reflect.Struct,
"*struct": reflect.Struct,
"float32": reflect.Float32,
"*float32": reflect.Float32,
"float64": reflect.Float64,
"*float64": reflect.Float64,
"string": reflect.String,
"*string": reflect.String,
"int": reflect.Int,
"*int": reflect.Int,
"uint": reflect.Uint,
"*uint": reflect.Uint,
"int8": reflect.Int8,
"*int8": reflect.Int8,
"uint8": reflect.Uint8,
"*uint8": reflect.Uint8,
"int16": reflect.Int16,
"*int16": reflect.Int16,
"uint16": reflect.Uint16,
"*uint16": reflect.Uint16,
"int32": reflect.Int,
"*int32": reflect.Int,
"uint32": reflect.Int,
"*uint32": reflect.Int,
"uint64": reflect.Int64,
"*uint64": reflect.Int64,
"int64": reflect.Int64,
"*int64": reflect.Int64,
"[]string": reflect.Slice,
"[]int": reflect.Slice,
"[]int64": reflect.Slice,
"[]int32": reflect.Slice,
"[]uint32": reflect.Slice,
"[]uint64": reflect.Slice,
"[]bool": reflect.Slice,
"[]float32": reflect.Slice,
"[]float64": reflect.Slice,
"bool": reflect.Bool,
"*bool": reflect.Bool,
"struct": reflect.Struct,
"*struct": reflect.Struct,
"float32": reflect.Float32,
"*float32": reflect.Float32,
"float64": reflect.Float64,
"*float64": reflect.Float64,
}

// http://swagger.io/specification/#infoObject
Expand Down
26 changes: 21 additions & 5 deletions generate/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,20 @@ func parseRangeOption(option string) (float64, float64, bool) {
}

func applyGenerate(p *plugin.Plugin, host string, basePath string, schemes string) (*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"])
var (
title, version, desc string
err error
)

if title, err = strconv.Unquote(p.Api.Info.Properties["title"]); err != nil {
title = p.Api.Info.Properties["title"]
}
if version, err = strconv.Unquote(p.Api.Info.Properties["version"]); err != nil {
version = p.Api.Info.Properties["version"]
}
if desc, err = strconv.Unquote(p.Api.Info.Properties["desc"]); err != nil {
desc = p.Api.Info.Properties["desc"]
}

s := swaggerObject{
Swagger: "2.0",
Expand Down Expand Up @@ -237,9 +248,14 @@ func renderServiceRoutes(service spec.Service, groups []spec.Group, paths swagge
if value := group.GetAnnotation("swtags"); len(value) > 0 {
tags = value
}
if route.AtDoc.Properties["tags"] != "" {
// Acccept tags from @doc annotation
tags = route.AtDoc.Properties["tags"]
tags = strings.Trim(tags, "\"")
}

operationObject := &swaggerOperationObject{
Tags: []string{tags},
Tags: strings.Split(tags, ","),
Parameters: parameters,
Responses: swaggerResponsesObject{
"200": swaggerResponseObject{
Expand Down Expand Up @@ -592,7 +608,7 @@ func schemaOfField(member spec.Member) swaggerSchemaObject {
}
}
if strings.HasPrefix(member.Type.Name(), "map") {
fmt.Println("暂不支持map类型")
// fmt.Println("暂不支持map类型")
}
default:
ret = swaggerSchemaObject{
Expand Down
61 changes: 60 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module github.com/zeromicro/goctl-swagger

go 1.16
go 1.21

toolchain go1.22.2

require (
github.com/grpc-ecosystem/grpc-gateway v1.16.0
Expand All @@ -9,3 +11,60 @@ require (
github.com/zeromicro/go-zero/tools/goctl v1.6.5
golang.org/x/oauth2 v0.17.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/fatih/color v1.16.0 // indirect
github.com/fatih/structtag v1.2.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.0 // indirect
github.com/golang/glog v1.2.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.18.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
github.com/openzipkin/zipkin-go v0.4.2 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
github.com/spf13/cobra v1.8.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xo/terminfo v0.0.0-20210125001918-ca9a967f8778 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
github.com/zeromicro/antlr v0.0.1 // indirect
go.opentelemetry.io/otel v1.22.0 // indirect
go.opentelemetry.io/otel/exporters/jaeger v1.17.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/stdout/stdouttrace v1.19.0 // indirect
go.opentelemetry.io/otel/exporters/zipkin v1.19.0 // indirect
go.opentelemetry.io/otel/metric v1.22.0 // indirect
go.opentelemetry.io/otel/sdk v1.21.0 // indirect
go.opentelemetry.io/otel/trace v1.22.0 // indirect
go.opentelemetry.io/proto/otlp v1.0.0 // indirect
go.uber.org/automaxprocs v1.5.3 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/genproto v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20240227224415-6ceb2ff114de // indirect
google.golang.org/grpc v1.63.2 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading