Spring-boot – Spring REST API with swagger – map of values in request param

http-request-parametersspring-bootspringfoxswaggerswagger-codegen

I have a Spring Boot based REST API application with the following endpoint (Written in Kotlin)

    @RequestMapping(value = ["/search"], method = [RequestMethod.GET])
    @ApiOperation("Check whether any of the map values exists. Returns string 'true' if stamp exists, else 'false'")
    fun checkExists(
            @ApiParam("information about the stamp as key-value pairs (example: ds=2017-11-34&hh=05)", required = true)
            @RequestParam searchValues: Map<String, String>
    ): Boolean {
        return service.checkExists(searchValues)
    }

And I know Spring supports sending a dynamic map of key value pairs as documented here.

I am also using Swagger to document the API definitions, and further more, I am using swagger-codegen-cli to generate the client library using which someone can connect with this REST API.

Now, the issue is, I am not able to send a map of values from the swagger generated client to the Spring REST API (even though Spring supports it). Starting from Swagger OpenAPI 3, they've added support for Object types in the specification. But this works in a different way than I need. For example with just Spring and RequestParam of type Map

http://localhost:8080/search?foo=A&bar=B

is parsed as a map of key value pairs

key="foo",value="A"
key="bar",value="B"

But, When I send a Map Object from the swagger client with the same key-value pairs

Map<String, String> values = new HashMap<>();
values.put("foo","A");
values.put("bar","B");
return out = clientApi.checkExistsUsingGET(values);

This sends a request to the REST API in form of

http://localhost:8080/search?searchValues={foo=A,bar=B}

and the map in Spring side ends up as

key="searchValues",value="{foo=A,bar=B}"

I've been struggling to get the swagger client api to send the request in a way the Spring API is intended to work with Map of values, but I am not able to figure a solution.

Am I doing using the client API in a wrong way?, or this just can't be done with swagger?

Any suggestions/opinions appreciated!

Best Answer

This is not yet supported by swagger-ui. See this issue https://github.com/swagger-api/swagger-ui/issues/2241