コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigureSwaggerOptions"/> class.
 /// </summary>
 /// <param name="provider">The <see cref="IApiVersionDescriptionProvider">provider</see> used to generate Swagger documents.</param>
 /// <param name="apiMetadata">The api metadata object who describe all metadata about api</param>
 public ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider,
                                SwaggerApiInfo swaggerApiInfo, ILoggerFactory loggerFactory)
 {
     this.provider       = provider;
     this.swaggerApiInfo = swaggerApiInfo ??
                           throw new ArgumentNullException(nameof(swaggerApiInfo));
     logger = loggerFactory?.CreateLogger <ConfigureSwaggerOptions>();
 }
コード例 #2
0
        private void ConfigureSwagger(IServiceCollection services)
        {
            if (ApiBootOptions.EnableSwagger)
            {
                var swaggerApiInfo = new SwaggerApiInfo()
                {
                    ApiDescription      = ApiMetadata.Description,
                    ApiName             = ApiMetadata.Name,
                    BuildId             = BuildId,
                    XmlCommentsFilePath = XmlCommentsFilePath
                };

                services.AddOtcApiBootSwagger(swaggerApiInfo);
            }
        }
コード例 #3
0
        public static IServiceCollection AddOtcApiBootSwagger(
            this IServiceCollection services, SwaggerApiInfo swaggerApiInfo)
        {
            if (services == null)
            {
                throw new System.ArgumentNullException(nameof(services));
            }

            if (swaggerApiInfo is null)
            {
                throw new System.ArgumentNullException(nameof(swaggerApiInfo));
            }

            services.AddSingleton(swaggerApiInfo);

            services
            .AddTransient <IConfigureOptions <SwaggerGenOptions>, ConfigureSwaggerOptions>();

            services.AddSwaggerGen();

            return(services);
        }