我的环境
弹跳:2.6.4
springdoc ui:1.6.6
普罗布罗姆
我想要创建一个API定义来接收x-www格式的请求.使用@RequestBody将创建一个swagger显示,没有参数符号,只有主体。但是,当接收到x-www-form-urlencoded格式的请求时,必须使用@RequestParam接收请求,如果这样做了,就会创建swagger-ui显示作为查询参数。
@PostMapping(value = "/v1/hoge")
public ResponseEntity<SampleResponse> postProc(
@RequestParam("param1") int param1,
@RequestParam("param2") String param2,
@RequestParam("param3") String param3,
HttpServletRequest request) {
・・・
}但是,由于没有实际的查询参数,所以我不希望以与使用@RequestBody接收请求时相同的方式显示参数。没有参数的显示是正确的,如下链接中的POST /user所示。
http://158.101.191.70:8081/swagger-ui/4.5.0/index.html#/user/createUser
这个问题有解决办法吗?
发布于 2022-10-31 07:49:38
我可能有个解决办法给你:
@PostMapping(value = "/v1/hoge", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<SampleResponse> postProc(
@RequestPart("param1") int param1,
@RequestPart("param2") String param2,
@RequestPart("param3") String param3,
HttpServletRequest request) {
・・・
}在一个完美的世界里,你可以坚持@RequestParam,但我相信目前有一个错误与springdoc,使它不可能。
https://stackoverflow.com/questions/71437832
复制相似问题