question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'No operations defined in spec!' problem after update of 'Microsoft.AspNetCore.Mvc.ApiExplorer' nuget

See original GitHub issue

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 ?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
erinevcommented, May 31, 2019

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: image 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

3reactions
erinevcommented, Jun 5, 2019

@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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Swashbuckle.AspNetCore: 'No operations defined in spec! ...
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 ...
Read more >
Swashbuckle.AspNetCore: 'No operations defined in spec! ...
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 ( / ......
Read more >
Get started with Swashbuckle and ASP.NET Core
Go to View > Other Windows > Package Manager Console · Navigate to the directory in which the .csproj file exists · Execute...
Read more >
How to use OpenAPI in Minimal API apps
Learn how to use OpenAPI (Swagger and Swashbuckle) features of minimal APIs in ASP.NET Core.
Read more >
Enriched Web API Documentation using Swagger/OpenAPI in ...
- Installing the Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer NuGet package. Our next step is to register some services and add some ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found