title: Spring REST API with swagger - map of values in request param
body: <p>I have a Spring Boot based REST API application with the following endpoint (Written in Kotlin)</p>
  
  <pre><code>    @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&amp;hh=05)", required = true)
              @RequestParam searchValues: Map&lt;String, String&gt;
      ): Boolean {
          return service.checkExists(searchValues)
      }
  </code></pre>
  
  <p>And I know Spring supports sending a dynamic map of key value pairs as documented <a href="https://docs.spring.io/spring/docs/3.2.x/javadoc-api/org/springframework/web/bind/annotation/RequestParam.html" rel="nofollow noreferrer">here</a>.</p>
  
  <p>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.</p>
  
  <p>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</p>
  
  <pre><code>http://localhost:8080/search?foo=A&amp;bar=B
  </code></pre>
  
  <p>is parsed as a map of key value pairs</p>
  
  <pre><code>key="foo",value="A"
  key="bar",value="B"
  </code></pre>
  
  <p>But, When I send a Map Object from the swagger client with the same key-value pairs</p>
  
  <pre><code>Map&lt;String, String&gt; values = new HashMap&lt;&gt;();
  values.put("foo","A");
  values.put("bar","B");
  return out = clientApi.checkExistsUsingGET(values);
  </code></pre>
  
  <p>This sends a request to the REST API in form of</p>
  
  <pre><code>http://localhost:8080/search?searchValues={foo=A,bar=B}
  </code></pre>
  
  <p>and the map in Spring side ends up as</p>
  
  <pre><code>key="searchValues",value="{foo=A,bar=B}"
  </code></pre>
  
  <p>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.</p>
  
  <p>Am I doing using the client API in a wrong way?, or this just can't be done with swagger?</p>
  
  <p>Any suggestions/opinions appreciated!</p>