Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swagger cross out method

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?

like image 710
Sebastian Avatar asked May 20 '16 15:05

Sebastian


People also ask

How do you mark deprecated in Swagger?

There is no special attribute which can mark service endpoint to show it as deprecated in swagger schema, but you can use OperationFilter action when register SwaggerFeature to modify swagger declarations and set Deprecated property to string “true” for obsolete methods.

What is cURL in Swagger?

Firstly, the cURL command is for display and copy-pasting only. Swagger UI does not actually use cURL for requests – it's a web page so it makes requests using JavaScript (fetch API or XMLHttpRequest or similar).


1 Answers

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

like image 52
Mik Avatar answered Oct 19 '22 09:10

Mik