restdocs-spec icon indicating copy to clipboard operation
restdocs-spec copied to clipboard

WebTestClient support

Open okosiuta opened this issue 6 years ago • 2 comments

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!

okosiuta avatar Aug 21 '19 16:08 okosiuta

I have the same problem now. Have you solved it?

image It should not generate empty results, which is not as expected. What may be the problem?

tianmingxing avatar Apr 07 '22 12:04 tianmingxing

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(...

gokhanus avatar Feb 06 '24 08:02 gokhanus