From 3750021bec34b219a496fa9635134e66031d038f Mon Sep 17 00:00:00 2001 From: Viacheslav Poturaev Date: Wed, 1 Jan 2025 15:05:44 +0100 Subject: [PATCH] Add example to dump schema (#216) --- _examples/advanced-generic-openapi31/main.go | 9 ++++++++- _examples/advanced-generic-openapi31/router.go | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/_examples/advanced-generic-openapi31/main.go b/_examples/advanced-generic-openapi31/main.go index 6b31471..aa33ab8 100644 --- a/_examples/advanced-generic-openapi31/main.go +++ b/_examples/advanced-generic-openapi31/main.go @@ -4,6 +4,7 @@ package main import ( "context" + "encoding/json" "errors" "log" "net/http" @@ -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") diff --git a/_examples/advanced-generic-openapi31/router.go b/_examples/advanced-generic-openapi31/router.go index 93c0063..9e65613 100644 --- a/_examples/advanced-generic-openapi31/router.go +++ b/_examples/advanced-generic-openapi31/router.go @@ -25,7 +25,7 @@ import ( "github.com/swaggest/usecase" ) -func NewRouter() http.Handler { +func NewRouter() *web.Service { r := openapi31.NewReflector() s := web.NewService(r)