Skip to content

Commit b30030a

Browse files
authored
OpenAPI: Add support for query string parameters (#1378)
* Fixed: the 'first' link should not be required, because JsonApiDotNetCore omits it when no resources are returned * Fixed: do not generate duplicate operation ID when secondary resource type is same as primary resource type at secondary endpoint * Fixed: resource fields are never required in response objects (sparse fieldsets may exclude them) * Publicly expose ApiResponse * Add OpenAPI support for JSON:API query string parameters, introduce end-to-end tests * Correct the nullability of values in "meta" (`IDictionary<string, object>` becomes `IDictionary<string, object?>`) * Refresh example
1 parent 6f89ded commit b30030a

File tree

49 files changed

+11133
-1384
lines changed

Some content is hidden

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

49 files changed

+11133
-1384
lines changed

docs/usage/openapi-client.md

+8-16
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)