Java Spring restdocs使用ascidoc有条件地突出显示可选参数
我正在使用SpringRestDocs在我的RESTWebAPI上生成文档;我集成了这个东西,生成了我的html(maven+Ascidoc插件,重新发布API)。 我唯一的问题是ifeval要么没有像广告宣传的那样工作,要么我搞错了 我的自定义request-fields.snippet如下所示:Java Spring restdocs使用ascidoc有条件地突出显示可选参数,java,maven,rest-assured,asciidoctor,spring-restdocs,Java,Maven,Rest Assured,Asciidoctor,Spring Restdocs,我正在使用SpringRestDocs在我的RESTWebAPI上生成文档;我集成了这个东西,生成了我的html(maven+Ascidoc插件,重新发布API)。 我唯一的问题是ifeval要么没有像广告宣传的那样工作,要么我搞错了 我的自定义request-fields.snippet如下所示: |=== |Path|Type|Description|Optional {{#fields}} |{{#tableCellContent}} ifeval::["{optional}"=="t
|===
|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()支持
根据要求,我正在添加生成的.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
|===
问题在于自定义模板中使用的是
{optional}
,而不是ifeval
宏中的{{optional}
。这意味着{optional}
不会被字段的optional
属性替换,因此,AscidActor正在计算“{optional}”==“true”
或“{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}}
|===
我刚刚了解到指令必须在行的开头;但即使纠正了我仍然没有得到正确的结果(所有行都有相同的格式,忽略可选值),您在上面的一个错误是第二个条件中的
=
而不是=
,但这可能只是问题中的一个输入错误。您可以共享生成的.adoc
代码片段,而不是查看自定义模板吗?另外,您是如何将代码段包含在主.adoc
文件中的?是的,它包括在内,并且=是一个输入错误;我添加了生成的adoc。这尤其导致没有打印“路径”的值。谢谢,我确信我以前尝试过,但它不起作用;今天早上是的。可能之前还有其他错误…第二个if中有错误。应该是ifeval::[“{{optional}}”==“false”]
Fixed。非常感谢。