ePages-de / ePages-de/restdocs-api-spec
When i use webtestclient, i am getting on error message 'please use RestDocumentationRequestBuilders with urlTemplate to construct the request'
- Dominant language
- Kotlin
- Stars
- 427
- Forks
- 116
- Avg merge
- 23h 54m
- Merged PRs (30d)
- 1
Description
`RestDocumentationRequestBuilders` class is only use mockmvc. isn't it? However, when using the webtestclient, you must also use the `RestDocumentationRequestBuilders`.
- `build.gradle.kts` dependencies
~~~
dependencies {
// 2.0.6.RELEASE
testImplementation("org.springframework.restdocs:spring-restdocs-core")
testImplementation("org.springframework.restdocs:spring-restdocs-webtestclient")
// 0.16.4
testImplementation("com.epages:restdocs-api-spec:${project.extra["version.restdocsApiSpec"]}")
testImplementation("com.epages:restdocs-api-spec-webtestclient:${project.extra["version.restdocsApiSpec"]}")
}
~~~
- webtestclient usage
~~~
client.get()
.uri {
it.path(testPath)
.queryParam("styles", styles)
.build()
}
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus().isOk
.expectBody(String::class.java)
.consumeWith (
document("test try on", "get result", true,
requestParameters(
parameterWithName("styles").description("Sequence")
),
responseHeaders(
headerWithName(HttpHeaders.CONTENT_TYPE).description(MediaType.APPLICATION_JSON),
),
responseFields(
fieldWithPath("estimatedTime").type(JsonFieldType.NUMBER).description("Estimated time"),
fieldWithPath("estimatedCount").type(JsonFieldType.NUMBER).description("Estimated count"),
fieldWithPath("requestTotalCount").type(JsonFieldType.NUMBER).description("Request total count"),
)
)
)
~~~
- Error message
~~~
Missing URL template - please use RestDocumentationRequestBuilders with urlTemplate to construct the request
com.epages.restdocs.apispec.ResourceSnippet$MissingUrlTemplateException: Missing URL template - please use RestDocumentationRequestBuilders with urlTemplate to construct the request
at com.epages.restdocs.apispec.ResourceSnippet$getUriComponents$2.get(ResourceSnippet.kt:104)
at com.epages.restdocs.apispec.ResourceSnippet$getUriComponents$2.get(ResourceSnippet.kt:21)
at java.base/java.util.Optional.orElseThrow(Optional.java:403)
at com.epages.restdocs.apispec.ResourceSnippet.getUriComponents(ResourceSnippet.kt:104)
at com.epages.restdocs.apispec.ResourceSnippet.createModel(ResourceSnippet.kt:56)
at com.epages.restdocs.apispec.ResourceSnippet.document(ResourceSnippet.kt:34)
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$DefaultBodySpec.lambda$consumeWith$4(DefaultWebTestClient.java:582)
at org.springframework.test.web.reactive.server.ExchangeResult.assertWithDiagnostics(ExchangeResult.java:231)
at org.springframework.test.web.reactive.server.DefaultWebTestClient$DefaultBodySpec.consumeWith(DefaultWebTestClient.java:582)
~~~
Is there any way to solve this problem?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.