we have .net core 2.1 mvc webapi project which uses Swagger. we use following packages:
<PackageReference Include="Swashbuckle.AspNetCore" Version="3.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="3.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="4.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="2.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.1.1" />
swashbuckle is configured in following way:
services.AddMvcCore().AddVersionedApiExplorer();
services.AddApiVersioning();
services.AddSwaggerGen();
everything woks in such setup (/swagger/v1/swagger.json
has all operations and definitions and UI is rendered properly -> having all controllers and actions, etc)
we are trying to migrate our .net core project from 2.1 to 2.2 .net core.
In order to do that (without warnings) we need upgrade Microsoft.AspNetCore.Mvc.ApiExplorer
nuget from 2.1.2 to 2.2.0.
After this nuget update swagger.json (/swagger/v1/swagger.json
) doesn't contain any "paths": {}
and "definitions": {}
and this results in swagger UI showing no controllers/actions (it renders: No operations defined in spec!
after upgrade package these package versions is updated:
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="2.2.0" /> //was 2.1.2
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" /> //was 2.1.1
I've tried to upgrade swashbuckle version to v4.0.0 but it did not resolved the issue.
what im missing which packages needs to be updated also so swagger.json
would be generated properly when using Microsoft.AspNetCore.Mvc.ApiExplorer 2.2.0
package ?
or i'm missing something else ?
Just had the same issue, thought I'd share my solution too. Version 6.0.4.
I had to add the [ApiController] attribute to my controllers. Swagger must be using that for discovery.
change public methods in controllers to [NoAction] Attribute.
Also, Change all actions with explicit action Methods to [HttpGet("api/get-customer")], [HttpPost("api/save-customer")] instead of [Route("api/get-customer")].
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With