简体   繁体   English

如何使用Swagger @RequestParam Map进行文档记录<String, String>

[英]How to document with Swagger @RequestParam Map<String, String>

I'm trying to document my RESTFUL API made with Spring Boot using Swagger UI, the problem is that when i open the swagger-ui.html to view my documentation. 我正在尝试使用Swagger UI记录由Spring Boot制作的RESTFUL API,问题是当我打开swagger-ui.html查看我的文档时。

When I open the controller on the swagger-ui.html to view my methods, they are blank, with only one parameter which is a Map type. 当我在swagger-ui.html上打开控制器以查看我的方法时,它们为空白,只有一个参数,即Map类型。 Obvious with this map object I fetch the parameters I need and make the request to the database or whatever. 显然,使用此映射对象,我可以获取所需的参数,并向数据库或其他对象发出请求。

I would like to know how I could tell swagger that those methods need some specific values or arguments, not just a simple Map object , i would like to tell the user with the api doc that he needs to input the key1,key2,key3 to call this method. 我想知道我该如何告诉那些方法需要一些特定的值或参数,而不仅仅是一个简单的Map对象,我想告诉具有api文档的用户他需要输入key1,key2,key3来调用此方法。

There is an example of one method 有一种方法的例子

@GetMapping("/technical/sma/**")
    public ArrayList<RegistroTecnico> recuperarSMA(@RequestParam Map<String, String> queryParameters) {
        return this.recuperarIndicadorAVG("sma",queryParameters);
    }

I would like to tell swagger to document the parameters needed for the method manually if there is no way. 如果没有办法,我想告诉swagger手动记录该方法所需的参数。

It looks like there is no direct support from SpringFox in Spring boot application for Map type. 在Spring引导应用程序中,SpringFox似乎没有针对Map类型的直接支持。 You have to write your own custom plugin. 您必须编写自己的自定义插件。 You can get more details from this issue. 您可以从此问题中获取更多详细信息。

https://github.com/springfox/springfox/issues/1503# https://github.com/springfox/springfox/issues/1503#

I think till now there is no support for Map type parameter auto-detect doc from swagger. 我想到现在为止,还不支持swagger的Map类型参数自动检测doc。 If you need auto-detect Param from swagger just convert the map into POJO and wrap it in response body but for that you need to change request type to POST. 如果您需要从招摇中自动检测参数,只需将地图转换为POJO并将其包装在响应主体中,但是为此您需要将请求类型更改为POST。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring RequestParam Map <String,String> - Spring RequestParam Map<String, String> 如何转换@RequestParam地图 <String, String> 到自定义Map &lt;&gt; - How to convert a @RequestParam Map<String, String> to a custom a Map<> 如何获取地图 <String, String[]> 控制器中的@RequestParam获取数据? - How to get Map<String, String[]> data with @RequestParam in controller? 如何为 Map 类型的 RequestParam 指定默认值<string, string> ?</string,> - How to specify default value for RequestParam of type Map<String, String>? Spring MVC 填充@RequestParam Map<string, string></string,> - Spring MVC populate @RequestParam Map<String, String> MultipartFile 不在“@RequestParam Map”中<String, Object> requestParams”变量 - MultipartFile not in “@RequestParam Map<String, Object> requestParams” variable 如何生成地图<String, ...>使用 Swagger Codegen? - How to generate Map<String, ...> with Swagger Codegen? @RequestParam地图 <String, String> 在Spring Boot中将变量名称打印为键 - @RequestParam Map<String, String> Prints variable name as key in spring boot Spring @RequestParam-混合命名的参数和Map <String,String> 参数 - Spring @RequestParam - Mixing named params and Map<String,String> params 如何在Spring Boot中不解码@RequestParam设置的字符串? - How to not decode the string set by @RequestParam in Spring Boot?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM