Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 666
SpiritBob Avatar asked Aug 19 '19 15:08

SpiritBob


2 Answers

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

like image 200
Peter Marshall Avatar answered Nov 15 '22 19:11

Peter Marshall


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, as you noticed, and (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/)

like image 32
Pac0 Avatar answered Nov 15 '22 20:11

Pac0