Skip to content

Commit

Permalink
chore: update gin-compat example to use engine.OutputOpenAPISpec
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanhitt committed Jan 8, 2025
1 parent f857cfd commit 30f8cdc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions examples/gin-compat/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ func fuegoControllerPost(c fuego.ContextWithBody[HelloRequest]) (*HelloResponse,
}, nil
}

func serveOpenApiJSONDescription(s *fuego.OpenAPI) func(ctx *gin.Context) {
func serveOpenAPISpec(openAPISpec []byte) func(ctx *gin.Context) {
return func(ctx *gin.Context) {
ctx.JSON(http.StatusOK, s.Description())
ctx.Data(http.StatusOK, "application/json", openAPISpec)
}
}

func DefaultOpenAPIHandler(specURL string) gin.HandlerFunc {
return func(ctx *gin.Context) {
ctx.Header("Content-Type", "text/html; charset=utf-8")
ctx.String(200, fuego.DefaultOpenAPIHTML(specURL))
ctx.String(http.StatusOK, fuego.DefaultOpenAPIHTML(specURL))
}
}
2 changes: 1 addition & 1 deletion examples/gin-compat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func server() (*gin.Engine, *fuego.OpenAPI) {
)

// Serve the OpenAPI spec
ginRouter.GET("/openapi.json", serveOpenApiJSONDescription(engine.OpenAPI))
ginRouter.GET("/openapi.json", serveOpenAPISpec(engine.OutputOpenAPISpec()))
ginRouter.GET("/swagger", DefaultOpenAPIHandler("/openapi.json"))

return ginRouter, engine.OpenAPI
Expand Down

0 comments on commit 30f8cdc

Please sign in to comment.