问题
I'm generating documentation for an api implemented in Web Api 2 using swagger/swashbuckle.
The only xml documentation tags recognized are the <summary>
, <remarks>
and <param>
.
This means I cannot use <para>
tag to format my text in new lines or paragraphs, everything is generated as a continuous long paragraph in the Implementation Notes entry of the docs.
Is there any way to do this?
回答1:
Another way to achieve is creating a custom OperationFilter and use the xml documentation tags as explained in :
https://github.com/domaindrivendev/Swashbuckle/issues/258
Hope this helps
Sam
回答2:
I found that you can just add <br />
tags to the comments to achieve this.
Adding:
/// <br />
will cause a line break in the generated documentation.
回答3:
In SwashBuckle.AspNetCore <br />
and <br />
(suggested in github) do not work.
In <remarks>
you can specify backslash at the end of line.
For example
/// <remarks>
/// before. \
/// after.
/// </remarks>
generates 2 lines
before.
after.
However I wasn't able to generate multiple lines in <summary>
section.
Note, If the line has trailing spaces(e.g. "before. \ "
), backslash will be shown literally in the output.
You can see a few my attempts in https://github.com/MNF/Samples/blob/master/SwashbuckleExample/SwashbuckleExample/Controllers/SwashBuckleTest.cs
回答4:
None of the posted solutions will work with the newer version of Swagger. If you want a newline separation between your comment lines, you have to add ///
for newline. That makes method comments lengthy but they will be more readable in the Swagger documentation.
/// <summary>
/// Comment Line 1
///
/// Comment Line 2
///
/// Comment Line 3
/// </summary>
回答5:
Using the structure below, both the Swashbuckle UI and the ReDoc UI will work:
/// <summary>
/// Title
///
/// <para>Content line 1</para>
/// <para>Content line 2</para>
/// <para>Content line 3/</para>
/// </summary>
Important note: Do not ignore the spaces at the end of each line
回答6:
If none of the answers worked for you, worked partially in some case like it was with me.
You can use <br></br>
. Do not use </br>
. It can break XML sometimes. Visual studio showed bad XML formatting for <br/>
来源:https://stackoverflow.com/questions/32559028/how-to-add-line-break-to-swashbuckle-documentation