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
Copy file name to clipboardExpand all lines: docs/usage/openapi-client.md
+26-10Lines changed: 26 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
1
# OpenAPI Client
2
2
3
-
You can generate a JSON:API client in various programming languages from the OpenAPI specification file that JsonApiDotNetCore APIs provide. For C# .NET clients generated using NSwag, we provide an additional package that introduces support for partial PATCH/POST requests. The issue here is that a property on a generated C# class being `null` could mean "set the value to `null` in the request" or "this is `null` because I never touched it".
3
+
You can generate a JSON:API client in various programming languages from the [OpenAPI specification](https://swagger.io/specification/) file that JsonApiDotNetCore APIs provide.
4
+
5
+
For C# .NET clients generated using [NSwag](https://github.com/RicoSuter/NSwag), we provide an additional package that introduces support for partial PATCH/POST requests. The issue here is that a property on a generated C# class being `null` could mean "set the value to `null` in the request" or "this is `null` because I never touched it".
4
6
5
7
## Getting started
6
8
@@ -9,28 +11,38 @@ You can generate a JSON:API client in various programming languages from the Ope
9
11
The easiest way to get started is by using the built-in capabilities of Visual Studio. The next steps describe how to generate a JSON:API client library and use our package.
10
12
11
13
1. In **Solution Explorer**, right-click your client project, select **Add** > **Service Reference** and choose **OpenAPI**.
14
+
12
15
2. On the next page, specify the OpenAPI URL to your JSON:API server, for example: `http://localhost:14140/swagger/v1/swagger.json`.
13
16
Optionally provide a class name and namespace and click **Finish**.
14
17
Visual Studio now downloads your swagger.json and updates your project file. This results in a pre-build step that generates the client code.
18
+
15
19
Tip: To later re-download swagger.json and regenerate the client code, right-click **Dependencies** > **Manage Connected Services** and click the **Refresh** icon.
16
20
3. Although not strictly required, we recommend to run package update now, which fixes some issues and removes the `Stream` parameter from generated calls.
21
+
17
22
4. Add some demo code that calls one of your JSON:API endpoints. For example:
6. Add the following glue code to connect our package with your generated code. The code below assumes you specified `ExampleApiClient` as class name in step 2.
45
+
34
46
```c#
35
47
using JsonApiDotNetCore.OpenApi.Client;
36
48
using Newtonsoft.Json;
@@ -43,7 +55,9 @@ The easiest way to get started is by using the built-in capabilities of Visual S
43
55
}
44
56
}
45
57
```
58
+
46
59
7. Extend your demo code to send a partial PATCH request with the help of our package:
60
+
47
61
```c#
48
62
var patchRequest = new PersonPatchRequestDocument
49
63
{
@@ -58,10 +72,11 @@ The easiest way to get started is by using the built-in capabilities of Visual S
58
72
};
59
73
60
74
// This line results in sending "lastName: null" instead of omitting it.
61
-
using (apiClient.RegisterAttributesForRequestDocument<PersonPatchRequestDocument, PersonAttributesInPatchRequest>(
62
-
patchRequest, person => person.LastName))
75
+
using (apiClient.RegisterAttributesForRequestDocument<PersonPatchRequestDocument,
76
+
PersonAttributesInPatchRequest>(patchRequest, person => person.LastName))
@@ -105,17 +120,18 @@ Alternatively, the next section shows what to add to your client project file di
105
120
106
121
From here, continue from step 3 in the list of steps for Visual Studio.
107
122
108
-
## Customization
123
+
## Configuration
109
124
110
-
### NSwga
125
+
### NSwag
111
126
112
127
The `OpenApiReference` element in the project file accepts an `Options` element to pass additional settings to the client generator,
113
-
which are listed at https://github.com/RicoSuter/NSwag/blob/master/src/NSwag.Commands/Commands/CodeGeneration/OpenApiToCSharpClientCommand.cs.
128
+
which are listed [here](https://github.com/RicoSuter/NSwag/blob/master/src/NSwag.Commands/Commands/CodeGeneration/OpenApiToCSharpClientCommand.cs).
114
129
115
130
For example, the next section puts the generated code in a namespace, removes the `baseUrl` parameter and generates an interface (which is handy for dependency injection):
Copy file name to clipboardExpand all lines: docs/usage/openapi.md
+28-44Lines changed: 28 additions & 44 deletions
Original file line number
Diff line number
Diff line change
@@ -3,63 +3,47 @@
3
3
JsonApiDotNetCore provides an extension package that enables you to produce an [OpenAPI specification](https://swagger.io/specification/) for your JSON:API endpoints. 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. The package provides an integration with [Swashbuckle](https://github.com/domaindrivendev/Swashbuckle.AspNetCore).
4
4
5
5
6
-
## Installation
6
+
## Getting started
7
7
8
-
Install the `JsonApiDotNetCore.OpenApi` NuGet package.
8
+
1.Install the `JsonApiDotNetCore.OpenApi` NuGet package:
9
9
10
-
### CLI
10
+
```
11
+
dotnet add package JsonApiDotNetCore.OpenApi
12
+
```
11
13
12
-
```
13
-
dotnet add package JsonApiDotNetCore.OpenApi
14
-
```
15
-
16
-
### Visual Studio
17
-
18
-
```powershell
19
-
Install-Package JsonApiDotNetCore.OpenApi
20
-
```
21
-
22
-
### *.csproj
23
-
24
-
```xml
25
-
<ItemGroup>
26
-
<!-- Be sure to check NuGet for the latest version # -->
By default, the OpenAPI specification will be available at `http://localhost:<port>/swagger/v1/swagger.json`.
61
43
62
-
Swashbuckle also ships with [SwaggerUI](https://swagger.io/tools/swagger-ui/), tooling for a generated documentation page. This can be enabled by installing the `Swashbuckle.AspNetCore.SwaggerUI` NuGet package and adding the following to your `Startup` class.
44
+
## Documentation
45
+
46
+
Swashbuckle also ships with [SwaggerUI](https://swagger.io/tools/swagger-ui/), tooling for a generated documentation page. This can be enabled by installing the `Swashbuckle.AspNetCore.SwaggerUI` NuGet package and adding the following to your `Startup` class:
0 commit comments