Skip to content

Commit abc9fff

Browse files
committed
Add OpenAPI support for JSON:API query string parameters, introduce end-to-end tests
1 parent 0a4be97 commit abc9fff

File tree

39 files changed

+8705
-894
lines changed

39 files changed

+8705
-894
lines changed

docs/usage/openapi-client.md

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,12 @@ The next steps describe how to generate a JSON:API client library and use our pa
3232
using var httpClient = new HttpClient();
3333
var apiClient = new ExampleApiClient("http://localhost:14140", httpClient);
3434

35-
PersonCollectionResponseDocument getResponse = await apiClient.GetPersonCollectionAsync();
35+
PersonCollectionResponseDocument getResponse = await apiClient.GetPersonCollectionAsync(new Dictionary<string, string?>
36+
{
37+
["filter"] = "has(assignedTodoItems)",
38+
["sort"] = "-lastName",
39+
["page[size]"] = "5"
40+
});
3641

3742
foreach (PersonDataInResponse person in getResponse.Data)
3843
{
@@ -88,7 +93,8 @@ The next steps describe how to generate a JSON:API client library and use our pa
8893
using (apiClient.WithPartialAttributeSerialization<PersonPatchRequestDocument, PersonAttributesInPatchRequest>(patchRequest,
8994
person => person.FirstName))
9095
{
91-
await TranslateAsync(async () => await apiClient.PatchPersonAsync(1, patchRequest));
96+
// Workaround for https://github.com/RicoSuter/NSwag/issues/2499.
97+
await TranslateAsync(async () => await apiClient.PatchPersonAsync(1, null, patchRequest));
9298

9399
// The sent request looks like this:
94100
// {
@@ -102,20 +108,6 @@ The next steps describe how to generate a JSON:API client library and use our pa
102108
// }
103109
// }
104110
}
105-
106-
static async Task<TResponse?> TranslateAsync<TResponse>(Func<Task<TResponse>> operation)
107-
where TResponse : class
108-
{
109-
try
110-
{
111-
return await operation();
112-
}
113-
catch (ApiException exception) when (exception.StatusCode == 204)
114-
{
115-
// Workaround for https://github.com/RicoSuter/NSwag/issues/2499
116-
return null;
117-
}
118-
}
119111
```
120112

121113
### Other IDEs

0 commit comments

Comments
 (0)