public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, System.Web.Http.Description.IApiExplorer apiExplorer) { //make operations alphabetic var paths = swaggerDoc.paths.OrderBy(e => e.Key).ToList(); swaggerDoc.paths = paths.ToDictionary(e => e.Key, e => e.Value); //controller comments do not get added to swagger docs. This is how to add them. RemoveControllerDescriptions(swaggerDoc, apiExplorer); }
public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, System.Web.Http.Description.IApiExplorer apiExplorer) { foreach (var apiDescription in apiExplorer.ApiDescriptions) { if (!apiDescription.ActionDescriptor.ControllerDescriptor.GetCustomAttributes <SwaggerHideAttribute>().Any() && !apiDescription.ActionDescriptor.GetCustomAttributes <SwaggerHideAttribute>().Any()) { continue; } var route = "/" + apiDescription.Route.RouteTemplate.TrimEnd('/'); swaggerDoc.paths.Remove(route); } }
private static void RemoveControllerDescriptions(SwaggerDocument swaggerDoc, System.Web.Http.Description.IApiExplorer apiExplorer) { List <ApiDescription> removeDescriptions = new List <ApiDescription>(); foreach (var api in apiExplorer.ApiDescriptions) { if (api.ID.Contains("GETapi/AlertApi") || api.ID == "GETapi/ApiSearch" || api.ID == "GETapi/OrganizationsApi" || api.ID.Contains("ApiRoot") || api.ID.Contains("report") || api.ID.Contains(".{ext}")) { removeDescriptions.Add(api); } } foreach (var description in removeDescriptions) { apiExplorer.ApiDescriptions.Remove(description); var descriptionId = description.ID.Replace("GET", "/"); swaggerDoc.paths.Remove(descriptionId); } }