Mark .NET Web API endpoint as obsolete / deprecated

problem

How to do this, in order to let developers know not to use it?

It should be clearly visible in Swagger (the default in Web API) too.

solution

Just use the normal Obsolete attribute in C# on the endpoint method:

[Obsolete("This endpoint is obsolete. Call /WeatherForecastAI instead.")]
[HttpGet(Name = "GetWeatherForecast")]
public IEnumerable<WeatherForecast> Get()

This will make the endpoint show up on Swagger as grayed out and with a strike-through:

endpoint obsolete

I've also tried to use the Deprecated property of ApiVersion, but it didn't have any effect on Swagger.

(This is a simple thing, I posted it on A Dev just because I couldn't find something clear in my web searches.)

Gravatar
Author: Dan Dumitru
Last Edit: August 7, 2024
Last Edit August 7, 2024
Created August 7, 2024
Views 178
Tags
ASP.NET

Join us!

Do you like this website?

Bookmark it and come back here to write a post yourself when you run into something shareable.

Early collaborators will get to own a part of the project (5 to 20%)... >> read more

Your Comment

Feel free to post additional info or improvement suggestions.
preview
Optional, never shown, displays gravatar.

Formatting Tips

This editor uses Markdown to easily add code in your posts.

Triple backticks for full line(s) of code (or indent 4 spaces)

```
let foo = 'bar';
```

[link text](http://a.com)

*italic* **bold**

More Tips