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
+33-22
Original file line number
Diff line number
Diff line change
@@ -3,8 +3,9 @@
3
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
4
5
5
For C# .NET clients generated using [NSwag](https://github.com/RicoSuter/NSwag), we provide an additional package
6
-
that introduces support for partial PATCH/POST requests. The concern here is that a property on a generated C# class
7
-
being `null` could mean "set the value to `null` in the request" or "this is `null` because I never touched it".
6
+
that provides workarounds for NSwag bugs and introduces support for partial PATCH/POST requests.
7
+
The concern here is that a property on a generated C# class being `null` could either mean: "set the value to `null`
8
+
in the request" or: "this is `null` because I never touched it".
8
9
9
10
## Getting started
10
11
@@ -26,29 +27,19 @@ The next steps describe how to generate a JSON:API client library and use our pa
26
27
27
28
3. Although not strictly required, we recommend to run package update now, which fixes some issues.
28
29
29
-
4. Add code that calls one of your JSON:API endpoints.
30
+
> [!WARNING]
31
+
> NSwag v14 is currently *incompatible* with JsonApiDotNetCore (tracked [here](https://github.com/RicoSuter/NSwag/issues/4662)). Stick with v13.x for the moment.
6. Add the following glue code to connect our package with your generated code.
@@ -73,8 +64,28 @@ The next steps describe how to generate a JSON:API client library and use our pa
73
64
74
65
> [!TIP]
75
66
> The project at src/Examples/JsonApiDotNetCoreExampleClient contains an enhanced version that logs the HTTP requests and responses.
67
+
> 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.
68
+
69
+
7. Add code that calls one of your JSON:API endpoints.
70
+
71
+
```c#
72
+
using var httpClient = new HttpClient();
73
+
var apiClient = new ExampleApiClient(httpClient);
74
+
75
+
var getResponse = await apiClient.GetPersonCollectionAsync(new Dictionary<string, string?>
76
+
{
77
+
["filter"] = "has(assignedTodoItems)",
78
+
["sort"] = "-lastName",
79
+
["page[size]"] = "5"
80
+
});
81
+
82
+
foreach (var person in getResponse.Data)
83
+
{
84
+
Console.WriteLine($"Found person {person.Id}: {person.Attributes.DisplayName}");
0 commit comments