Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mum-viadee opened this issue May 9, 2025 · 2 comments

Comments

@mum-viadee
Copy link

mum-viadee commented May 9, 2025

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"
                ]
              }
            }
          },
@mum-viadee mum-viadee changed the title Issues with POST Request with only one parameter Issues with POST Request, application/x-www-form-urlencoded and only one parameter May 9, 2025
@Mattias-Sehlstedt
Copy link

Hi @mum-viadee,

This looks to be an issue in swagger-core,

I have create a branch where I tested their introspection for a single primitive parameter

@POST
@Path("/search-id")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response searchForThing(@BeanParam String id) {
    return Response.status(200).entity("Searching for something").build();
}

and it fails as

Image
which is your reported issue.

@Mattias-Sehlstedt
Copy link

Mattias-Sehlstedt commented May 13, 2025

I saw that I used the incorrect parameter annotation (@BeanParam rather than @FormParam) and with the correction swagger-core seems to behave as expected. So more investigation is necessary.

Most likely a corner case that hasn't been covered here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants