ScaCap / spring-auto-restdocs

Spring Auto REST Docs is an extension to Spring REST Docs
https://scacap.github.io/spring-auto-restdocs/
Apache License 2.0
311 stars 86 forks source link

Support for Rest Assured #96

Closed sudr closed 6 years ago

sudr commented 7 years ago

This is to track work towards supporting Rest Assured. Pointers to how to get started with this will be helpful.

fbenz commented 7 years ago

Thank you for opening the issue. It has been on our TODO list for a while. We can not provide any pointers yet, but plan to take a look in the next few days to see how much work it is and where to start.

fbenz commented 7 years ago

In a MockMVC test, the entry point for the introspection is the HandlerMethod. We get the HandlerMethod instance with the following steps:

  1. JacksonResultHandler is registered as a MockMVC ResultHandler: https://github.com/ScaCap/spring-auto-restdocs/blob/master/spring-auto-restdocs-example/src/test/java/capital/scalable/restdocs/example/testsupport/MockMvcBase.java#L108
  2. HandlerMethod instance is retrieved from MvcResult: https://github.com/ScaCap/spring-auto-restdocs/blob/master/spring-auto-restdocs-core/src/main/java/capital/scalable/restdocs/jackson/JacksonResultHandlers.java#L48
  3. The HandlerMethod instance is used as an entry point for introspection: https://github.com/ScaCap/spring-auto-restdocs/blob/master/spring-auto-restdocs-core/src/main/java/capital/scalable/restdocs/snippet/StandardTableSnippet.java#L47

When using Rest Assured, one only gets information about the HTTP request and response and no additional information about the MVC method. This information can be retrieved via a filter: https://github.com/rest-assured/rest-assured/blob/master/rest-assured/src/main/java/io/restassured/filter/Filter.java#L44 and the following information can be retrived from the request: https://github.com/rest-assured/rest-assured/blob/master/rest-assured/src/main/java/io/restassured/specification/FilterableRequestSpecification.java Example a Spring REST Docs test with Rest Assured: https://github.com/spring-projects/spring-restdocs/blob/master/samples/rest-assured/src/test/java/com/example/restassured/SampleRestAssuredApplicationTests.java

So the question is on how to get to the HandlerMethod instance that is tested. An inconvenient option is to add a manual pointer to each test.

jmisur commented 6 years ago

idle issue, closing.