コード例 #1
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IApiVersionDescriptionProvider apiVersionDescriptionProvider)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseHttpsRedirection();

            app.UseRouting();

            app.UseAuthorization();

            app.UseAuthentication();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

            app.UseSwagger();

            app.UseSwaggerUI(setupAction =>
            {
                foreach (var description in apiVersionDescriptionProvider.ApiVersionDescriptions)
                {
                    setupAction.SwaggerEndpoint(
                        $"/swagger/{SwaggerGenHelper.GetVersionedApiName(description.ApiVersion)}/swagger.json",
                        description.GroupName.ToUpperInvariant());
                }
                setupAction.RoutePrefix = string.Empty;
            });
        }
 private static void AddSwaggerDocument(this SwaggerGenOptions setupAction,
                                        ApiVersion apiVersion, string apiName)
 {
     setupAction.SwaggerDoc(SwaggerGenHelper.GetVersionedApiName(apiVersion),
                            new OpenApiInfo()
     {
         Title       = apiName,
         Version     = apiVersion.ToString(),
         Description = "Through this API you can access books",
         Contact     = new OpenApiContact
         {
             Email = "*****@*****.**",
             Name  = "John Doe",
             Url   = new Uri("https://my.homepage.com")
         },
         License = new OpenApiLicense
         {
             Name = "MIT License",
             Url  = new Uri("https://opensource.org/licenses/MIT")
         }
     });
 }