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

MustacheException on response field named "description"

Open thuri opened this issue 5 years ago • 1 comments

The response I'd like to document has a field named "description"

{
    "filename": "test.pdf",
    "documentName": "testdoc",
    "description": "Spring REST Docs rocks",
    "insertDate": "2021-02-15T07:54:32.623798Z"
}

when the test code calls

   fieldWithPath("description").description("Spring REST Docs is great").

the following MustacheException is thrown:

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.mockmvc.RestDocumentationResultHandler.handle(RestDocumentationResultHandler.java:52)
	at org.springframework.test.web.servlet.MockMvc$1.andDo(MockMvc.java:201)
....

I think the problem may be that description is actually used in the templates like in org.springframework.restdocs.templates.asciidoctor.default-response-fields.snippet

Would it be a good idea or possible to prefix the variables/expressions used in the templates? Like restdocs.description or something like that?

thuri avatar Feb 15 '21 11:02 thuri

Sorry my fault.

the next line in the testcode was

subsectionWithPath("_links"),

where i simply forgotten the .ignored i wanted to add there. The field name sent me down the wrong path.

Everything works as expected now. Even the description field can be documented :-)

thuri avatar Feb 15 '21 13:02 thuri