Swagger API for MultivaluedMap Jersey? Is it possible?

Can API documentation be annotated for MultivaluedMap param in Jersey using Swagger?

I have a small piece of code:

 /** * Method which serves requests of adding {@link StudentGroup} to DB * * @param name * @param description * @return {@link Response} * @throws RestServiceException */ @POST @Path("/add") public Response addStudentGroup(MultivaluedMap<String, String> formParams) throws RestServiceException { String name = formParams.getFirst("name"); String description = formParams.getFirst("description"); String studentIds = formParams.getFirst("studentIds"); (...) } 

and I want to use @ApiParam to generate JSON with documentation data using Swagger and Swagger UI.

If I put @ApiParam before MultivaluedMap<String, String> formParams, this will not work. Swagger cannot list any parameters.

+4
source share
3 answers

This seems to be a bug in Swagger - I get this behavior too. Using other common classes with two type parameters (e.g. @ApiParam () HashMap) works fine. This probably drops the parser.

I discovered a problem for this in Swagger's bug tracking system .

You can also ask them in your Google group or find them in the IRC when using Freenode # swagger.

+2
source

Currently not supported, but, as Eyal said, a ticket is open there on github issues, and it can be pretty easily implemented.

+1
source

I could solve this problem as follows. We can use the @APIImplicitParams annotation provided by the Swagger API to list all elements of the MultiValueMap form and use @APIignore in the MultiValueMap itself. Try it if something in the lines of code below works. Good luck. :)

 @ApiOperation(value = "Create a new 'Student' object") @ApiImplicitParams({ @ApiImplicitParam(name = "X-ClientId", value = "X-ClientId", required = true, dataType = "String", paramType = "header"), @ApiImplicitParam(name = "id", value = "Enter an ID for the student.", dataTypeClass = String.class, paramType = "query"), @ApiImplicitParam(name = "name", value = "Enter a Name for the Student.", dataTypeClass = String.class, paramType = "query") }) ResponseEntity addStudent( @NotBlank @RequestHeader(value = X_CLIENTID) String headerXclient, @ApiIgnore @RequestParam MultiValueMap<String, String> requestParams) { StudentRequest request = new StudentRequest(requestParams); (... Your Code Implementation ...) }; 
0
source

All Articles