javaspring-bootmustachespring-restdocs

Spring REST Docs throwing MustacheException


I am getting a weird exception with a trouble on non-existing field either on my response or request. I have configuration setup to generate snippets for response/requests on my endpoints with documentation on the fields of those beans. Except I am getting the following exception from org.springframework.restdocs.mustache package;

MustacheException$Context: No method or field with name 'required' on line 6

I have no 'required' field declared anywhere on my descriptor snippets, or within my request/response beans, and what is the deal with line 6? What a mysterious exception! What is the issue here?


Solution

  • The trouble stemmed from a custom request-parameters template, in src/test/resources/org/springframework/restdocs/templates/ resource folder. Due to the addition of a custom field within the template of request descriptor, the lack of this field was causing the issue. List 6 was where the 'request' field was being used within this file, thus the error.

    Removing the custom template to let REST Docs use its default template resolved the issue.