How to install Swashbuckle for ASP.NET Core

Swashbuckle.AspNetCore.Swagger: a Swagger object model and middleware to expose SwaggerDocument objects as JSON endpoints.

Swashbuckle.AspNetCore.SwaggerGen: a Swagger generator that builds SwaggerDocument objects directly from your routes, controllers, and models. It's typically combined with the Swagger endpoint middleware to automatically expose Swagger JSON.

Swashbuckle.AspNetCore.SwaggerUI: an embedded version of the Swagger UI tool. It interprets Swagger JSON to build a rich, customizable experience for describing the web API functionality. It includes built-in test harnesses for the public methods.
From the Manage NuGet Packages dialog:

From menu Tools->Nuget Package Manager->Manage  Nuget Packages for Solution... 
Enter "Swashbuckle.AspNetCore" in the search box

Select the "Swashbuckle.AspNetCore" package from the Browse tab and click Install

After installed

In Startup.cs

// This method gets called by the runtime. Use this method to add services to the container.

         public void ConfigureServices(IServiceCollection services)
            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen(c =>
                c.SwaggerDoc("v1", new Info { Title = "GamePlay API", Version = "v1" });



// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env)
            if (env.IsDevelopment())
            // Enable middleware to serve generated Swagger as a JSON endpoint.

            // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
            // specifying the Swagger JSON endpoint.
            app.UseSwaggerUI(c =>
                c.SwaggerEndpoint("../swagger/v1/swagger.json", "My API V1");
                c.RoutePrefix = "docs";


=> And see result



Post a Comment