Open leorg99 opened 1 month ago
Thanks in advance! @devhl-labs @wing328
I don't believe this is a part of the openapi spec. To get some support for it, you may need to manually edit the spec before using it, or ask the api owners for changes.
@devhl-labs Yeah this isn't my API. I am just a consumer who is looking for a sane way to generate a client to consume it.
Maybe I can do it somehow with user defined templates and customizing this block? https://github.com/OpenAPITools/openapi-generator/blob/38dac13c261d26a72be78bba89ee4a681843e7b0/modules/openapi-generator/src/main/resources/csharp/libraries/generichost/api.mustache#L360-L443
I think I would try to create some kind of class models for sort and filter operations. Then, I would modify the template above to add these models as parameters and use them to generate and update the query parameters collection.
Using the example in the original post, we would end up with instead something like
public async Task<IGetGroupsApiResponse> GetGroupsAsync(...,
Option<Sort> sortBy = default,
Option<Filter> filter = default,
...)
{
...
System.Collections.Specialized.NameValueCollection parseQueryStringLocalVar = System.Web.HttpUtility.ParseQueryString(string.Empty);
if (sortBy.IsSet)
// sortBy.Key= "sort_by[someField]"
// sortBy.Value = "asc" or "desc"
parseQueryStringLocalVar[sortBy.Key] = ClientUtils.ParameterToString(sortBy.Value);
if (filter.IsSet)
// filter.Key= "filter[someField]"
// filter.Value = "someValue"
parseQueryStringLocalVar[filter.Key] = ClientUtils.ParameterToString(filter.Value);
...
uriBuilderLocalVar.Query = parseQueryStringLocalVar.ToString();
httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri;
...
}
If you have any suggestions or guidance on how I should go about doing this, I would very much appreciate it!
Thanks again
Bug Report Checklist
Description
I am not able to specify a sort or filter query parameter in the required form using the generated code.
I am not sure if it's a bug in the generator or simply a limitation of the OpenAPI V2 Definition File or the spec. If this is the case, then maybe there is a work around that I can implement?
Background:
The API that I am working with shows that sort and filter can be used as follows:
where: \<field> is the name of the field to sort by, placed within square brackets [] \<value> is asc or desc.
where: \<filter> is the filter type to use; \<field>is the name of the field to filter by, placed within square brackets []; \<value> is the field value that the filter should apply to.
As an example, this is how the sort and filter is generated for the following method in
GroupsApi.cs
:The OpenAPI V2 Definition File defines this method as follows:
openapi-generator version
7.9.0
OpenAPI declaration file content or url
Generation Details
csharp.config
Steps to reproduce
Build
Related issues/PRs
19626
19892
Suggest a fix