Skip to content

Issues with POST Request, application/x-www-form-urlencoded and only one parameter #2990

Closed
@mum-viadee

Description

@mum-viadee

Describe the bug
I have a REST API with Spring MVC. One REST controller has a method with only one parameter. It has a PostMapping with consumes set to "application/x-www-form-urlencoded". The generated openapi definition says, that the request body is of type String and directly contains the value of the parameter, in my case a UUID. There is no key-value pair like i had expected. If I use the button "Try it out" in the Swagger UI I get a bad request response.

[org.springframework.web.bind.MissingServletRequestParameterException: Required request parameter 'test_id' for method parameter type UUID is not present]

Steps to reproduce the behavior

  • spring-boot 3.4.5
  • springdoc-openapi-starter-webmvc-ui 2.8.8 (2.8.6)

Code-Example

@RestController
@Validated
public class DemoController {

    @PostMapping(path = "/api/test", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public Result postSingleParameter(@RequestParam(name = "test_id") @NotNull final UUID testId) {
        return new Result("Test", "Just a simple test.");
    }

}

Actual Result:

"requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "string",
                "format": "uuid"
              }
            }
          },

Expected Result:

"requestBody": {
          "content": {
            "application/x-www-form-urlencoded": {
              "schema": {
                "type": "object",
                "properties": {
                  "test_id": {
                    "type": "string",
                    "format": "uuid"
                  }
                },
                "required": [
                  "test_id"
                ]
              }
            }
          },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions