3

My environment

springboot:2.6.4
springdoc-openapi-ui:1.6.6

Probrem

I want to create an API definition to receive requests in x-www-form-urlencoded format. Using @RequestBody will create a swagger-ui display with no Parameter notation, just the body. However, when receiving a request in x-www-form-urlencoded format, it is necessary to receive it with @RequestParam, and if this is done, the swagger-ui display is created as a query parameter.

@PostMapping(value = "/v1/hoge")
public ResponseEntity<SampleResponse> postProc(
    @RequestParam("param1") int param1,
    @RequestParam("param2") String param2,
    @RequestParam("param3") String param3,
    HttpServletRequest request) {
  ・・・
}

swagger-image

However, since there is no actual query parameter, I do not want to display the Parameter in the same way as when receiving a request with @RequestBody. The display without parameters is correct, as in POST /user in the following link.

http://158.101.191.70:8081/swagger-ui/4.5.0/index.html#/user/createUser

Is there a solution to this problem?

aoiro27
  • 31
  • 1

1 Answers1

1

I might have a solution for you:

@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) {
  ・・・
}

In a perfect world, you could stick to the @RequestParam but I believe there is currently a bug with springdoc that make it impossible.

  • With your solution, requests from ARC are accepted and processed correctly. But the Swagger UI still displays the parameters as query parameters and tries to send them as query parameters. – Matthias Aug 28 '23 at 12:11