SpiritBob
SpiritBob

Reputation: 2702

What does the attribute "[ApiExplorerSettings(IgnoreApi = true)]" do?

EDIT: I'm aware of what attributes in general do, the question is for this specific attribute alone. Sorry for the confusion!

I've read the following question, along with this one, which point to how the attribute is used to ignore the generated swagger/swashbuckle documentation for specific methods or whole controllers. (documentation is the swagger page with all the api's listed I believe?)

But other than swagger/swashbuckle (which is a NuGet package), what other function does this attribute possess in ASP.NET?

Upvotes: 16

Views: 32554

Answers (3)

Pac0
Pac0

Reputation: 23174

First of all, to clarify, an attribute in C# does not trigger anything by itself. External code searches for classes, methods or properties marked with a specific attribute, and act accordingly.

Of course, there are many building blocks in ASP.NET MVC, it can be confusing sometimes.

This attribute is used by Swagger to hide the endpoint.

Also usedd (in .NET core at least) by the given implementations of IApiDescriptionProvider and other related interfaces, but that would be effective only if you actually use them (by configuring them up in Startup.cs)

(for some more details and example, see https://andrewlock.net/introduction-to-the-apiexplorer-in-asp-net-core/)

Upvotes: 9

Asif Khokhar
Asif Khokhar

Reputation: 35

This attribute helps to control the visibility. We can use this on the controller class or an action method when we want to hide that specific controller or action from showing in the swagger UI.

Upvotes: 0

Peter Marshall
Peter Marshall

Reputation: 1355

When applied to a public method on a controller, it prevents that method from appearing in the swagger ui.

Upvotes: 37

Related Questions