Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
I have a custom snippet as below:
When I set the attribute "constraints" for each field in request fields snippet in Test like this:
it works, but when even one field is missing constraints attribute the whole suite fails with:
How to fix this?
There are a couple of approaches you could take.
You could subclass
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:
MustacheTemplateEngine templateEngine = new MustacheTemplateEngine( new StandardTemplateResourceResolver(TemplateFormats.asciidoctor()), Mustache.compiler().escapeHTML(false).defaultValue("")); MockMvcRestDocumentationConfigurer configurer = new MockMvcRestDocumentationConfigurer( this.restDocumentation).templateEngine(templateEngine); MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context) .apply(configurer).build();
On the snippet above, I've found that you need an extra parameter to the Mustache template engine constructor. Without it I was getting some documentation, but all table cells were empty of values.
Map<String, Object> templateContext = new HashMap<>(); templateContext.put("tableCellContent", new AsciidoctorTableCellContentLambda()); MustacheTemplateEngine templateEngine = new MustacheTemplateEngine( new StandardTemplateResourceResolver(TemplateFormats.asciidoctor()), Mustache.compiler().escapeHTML(false).defaultValue(""), templateContext);
That's a neat trick, @helpermethod. Thank you.
For anyone else who, like me, was wondering how it works,