JavaSpringRestDocs使用asciidoc有条件地突出显示可选参数
我正在使用SpringRestDocs在我的RESTWebAPI上生成文档;我集成了这个东西,生成了我的html(maven+Ascidoc插件,重新发布API)。 我唯一的问题是ifeval要么没有像广告宣传的那样工作,要么我搞错了
我的自定义请求字段。代码段如下所示:
|===
|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}}
|===
tablecellcontent中的“可选”值被正确呈现(“true”或“false”,具体取决于大小写),但ifeval没有被解析(因此在最终html上显示为未解析,没有错误)
我试着用不同的语法来表达,但似乎都不管用;关于正确语法的任何提示(如果有)? 我正在考虑定义一个自定义属性并使用ifndef来获得相同的结果,但是如果可能的话,我更愿意使用现有的optional()支持
根据要求,我正在添加结果。阿多克
|===
|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
|===
# 1 楼答案
问题在于自定义模板中使用的是
{optional}
而不是{{optional}}
宏中的ifeval
。这意味着{optional}
不会被字段的optional
属性替换,因此,AscidActor正在计算"{optional}"=="true"
或"{optional}"=="false"
您需要更新模板以使用
{{optional}}
: