Skip to content

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

@cmiles74

Description

@cmiles74

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    invalidThis doesn't seem right

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions