How to set up Swashbuckle vs Microsoft.AspNetCore.Mvc.Versioning

At the moment Swashbuckle and Microsoft.AspNetCore.Mvc.Versioning are friends. It works good. I just created test project in VS2017 and checked how it works. First include these two nuget packages: <PackageReference Include=”Microsoft.AspNetCore.Mvc.Versioning” Version=”1.2.1″ /> <PackageReference Include=”Swashbuckle.AspNetCore” Version=”1.0.0″ /> Configure everything in Startup.cs (read my comments): public void ConfigureServices(IServiceCollection services) { services.AddMvc(); // Configure versions services.AddApiVersioning(o => … Read more

Not supported by Swagger 2.0: Multiple operations with path

In the file AppStart/SwaggerConfig.cs First one, you must import Linq using System.Linq; And add in the same file, this line c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First()); just inside of: GlobalConfiguration.Configuration .EnableSwagger(c => { … One consideration: In your controllers, you must use the Http methods : [HttpGet] [Route(“something”)] public List<model> something(){….} [HttpGet] [Route(“something2”)] public List<model2> something2(){….} [HttpPost] [Route(“mypost1”)] … Read more

Is there a way change the Controller’s name in the swagger-ui page?

Starting with ASP.NET Core 6, you can use the TagsAttribute either on Controller level: [Tags(“entity”)] [ApiController] public class DerivedEntitiesController : ControllerBase { or on Action level: [Tags(“entity”)] [HttpPut(“entity/{key}”)] public IActionResult PutEntity(Guid key, [FromBody] Entity entity) { Swagger will group according to the Tags and respect API Versioning.

How do I generate API documentation for SignalR

Here’s a Nuget package which can help you. Nuget link: https://www.nuget.org/packages/SignalRSwaggerGen/ Github link: https://github.com/essencebit/SignalRSwaggerGen/wiki First you need to decorate your SignalR hubs with attributes from SignalRSwaggerGen.Attributes namespace: [SignalRHub] public class SomeHub : Hub { } Then you add SignalRSwaggerGen to Swagger generator: services.AddSwaggerGen(options => { options.SwaggerDoc(“v1”, new OpenApiInfo { Title = “Some API v1”, Version … Read more

Enable bearer token in Swashbuckle (Swagger document)

Update The issue detailed below is now resolved in Swashbuckle v5.5.0. Issue Just ran into the exact same issue. I think the root cause is this line in Swashbuckle’s source code: var key = encodeURIComponent($(‘#input_apiKey’)[0].value); This is where the value from the HTML input field goes through URL encoding turning the space into %20. I’m … Read more

What is AddEndpointsApiExplorer in ASP.NET Core 6

AddEndpointsApiExplorer is for Minimal APIs whereas AddApiExplorer requires, at least, MVC Core. For API projects, AddControllers calls AddApiExplorer on your behalf. But Why Does Everything Still Work With AddEndpointsApiExplorer? With the introduction of Endpoint Routing, everything in the routing system boils down to an Endpoint. ASP.NET Core uses the Application Model, namely ApplicationModel, ControllerModel, and … Read more

What is Swagger, Swashbuckle and Swashbuckle UI

Swagger is a notation/rules to write documentation. But why is it called a framework(Like angular/MVC)? It is probably called a “framework” because its’ purpose is to offer a systematic way of notating the interface of any RESTful service under the OpenAPI Specification. This is a big deal to developers because the spec is overseen by … Read more

swagger .net core API ambiguous HTTP method for Action Error

This can occur when a method is declared public in a controller, but without REST attributes. Changing the method to protected may address the issue. I have seen this kind of error before and usually the error message points to the culprit: EBisAPI.Controllers._class.HandleError I guess HandleError is a public method in your base class, right? … Read more

JWT Authentication and Swagger with .NET Core 3.0

After some research, I eventually found the answer here Before seeing this page, I knew that I should use AddSecurityRequirement after AddSecurityDefinition because of many samples, but it was a problem that the function parameters have changed on .NET Core 3.0. By the way, the final answer is as below: services.AddSwaggerGen(c => { c.SwaggerDoc(“v1”, new … Read more