Skip to content

Commit

Permalink
fix: 2024-04-27 16:04:39
Browse files Browse the repository at this point in the history
  • Loading branch information
kooksee committed Apr 27, 2024
1 parent cd5387e commit 834e540
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 50 deletions.
12 changes: 7 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/getkin/kin-openapi v0.123.0
github.com/goccy/go-json v0.10.0
github.com/invopop/yaml v0.2.0
github.com/pubgo/funk v0.5.30
github.com/pubgo/funk v0.5.41
github.com/stretchr/testify v1.8.4
k8s.io/kube-openapi v0.0.0-20221123214604-86e75ddd809a
)
Expand All @@ -17,7 +17,7 @@ require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/go-openapi/jsonpointer v0.20.2 // indirect
github.com/go-openapi/swag v0.22.8 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/k0kubun/pp/v3 v3.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
Expand All @@ -29,8 +29,10 @@ require (
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/zerolog v1.29.0 // indirect
golang.org/x/exp v0.0.0-20221114191408-850992195362 // indirect
golang.org/x/sys v0.4.0 // indirect
golang.org/x/text v0.5.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
golang.org/x/sys v0.18.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/genproto v0.0.0-20221027153422-115e99e71e1c // indirect
google.golang.org/grpc v1.51.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
29 changes: 13 additions & 16 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
github.com/goccy/go-json v0.10.0 h1:mXKd9Qw4NuzShiRlOXKews24ufknHO7gx30lsDyokKA=
github.com/goccy/go-json v0.10.0/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/invopop/yaml v0.2.0 h1:7zky/qH+O0DwAyoobXUqvVBwgBFRxKoQ/3FjcVpjTMY=
github.com/invopop/yaml v0.2.0/go.mod h1:2XuRLgs/ouIrW3XNzuNj7J3Nvu/Dig5MXvbCEdiBN3Q=
Expand Down Expand Up @@ -46,8 +44,8 @@ github.com/phuslu/goid v1.0.0/go.mod h1:txc2fUIdrdnn+v9Vq+QpiPQ3dnrXEchjoVDgic+r
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pubgo/funk v0.5.30 h1:uo5RblUBR9Opl9j0yzbQoACXNoegtrcvydfLQIdWgu4=
github.com/pubgo/funk v0.5.30/go.mod h1:Z5Wp7OoxjmSlWH+6waFSbao5MSD942LVhkBSlUu4s4s=
github.com/pubgo/funk v0.5.41 h1:vcDD6SWsz6g9CoD/whMIDgcfnGBfvCoZa6OTJ9iB9Tk=
github.com/pubgo/funk v0.5.41/go.mod h1:gKCw72+MK7xPiUGY1Z/bdGJMrSfVi87r0x/7d1GtKU4=
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
github.com/rs/xid v1.4.0 h1:qd7wPTDkN6KQx2VmMBLrpHkiyQwgFXRnkOLacUiaSNY=
github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
Expand All @@ -58,21 +56,20 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
github.com/ugorji/go/codec v1.2.7 h1:YPXUKf7fYbp/y8xloBqZOw2qaVggbfwMlI8WM3wZUJ0=
golang.org/x/exp v0.0.0-20221114191408-850992195362 h1:NoHlPRbyl1VFI6FjwHtPQCN7wAMXI6cKcqrmXhOOfBQ=
golang.org/x/exp v0.0.0-20221114191408-850992195362/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
golang.org/x/net v0.4.0 h1:Q5QPcMlvfxFTAPV0+07Xz/MpK9NTXu2VDUuy0FeMfaU=
golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4=
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4=
golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
google.golang.org/genproto v0.0.0-20221027153422-115e99e71e1c h1:QgY/XxIAIeccR+Ca/rDdKubLIU9rcJ3xfy1DC/Wd2Oo=
google.golang.org/genproto v0.0.0-20221027153422-115e99e71e1c/go.mod h1:CGI5F/G+E5bKwmfYo09AXuVN4dD894kIKUFmVbP2/Fo=
google.golang.org/grpc v1.51.0 h1:E1eGv1FTqoLIdnBCZufiSHgKjlqG6fKFf6pPWtMTh8U=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.28.1 h1:d0NfwRgPtno5B1Wa6L2DAG+KivqkdutMf1UhdNx175w=
google.golang.org/protobuf v1.28.1/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/grpc v1.51.0/go.mod h1:wgNDFcnuBGmxLKI/qn4T+m5BtEBYXJPvibbUPsAIPww=
google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI=
google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
13 changes: 8 additions & 5 deletions internal/examples/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package main

import (
"fmt"
"net/http"

"github.com/pubgo/funk/assert"
"github.com/pubgo/funk/recovery"
"github.com/pubgo/opendoc/opendoc"
"github.com/pubgo/opendoc/security"
"net/http"
)

type TestQueryReqAAA struct {
Expand All @@ -19,7 +21,7 @@ type TestQueryReqAAA struct {
func main() {
defer recovery.Exit()

var doc = opendoc.New(func(swag *opendoc.Swagger) {
doc := opendoc.New(func(swag *opendoc.Swagger) {
swag.Config.Title = "this service web title "
swag.Description = "this is description"
swag.License = &opendoc.License{
Expand Down Expand Up @@ -63,10 +65,11 @@ func main() {
})
})

//data := assert.Must1(doc.MarshalYAML())
//assert.Exit(os.WriteFile("openapi.yaml", data, 0644))
// data := assert.Must1(doc.MarshalYAML())
// assert.Exit(os.WriteFile("openapi.yaml", data, 0644))

var app = http.NewServeMux()
app := http.NewServeMux()
doc.InitRouter(app)
fmt.Println("http://localhost:8080/debug/apidocs")
assert.Exit(http.ListenAndServe("localhost:8080", app))
}
10 changes: 6 additions & 4 deletions opendoc/aaa.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"github.com/getkin/kin-openapi/openapi3"
)

type License = openapi3.License
type Contact = openapi3.Contact
type Servers = openapi3.Servers
type Server = openapi3.Server
type (
License = openapi3.License
Contact = openapi3.Contact
Servers = openapi3.Servers
Server = openapi3.Server
)

// NamedEnum returns the enumerated acceptable values with according string names.
type NamedEnum interface {
Expand Down
2 changes: 1 addition & 1 deletion opendoc/operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (op *Operation) SetOperation(operationID string) *Operation {
return op
}

func (op *Operation) SetModel(req interface{}, rsp interface{}) *Operation {
func (op *Operation) SetModel(req, rsp interface{}) *Operation {
checkModelType(req)
op.request = req

Expand Down
2 changes: 1 addition & 1 deletion opendoc/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (s *Service) PostOf(cb func(op *Operation)) *Service {
}

func (s *Service) Openapi() map[string]*openapi3.PathItem {
var routes = make(map[string]*openapi3.PathItem)
routes := make(map[string]*openapi3.PathItem)
for i := range s.operations {
op := s.operations[i]
if routes[op.path] == nil {
Expand Down
8 changes: 4 additions & 4 deletions opendoc/swagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,14 @@ func (s *Swagger) SetRootPath(path string) {
}

func (s *Swagger) ServiceOf(name string, cb func(srv *Service)) {
var srv = newService(name)
srv := newService(name)
srv.prefix = s.rootPath
s.Routers = append(s.Routers, srv)
cb(srv)
}

func (s *Swagger) WithService() *Service {
var srv = new(Service)
srv := new(Service)
srv.prefix = s.rootPath
s.Routers = append(s.Routers, srv)
return srv
Expand All @@ -50,7 +50,7 @@ func (s *Swagger) buildSwagger() *openapi3.T {
s.Config = DefaultCfg()
}

var t = &openapi3.T{
t := &openapi3.T{
OpenAPI: "3.0.0",
Servers: s.Servers,
Components: &components,
Expand Down Expand Up @@ -87,7 +87,7 @@ func (s *Swagger) InitRouter(r *http.ServeMux) {
}

func (s *Swagger) OpenapiDataHandler() http.HandlerFunc {
var bytes = assert.Must1(s.MarshalYAML())
bytes := assert.Must1(s.MarshalYAML())
return func(writer http.ResponseWriter, request *http.Request) {
assert.Must1(writer.Write(bytes))
}
Expand Down
6 changes: 3 additions & 3 deletions opendoc/swagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,18 @@ type testQueryReq struct {
}

func TestGenSchema(t *testing.T) {
var ref, s = genSchema(testQueryReq{})
ref, s := genSchema(testQueryReq{})
assert.NotNil(t, s)
assert.Equal(t, "#/components/schemas/com.github.pubgo.opendoc.testQueryReq", ref)

var data, err = json.Marshal(s)
data, err := json.Marshal(s)
assert.NoError(t, err)
assert.Equal(t,
`{"properties":{"name":{"default":"test","description":"name of model","nullable":true,"type":"string"},"rsp":{"$ref":"#/components/schemas/com.github.pubgo.opendoc.testQueryRsp"}},"required":["name","rsp"],"type":"object"}`,
string(data),
)

var p = genParameters(testQueryReq{})
p := genParameters(testQueryReq{})
data, err = json.Marshal(p)
assert.NoError(t, err)
assert.Equal(t,
Expand Down
8 changes: 4 additions & 4 deletions opendoc/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
)

func getTag(tags *structtag.Tags, key string, fn func(tag *structtag.Tag)) {
var tag, err = tags.Get(key)
tag, err := tags.Get(key)
if err == nil && tag.Key != "" {
fn(tag)
}
Expand Down Expand Up @@ -249,8 +249,8 @@ func genResponses(response interface{}, contentType ...string) *openapi3.Respons

_, schema := genSchema(response)
content := openapi3.NewContentWithSchema(schema, contentType)
var docText = http.StatusText(http.StatusOK)
var rsp = &openapi3.ResponseRef{
docText := http.StatusText(http.StatusOK)
rsp := &openapi3.ResponseRef{
Value: &openapi3.Response{
Description: &docText,
Content: content,
Expand All @@ -264,7 +264,7 @@ func genResponses(response interface{}, contentType ...string) *openapi3.Respons
}

func isParameter(val *structtag.Tags) bool {
var params = []string{queryTag, uriTag, pathTag, headerTag, cookieTag}
params := []string{queryTag, uriTag, pathTag, headerTag, cookieTag}
for i := range params {
if _, err := val.Get(params[i]); err == nil {
return true
Expand Down
3 changes: 1 addition & 2 deletions security/basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import (
"github.com/getkin/kin-openapi/openapi3"
)

type Basic struct {
}
type Basic struct{}

type User struct {
Username string
Expand Down
3 changes: 1 addition & 2 deletions security/bearer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import (
"github.com/getkin/kin-openapi/openapi3"
)

type Bearer struct {
}
type Bearer struct{}

func (b Bearer) Provider() string {
return "Bearer"
Expand Down
8 changes: 5 additions & 3 deletions templates/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ var swaggerFile string
//go:embed rapidoc.html
var rApiDocFile string

var reDocTemplate = assert.Exit1(template.New("").Parse(reDocFile))
var swaggerTemplate = assert.Exit1(template.New("").Parse(swaggerFile))
var rApiDocFileTemplate = assert.Exit1(template.New("").Parse(rApiDocFile))
var (
reDocTemplate = assert.Exit1(template.New("").Parse(reDocFile))
swaggerTemplate = assert.Exit1(template.New("").Parse(swaggerFile))
rApiDocFileTemplate = assert.Exit1(template.New("").Parse(rApiDocFile))
)

func RApiDocHandler(url string) http.HandlerFunc {
return func(writer http.ResponseWriter, request *http.Request) {
Expand Down

0 comments on commit 834e540

Please sign in to comment.