springdoc / springdoc-openapi

Library for OpenAPI 3 with spring-boot
https://springdoc.org
Apache License 2.0
3.27k stars 494 forks source link

Wrong request body was added #805

Closed wltj920 closed 4 years ago

wltj920 commented 4 years ago

Describe the bug When I add HttpServletRequest parameter or HttpServletResponse parameter into a interface and other parameters did not use the @RequestParam annotation, the swagger ui ask me add a request body by json, and the header content type is updated to application/json, but I didn't use @RequestBody anywhere.

The example code like:

@PostMapping("/phone-login")
@Operation(summary = "Login by phone", description = "Use sms system to login system")
@Parameters({
            @Parameter(name = "userPhone", description = "Phone number", required = true, in = ParameterIn.QUERY, example = "18900001234")
            , @Parameter(name = "phoneCode", description = "The code in sms", required = true, in = ParameterIn.QUERY, example = "123456")
    })
public Object phoneLogin(HttpServletRequest request, String userPhone, String phoneCode, HttpServletResponse response) {
//do something
}

image

debargharoy commented 4 years ago

Changing the code as below should help

@PostMapping("/phone-login")
@Operation(summary = "Login by phone", description = "Use sms system to login system")
public Object phoneLogin(
    HttpServletRequest request, 
    @Parameter(name = "userPhone", description = "Phone number", required = true, in = ParameterIn.QUERY, example = "18900001234") String userPhone, 
    @Parameter(name = "phoneCode", description = "The code in sms", required = true, in = ParameterIn.QUERY, example = "123456") String phoneCode, 
    HttpServletResponse response) {
//do something
}
bnasslahsen commented 4 years ago

@wltj920,

You should pass as described by @debargharoy or wrap put your parameters inside an object and pass them as a @RequestBody.