Is it possible to generate a client method executing a GET request with a filter parameter having a complex data type?
See original GitHub issueHi there,
my controller currently looks like this:
[Route("/api/[controller]")]
public class MyController
{
...
[HttpGet]
public async Task<ActionResult<...>> ListAsync([FromQuery] MyFilterModel filter)
{
...
}
}
The MyFilterModel
is defined as
public class MyFilterModel
{
public string Name { get; set; }
public string Description { get; set; }
}
Now when I generate a C# client from this controller via NSwag the resulting method signature looks like this
Task<...> ListAsync(string name, string description)
Is it possible to generate a method signature that uses the filter model class instead like
Task<...> ListAsync(MyFilterModel filter)
I am asking because currently calling ListAsync("foo", "bar")
in multiple places has some drawbacks like you would need to revisit and change these calls when MyFilterModel
is changed and its not pretty readable at the first glance. I would rather like to call it like ListAsync(new MyFilterModel { Name = "foo", Description = "bar" })
.
Perhaps it is just not possible at the moment due to the still ongoing work for issue #1594 which is part of epic #945.
So lonG
Daniel
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:12 (1 by maintainers)
Top Results From Across the Web
What is a proper way to do a complex RESTful search ...
Following REST principles, I would want to create a GET method for my API that make a search using some criteria and return...
Read more >rest - What is the best way to design a HTTP request when ...
There's no perfect way to do this. The correct HTTP/REST way would be to use a GET and have all your parameters in...
Read more >REST API Design: Filtering, Sorting, and Pagination
The problem is URL parameters only have a key and a value but filters are composed of three components: The property or field...
Read more >Why an HTTP Get Request Shouldn't Have a Body
In this tutorial, we'll learn why an HTTP GET request shouldn't be sent with a body. First, we'll see why that request is...
Read more >Parameter Binding in ASP.NET Web API - ASP.NET 4.x
The id parameter is a "simple" type, so Web API tries to get the value from the request URI. The item parameter is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
If anyone’s interested, I implemented it using a custom liquid template. You could take the folder, and run nswag pointing to it (
/templateDirectory:PATH
).It will add another overload to Client for all GET requests having at least 1 parameter. E.g. for initial method like this:
public Task<ResultDto> GetSomething(string searchQuery, bool? filter1, int filter2)
it will generate:Hello @RicoSuter , I want this feature that is disponible in OpenApi 3.0. So, I guess I will implement this and create a pull request for you. However, can you help me saying some words that help me in implement this feature? I don’t know nothing about nswag implementation and how I should send for you my pull request. I want this feature just for typescript client but if I implement I will should implement for all languages? In this project we have a pattern for pull requests or not?
Reference: https://github.com/RicoSuter/NSwag/issues/3301#issuecomment-779043342