【问题标题】:Swagger cross out method大摇大摆的划掉方法
【发布时间】:2016-09-17 22:17:17
【问题描述】:

我正在为我的 .NET Swagger Web API 服务使用 Swaschbuckle。

我查看了来自http://petstore.swagger.io/#/pet 的样本,其中的 Action findByTags 被划掉了。

我想在我的 api 服务中划掉一个动作,但是当我使用过时的属性时,这个动作是不可见的。

知道如何处理这个问题吗?

【问题讨论】:

  • 我认为这不适用于 Web API 操作。它仅适用于 MVC 操作。尝试将 @Deprecated 属性添加到 MVC 操作中。然后它应该工作。另一种方法是在看到已弃用的操作时更改 CSS 以使用 text-decoration: line-through
  • [Obsolete] 工作得很好。如果您检查 Web API 的规范,您将看到路径的属性 depricated 设置为 true。正如 Venky 所说,您确实必须添加自定义 css 样式以应用该行。
  • 具有过时属性的操作将在我生成的 json 中被忽略,因此我无法修改我的 css。我有一个这样的操作:[System.Obsolete] public HttpResponseMessage Get(){} 我在我的 json 或其他任何地方都看不到这个操作

标签: .net asp.net-web-api swagger swagger-ui swashbuckle


【解决方案1】:

我的 WebApi 项目遇到了同样的问题,但在将 Swashbuckle.Core nuget 包更新到 5.6.0 版后,它开始工作了。

我有一个 SwaggerConfig 类,如下所示:

public static class SwaggerConfig
{
    public static void Register(HttpConfiguration configuration)
    {
        configuration.EnableSwagger(Configure).EnableSwaggerUi(ConfigureUi);

    }

    static void Configure(SwaggerDocsConfig config)
    {
        config.SingleApiVersion("V1", "MichalBialecki.com.Swagger.Example");
        config.UseFullTypeNameInSchemaIds();
    }

    static void ConfigureUi(SwaggerUiConfig config)
    {
        config.DocExpansion(DocExpansion.None);
        config.DisableValidator();
    }
}

还需要在 Startup.cs 中注册:

SwaggerConfig.Register(config);

在 ApiController 中使用这样的方法:

[HttpGet]
[Obsolete("This method is obsolete, please use /accounts/{accountId}")]
[Route("personalAccount/{accountId}")]
public AccountDTO GetPersonalAccount(int accountId)

我可以在 Swagger 中看到,它被抚平了:

【讨论】:

    猜你喜欢
    • 2018-11-29
    • 2014-07-19
    • 2015-12-14
    • 1970-01-01
    • 2018-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多