public SwaggerDocument GetSwagger(string rootUrl, string apiVersion, AreaDescription area, IList <AreaDescription> allAreas) { var schemaRegistry = new SchemaRegistry( _jsonSerializerSettings, _options.CustomSchemaMappings, _options.SchemaFilters, _options.ModelFilters, _options.IgnoreObsoleteProperties, _options.SchemaIdSelector, _options.DescribeAllEnumsAsStrings, _options.DescribeStringEnumsInCamelCase, _options.ApplyFiltersToAllSchemas); Info info; _apiVersions.TryGetValue(apiVersion, out info); if (info == null) { throw new UnknownApiVersion(apiVersion); } var paths = GetApiDescriptionsFor(apiVersion, area, allAreas) .Where(apiDesc => !(_options.IgnoreObsoleteActions && apiDesc.IsObsolete())) .OrderBy(_options.GroupingKeySelector, _options.GroupingKeyComparer) .GroupBy(apiDesc => apiDesc.RelativePathSansQueryString()) .ToDictionary(group => "/" + group.Key, group => CreatePathItem(group, schemaRegistry)); var rootUri = new Uri(rootUrl); var port = (!rootUri.IsDefaultPort) ? ":" + rootUri.Port : string.Empty; var swaggerDoc = new SwaggerDocument { info = info, host = rootUri.Host + port, basePath = (rootUri.AbsolutePath != "/") ? rootUri.AbsolutePath : null, schemes = _options.Schemes?.ToList() ?? new[] { rootUri.Scheme }.ToList(), paths = paths, definitions = schemaRegistry.Definitions, securityDefinitions = _options.SecurityDefinitions }; foreach (var filter in _options.DocumentFilters) { filter.Apply(swaggerDoc, schemaRegistry, _apiExplorer); } return(swaggerDoc); }
protected bool Equals(AreaDescription other) { return(string.Equals(Name, other.Name) && Equals(RegistrationType, other.RegistrationType)); }
public static bool IsNullOrEmpty(AreaDescription area) { return(area == null || area.Equals(Empty)); }
private IEnumerable <ApiDescription> GetApiDescriptionsFor(string apiVersion, AreaDescription area, IList <AreaDescription> allAreas) { var apiDescriptions = _options.VersionSupportResolver == null ? _apiExplorer.ApiDescriptions : _apiExplorer.ApiDescriptions.Where(apiDesc => _options.VersionSupportResolver(apiDesc, apiVersion)); if (area == null && allAreas.Count <= 0) { return(apiDescriptions); } if (area == null) { return(GetApiDescriptionsExcludingAreas(apiDescriptions, allAreas)); } return(GetAreaApiDescriptionsFor(area, apiDescriptions)); }
private static IEnumerable <ApiDescription> GetAreaApiDescriptionsFor(AreaDescription area, IEnumerable <ApiDescription> apiDescriptions) { return(apiDescriptions .Where(api => api.ActionDescriptor.ControllerDescriptor.ControllerType.Namespace.StartsWith(area.RegistrationType.Namespace))); }