You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code generators are supported, though you may try others as well:
6
10
-[NSwag](https://github.com/RicoSuter/NSwag): Produces clients for C# and TypeScript
7
11
-[Kiota](https://learn.microsoft.com/en-us/openapi/kiota/overview): Produces clients for C#, Go, Java, PHP, Python, Ruby, Swift and TypeScript
8
12
@@ -51,7 +55,8 @@ The following steps describe how to generate and use a JSON:API client in C#, us
51
55
3. Although not strictly required, we recommend running package update now, which fixes some issues.
52
56
53
57
> [!WARNING]
54
-
> NSwag v14 is currently *incompatible* with JsonApiDotNetCore (tracked [here](https://github.com/RicoSuter/NSwag/issues/4662)). Stick with v13.x for the moment.
58
+
> NSwag v14 is currently *incompatible* with JsonApiDotNetCore (tracked [here](https://github.com/RicoSuter/NSwag/issues/4662)).
59
+
> Stick with v13.x for the moment.
55
60
56
61
4. Add our client package to your project:
57
62
@@ -141,8 +146,11 @@ The following steps describe how to generate and use a JSON:API client in C#, us
141
146
```
142
147
143
148
> [!TIP]
144
-
> The [example project](https://github.com/json-api-dotnet/JsonApiDotNetCore/tree/openapi/src/Examples/OpenApiNSwagClientExample) contains an enhanced version that uses `IHttpClientFactory` for [scalability](https://learn.microsoft.com/en-us/dotnet/core/extensions/httpclient-factory) and [resiliency](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/http-requests#use-polly-based-handlers) and logs the HTTP requests and responses.
145
-
> Additionally, the example shows how to write the swagger.json file to disk when building the server, which is imported from the client project. This keeps the server and client automatically in sync, which is handy when both are in the same solution.
149
+
> The [example project](https://github.com/json-api-dotnet/JsonApiDotNetCore/tree/openapi/src/Examples/OpenApiNSwagClientExample) contains an enhanced version
150
+
> that uses `IHttpClientFactory` for [scalability](https://learn.microsoft.com/en-us/dotnet/core/extensions/httpclient-factory) and
151
+
> [resiliency](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/http-requests#use-polly-based-handlers) and logs the HTTP requests and responses.
152
+
> Additionally, the example shows how to write the swagger.json file to disk when building the server, which is imported from the client project.
153
+
> This keeps the server and client automatically in sync, which is handy when both are in the same solution.
146
154
147
155
### Other IDEs
148
156
@@ -215,7 +223,8 @@ Likewise, you can enable nullable reference types by adding `/GenerateNullableRe
215
223
The available command-line switches for Kiota are described [here](https://learn.microsoft.com/en-us/openapi/kiota/using#client-generation).
216
224
217
225
At the time of writing, Kiota provides [no official integration](https://github.com/microsoft/kiota/issues/3005) with MSBuild.
218
-
Our [example project](https://github.com/json-api-dotnet/JsonApiDotNetCore/tree/openapi/src/Examples/OpenApiKiotaClientExample) takes a stab at it, although it has glitches. If you're an MSBuild expert, please help out!
226
+
Our [example project](https://github.com/json-api-dotnet/JsonApiDotNetCore/tree/openapi/src/Examples/OpenApiKiotaClientExample) takes a stab at it,
227
+
although it has glitches. If you're an MSBuild expert, please help out!
219
228
220
229
```xml
221
230
<TargetName="KiotaRunTool"BeforeTargets="BeforeCompile;CoreCompile"Condition="$(DesignTimeBuild) != true And $(BuildingProject) == true">
After [enabling OpenAPI](~/usage/openapi.md), you can expose a documentation website with SwaggerUI or Redoc.
4
+
5
+
### SwaggerUI
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:
9
+
10
+
```c#
11
+
app.UseSwaggerUI();
12
+
```
13
+
14
+
By default, SwaggerUI will be available at `http://localhost:<port>/swagger`.
15
+
16
+
### Redoc
17
+
18
+
[Redoc](https://github.com/Redocly/redoc) is another popular tool that generates a documentation website from an OpenAPI document.
19
+
It lists the endpoints and their schemas, but doesn't provide the ability to execute requests.
20
+
The `Swashbuckle.AspNetCore.ReDoc` NuGet package provides integration with Swashbuckle.
Copy file name to clipboardExpand all lines: docs/usage/openapi.md
+35-13Lines changed: 35 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,9 +1,11 @@
1
1
# OpenAPI
2
2
3
-
JsonApiDotNetCore provides an extension package that enables you to produce an [OpenAPI specification](https://swagger.io/specification/) for your JSON:API endpoints.
4
-
This can be used to generate a [documentation website](https://swagger.io/tools/swagger-ui/)or to generate [client libraries](https://openapi-generator.tech/docs/generators/) in various languages.
5
-
The package provides an integration with [Swashbuckle](https://github.com/domaindrivendev/Swashbuckle.AspNetCore).
3
+
Exposing an [OpenAPI document](https://swagger.io/specification/) for your JSON:API endpoints enables to provide a
4
+
[documentation website](https://swagger.io/tools/swagger-ui/)and to generate typed
5
+
[client libraries](https://openapi-generator.tech/docs/generators/) in various languages.
6
6
7
+
The [JsonApiDotNetCore.OpenApi](https://github.com/json-api-dotnet/JsonApiDotNetCore/pkgs/nuget/JsonApiDotNetCore.OpenApi) NuGet package
8
+
provides OpenAPI support for JSON:API by integrating with [Swashbuckle](https://github.com/domaindrivendev/Swashbuckle.AspNetCore).
7
9
8
10
## Getting started
9
11
@@ -13,7 +15,11 @@ The package provides an integration with [Swashbuckle](https://github.com/domain
13
15
dotnet add package JsonApiDotNetCore.OpenApi
14
16
```
15
17
16
-
2. Add the integration in your `Program.cs` file.
18
+
> [!NOTE]
19
+
> Because this package is still experimental, it's not yet available on NuGet.
20
+
> Use the steps [here](https://github.com/json-api-dotnet/JsonApiDotNetCore?tab=readme-ov-file#trying-out-the-latest-build) to install.
21
+
22
+
2. Add the JSON:API support to your `Program.cs` file.
17
23
18
24
```c#
19
25
builder.Services.AddJsonApi<AppDbContext>();
@@ -30,22 +36,37 @@ The package provides an integration with [Swashbuckle](https://github.com/domain
30
36
app.UseSwagger();
31
37
```
32
38
33
-
By default, the OpenAPI specification will be available at `http://localhost:<port>/swagger/v1/swagger.json`.
39
+
By default, the OpenAPI document will be available at `http://localhost:<port>/swagger/v1/swagger.json`.
40
+
41
+
### Customizing the Route Template
34
42
35
-
## Documentation
43
+
Because Swashbuckle doesn't properly implement the ASP.NET Options pattern, you must *not* use its
Swashbuckle also ships with [SwaggerUI](https://swagger.io/tools/swagger-ui/), which enables to visualize and interact with the API endpoints through a web page.
40
-
This can be enabled by installing the `Swashbuckle.AspNetCore.SwaggerUI` NuGet package and adding the following to your `Program.cs` file:
52
+
Instead, always call `UseSwagger()`*without parameters*. To change the route template, use the code below:
Documentation for JSON:API endpoints is provided out of the box, which shows in SwaggerUI and through IDE IntelliSense in auto-generated clients.
51
72
To also get documentation for your resource classes and their properties, add the following to your project file.
@@ -58,5 +79,6 @@ The `NoWarn` line is optional, which suppresses build warnings for undocumented
58
79
</PropertyGroup>
59
80
```
60
81
61
-
You can combine this with the documentation that Swagger itself supports, by enabling it as described [here](https://github.com/domaindrivendev/Swashbuckle.AspNetCore#include-descriptions-from-xml-comments).
82
+
You can combine this with the documentation that Swagger itself supports, by enabling it as described
0 commit comments