您如何在“请求和响应模型"中添加醒目的注释? [英] How do you add a swagger comment to the "Request and Response Model"?

查看:57
本文介绍了您如何在“请求和响应模型"中添加醒目的注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以在类似于以下示例的方法上添加注释,但是如何在请求和响应模型中添加注释呢?

You can add a comment on the methods like the example below but what about adding comments to the request and response model?

/// <summary>
/// my summary
/// </summary>
/// <remarks>
/// remark goes here.
/// </remarks>
/// <param name="somepara">Required parameter: Example: </param>
/// <return>Returns comment</return>
/// <response code="200">Ok</response>

推荐答案

是的,就像Dimitar所说的那样,您可以使用 SwaggerResponse 向响应中添加评论,就像您一样,请求也有所不同为您的操作添加了xml注释,您应该将其添加至参数,这是一个示例:

Yes just like Dimitar said, you can add comments to the responses with SwaggerResponse, the request is a bit different, just like you added xml comments to your action you should add to the parameters, here is an example:

using Swagger.Net.Annotations;
using System;
using System.Collections.Generic;
using System.Net;
using System.Web.Http;
using System.Web.Http.Results;

namespace Swagger_Test.Controllers
{
    public class IHttpActionResultController : ApiController
    {

        [SwaggerResponse(HttpStatusCode.OK, "List of customers", typeof(IEnumerable<int>))]
        [SwaggerResponse(HttpStatusCode.NotFound, Type = typeof(NotFoundResult))]
        public IHttpActionResult Post(MyData data)
        {
            throw new NotImplementedException();
        }
    }

    /// <summary>My super duper data</summary>
    public class MyData
    {
        /// <summary>The unique identifier</summary>
        public int id { get; set; }

        /// <summary>Everyone needs a name</summary>
        public string name { get; set; }
    }
}

并且大张旗鼓地看起来像:

And in swagger that will look like:

这篇关于您如何在“请求和响应模型"中添加醒目的注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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