Swagger UI Generation for Common REST Calls

What I need:

I want to be able to generate swagger documentation that passes the key / value to the URL. This is so that I can use the general argument controller to handle my queries, such as Dictionary.

If swagger cannot generate it, is there a way to generate documentation using reflection on my objects? It is so that I can still use common methods

If not, what will be the best way to tell everyone what is right.

Why do I need it

I am developing a new API and I am using swagger to create documentation. In this API, I want to work with some universal methods to prevent hard coding things. For example, in the PATCH method, I use Dictionary<string, string> to get a combination of properties / values, and in GET I use a custom object as an argument. In both cases, swagger cannot generate the correct parameter fields because it takes an argument as a URL key.

Example action and form - wrong

 public async Task<IActionResult> Patch(int id, Dictionary<string, string> viewModel) { return await ConnectionWrapper(() => connector.Patch(id, viewModel)); } 

enter image description here

This uses the body, not the request.

Other examples are incorrect

In GET, I have a model with a custom template to handle all other URLs. The problem is that the model is defined as a filter.

enter image description here

Then it is in the url, but it will look like http://example.com/controller/method/id?sort=prop_asc&filter=propTwo%3D=value instead of http://example.com/controller/method/id ? sort = prop_asc & propTwo = value

Desired Conclusion

enter image description here

I modified the HTML to simulate what I would like in the image above. The URL to be called will be http://example.com/controller/method/id?propertyName=propertyValue .

I do not mind if there is only one opportunity to add a common key / value pair, because with it I can demonstrate what I want.

Expected Solution

I think the solution lies in the MapType launch method to launch or implement IOperationFilter , but I could not figure it out.

+5
source share

Source: https://habr.com/ru/post/1272466/


All Articles