I'm trying to generate rest docs for my endpoint:
webTestClient.patch()
.uri(ENTITY_BY_ID, entityId)
.accept(APPLICATION_JSON)
.header(AUTHORIZATION, accessToken)
.bodyValue(body)
.exchange()
.expectStatus()
.isOk()
.expectBody()
.consumeWith(document("Entity/PATCH_API", //
pathParameters(parameterWithName("id").description("ID of the entity to patch")),
requestFields(fieldWithPath("condition"),//
fieldWithPath("type").description("one of A, B, S"),
fieldWithPath("applyTo"),//
fieldWithPath("substituteWith"),//
fieldWithPath("priority"),//
fieldWithPath("comment"))));
But it throws the error:
org.springframework.restdocs.mustache.MustacheException$Context: No key, method or field with name 'description' on line 7
at org.springframework.restdocs.mustache.Mustache$VariableSegment.execute(Mustache.java:789)
at org.springframework.restdocs.mustache.Template$1.execute(Template.java:131)
at org.springframework.restdocs.mustache.Template$1.execute(Template.java:124)
at org.springframework.restdocs.mustache.Template$Fragment.execute(Template.java:59)
at org.springframework.restdocs.templates.mustache.AsciidoctorTableCellContentLambda.execute(AsciidoctorTableCellContentLambda.java:36)
at org.springframework.restdocs.mustache.Mustache$SectionSegment.execute(Mustache.java:856)
at org.springframework.restdocs.mustache.Mustache$BlockSegment.executeSegs(Mustache.java:827)
at org.springframework.restdocs.mustache.Mustache$SectionSegment.execute(Mustache.java:848)
at org.springframework.restdocs.mustache.Template.executeSegs(Template.java:114)
at org.springframework.restdocs.mustache.Template.execute(Template.java:91)
at org.springframework.restdocs.mustache.Template.execute(Template.java:82)
at org.springframework.restdocs.templates.mustache.MustacheTemplate.render(MustacheTemplate.java:62)
at org.springframework.restdocs.snippet.TemplatedSnippet.document(TemplatedSnippet.java:82)
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:564)
at org.springframework.test.web.reactive.server.ExchangeResult.assertWithDiagnostics(ExchangeResult.java:206)
at org.springframework.test.web.reactive.server.DefaultWebTestClient$DefaultBodyContentSpec.consumeWith(DefaultWebTestClient.java:564)
at org.my.routers.EntityRouterTest$PATCH_API.patch_success(EntityRouterTest.java:319)
Any ideas?
Okay, I found the issue. All fieldWithPath
should have a description:
.consumeWith(document("Entity/PATCH_API", //
pathParameters(parameterWithName("id").description("ID of the entity to patch")),
requestFields(fieldWithPath("condition").description("JS boolean condition"),//
fieldWithPath("type").description("one of A, B, C"),
fieldWithPath("applyTo").description("some descr"),//
fieldWithPath("substituteWith").description("some descr"),//
fieldWithPath("priority").description("int value"),//
fieldWithPath("comment").description("any text"))));