Esempio n. 1
0
        public static SwaggerDocsConfig VersioningSwaggerDoc(this SwaggerDocsConfig config,
                                                             VersionedApiExplorer apiExplorer, string docTitleFormat, string versionParamName)
        {
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }

            if (apiExplorer == null)
            {
                throw new ArgumentNullException(nameof(apiExplorer));
            }

            if (string.IsNullOrWhiteSpace(docTitleFormat))
            {
                throw new ArgumentNullException(nameof(docTitleFormat));
            }

            if (string.IsNullOrWhiteSpace(versionParamName))
            {
                throw new ArgumentNullException(nameof(versionParamName));
            }

            config.MultipleApiVersions(
                (apiDescription, version) => apiDescription.GetGroupName() == version,
                info =>
            {
                foreach (var group in apiExplorer.ApiDescriptions)
                {
                    info.Version(group.Name, string.Format(docTitleFormat, group.ApiVersion));
                }
            });

            config.OperationFilter(() => new RemoveVersionParameters(versionParamName));
            config.DocumentFilter(() => new SetVersionInPaths(versionParamName));

            return(config);
        }