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

Support @RequestParam of type Map<String, String> #1061

Closed
matias2681 opened this issue Nov 18, 2015 · 12 comments
Closed

Support @RequestParam of type Map<String, String> #1061

matias2681 opened this issue Nov 18, 2015 · 12 comments
Labels
Milestone

Comments

@matias2681
Copy link

Hi,

I have a project that is using Spring Cloud and the class EnvironmentManagerMvcEndpoint.java seems to be generating a wrong swagger file. The method value (POST) with a parameter that is a Map is mapped as this:

"parameters":[
   {
      "name":"params",
      "in":"query",
      "description":"params",
      "required":true,
      "type":"ref"
   }
]

The type:ref makes the file invalid, I tried changing to "string" instead of "ref" and it results in a valid swagger file.

I also run the debugger that you have available in http://online.swagger.io/validator/debug and I had this error message.

[
   {
      "level":"error",
      "domain":"validation",
      "keyword":"oneOf",
      "message":"instance failed to match exactly one schema (matched 0 out of 2)",
      "schema":{
         "loadingURI":"http://swagger.io/v2/schema.json#",
         "pointer":"/definitions/parametersList/items"
      },
      "instance":{
         "pointer":"/paths/~1env/post/parameters/0"
      }
   }
]

I created this project where you can see the problem.

I would like to know if there is a workaround to make this works.
Thanks

@dilipkrish dilipkrish added this to the 2.3.0 milestone Nov 19, 2015
@dilipkrish
Copy link
Member

Thanks for the detailed issue 🤘 It will likely not be soon that this is fixed, but ill definitely take a look

@matias2681
Copy link
Author

Glad to help!

I can take a look at the code and see what's going on. Do you have a pointer to the code where the problem might be? that would be helpful.

@dilipkrish
Copy link
Member

@matias2681 I'm unable to see the endpoint in your project. Are you sure you've committed and pushed all the changes to your project?

@matias2681
Copy link
Author

@dilipkrish I added a readme file to the project. I cloned and I could reproduce the issue. All the endpoints are inside the initial folder.

@dilipkrish
Copy link
Member

ah! I was using the gradle file instead of the maven pom.

I narrowed it down to the endpoint exposing a patter we don't support yet...

specifically

requestMapping(@RequestParam Map<String, String> params) we currently only support Maps as @RequestBody (and may be as a url encoded form data). I'll create a feature to address this

@dilipkrish dilipkrish changed the title Spring Cloud parameter resolved as "type":"ref" Support @RequestParam of type Map<String, String> Dec 3, 2015
@pathikmehta
Copy link

Are there any documentation available to see how to test (@RequestParam Map<String, String> params) params from swagger ui HTML page?

@dilipkrish
Copy link
Member

It is an any type... so you can basically send any arbitrary json with key value pair of string type and it will work.

For e.g.

{
    "a" : "hello",
    "b" : "world"
....
}

@pathikmehta
Copy link

Thank you @dilipkrish.

@chrisinmtown
Copy link

chrisinmtown commented Feb 12, 2018

Yes you can send anything, but the Swagger "try it out" feature doesn't allow me to edit the parameter names as I need to do. Perhaps keeping this as an open feature request is an option? How about defining new annotations to let me pass some clues over to swagger for a map (flexible) parameter situation? What about changing the swagger UI so that I can edit the query parameter names?

@dilipkrish
Copy link
Member

@chrisinmtown Strictly per spec, @RequestParam Map<String, String> is not supported. thats why the UI will not support it either

@kapishmalik
Copy link

It still does not support this feature ?

@dilipkrish
Copy link
Member

@kapishmalik what is not supported, please report a different issue with additional details, this is an issue pertaining to v2.4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants