【问题标题】:Swashbuckle OData Mapping with EnableUnqualifiedNameCall带有 EnableUnqualifiedNameCall 的 Swashbuckle OData 映射
【发布时间】:2016-12-28 19:50:03
【问题描述】:

我有以下操作

POST /odata/Individuals({individualId})/Default.SendEmail

使用 Swashbuckle 生成 Swagger 文档已针对 OData 进行设置和配置,并正确记录。

当我启用非限定名称调用时

config.EnableUnqualifiedNameCall(true);

路由正常工作

POST /odata/Individuals({individualId})/SendEmail

但是 Swagger 仍然显示带有“默认值”的原件。前缀,并且测试不再适用于 Swagger UI。

如何同时允许 Default.SendEmail 和 SendEmail,或者让 Swagger 根据 EnableUnqualifiedNameCall 正确更新?

【问题讨论】:

    标签: c# asp.net-web-api2 odata swagger


    【解决方案1】:

    同样的事情发生在我身上,我发现解决它的唯一方法是在 documentFilter 中使用正则表达式删除前缀。

    c.DocumentFilter(() => new SwaggerDocumentFilter());

    class SwaggerDocumentFilter : IDocumentFilter
    {
        public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer)
        {
        swaggerDoc.paths = swaggerDoc.paths.Select(entry=>
          new {
            key = new Regex(ODataNameSpace + @"\.",
                      RegexOptions.Compiled | RegexOptions.IgnoreCase)
                .Replace(entry.key, string.Empty),
            value = entry.Value
         })
        }
    }
    

    在 ODataConventionModelBuilder 对象的属性中设置相同的命名空间(很遗憾,删除它不是一个有效的选项)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-04-21
      • 2017-08-24
      • 2013-08-28
      • 2018-06-20
      • 2022-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多