1

I have an api that accepts any param by query string. I want to use springfox to document it but the ui does not allow me to show a field to send.

When I set the controller to accept a Map<String, String>, I can deal with params under controller, but the ui does not show as expected.

@RequestParam Map<String, String> allParams

enter image description here

When I set send value, the interface send the field allParams with value that I sent. Like:

curl -X GET "http://localhost/articles/term?allParams=term%3Dvalue"

enter image description here

I want set multiple values or send the full query string. Is it possible to show a field to send all query string like term=value or some like this?

curl -X GET "http://localhost/articles/term?term=value&otherterm=othervalue"

I am using spring 2.3.1 and springfox 2.9.2

LuisComS
  • 452
  • 4
  • 20
  • To specify the parameter values, you'll need to click "try it out" first. See https://stackoverflow.com/a/49587746/113116 – Helen Sep 22 '20 at 20:34
  • Hi @Helen when i click on "try it out" it send the value inside allParams field, I want to send each value on each field. – LuisComS Sep 23 '20 at 11:44
  • Just to clarify - even though you enter all parameters in the same field, they will actually be sent as separate `key=value` pairs in the query string. There's also an existing feature request to add a form-like editor for object/map parameters - https://github.com/swagger-api/swagger-ui/issues/2771 – Helen Sep 23 '20 at 15:52
  • As I explained before, when I send values on the field, the reques resulted is `/term?allParams=term%3Dvalue`, what I want is `/term?term=value` – LuisComS Sep 23 '20 at 17:49
  • Can you please post your OpenAPI YAML/JSON file? Here's how to export it from Swagger UI: https://stackoverflow.com/a/48525934. Can you also post the full declaration with annotations of the controller method? – Helen Sep 23 '20 at 18:27
  • I am using `swagger: "2.0"` – LuisComS Sep 25 '20 at 18:29
  • 1
    OpenAPI 2.0 (`swagger: '2.0'`) doesn't support objects and maps in the query string - that's probably why it doesn't work. The API definition needs to be in the OpenAPI 3.0 format (`openapi: 3.0.0`). You'll need to upgrade Springfox to v. 3.0.0 to generate an OpenAPI 3.0 API definition. – Helen Sep 25 '20 at 20:47
  • I have updated to Springfox to v. 3.0.0 and the data was sent correctly, but now interface do not show example values, neither than json docs – LuisComS Oct 01 '20 at 15:25

0 Answers0