| 123456789101112131415161718192021222324252627282930313233343536 | using Microsoft.AspNetCore.Mvc.ApiExplorer;using System.ComponentModel;namespace OASystem.API{        public class SwaggerApi : IDocumentFilter    {        [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class)]        public class HideApiAttribute : System.Attribute { }        public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)        {            foreach (ApiDescription description in context.ApiDescriptions)            {                if (description.TryGetMethodInfo(out MethodInfo method))                {                    if (method.ReflectedType.CustomAttributes.Any(t => t.AttributeType == typeof(HideApiAttribute))                            || method.CustomAttributes.Any(t => t.AttributeType == typeof(HideApiAttribute))                            )                    {                        string key = "/" + description.RelativePath;                        if (key.Contains("?"))                        {                            int idx = key.IndexOf("?", System.StringComparison.Ordinal);                            key = key.Substring(0, idx);                        }                        swaggerDoc.Paths.Remove(key);                    }                }            }        }    }}
 |