Skip to content

Commit

Permalink
docs: reworded openapi docs
Browse files Browse the repository at this point in the history
  • Loading branch information
EwenQuim committed Feb 21, 2024
1 parent c70ce0d commit 97ca254
Showing 1 changed file with 36 additions and 32 deletions.
68 changes: 36 additions & 32 deletions documentation/docs/guides/openapi.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
# OpenAPI Specification

Fuego automatically provides an OpenAPI specification for your API in several ways:

- **JSON file**
- **Swagger UI**
- **JSON endpoint**

Fuego will indicate in a log the paths where the OpenAPI specifications and Swagger UI are available.
Fuego automatically generates an OpenAPI specification for your API.

```go
package main
Expand Down Expand Up @@ -34,9 +28,11 @@ Result for this simple example:

The core idea of Fuego is to generate the OpenAPI specification automatically, so you don't have to worry about it. However, you can customize it if you want.

## Customize the OpenAPI specification output
## Customize the operations caracteristics

You can customize the path and to activate or not the feature, with the option WithOpenAPIConfig.
Each route can be customized to add more information to the OpenAPI specification.

Just add methods after the route declaration.

```go
package main
Expand All @@ -46,27 +42,35 @@ import (
)

func main() {
s := fuego.NewServer(fuego.WithOpenAPIConfig(fuego.OpenAPIConfig{
DisableSwagger : false, // If true, the server will not serve the swagger ui nor the openapi json spec
DisableLocalSave : false, // If true, the server will not save the openapi json spec locally
SwaggerUrl : "/xxx", // URL to serve the swagger ui
JsonUrl : "/xxx/swagger.json", // URL to serve the openapi json spec
JsonFilePath : "./foo/bar.json", // Local path to save the openapi json spec
}))
s := fuego.NewServer()

fuego.Get(s, "/", func(c fuego.ContextNoBody) (string, error) {
return "Hello, World!", nil
})
fuego.Get(s, "/", helloWorld).
WithSummary("A simple hello world").
WithDescription("This is a simple hello world").
SetDeprecated()

s.Run()
}

func helloWorld(c fuego.ContextNoBody) (string, error) {
return "Hello, World!", nil
}

```

## Customize the OpenAPI specification output
## Output

Each route can be customized to add more information to the OpenAPI specification.
Fuego automatically provides an OpenAPI specification for your API in several ways:

Just add methods after the route declaration.
- **JSON file**
- **Swagger UI**
- **JSON endpoint**

Fuego will indicate in a log the paths where the OpenAPI specifications and Swagger UI are available.

## Customize the OpenAPI specification output

You can customize the path and to activate or not the feature, with the option WithOpenAPIConfig.

```go
package main
Expand All @@ -76,18 +80,18 @@ import (
)

func main() {
s := fuego.NewServer()
s := fuego.NewServer(fuego.WithOpenAPIConfig(fuego.OpenAPIConfig{
DisableSwagger : false, // If true, the server will not serve the swagger ui nor the openapi json spec
DisableLocalSave : false, // If true, the server will not save the openapi json spec locally
SwaggerUrl : "/xxx", // URL to serve the swagger ui
JsonUrl : "/xxx/swagger.json", // URL to serve the openapi json spec
JsonFilePath : "./foo/bar.json", // Local path to save the openapi json spec
}))

fuego.Get(s, "/", helloWorld).
WithSummary("A simple hello world").
WithDescription("This is a simple hello world").
SetDeprecated()
fuego.Get(s, "/", func(c fuego.ContextNoBody) (string, error) {
return "Hello, World!", nil
})

s.Run()
}

func helloWorld(c fuego.ContextNoBody) (string, error) {
return "Hello, World!", nil
}

```

0 comments on commit 97ca254

Please sign in to comment.