question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Annotating Spring Controller's query params with @RequestParam Map<String,String> is sending wrong request from Swagger UI

See original GitHub issue

SpringFox version: 2.8.0 SpringFox modules: springfox-swagger2, springfox-swagger-ui lib/springfox-swagger-common-2.8.0.jar lib/springfox-swagger-ui-2.8.0.jar lib/springfox-swagger2-2.8.0.jar lib/swagger-annotations-1.5.14.jar lib/swagger-models-1.5.14.jar

Referencing issue - #2279

Code:

I have annotated the Contoller method with the following annotation

    @RequestMapping(value = "/search", method = RequestMethod.GET)
    @ApiOperation(value = "Search based on the search term", response = SearchResult.class)
    public SearchResult search(
            @ApiParam(name="allParams", value="All Params for the search request")
            @RequestParam Map<String,String> allParams) {
                 //doSomething with the query params
            }

This shows up like this in Swagger UI

allParams
[object]
(query)

I specify a value for the allParams as below { "searchTerm" : "cnn" }

Expected output:

(This is how spring expects the input to be where all the query parameters are mapped as key value pairs in a java.util.Map) http://localhost:8090/search?searchTerm=cnn

Actual output from Swagger UI:

Swagger UI is generating a URL like the one below (the curl command in UI) http://localhost:8090/search?allParams={ "searchTerm" %3A "cnn" }

Question:

How to handle Map<String,String> for request parameters when using SpringFox ??

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
ghostcommented, Feb 20, 2020
@RequestMapping(method = RequestMethod.GET, path = "scan")
@ApiOperation(value = "Desc")
public Collection<XobjCore> getProjectsByScan(@RequestParam(required = false) Map<String,String> search) {

    return objCoreService.getXobjCore(search);
}

input name=stefan

Expected curl http://localhost:8080/scan?name=stefan Actual curl http://localhost:8080/scan?search=name=stefan

It’s prepending variable name and = before actual input. Doesn’t work in 2.9.2 still or I am doing something wrong.

0reactions
agnias-stratagemcommented, Nov 23, 2021

@VanTamNguyen See here and here and here

These functions throw new UnsupportedOperationException()

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swagger ui dose not work when @RequestParam annotation ...
I want use swagger and spring fox for api doc .but when do not set @RequestParam it parameter swagger dose not work .I...
Read more >
F.A.Q - Springdoc-openapi
Request parameter annotated with @ParameterObject will help adding each field of the parameter as a separate request parameter. This is compatible with Spring...
Read more >
docs/release-notes.md · serv/springfox - Gitee.com
... (#2194) Swagger-UI authorization headers stopped being sent in 2.8.0 @ctmay4 ... parameter type for @RequestParam Map<String, String> wontfix @nikit ...
Read more >
Swagger ui dose not work when @RequestParam annotation ...
Coding example for the question Swagger ui dose not work when @RequestParam annotation dose not set to method parameter-Spring MVC.
Read more >
Custom Error Messages in Spring REST API - amitph
Although sending a correct status code is enough for a client to take real action based on the outcome of a request, in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found