Skip to content
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

API Endpoint that Accepts Form Data as MultiValueMap Renders as Multiple Fields in Swagger UI #2912

Open
cmiles74 opened this issue Feb 20, 2025 · 0 comments

Comments

@cmiles74
Copy link

cmiles74 commented Feb 20, 2025

Describe the bug

My application has an API endpoint that accepts a dynamic form post (we don't know the fields of the form ahead of time). The endpoint is looking for a POST with a request body of MultiValueMap<String, String>. This works well in my application but the Swagger API displays with two fields, "all" and "empty"; when the "all" field is filled in the data doesn't make it to the actual endpoint.

To Reproduce

I'm on the newest version of Spring Boot and the library. My controller methods looks like this...

    @RequestMapping(value = "/{name}/{version}/html", method = RequestMethod.POST,
            consumes = "application/x-www-form-urlencoded", produces = "application/json")
    public ResponseEntity<ValidatedFormDefinitionData> postFormDefinitionSubmission(
            @PathVariable String name,
            @PathVariable String version,
            @RequestBody MultiValueMap<String, String> formData) {

     // code goes here 

    }

That @RequestBody mapping is from the org.springframework.web.bind.annotation package, which I believe is correct.

Screenshots

When I visit the Swagger documentation page, the endpoint's API documentation is rendered like so:

Image

Additional context

My expectation is that there's one text area where I could paste URL encoded parameters, delineated with an ampersand. When I press the "Execute" button I'd like it to generate a cURL command that looks like this...

curl -X 'POST' \
     'http://localhost:8080/form/definition/sample/1/html' \
     -H 'accept: application/json' \
     -H 'Content-Type: application/x-www-form-urlencoded' \
     -d 'sample-form.biographical.first-name=Leonard&sample-form.biographical.last-name=McCoy'

There could be something obvious I'm missing but I have spent a good amount of time trying to make this work and I am stumped. Any help would be greatly appreciated.

Thank you!

@cmiles74 cmiles74 changed the title API Endpoint that Accepts Form Data as MultiValueMap Renders as Fields in Swagger UI API Endpoint that Accepts Form Data as MultiValueMap Renders as Multiple Fields in Swagger UI Feb 20, 2025
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

1 participant