forked from go-fuego/fuego
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenapi_description.go
61 lines (45 loc) · 1.46 KB
/
openapi_description.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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").
` + "```" + `
`