it works, but when even one field is missing constraints attribute the whole suite fails with:
org.springframework.restdocs.mustache.MustacheException$Context: No method or field with name 'constraints' on line 8
How to fix this?
The text was updated successfully, but these errors were encountered:
You could subclass RequestFieldsSnippet and override createModelFromDescriptor to add a default value for the constraints attribute.
Alternatively, you need to tell Mustache to use a default value when an entry in a template can't be resolved. Unfortunately, Mustache doesn't provide support for doing that in the template itself so you need to configure its compiler with a default value. You can do that like this:
For anyone else who, like me, was wondering how it works, . is a special variable that's the equivalent of this and #constraints is a section. When constraints exists in the model and isn't false or an empty list, whatever is within the section is rendered. In this case, the contents of the section are a reference to this which is the value of the constraints entry in the model. When constraints does not exist, the content of the section is skipped.