胡子例外$上下文:没有键、方法或字段的名称'description'在线



我正在尝试为我的端点生成rest文档:

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"))));

但它抛出了一个错误:

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)

有什么想法吗?

好的,我发现了问题。所有fieldWithPath都应该有一个描述:

.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"))));

此外,如果您试图使用描述作为显示示例值的手段,请确保它不是null,如果是,它也会抛出此错误。示例:

class Customer {
private final String name;
private final String id;
public Customer(String name, String id){
this.name = name;
this.id = id;
}
}
final Customer = new Customer("test name", null);
....
fieldWithPath("id")
.description(customer.getId())
.type(String.class),

这样的字段将导致错误

最新更新