asp.net-coreswashbuckle.aspnetcore

NSwag generates openapi document, but Swashbuckle does not


I have an asp.net core 6.5.0 app with dotnet 7.0 using Controllers, and am trying to generate OpenApi json document for it.

Read the instructions in https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-6.0&tabs=visual-studio for both NSwag and Swashbuckle.

I tried with both, and for some reason Swashbuckle gives JSON that does not have any components or paths:

{
    "components": {},
    "info": {
        "title": "...",
        "version": "1.0"
    },
    "openapi": "3.0.1",
    "paths": {}
}

and changing it to NSwag produces a doc with all the endpoints and requests.

My controller is inherited from ControllerBase like so:

[ApiController]
[ApiVersion("1.0")]
[Route("/api/[controller]")]
public class SomeController : ControllerBase
{
  ...
  [HttpPost]
  [ProducesResponseType(StatusCodes.Status200OK)]
  [ProducesResponseType(StatusCodes.Status401Unauthorized)]
  public async Task<ActionResult<SomeResponse>> SomeAction([FromBody] SomeRequest req) { ... }
  ...
   
}

Anybody have an idea why Swashbuckle does not see the controller?

it was configured like this

builder.Services.AddControllers();
builder.Services.AddVersionedApiExplorer();
builder.Services.AddSwaggerGen();
...
app.UseSwagger();

Solution

  • Okay, at the end I followed the sample code at

    https://github.com/dotnet/aspnet-api-versioning/tree/ms/samples/aspnetcore/SwaggerSample

    and things started working and all API versions show up as openapi docs. no time to analyze why, but maybe this helps someone.