Skip to content

Commit 3750021

Browse files
authored
Add example to dump schema (#216)
1 parent 35aa7c7 commit 3750021

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

_examples/advanced-generic-openapi31/main.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package main
44

55
import (
66
"context"
7+
"encoding/json"
78
"errors"
89
"log"
910
"net/http"
@@ -36,7 +37,13 @@ func main() {
3637
close(idleConnsClosed)
3738
}()
3839

39-
srv.Handler = NewRouter()
40+
r := NewRouter()
41+
42+
// You can access OpenAPI schema of an instrumented *web.Service if you need.
43+
j, _ := json.Marshal(r.OpenAPISchema())
44+
println("OpenAPI schema head:", string(j)[0:300], "...")
45+
46+
srv.Handler = r
4047
srv.Addr = "localhost:8012"
4148

4249
log.Println("http://localhost:8012/docs")

_examples/advanced-generic-openapi31/router.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/swaggest/usecase"
2626
)
2727

28-
func NewRouter() http.Handler {
28+
func NewRouter() *web.Service {
2929
r := openapi31.NewReflector()
3030
s := web.NewService(r)
3131

0 commit comments

Comments
 (0)