swashbuckle如何显示一个示例词典而不是其他词语?

发布于 2025-02-08 03:21:54 字数 893 浏览 3 评论 0原文

我有一个API,我想让我感到自动为我自动化所有摇摇欲坠的文档。

我有一个端点,它返回带有字典属性的类,但是摇摇欲坠的示例包含“ fromeprop1,fropeprop2”等,而不是示例值。是否有一种方法可以使用 Simpleclass 类中指定的示例值?

班级示例的班级(这不起作用)。

public class SimpleClass
{
    /// <example>"{"age":31,"height":234}"</example>
    public Dictionary<string, int> DictionaryProperty { get; set; }

    /// <example>The cow jumped over the moon</example>
    public string someProperty { get; set; }
}

控制器的

    [HttpGet]
    [Route("/testexample")]
    [ProducesResponseType(typeof(SimpleClass), StatusCodes.Status200OK)]
    public async Task<IActionResult> TestExample()
    {
        return Ok();
    }

结果大肆宣传:

I have an API and I want swashbuckle to autogenerate all the swagger documentation for me.

I have an endpoint that returns a class with a dictionary property but the swagger generated example contains "additionalProp1, additionalProp2" etc instead of example values. Is there a way to instead use example values specified in the SimpleClass class?

The class with the example for swagger (that doesn't work).

public class SimpleClass
{
    /// <example>"{"age":31,"height":234}"</example>
    public Dictionary<string, int> DictionaryProperty { get; set; }

    /// <example>The cow jumped over the moon</example>
    public string someProperty { get; set; }
}

The controller

    [HttpGet]
    [Route("/testexample")]
    [ProducesResponseType(typeof(SimpleClass), StatusCodes.Status200OK)]
    public async Task<IActionResult> TestExample()
    {
        return Ok();
    }

The result in swagger:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神回复 2025-02-15 03:21:54

取出XML 示例中的引号值:

/// <example>{"age":31,"height":234}</example>

Take out the quotes inside the XML example value:

/// <example>{"age":31,"height":234}</example>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文