【问题标题】:Custom schema name in NSwagNSwag 中的自定义模式名称
【发布时间】:2019-06-12 04:46:52
【问题描述】:

我浏览了很多文档并搜索了互联网,但是我无法找到如何使用 NSwag 执行以下操作:

services.AddSwaggerGen(c =>
{
    c.CustomSchemaIds(type => type.FullName);
};

这取自 Swashbuckle,我正在寻找 NSwag 中的等价物。

我想要这个是因为我有嵌套的 DTO 类,它们带有编号后缀,我希望能够通过父类 + 实际 DTO 而不是编号后缀来区分这些 DTO:

using System.Collections.Generic;

namespace Blog.Api.Responses
{
    public class IndustriesResponse : List<IndustriesResponse.IndustryDto>
    {
        public class IndustryDto
        {
            public string Code { get; set; }
            public bool IsEditable { get; set; }
        }
    }
}
using System.Collections.Generic;

namespace Blog.Api.Requests
{
    public class UpdateIndustriesRequest : List<UpdateIndustriesRequest.IndustryDto>
    {
        public class IndustryDto
        {
            public string Code { get; set; }
            public bool IsEditable { get; set; }
        }
    }
}

【问题讨论】:

    标签: nswag


    【解决方案1】:

    实现自己的 ISchemaNameGenerator 并将其与 SchemaNameGenerator 设置属性一起使用

    【讨论】:

    • 太棒了。谢谢!
    猜你喜欢
    • 2017-12-27
    • 1970-01-01
    • 2014-04-25
    • 1970-01-01
    • 2017-04-11
    • 2012-05-27
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    相关资源
    最近更新 更多