예제 #1
0
 public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
 {
     swaggerDoc.Paths = swaggerDoc.Paths.ToDictionary(
         entry => entry.Key.Replace("{version}", swaggerDoc.Info.Version),
         entry =>
         {
             var pathItem = entry.Value;
             RemoveVersionParamFrom(pathItem.Get);
             RemoveVersionParamFrom(pathItem.Put);
             RemoveVersionParamFrom(pathItem.Post);
             RemoveVersionParamFrom(pathItem.Delete);
             RemoveVersionParamFrom(pathItem.Options);
             RemoveVersionParamFrom(pathItem.Head);
             RemoveVersionParamFrom(pathItem.Patch);
             return pathItem;
         });
 }
예제 #2
0
        public SwaggerDocument GetSwagger(
            string apiVersion,
            string host = null,
            string basePath = null,
            string[] schemes = null)
        {
            var schemaRegistry = _schemaRegistryFactory.Create();

            var info = _options.ApiVersions.FirstOrDefault(v => v.Version == apiVersion);
            if (info == null)
                throw new UnknownApiVersion(apiVersion);

            var paths = GetApiDescriptionsFor(apiVersion)
                .Where(apiDesc => !(_options.IgnoreObsoleteActions && apiDesc.IsObsolete()))
                .OrderBy(_options.GroupNameSelector, _options.GroupNameComparer)
                .GroupBy(apiDesc => apiDesc.RelativePathSansQueryString())
                .ToDictionary(group => "/" + group.Key, group => CreatePathItem(group, schemaRegistry));

            var swaggerDoc = new SwaggerDocument
            {
                Info = info,
                Host = host,
                BasePath = basePath,
                Schemes = schemes,
                Paths = paths,
                Definitions = schemaRegistry.Definitions,
                SecurityDefinitions = _options.SecurityDefinitions
            };

            var filterContext = new DocumentFilterContext(
                _apiDescriptionsProvider.ApiDescriptionGroups,
                null);

            foreach (var filter in _options.DocumentFilters)
            {
                filter.Apply(swaggerDoc, filterContext);
            }

            return swaggerDoc;
        }
 public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
 {
     swaggerDoc.Extensions.Add("X-property1", "value");
 }
예제 #4
0
 /// <summary>
 /// Called when genrating the document
 /// </summary>
 public void Apply(SwaggerDocument swaggerDoc, DocumentFilterContext context)
 {
     swaggerDoc.BasePath = null;
 }