'No operations defined in spec!' problem after update of 'Microsoft.AspNetCore.Mvc.ApiExplorer' nuget
See original GitHub issueHi,
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.
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
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 ?
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (4 by maintainers)
i created demo repository with 100% reproducible problem.
Master branch: https://github.com/erinev/net-core-api-for-digging-swashbuckle-issue/tree/master uses following packages:
**note: “Microsoft.AspNetCore.Mvc.ApiExplorer” Version=“2.1.3” & “Swashbuckle.AspNetCore” Version=“4.0.1”
everything works after running solution and opening http://localhost:5000/swagger -> swagger UI displays ad relations controller and requests can be executed
i updated just “Microsoft.AspNetCore.Mvc.ApiExplorer” to 2.2.0 in branch:
ApiExplorer_2.2.0
PR: https://github.com/erinev/net-core-api-for-digging-swashbuckle-issue/pull/1/fileseverything compiles but when i open http://localhost:5000/swagger i see empty list of operations:
http://localhost:5000/swagger/v1/swagger.json outputs just:
cc: @MikeBeaton
@MikeBeaton your suggestion (comparing with default API template by MS) worked! 😃
i found and issue:
in order to make ApiExplorer v2.2.0 version work one line needs to be changed in .csproj of HOST project: from
<Project Sdk="Microsoft.NET.Sdk">
to<Project Sdk="Microsoft.NET.Sdk.Web">
just i don’t know why, but in default MS API template if i change Sdk to
Microsoft.NET.Sdk
it instantly stops workingi will go to google it what are the differences and is it safe to change to
.Web
skd