Skip to content

Commit

Permalink
Add example to dump schema (#216)
Browse files Browse the repository at this point in the history
  • Loading branch information
vearutop authored Jan 1, 2025
1 parent 35aa7c7 commit 3750021
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion _examples/advanced-generic-openapi31/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package main

import (
"context"
"encoding/json"
"errors"
"log"
"net/http"
Expand Down Expand Up @@ -36,7 +37,13 @@ func main() {
close(idleConnsClosed)
}()

srv.Handler = NewRouter()
r := NewRouter()

// You can access OpenAPI schema of an instrumented *web.Service if you need.
j, _ := json.Marshal(r.OpenAPISchema())
println("OpenAPI schema head:", string(j)[0:300], "...")

srv.Handler = r
srv.Addr = "localhost:8012"

log.Println("http://localhost:8012/docs")
Expand Down
2 changes: 1 addition & 1 deletion _examples/advanced-generic-openapi31/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"github.com/swaggest/usecase"
)

func NewRouter() http.Handler {
func NewRouter() *web.Service {
r := openapi31.NewReflector()
s := web.NewService(r)

Expand Down

0 comments on commit 3750021

Please sign in to comment.