Skip to content

Optional attributes with custom snippet #291

@melwas

Description

@melwas

Hi,

I have a custom snippet as below:

|===
|Path|Type|Description|Constraints

{{#fields}}

|{{#tableCellContent}}{{path}}{{/tableCellContent}}
|{{#tableCellContent}}{{type}}{{/tableCellContent}}
|{{#tableCellContent}}{{description}}{{/tableCellContent}}
|{{#tableCellContent}}{{constraints}}{{/tableCellContent}}

{{/fields}}
|===

When I set the attribute "constraints" for each field in request fields snippet in Test like this:

key("constraints") .value("Format: YYYY-MM-DD'T'HH:mm:ssZ"))

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
    at org.springframework.restdocs.mustache.Template.checkForMissing(Template.java:270)
    at org.springframework.restdocs.mustache.Template.getValue(Template.java:178)
    at org.springframework.restdocs.mustache.Template.getValueOrDefault(Template.java:223)
    at org.springframework.restdocs.mustache.Mustache$VariableSegment.execute(Mustache.java:787)
    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)

How to fix this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions