Swagger-Implementation On and Off

By default when creating a Web-API project the Swagger tool is automatically implemented. In certain cases you need to eliminatate the Swagger functionality, but later you might need it for test purposes. Following is an example of what to do to disable the Swagger functionality :
//launchSettings.json - the lines with bold-face is what are needed to disable Swagger { "iisSettings": { "windowsAuthentication": false, "anonymousAuthentication": true, "iisExpress": { "applicationUrl": "http://localhost:23005", "sslPort": 0 } }, "$schema": "http://json.schemastore.org/launchsettings.json", "profiles": { "IIS Express": { "commandName": "IISExpress", "launchBrowser": true, "launchUrl": "api/FishDatas" /*"swagger"*/, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" } }, "FishWebServer": { "commandName": "Project", "launchBrowser": true, "launchUrl": "api/FishDatas"/*"swagger"*/, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, "dotnetRunMessages": "true", "applicationUrl": "http://localhost:5000" } } }
And in the Startup.cs file:
public void ConfigureServices(IServiceCollection services) { services.AddControllers(); //services.AddSwaggerGen(c => //{ // c.SwaggerDoc("v1", new OpenApiInfo { Title = "FishWebServer", Version = "v1" }); //}); services.AddDbContext (options => options.UseSqlServer(Configuration.GetConnectionString("Fish"), sqlServerOptionsAction: sqlOptions => sqlOptions.EnableRetryOnFailure() )) ; } public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); //app.UseSwagger(); //app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "FishWebServer v1")); } app.UseRouting(); app.UseAuthorization(); app.UseEndpoints(endpoints => { endpoints.MapControllers(); }); }