NSwag-如何添加评论? [英] NSwag - how do I add comments?

查看:70
本文介绍了NSwag-如何添加评论?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.Net WebAPI项目中使用NSwag生成一个灵活的界面-效果很好.

I use NSwag in an ASP.Net WebAPI project to generate a swagger interface - which works great.

说我有一种方法想要添加一些解释-我该怎么做?

Say I have a method I want to add some explanations to - how can I do that?

通过评论,我的意思是当API的用户查看文档时会看到的东西.

By comment I mean something that when a user of the API is looking at the documentation will see.

我已经用谷歌搜索,加油并...躲开了?-但找不到任何相关信息.也许我使用了错误的术语.

I have googled, binged and ... ducked? - but was unable to find anything about it. Maybe I am using wrong terms.

推荐答案

您可以使用

You can use Document comments to achieve your goal. For example

/// <summary>This method changes the point's location by
///    the given x- and y-offsets.
/// <example>For example:
/// <code>
///    Point p = new Point(3,5);
///    p.Translate(-1,3);
/// </code>
/// results in <c>p</c>'s having the value (2,8).
/// </example>
/// </summary>

public void Translate(int xor, int yor) {
    X += xor;
    Y += yor;
}

翻译是您的API方法,并且您添加了适当的文档注释NSwag会选择这些注释,并在您通过API资源管理器探索API时将其显示出来.如果这样不起作用,请添加

Translate is your API method and you've added proper documentation comments NSwag will pick those up and show them when you explore the API via the API explorer. If that doesn't work add the following in your .csproj

<PropertyGroup>
  <GenerateDocumentationFile>true</GenerateDocumentationFile>
  <NoWarn>$(NoWarn);1591</NoWarn>
</PropertyGroup>

这篇关于NSwag-如何添加评论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆