Swagger 划掉方法

Seb*_*ian 6 .net asp.net-web-api swagger swagger-ui swashbuckle

我将 Swaschbuckle 用于我的 .NET Swagger Web API 服务。

我查看了http://petstore.swagger.io/#/pet中的示例,其中有一个被划掉的操作 findByTags。

在此处输入图片说明

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

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

Mik*_*Mik 11

我的 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();
    }
}
Run Code Online (Sandbox Code Playgroud)

您还需要在 Startup.cs 中注册它:

SwaggerConfig.Register(config);
Run Code Online (Sandbox Code Playgroud)

并使用 ApiController 中的方法,如下所示:

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

我可以在 Swagger 中看到它被划掉了: 在此输入图像描述