Document how to use Spring REST Docs with the MockMVC Kotlin DSL
See original GitHub issueWas trying to implement RestDocs MockMvc in our Kotlin project However noticed that when using the MockMvc Kotlin DSL snippets were not generated e.g.
fun shouldReturnDefaultMessageKotlinDSL() {
mockMvc.get("/hello")
.andExpect {
status { isOk }
content {
string(containsString("Hello, world!"))
}
}.andDo {
print()
document("home")
}
}
However using the java format did correctly generate e.g.
fun shouldReturnDefaultMessage() {
this.mockMvc.perform(get("/hello"))
.andDo(print())
.andExpect(status().isOk)
.andExpect(content().string(containsString("Hello, world!")))
.andDo(document("home"))
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Document how to use Spring REST Docs with the MockMVC ...
Document how to use Spring REST Docs with the MockMVC Kotlin DSL.
Read more >spring-projects/spring-restdocs - Gitter
My use case is the following: I'm using swagger2markup to generate the documentation and REST Docs to generate the code snippets; I want...
Read more >MockMvc Kotlin DSL - Baeldung
In this quick tutorial, we'll have a look at the new Kotlin-specific MockMvc support available in Spring Framework 5.2+.
Read more >Spring REST Docs
The MockMvc instance is configured by using a MockMvcRestDocumentationConfigurer . You can obtain an instance of this class from the static ...
Read more >Spring Auto REST Docs - Scalable Capital Engineering
In Spring REST Docs you have to add the documentation for your JSON with a DSL in your test. We moved this documentation...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thanks for the sample. When using the Kotlin DSL for MockMvc, you need to pass the result handler that is returned from
document(…)
tohandle(ResultHandler)
:It’s a shame that for this one piece, the Kotlin DSL isn’t quite as elegant as the Java equivalent. I’m not sure how it could be improved while keeping the existing more elegant access to the built-in result handlers such as
print()
. @sdeleuze any suggestions here?I’ll keep this issue open as I think it’s worth documenting the above.
Sorry for the delay of my response.
You could probably extend MockMvc DSL in Spring REST Docs with something like:
Let’s maybe discuss that in https://github.com/spring-projects/spring-restdocs/issues/547#issuecomment-812611417.