spring-projects / spring-restdocs

Test-driven documentation for RESTful services
https://spring.io/projects/spring-restdocs
Apache License 2.0
1.16k stars 736 forks source link

Give a way to document Multipart content #267

Closed mathieu-pousse closed 8 years ago

mathieu-pousse commented 8 years ago

I have an endpoint to upload a file and its associated metadata.

It is a multipart request with:

I am able to document the parts but I can't find a way to document the content of the metadata part:

.andDo(document("upload",
    getDocRequestPreprocess(simplifyFileUpload("file", "<<zip content>>\n\n")),
    getDocResponsePreprocess(),
        RequestDocumentation.requestParts(
            partWithName("file").description("the file to upload"),
            partWithName("metadata").description("json that describes the file to import"))
            // How to document the metadata part content ?
    ));
----
POST /v1/somewhere/
Content-Type: multipart/form-data; boundary=6o2knFse3p53ty9dmcQvWAIx1zInP11uCfbm
Authorization: Bearer [Encoded-Bearer]
Host: localhost

--6o2knFse3p53ty9dmcQvWAIx1zInP11uCfbm
Content-Disposition: form-data; name=file
Content-Type: application/octet-stream

<<zip content>>

--6o2knFse3p53ty9dmcQvWAIx1zInP11uCfbm
Content-Disposition: form-data; name=metadata
Content-Type: application/json

{"something":10,"somethingElse":"matter"}
--6o2knFse3p53ty9dmcQvWAIx1zInP11uCfbm--
----

I think we need a way to set the part on which applies the FieldDescriptor or a way to document more precisely the part content

mathieu-pousse commented 8 years ago

I'll submit a PR as I finally managed to implement this one

wilkinsona commented 8 years ago

I think we need a way to set the part on which applies the FieldDescriptor or a way to document more precisely the part content

Agreed. https://github.com/spring-projects/spring-restdocs/issues/161 was a small step in that direction, but there's plenty of room to do more. The hardest part will probably be getting the API right. Suggestions for how you'd like it to look would be most welcome.

wilkinsona commented 8 years ago

I'll submit a PR as I finally managed to implement this one

Great stuff! Thanks

mathieu-pousse commented 8 years ago

here it is https://github.com/spring-projects/spring-restdocs/pull/270

any comment will be appreciated

M.

wilkinsona commented 8 years ago

Closing in favour of the PR (#270).