Skip to content

Commit

Permalink
OpenAPI default description is a Fuego Cheatsheet
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenQuim committed Jul 22, 2024
1 parent c6ac637 commit 67a491c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
2 changes: 1 addition & 1 deletion openapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func NewOpenApiSpec() openapi3.T {
info := &openapi3.Info{
Title: "OpenAPI",
Description: "OpenAPI",
Description: openapiDescription,
Version: "0.0.1",
}
spec := openapi3.T{
Expand Down
61 changes: 61 additions & 0 deletions openapi_description.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package fuego

const openapiDescription = `
This is the autogenerated OpenAPI documentation for your [Fuego](https://github.com/go-fuego/fuego) API.
Below is a Fuego Cheatsheet to help you get started. Don't hesitate to check the [Fuego documentation](https://go-fuego.github.io/fuego) for more details.
Happy coding! 🔥
## Usage
### Route registration
` + "```go" + `
func main() {
// Create a new server
s := fuego.NewServer()
// Register some routes
fuego.Post(s, "/hello", myController)
fuego.Get(s, "/myPath", otherController)
fuego.Put(s, "/hello", thirdController)
adminRoutes := fuego.Group(s, "/admin")
fuego.Use(adminRoutes, myMiddleware) // This middleware (for authentication, etc...) will be available for routes starting by /admin/*,
fuego.Get(adminRoutes, "/hello", groupController) // This route will be available at /admin/hello
// Start the server
s.Start()
}
` + "```" + `
### Basic controller
` + "```go" + `
type MyBody struct {
Name string ` + "`json:\"name\" validate:\"required,max=30\"`" + `
}
type MyResponse struct {
Answer string ` + "`json:\"answer\"`" + `
}
func hello(ctx *fuego.ContextWithBody[MyBody]) (*MyResponse, error) {
body, err := ctx.Body()
if err != nil {
return nil, err
}
return &MyResponse{Answer: "Hello " + body.Name}, nil
}
` + "```" + `
### Add more details to the route
` + "```go" + `
fuego.Get(s, "/hello", myController).
Description("This is a route that says hello").
Summary("Say hello").
` + "```" + `
`

0 comments on commit 67a491c

Please sign in to comment.