2

I am using spring restdocs to produce documentation on my REST webapi; I have integrated the thing and my html gets generated (maven + asciidoc plugin, restassured apis). The only problem I have is that ifeval either doesn't work as advertised or I got it wrong.

My custom request-fields.snippet looks like this:

|===
|Path|Type|Description|Optional

{{#fields}}
 |{{#tableCellContent}}
ifeval::["{optional}"=="true"]
   `{{path}}`
endif::[]
ifeval::["{optional}"="false"]
   *`{{path}}`*
endif::[]
  {{/tableCellContent}}
  |{{#tableCellContent}}`{{type}}`{{/tableCellContent}}
  |{{#tableCellContent}}{{description}}{{/tableCellContent}}
  |{{#tableCellContent}}{{optional}}{{/tableCellContent}}

{{/fields}}
|===

The 'optional' value in the tablecellcontent is rendered correctly ('true' or 'false' depending on the case), but the ifeval is not parsed (and thus shows itself unparsed on the final html, with no error).

I tried different syntaxes for the expression but none seem to work; any hints on what may be the correct syntax, if any? I am thinking about defining a custom attribute and use ifndef to get the same result, but I would prefer to use the existing optional() support if possible.

As requested I am adding the resulting .adoc

|===
|Path|Type|Description|Optional

|
ifeval::["{optional}"=="true"]
   `name`
endif::[]
ifeval::["{optional}"=="false"]
   *`name`*
endif::[]
|`String`
|Name of the new Axis
|false

|
ifeval::["{optional}"=="true"]
   `description`
endif::[]
ifeval::["{optional}"=="false"]
   *`description`*
endif::[]
|`String`
|Description of the new Axis
|true

|
ifeval::["{optional}"=="true"]
   `tags[]`
endif::[]
ifeval::["{optional}"=="false"]
   *`tags[]`*
endif::[]
|`TagDto[]`
|Hierarchical view of axis' tags
|false

|
ifeval::["{optional}"=="true"]
   `tags[].id`
endif::[]
ifeval::["{optional}"=="false"]
   *`tags[].id`*
endif::[]
|`Number`
|Id of the tag
|false

|
ifeval::["{optional}"=="true"]
   `tags[].name`
endif::[]
ifeval::["{optional}"=="false"]
   *`tags[].name`*
endif::[]
|`String`
|Name of the tag
|false

|
ifeval::["{optional}"=="true"]
   `tags[].children`
endif::[]
ifeval::["{optional}"=="false"]
   *`tags[].children`*
endif::[]
|`TagDto[]`
|Child tags for this tag, if any
|true

|===
4

1 回答 1

2

问题出在您正在使用的自定义模板中,{optional}而不是{{optional}}ifeval宏中。这意味着{optional}不会被字段的optional属性替换,因此,Asciidoctor 正在评估"{optional}"=="true"or "{optional}"=="false"

您需要更新模板以使用{{optional}}

|===
|Path|Type|Description|Optional

{{#fields}}
 |{{#tableCellContent}}
ifeval::["{{optional}}"=="true"]
   `{{path}}`
endif::[]
ifeval::["{{optional}}"=="false"]
   *`{{path}}`*
endif::[]
  {{/tableCellContent}}
  |{{#tableCellContent}}`{{type}}`{{/tableCellContent}}
  |{{#tableCellContent}}{{description}}{{/tableCellContent}}
  |{{#tableCellContent}}{{optional}}{{/tableCellContent}}

{{/fields}}
|===
于 2016-06-21T14:19:53.520 回答