restdocs-spec
restdocs-spec copied to clipboard
WebTestClient support
Hello!
Did you support WebTestClient? Because I received an empty openapi-2.0.json:
{
"swagger" : "2.0",
"info" : {
"description" : "Description",
"version" : "0.0.1-SNAPSHOT",
"title" : "title"
},
"host" : "localhost:8080",
"tags" : [ ],
"schemes" : [ "http" ],
"paths" : { },
"definitions" : { }
}
With this test:
@Test
public void getEmployeeByName() throws Exception {
when(edManager.searchEmployees("John")).thenReturn(getEmployees(2));
webTestClient.get().uri("/api/employees?query={query}", "John")
.exchange()
.expectStatus().isOk()
.expectBodyList(Employee.class)
.consumeWith(document("employee/{method-name}",
requestParameters(parameterWithName("query").description("Employee name")),
responseFields(
fieldWithPath("[].aNumber").description("Employee's unique number"),
fieldWithPath("[].firstName").description("Employee's first name"),
fieldWithPath("[].lastName").description("Employee's lastName name"),
fieldWithPath("[].display").description("Employee's display"),
fieldWithPath("[].businessPhone").description("Employee's business phone"),
fieldWithPath("[].email").description("Employee's email"),
fieldWithPath("[].title").description("Employee's title"),
fieldWithPath("[].subscribedTo").description("Employee's subscriptions"),
fieldWithPath("[].groups").description("Employee's groups")
)));
}
Thank you!
I have the same problem now. Have you solved it?
It should not generate empty results, which is not as expected. What may be the problem?
It works with WebTestClient. You should add resource("...") snippet in between document(...) and requestParameters(...).
Example:
...
.consumeWith(document("employee/{method-name}",
resource("employee-method-name"),
requestParameters(...