Swagger cross out method

2020-07-13 07:19发布

问题:

I am using Swaschbuckle for my .NET Swagger Web API Service.

I have looked at the sample from http://petstore.swagger.io/#/pet and there ist the Action findByTags which is crossed out.

I want to cross out an action in my api service, but when i am using the obsolete attribute the action isn't visible.

Any idea how to handle this issue?

回答1:

I had the same problem with my WebApi project, but after updating Swashbuckle.Core nuget package to version 5.6.0 it started to work.

I have a SwaggerConfig class that looks like this:

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();
    }
}

You also need to register it in Startup.cs:

SwaggerConfig.Register(config);

And with method in ApiController like this:

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

I can see in Swagger, that it is stroked out: