Skip to content

Sending multi-part-formdata #1126

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

Closed
mayuranchalia opened this issue Apr 6, 2015 · 8 comments
Closed

Sending multi-part-formdata #1126

mayuranchalia opened this issue Apr 6, 2015 · 8 comments

Comments

@mayuranchalia
Copy link

I have a use case where a jersey rest service accepts multiple complex object as @FormDataParam.
Below is the code snippet

    @POST
    @Produces(MediaType.APPLICATION_JSON)
    @Consumes(MediaType.MULTIPART_FORM_DATA)
    @ApiOperation(value="setx")
    public Bean setBean(@FormDataParam("beanx")Bean bn1,@FormDataParam("beany")Bean bn2){
        return bn2;
    }

I am able to successfully call this service from Jersey client.
Below is the client snippet

final FormDataMultiPart mp = new FormDataMultiPart();
        mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("beanx").build(),
                bean1,
                MediaType.APPLICATION_JSON_TYPE));
        mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("beany").build(),
                bean2,
                MediaType.APPLICATION_JSON_TYPE));

        Bean response=webTarget.request().accept(MediaType.APPLICATION_JSON).post(Entity.entity(mp, MediaType.MULTIPART_FORM_DATA_TYPE), Bean.class);

I intercepted the request generated by the client...which is

POST /JeresyTestMultipart/rest/servicex HTTP/1.1
Accept: application/json
Content-Type: multipart/form-data; boundary=Boundary_1_602703068_1428318465523
User-Agent: Jersey/2.1 (HttpUrlConnection 1.7.0_09)
MIME-Version: 1.0
Host: 10.192.163.50:1234
Connection: keep-alive
Content-Length: 378

--Boundary_1_602703068_1428318465523
Content-Type: application/json
Content-Disposition: form-data; filename="beanx"; name="beanx"

{"name":"Paul","value":"Nibin"}
--Boundary_1_602703068_1428318465523
Content-Type: application/json
Content-Disposition: form-data; filename="beany"; name="beany"

{"name":"Mayur","value":"Jain"}
--Boundary_1_602703068_1428318465523--

and I am able to get the response successfully.

Now the issue is how to call the this service from swagger UI, I see the the swagger doc is generated and its taking two formData parameter and Model is also present...but the swagger UI is not able to invoke the service , I am getting error code 415.

Please help me with this issue so that I can post multiple complex object from Swagger UI.

@webron
Copy link
Contributor

webron commented Apr 6, 2015

What's the Swagger definition you get from your code?

Strictly speaking, at the moment, Swagger does not support the structure you want to expose. You can say your operation accepts several files, but you cannot say that these files are of specific type or structure. With the current version of the spec, you also can't have complex data type as form parameters.

@webron
Copy link
Contributor

webron commented Apr 6, 2015

That's an invalid definition, but more of a question to swagger-core (I assume you use the wrong dependency). In any case, what you're trying to describe isn't supported by Swagger right now (there are plans to change it in a future version).

@mayuranchalia
Copy link
Author

I din't get wrong dependency for swagger-core?

@webron
Copy link
Contributor

webron commented Apr 6, 2015

Modifying comments makes it difficult to provide proper support. The original definition you posted was invalid. In any case, what you're trying to do is not supported.

@mayuranchalia
Copy link
Author

So ,Ron
In future versions of swagger is there plan to support multiple complex objects to be posted as mutipart request.

@webron
Copy link
Contributor

webron commented Apr 7, 2015

There's this issue - OAI/OpenAPI-Specification#222. I can't comment on whether or not that's going to be included in a future version of the spec.

@webron
Copy link
Contributor

webron commented May 4, 2015

Closing as not supported.

@webron webron closed this as completed May 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants