Forum Discussion

Staffan's avatar
Staffan
New Contributor
4 years ago

JAX-RS POST method with multipart/form-data and @RequestBody or @Parameter annotation

I'm writing a POST method that should include a request body with the data that should be posted, but I cannot add information to the openapi specification on how the request body should be structured. I've tried several different ways of supplying a @RequestBody annotation (both at method and parameter level). I've also tried to use @Parameter annotation as described in the documentation (https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Annotations#parameter). I'm using Jersey2 and the `jersey-media-multipart` to add @FormDataParam annotations of parameters to the method. When using the @FromDataParam the server works as expected, and picks up the data that is sent using e.g. Postman. But the openapi specification doesn't contain any 'contents' information so it is still undocumented and I cannot try it using e.g. Swagger UI.

 

I'm not considering myself a web-programmer, but I've gathered that the multipart/form-data is not standardized within the JAX-RS, which is could be par of why this is not straightforward and might be some lack of support in Swagger-core or other parties. But what is the prefered way (or workaround) that allows one to write these types of methods, so that the openapi-spec is correctly documenting the expected input to the server? It seems straightforward to add when reading the documentation (after I found it after much digging), but it's simply not working. I'm using the latest stable version of swagger core (2.1.10 for the following artifacts; swagger-jaxrs2, swagger-jaxrs2-servlet-initializer-v2 and swagger-annotations) together with Jersey 2.32.

  • Staffan's avatar
    Staffan
    New Contributor

    It seems, after putting in further efforts, that removing the @FormDataParam and using a newer version of the Swagger-UI resolved this issue.