Hi,
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 ?
Is it worth trying a newer version of Swashbuckle.AspNetCore? https://www.nuget.org/packages/Swashbuckle.AspNetCore
@MikeBeaton hi,
i forgot to mention that i tried to update Swashbuckle.AspNetCore to v4.0.0 but it was still not working at the same while having ApiExplorer with v2.2.0
i will try to create a mockup repo in public github with reproduced scenario
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:
<PackageReference Include="Microsoft.AspNetCore.Mvc.ApiExplorer" Version="2.1.3" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.2.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="4.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="4.0.1" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="4.5.5" />
**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/files
everything compiles but when i open http://localhost:5000/swagger i see empty list of operations:

http://localhost:5000/swagger/v1/swagger.json outputs just:
{
"swagger": "2.0",
"info": {
"version": "v1",
"title": "Ad Relations Reader",
"description": "Ad Relations Reader."
},
"paths": {},
"definitions": {}
}
cc: @MikeBeaton
I do get the symptoms you describe, and I am not quite sure what is going on but I don't think the problem is with Swashbuckle.AspNetCore.
If I run your example with Microsoft.AspNetCore.Mvc.ApiExplorer version 2.1.3 then at line 48 of src/Swashbuckle.AspNetCore.SwaggerGen/Generator/SwaggerGenerator.cs _apiDescriptionsProvider.ApiDescriptionGroups.Items contains 1 item for your GetByAdUuid. But if I run the example after upgrading to Microsoft.AspNetCore.Mvc.ApiExplorer version 2.2.0 then _apiDescriptionsProvider.ApiDescriptionGroups.Items contains no items. Which is where the problem lies.
I saw this by cloning Swashbuckle.AspNetCore locally, checking out v4.0.1 and then compiling your project directly with the required Swashbuckle.AspNetCore projects instead of the NuGet packages. Doing that, everything runs exactly the same (including that Microsoft.AspNetCore.Mvc.ApiExplorer 2.1.3 works but 2.2.0 doesn't), but now you can step in to and put breakpoints on the Swashbuckle.AspNetCore code and see what is happening.
Since the value of _apiDescriptionsProvider at that point is an instance of the Microsoft class Microsoft.AspNetCore.Mvc.ApiExplorer.ApiDescriptionGroupCollectionProvider, which has just been injected by Microsoft code (and which I don't think you have even configured?), then I think the problem lies outside Swashbuckle.AspNetCore.
@MikeBeaton thanks for deep investigation.
i liked the way you checked the issue.
Maybe you still have compiling code with Swashbuckle.AspNetCore added as project instead of nuget ? if yes maybe you can fork my demo repository and push changes i would create issue to Microsoft.AspNetCore.Mvc.ApiExplorer repository (by providing them debuggable Swashbuckle example) maybe they will help to understand why this is happening
if no i will try to add Swashbuckle locally my self (i want to save time if you still have the code)
Hi @erinev, I'm glad it helped.
You should reproduce my steps yourself, at this point.
git clone the Swashbuckle.AspNetCore project, so that you have your own local copySwashbuckle.AspNetCore then it might be easier to make your own fork first, and clone from thatcd into the Swashbuckle.AspNetCore project directory and git checkout v4.0.1Swashbuckle.AspNetCore packages from your projectSwashbuckle.AspNetCore.Filters project, since it's in a separate repoAdd existing project... twice, for the two .csproj files in the Swashbuckle.AspNetCore repo corresponding to the two NuGet packages which you just removedAdd existing project... for those three as well (no need to add any more project dependencies at this point)Okay, what I would do next:
IApiDescriptionGroupCollectionProvider (which you will see in the code is what the Swashbuckle Swagger generator is accepting), and which maybe just returns an integer for how many items are in its .ApiDescriptionGroups.ItemsMicrosoft.AspNetCore.Mvc.ApiExplorer version 2.1.3 it contains metadata about all your controllers, and on 2.2.0 it contains empty metadata (I don't know why, but that is the symptom you are seeing)2.1.3 but is empty in 2.2.0)startup.cs and NuGet dependencies, and check that the problem still replicatesBy this point, you will either have a very minimal example of something which works fine with Microsoft.AspNetCore.Mvc.ApiExplorer version 2.1.3 and which doesn't work but should with Microsoft.AspNetCore.Mvc.ApiExplorer version 2.2.0 (and not involving Swashbuckle.AspNetCore at all), or else you will maybe have realised what it was about your specific config setup which was causing the problem.
Obviously, report back if after stripping things back like this, you still find that you think that the problem lies in Swashbuckle.AspNetCore and not the Microsoft project.
HTH ;)
Thanks for detailed instructions and hints what to do next, i will try it and i will update you with results
Update on the issue:
In master branch: https://github.com/erinev/net-core-api-for-digging-swashbuckle-issue/tree/master
i left one project (Host) and also i removed all code which is not essential for swashbuckle to work
everything works with ApiExplorer 2.1.3.
i created a branch: https://github.com/erinev/net-core-api-for-digging-swashbuckle-issue/pull/2/files where i update ApiExplorer to 2.2.0.
and ofcourse swagger is not rendered.
but what i noticed that not just swagger is no longer works actually all mvc routing stops working.
it is not possible to perform GET request from browser (it returns 404)
after running project f5 and opening url: http://localhost:5000/v1/demo/resource in master branch ir works (returns string) in branch it returns 404 even though routing stayed the same
so problem is really not in the swashbuckle, but our project setup (or some missing nuget packages)
i also created branch with removed swashbuckle: https://github.com/erinev/net-core-api-for-digging-swashbuckle-issue/tree/remove_swashbuckle
And after update of ApiExplorer to 2.2.0: https://github.com/erinev/net-core-api-for-digging-swashbuckle-issue/pull/3
routings stops working and all requests returns 404
so problem really lies somewhere else
Hi. That's great. If you're happy that this issue doesn't lie with this repo, then you should probably close off this issue, if that's okay?
Just in the spirit of continuing to help, what I would try next is...
Create a brand new project - either directly from, or as close as possible to, a .NET Core project template - using ApiExplorer 2.2.0, just to prove to yourself that it does work sometimes
Modify the working ApiExplorer 2.2.0 project and your non-working project step by step until they are the same - at which point you will have found out how to make yours work, or what step stops the other one from working!
Keep me posted if you like but also, as I say, if the issue isn't here then probably close off this issue? Thanks!
ok i will close this issue, thanks for another notes.
@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 working
i will go to google it what are the differences and is it safe to change to .Web skd
@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 toMicrosoft.NET.Sdkit instantly stops workingi will go to google it what are the differences and is it safe to change to
.Webskd
For others attempting the fix quoted, you may have to recreate your publish profile(s) to be of the Web project type, since the shape and parameters in them are different. After that, it worked perfectly :)
Most helpful comment
@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.Sdkit instantly stops workingi will go to google it what are the differences and is it safe to change to
.Webskd