Skip to content

Commit 24123dd

Browse files
committed
Add support for returning included resources using allOf inheritance with discriminator
1 parent be4e5d9 commit 24123dd

File tree

52 files changed

+2744
-1260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+2744
-1260
lines changed

Diff for: docs/usage/openapi-client.md

+33-22
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
You can generate a JSON:API client in various programming languages from the [OpenAPI specification](https://swagger.io/specification/) file that JsonApiDotNetCore APIs provide.
44

55
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".
89

910
## Getting started
1011

@@ -26,29 +27,19 @@ The next steps describe how to generate a JSON:API client library and use our pa
2627
2728
3. Although not strictly required, we recommend to run package update now, which fixes some issues.
2829

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.
3032
31-
```c#
32-
using var httpClient = new HttpClient();
33-
var apiClient = new ExampleApiClient(httpClient);
34-
35-
PersonCollectionResponseDocument getResponse = await apiClient.GetPersonCollectionAsync(new Dictionary<string, string?>
36-
{
37-
["filter"] = "has(assignedTodoItems)",
38-
["sort"] = "-lastName",
39-
["page[size]"] = "5"
40-
});
33+
4. Add our client package to your project:
4134

42-
foreach (PersonDataInResponse person in getResponse.Data)
43-
{
44-
Console.WriteLine($"Found person {person.Id}: {person.Attributes.DisplayName}");
45-
}
35+
```
36+
dotnet add package JsonApiDotNetCore.OpenApi.Client
4637
```
4738
48-
5. Add our client package to your project:
39+
5. Add the next line inside the **OpenApiReference** section in your project file:
4940
50-
```
51-
dotnet add package JsonApiDotNetCore.OpenApi.Client
41+
```xml
42+
<Options>/GenerateExceptionClasses:false /AdditionalNamespaceUsages:JsonApiDotNetCore.OpenApi.Client.Exceptions</Options>
5243
```
5344
5445
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
7364
7465
> [!TIP]
7566
> 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}");
85+
}
86+
```
7687
77-
7. Extend your demo code to send a partial PATCH request with the help of our package:
88+
8. Extend your demo code to send a partial PATCH request with the help of our package:
7889
7990
```c#
8091
var patchRequest = new PersonPatchRequestDocument
@@ -94,7 +105,7 @@ The next steps describe how to generate a JSON:API client library and use our pa
94105
person => person.FirstName))
95106
{
96107
// Workaround for https://github.com/RicoSuter/NSwag/issues/2499.
97-
await TranslateAsync(async () => await apiClient.PatchPersonAsync(patchRequest.Data.Id, null, patchRequest));
108+
await ApiResponse.TranslateAsync(() => apiClient.PatchPersonAsync(patchRequest.Data.Id, null, patchRequest));
98109
99110
// The sent request looks like this:
100111
// {

0 commit comments

Comments
 (0)