|
1 | 1 | # OpenAPI documentation
|
2 | 2 |
|
3 |
| -After [enabling OpenAPI](~/usage/openapi.md), you can expose a documentation website with SwaggerUI or Redoc. |
| 3 | +After [enabling OpenAPI](~/usage/openapi.md), you can expose a documentation website with SwaggerUI, Redoc and/or Scalar. |
4 | 4 |
|
5 |
| -### SwaggerUI |
| 5 | +## SwaggerUI |
6 | 6 |
|
7 |
| -Swashbuckle ships with [SwaggerUI](https://swagger.io/tools/swagger-ui/), which enables to visualize and interact with the JSON:API endpoints through a web page. |
8 |
| -This can be enabled by installing the `Swashbuckle.AspNetCore.SwaggerUI` NuGet package and adding the following to your `Program.cs` file: |
| 7 | +[SwaggerUI](https://swagger.io/tools/swagger-ui/) enables to visualize and interact with the JSON:API endpoints through a web page. |
| 8 | +While it conveniently provides the ability to execute requests, it doesn't show properties of derived types when component schema inheritance is used. |
| 9 | + |
| 10 | +SwaggerUI can be enabled by installing the `Swashbuckle.AspNetCore.SwaggerUI` NuGet package and adding the following to your `Program.cs` file: |
9 | 11 |
|
10 | 12 | ```c#
|
11 | 13 | app.UseSwaggerUI();
|
12 | 14 | ```
|
13 | 15 |
|
14 |
| -By default, SwaggerUI will be available at `http://localhost:<port>/swagger`. |
| 16 | +Then run your app and open `/swagger` in your browser. |
15 | 17 |
|
16 |
| -### Redoc |
| 18 | +## Redoc |
17 | 19 |
|
18 | 20 | [Redoc](https://github.com/Redocly/redoc) is another popular tool that generates a documentation website from an OpenAPI document.
|
19 | 21 | It lists the endpoints and their schemas, but doesn't provide the ability to execute requests.
|
| 22 | +However, this tool most accurately reflects properties when component schema inheritance is used; choosing a different "type" from the |
| 23 | +dropdown box dynamically adapts the list of schema properties. |
| 24 | + |
20 | 25 | The `Swashbuckle.AspNetCore.ReDoc` NuGet package provides integration with Swashbuckle.
|
| 26 | +After installing the package, add the following to your `Program.cs` file: |
| 27 | + |
| 28 | +```c# |
| 29 | +app.UseReDoc(); |
| 30 | +``` |
| 31 | + |
| 32 | +Next, run your app and navigate to `/api-docs` to view the documentation. |
| 33 | + |
| 34 | +## Scalar |
| 35 | + |
| 36 | +[Scalar](https://scalar.com/) is a modern documentation website generator, which includes the ability to execute requests. |
| 37 | +It shows component schemas in a low-level way (not collapsing `allOf` nodes), but does a poor job in handling component schema inheritance. |
| 38 | + |
| 39 | +After installing the `Scalar.AspNetCore` NuGet package, add the following to your `Program.cs` to make it use the OpenAPI document produced by Swashbuckle: |
| 40 | + |
| 41 | +```c# |
| 42 | +app.MapScalarApiReference(options => options.OpenApiRoutePattern = "/swagger/{documentName}/swagger.json"); |
| 43 | +``` |
| 44 | + |
| 45 | +Then run your app and navigate to `/scalar/v1` to view the documentation. |
0 commit comments