简体   繁体   English

Swagger UI 响应示例 Asp.Net Core Web Api

[英]Swagger UI Response Example Asp.Net Core Web Api

I'm using Swagger.AspNetCore to document my api.我正在使用 Swagger.AspNetCore 来记录我的 api。 So far i was happy to use xml comments to generate response model examples until i reach the point when i've got to document embeded object.到目前为止,我很高兴使用 xml 注释来生成响应 model 示例,直到我必须记录嵌入的 object 示例。

So i have simple model:所以我有简单的 model:

public class SummaryResult
{
    /// <summary>Total Cost.</summary>
    /// <value>Total Cost.</value>
    /// <example>6433.2</example>
    public double TotalCost { get; set; }

    /// <summary>Owner.</summary>
    public Owner Owner { get; set; }
}

public class Owner
{
    /// <summary>Owner Name.</summary>
    /// <value>Owner Name.</value>
    /// <example>Michael</example>
    public string Name { get; set; }
}

And Swagger UI document it only for TotalCost, Owner property just skipped whatever i do. Swagger UI 仅针对 TotalCost 记录它,所有者属性只是跳过了我所做的任何事情。 Does anyone have a clue why this can happen?有谁知道为什么会发生这种情况? And how to fix it.以及如何解决它。
I know how to deal with List - just put on top xml comment like <list></list> but it's not my case.我知道如何处理列表 - 只需将 xml 评论放在顶部,如<list></list>但这不是我的情况。

Thank you谢谢

I just tested this and it shows fine on my end:我刚刚对此进行了测试,结果显示效果很好:
http://swagger-net-test.azurewebsites.net/swagger/ui/index#/ActionFilter/ActionFilter_Get http://swagger-net-test.azurewebsites.net/swagger/ui/index#/ActionFilter/ActionFilter_Get

Here is how that looks like on the model tab:这是 model 选项卡上的样子:

1

As you can see in the image it does show the summary and the example value.正如您在图像中看到的那样,它确实显示了摘要和示例值。

Here is the code:这是代码:
https://github.com/heldersepu/Swagger-Net-Test/blob/master/Swagger_Test/Controllers/ActionFilterController.cs#L29 https://github.com/heldersepu/Swagger-Net-Test/blob/master/Swagger_Test/Controllers/ActionFilterController.cs#L29

Educated guess there could be something else removing those elements.有根据的猜测可能还有其他东西可以删除这些元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM