Skip to content

OpenAPI: Add support for query string parameters #1378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions docs/usage/openapi-client.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ The next steps describe how to generate a JSON:API client library and use our pa
using var httpClient = new HttpClient();
var apiClient = new ExampleApiClient("http://localhost:14140", httpClient);

PersonCollectionResponseDocument getResponse = await apiClient.GetPersonCollectionAsync();
PersonCollectionResponseDocument getResponse = await apiClient.GetPersonCollectionAsync(new Dictionary<string, string?>
{
["filter"] = "has(assignedTodoItems)",
["sort"] = "-lastName",
["page[size]"] = "5"
});

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

// The sent request looks like this:
// {
Expand All @@ -102,20 +108,6 @@ The next steps describe how to generate a JSON:API client library and use our pa
// }
// }
}

static async Task<TResponse?> TranslateAsync<TResponse>(Func<Task<TResponse>> operation)
where TResponse : class
{
try
{
return await operation();
}
catch (ApiException exception) when (exception.StatusCode == 204)
{
// Workaround for https://github.com/RicoSuter/NSwag/issues/2499
return null;
}
}
```

### Other IDEs
Expand Down
Loading