2016-06-21 9 views
2

私はspring restdocsを使用して自分のREST webapiでドキュメントを作成しています。私は物事を統合し、私のHTMLが生成されます(maven + asciidocプラグイン、再保証apis)。 私が持っている唯一の問題は、ifevalが広告されたように動作しないか、間違っていることです。spring restdocsは条件付きでasciidocでオプションのパラメータを強調表示します

マイカスタム要求-fields.snippetは、次のようになります。tablecellcontentで

|=== 
|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}} 
|=== 

「オプション」値は(場合によっては「true」または「false」)正しくレンダリングが、ifevalされます解析されません(したがって、最終的なhtmlではエラーなしで解析されません)。

私は式の構文を変えてみましたが、どちらもうまくいかないようです。もしあれば正しい構文であるかもしれない何かに関するヒント? カスタム属性を定義してifndefを使用して同じ結果を得ることを考えていますが、可能ならば既存のoptional()サポートを使用することをお勧めします。

としては、私は、問題はあなたがifevalマクロで{optional}ではなく{{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 

|=== 
+0

私はちょうどディレクティブは行の先頭になければならないことを学びました。しかし、私はまだ正しい結果を得られていないことを訂正します(すべての行は同じ書式を持ち、任意の値を無視します)。 –

+1

上記の1つの間違いは、2番目の条件で '== 'ではなく' = 'その質問のタイプミスです。カスタムテンプレートを見るのではなく、生成された '.adoc'スニペットを共有できますか?また、どのようにスニペットをメインの '.adoc'ファイルに含めましたか? –

+0

はい、それは含まれていて、=は誤字です。私は生成されたadocを追加しました。 これは、特に "パス"の値が印刷されない結果となります ありがとうございます。 –

答えて

2

を追加してい要求しました。つまり、{optional}がフィールドのoptional属性に置き換えられていないため、Asciidoctorは"{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}} 
|=== 
+0

ありがとう、私はこれを前に試したと確信していた、それは動作しませんでした。今朝それがあった。おそらく前に何か間違ったことがあったでしょう... –

+0

2番目にエラーがあります。 'ifeval :: [" {optional}} "==" false "]' – Mateusz

+0

にする必要があります。ありがとうございました。 –

関連する問題