Warm tip: This article is reproduced from serverfault.com, please click

How to prevent child controller classes inheriting [ApiExplorerSettings(IgnoreApi = true)]

发布于 2020-12-01 08:19:57

I am putting together swagger documentation for a C# API (with NSWAG) It's written using ASP.NET Framework, not Core... I don't think I can take advantage of some of the newest features of Swagger / Open API

We have a baseapicontroller than inherits apicontroller

I don't want the baseapicontroller itself to appear in swagger

But I do want some of its child controllers to appear

If I use the following, it hides the base and the children

#if DEBUG
    [ApiExplorerSettings(IgnoreApi = false)]
#else
    [ApiExplorerSettings(IgnoreApi = true)]
#endif  

What is the solution?

I've read about [AttributeUsage (Inherited = True)] but I think that will affect all attributes... that's not what I want

Questioner
Neve
Viewed
0
Neve 2020-12-01 18:08:29

Actually I thought of two things that make me realise this is a stupid question:

I can apply the instruction to ignore the APIExplorerSettings at the level of an individual endpoint so this is moot

Also, everything in the baseApi is protected anyway so Swagger won't show it...