Mark strings as non-nullable in ASP.NET Core 3.0 Swagger

You can now use nullable reference types to mark strings as optional or required: Enable nullable reference types for your project/solution Mark strings in Dtos as nullable: public class ExampleDto { [StringLength(64, MinimumLength = 4)] public string RequiredString { get; set; } [StringLength(200)] public string? OptionalString { get; set; } } Enable Swagger support in … Read more

Swashbuckle parameter descriptions

With the latest Swashbuckle, or better said at least the Swashbuckle.AspNetCore variant which I’m using, the Description field for parameters can now be displayed correctly as output. It does require the following conditions to be met: XML comments must be enabled and configured with Swagger Parameters should be explicitly decorated with either [FromRoute], [FromQuery], [FromBody] … Read more

Grouping of API methods in documentation – is there some custom attribute

You could also use SwaggerOperationAttribute: public class UserController : ApiController { [Route(“api/user”)] [SwaggerOperation(Tags = new[] { “User” })] IHttpActionResult GetUser() { … } } public class ResumeController : ApiController { [Route(“api/user/resumes”)] [SwaggerOperation(Tags = new[] { “User” })] IHttpActionResult GetResumes() { … } }

Swashbuckle 5 can’t find my ApiControllers

I got stuck.. and these answers didn’t help me fully… although they led me there. Just to save other people some time: You have to pass the http config from OWIN and then register on that instead of using the GlobalConfiguration class like so: //starup.cs public void Configuration(IAppBuilder app) { Config = new HttpConfiguration(); WebApiConfig.Register(Config); … Read more

NSwag vs Swashbuckle [closed]

I would like to share information that I have found so far. It doesn’t answer my question but might be useful for others. I found a comment from RicoSuter who develops NSwag: NSwag not only provides the functionality of Swashbuckle (Swagger generation) but also code generators. This way we can avoid incompatibilities and offer more … Read more

How to make Swagger show examples of objects returned from the API?

That should be pretty straightforward: [Route(“{organizationSys:int}”)] [ProducesResponseType(typeof(List<Door>), 200)] [ProducesResponseType(typeof(string), 400)] public IHttpActionResult Get(int organizationSys) Note that since you have 2 exit points: one normal return with data, and a catch that returns error message, I’ve defined in the example above two possible result types: http:200(OK) with List<Door> http:400(BadRequest) with string Swashbuckle Swagger infrastructure will read … Read more

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

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

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.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)