Created
October 6, 2016 18:51
-
-
Save casper-rasmussen/992579a7ac4fe6af572fa0221b8f317a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EPiServerDocumentFilter : IDocumentFilter | |
{ | |
private readonly string[] _assembliesToExclude = new string[] | |
{ | |
"EPiServer.ApplicationModules", | |
"EPiServer.BaseLibrary", | |
"EPiServer.Configuration", | |
"EPiServer.Data.Cache", | |
"EPiServer.Data", | |
"EPiServer", | |
"EPiServer.Enterprise", | |
"EPiServer.Events", | |
"EPiServer.Find.Cms", | |
"EPiServer.Find", | |
"EPiServer.Find.Framework", | |
"EPiServer.Find.Optimizations", | |
"EPiServer.Find.Statistics", | |
"EPiServer.Find.UI", | |
"EPiServer.Find", | |
"EPiServer.Framework", | |
"EPiServer.ImageLibrary", | |
"EPiServer.Implementation", | |
"EPiServer.Licensing", | |
"EPiServer.LinkAnalyzer", | |
"EPiServer.Logging.Log4Net", | |
"EPiServer.Shell", | |
"EPiServer.Web.WebControls", | |
"EPiServer.WorkflowFoundation", | |
"EPiServer.XForms" | |
}; | |
public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, System.Web.Http.Description.IApiExplorer apiExplorer) | |
{ | |
IList<ApiDescription> removals = new List<ApiDescription>(); | |
foreach (ApiDescription description in apiExplorer.ApiDescriptions) | |
{ | |
if(description.ActionDescriptor == null) | |
continue; | |
if(description.ActionDescriptor.ControllerDescriptor == null) | |
continue; | |
if(description.ActionDescriptor.ControllerDescriptor.ControllerType == null) | |
continue; | |
//Derive name | |
AssemblyName assemblyName = description.ActionDescriptor.ControllerDescriptor.ControllerType.Assembly.GetName(); | |
if (this._assembliesToExclude.Contains(assemblyName.Name, StringComparer.InvariantCultureIgnoreCase)) | |
removals.Add(description); | |
} | |
foreach (ApiDescription index in removals) | |
{ | |
string apiPath = ApiDescriptionExtensions.RelativePathSansQueryString(index); | |
swaggerDoc.paths.Remove("/" + apiPath); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment