8

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.

enter image description here

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?

Sebastian
  • 131
  • 1
  • 6
  • I think this doesn't work for Web API actions. It only works for MVC Actions. Try putting @Deprecated attribute to the MVC action. Then it should work. Another way is to alter the CSS to use `text-decoration: line-through` whenever it sees a deprecated action. – Venkata Dorisala May 20 '16 at 15:49
  • 3
    `[Obsolete]` works perfectly fine. If you inspect the specification of your Web API you will see that the path has the attribute `depricated` set to true. You'll indeed have to add custom css styling to apply the line through as Venky stated. – venerik May 20 '16 at 16:55
  • The action with the obsolete attribute will be ignored in my generated json, and so i cannot modify my css. I have an Action like this: [System.Obsolete] public HttpResponseMessage Get(){} I cannot see this action either in my json or anywere else – Sebastian May 23 '16 at 08:21

1 Answers1

10

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: enter image description here

Spikolynn
  • 4,067
  • 2
  • 37
  • 44
Mik
  • 3,998
  • 2
  • 26
  • 16