After upgrading to Spring-test-5.3.0-SNAPSHOT, spring rest docs is failing to document path parameters complaining it can't find urlTemplate
.
webTestClient.mutateWith(csrf()).get()
.uri("/products/{productId}", productId)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus().isOk()
.expectHeader().contentType(MediaType.APPLICATION_JSON)
.expectBody()
.consumeWith(document("find-product-by-id",
pathParameters(
parameterWithName("productId").description("...")
),
responseFields(getProductResponseFields())));
Error log:
urlTemplate not found. If you are using MockMvc did you use RestDocumentationRequestBuilders to build the request?
java.lang.IllegalArgumentException: urlTemplate not found. If you are using MockMvc did you use RestDocumentationRequestBuilders to build the request?
at org.springframework.util.Assert.notNull(Assert.java:201)
at org.springframework.restdocs.request.PathParametersSnippet.extractUrlTemplate(PathParametersSnippet.java:126)
at org.springframework.restdocs.request.PathParametersSnippet.extractActualParameters(PathParametersSnippet.java:113)
at org.springframework.restdocs.request.AbstractParametersSnippet.verifyParameterDescriptors(AbstractParametersSnippet.java:89)
at org.springframework.restdocs.request.AbstractParametersSnippet.createModel(AbstractParametersSnippet.java:74)
at org.springframework.restdocs.request.PathParametersSnippet.createModel(PathParametersSnippet.java:98)
at org.springframework.restdocs.snippet.TemplatedSnippet.document(TemplatedSnippet.java:78)
at org.springframework.restdocs.generate.RestDocumentationGenerator.handle(RestDocumentationGenerator.java:191)
at org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.lambda$document$0(WebTestClientRestDocumentation.java:77)
at org.springframework.test.web.reactive.server.DefaultWebTestClient$DefaultBodyContentSpec.lambda$consumeWith$3(DefaultWebTestClient.java:665)
at org.springframework.test.web.reactive.server.ExchangeResult.assertWithDiagnostics(ExchangeResult.java:223)
at org.springframework.test.web.reactive.server.DefaultWebTestClient$DefaultBodyContentSpec.consumeWith(DefaultWebTestClient.java:665)
Looks like DefaultWebTestClient is setting the uriTemplate to null when constructing uri but can't find a way to override it.
Unfortunately there's a regression in the latest Spring Framework 5.3 snapshots and I don't believe you can work around it. I've raised a Spring Framework issue. In the meantime, you could use Spring Framework 5.3.0.RC1 as it was released before the problem was introduced.