我正在使用 Swagger记录我的 REST API(使用 asp.net web api 2)。有没有办法 Swagger 为给定 api 调用的每个可能响应提供响应模型?我正在使用 xml 注释注释状态代码响应,如下所示:
/// <summary>
/// Save a person
/// </summary>
/// <response code="200">Ok</response>
/// <response code="400">Bad Request</response>
/// <response code="500">Internal Server error</response>
public HttpResponseMessage SavePerson() {...}
最佳答案
您可以像这样在您的 XML 注释上尝试使用 cref="TYPE HERE"。
/// <response code="400" cref="CustomErrorModel">Bad Request</response>
乙 但我建议使用 Swagger 为您提供的注释。
[SwaggerResponse(HttpStatusCode.OK, Type = typeof(OnlineMerchantQueryResponseInformation))]
将此归因于您的 Controller 。
关于c# - 使用 Swagger 的特定状态代码的响应模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29489304/