Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kooksee committed Feb 16, 2024
1 parent 0886dc9 commit dd2603d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 30 deletions.
1 change: 1 addition & 0 deletions docs/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ package templates
// https://github.com/long2ice/swagin
// https://github.com/long2ice/fibers
// https://github.com/getkin/kin-openapi
// https://github.com/danielgtaylor/huma
3 changes: 2 additions & 1 deletion internal/examples/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package main

import (
"os"

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

type TestQueryReqAAA struct {
Expand Down
9 changes: 4 additions & 5 deletions opendoc/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package opendoc

import (
"fmt"
"github.com/pubgo/funk/log"
"mime/multipart"
"net"
"net/http"
Expand All @@ -15,6 +14,7 @@ import (
"github.com/getkin/kin-openapi/openapi3"
"github.com/goccy/go-json"
"github.com/pubgo/funk/assert"
"github.com/pubgo/funk/log"
"github.com/pubgo/opendoc/security"
"k8s.io/kube-openapi/pkg/util"
)
Expand All @@ -38,7 +38,7 @@ func checkModelType(model interface{}) {
t = t.Elem()
}

assert.If(t.Kind() != reflect.Struct, "The native type of val should be struct")
assert.If(t.Kind() != reflect.Struct, "The native type of model should be struct")
}

func getSchemaName(val interface{}) string {
Expand Down Expand Up @@ -70,7 +70,7 @@ func getCanonicalTypeName(val interface{}) string {
path = path[strings.Index(path, "/vendor/")+len("/vendor/"):]
}

path = strings.TrimPrefix(path, "vendor/")
path = strings.Trim(strings.TrimPrefix(path, "vendor"), "/")
return path + "." + model.Name()
}

Expand Down Expand Up @@ -198,8 +198,7 @@ func genSchema(val interface{}) (ref string, schema *openapi3.Schema) {
getTag(tags, deprecated, func(tag *structtag.Tag) { fieldSchema.Deprecated = true })
getTag(tags, defaultName, func(tag *structtag.Tag) { fieldSchema.Default = tag.Name })
getTag(tags, example, func(tag *structtag.Tag) {
err = json.Unmarshal([]byte(tag.Value()), &fieldSchema.Example)
if err != nil {
if err := json.Unmarshal([]byte(tag.Value()), &fieldSchema.Example); err != nil {
log.Err(err).Str("tag-value", tag.Value()).Msg("failed to unmarshal example")
}
})
Expand Down
24 changes: 0 additions & 24 deletions templates/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package templates

import (
_ "embed"
"fmt"
"html/template"
"net/http"

Expand All @@ -18,29 +17,6 @@ var swaggerFile string
var reDocTemplate = assert.Exit1(template.New("").Parse(reDocFile))
var swaggerTemplate = assert.Exit1(template.New("").Parse(swaggerFile))

func RapiDocHandler(title, url string) http.HandlerFunc {
return func(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Content-Type", "text/html")
writer.Write([]byte(fmt.Sprintf(`<!doctype html>
<html>
<head>
<title>%s</title>
<meta charset="utf-8">
<script type="module" src="https://unpkg.com/[email protected]/dist/rapidoc-min.js"></script>
</head>
<body>
<rapi-doc
spec-url="%s"
render-style="read"
show-header="false"
primary-color="#f74799"
nav-accent-color="#47afe8"
> </rapi-doc>
</body>
</html>`, title, url)))
}
}

func ReDocHandler(title, url string) http.HandlerFunc {
return func(writer http.ResponseWriter, request *http.Request) {
writer.Header().Set("Content-Type", "text/html")
Expand Down

0 comments on commit dd2603d

Please sign in to comment.