Swagger file generated in cli missing paths, components (Swashbuckle.AspNetCore.Cli 5.1.0)
See original GitHub issueDuring the build process we are trying to generate the swagger.json
file.
We are using the following command:
dotnet swagger tofile .\bin\Debug\netcoreapp3.1\myWebService.dll v1
The output that gets generated:
{
"openapi": "3.0.1",
"info": {
"title": "myWebService",
"description": "myWebService",
"contact": {
"name": "John Doe",
"email": "john.doe@example.com"
},
"license": {
"name": "MIT",
"url": "https://opensource.org/licenses/MIT"
},
"version": "1.0"
},
"paths": { },
"components": { }
}
As you can see, the paths
and components
are empty. There are no errors or warnings shown from the CLI tool.
However, if we take the swagger.json
from the service (http://localhost:57016/swagger/v1/swagger.json), it includes all the relevant paths
and components
.
Can you please clarify how can we achieve the same output in CLI as from the web service?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:15 (4 by maintainers)
Top Results From Across the Web
Error while generating swagger.json with Swashbuckle. ...
and my Program.cs file is: using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.Extensions.
Read more >Aspnetcore 3.0 使用Swagger - microestc
The Swashbuckle CLI tool can retrieve Swagger JSON directly from your application startup assembly, and write it to file. This can be useful...
Read more >Get started with Swashbuckle and ASP.NET Core
SwaggerGen : a Swagger generator that builds SwaggerDocument objects directly from your routes, controllers, and models. It's typically combined ...
Read more >Swashbuckle CLI: Automating ASP.NET Core API Swagger ...
In this article, we will discuss automatically generating Swagger JSON files in ASP.NET Core via the Swashbuckle CLI. If you are an ASP....
Read more >Swagger in ASP.Net Core (Using Swashbuckle.AspNetCore ...
Steps to follow: NuGet Package Manager: Install-Package Swashbuckle. AspNetCore -Version 5.1.0 Startup.cs Inside of ConfigureServices method, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hello,
I’m not sure if it will help, but let’s give it a try.
I had a similar problem, but with custom
SwaggerHostFactory.CreateHost
. Thedotnet swagger tofile (...)
returned incomplete swagger definition:Everything worked just fine:
SwaggerHostFactory.CreateHost
during application startup:To resolve this issue I had to set a value for application name, so finally my
SwaggerHostFactory.CreateHost
looks like that:Problem might be related to
Microsoft.Extensions.DependencyInjection.MvcCoreServiceCollectionExtensions.GetApplicationPartManager
which initializesMicrosoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartManager
and callsvoid PopulateDefaultParts(string entryAssemblyName)
, whereentryAssemblyName
is set toenvironment?.ApplicationName
. It is called only for not empty, or null values.Why do I think so?
During normal runtime,
feature.Controllers
has records for each controller from my project, and duringdotnet swagger tofile (...)
it is empty,Cheers,
I ran across this when using
Swashbuckle.AspNetCore.Cli v6.4.0
, in anet7.0
API project. When usingvar builder = WebApplication.CreateBuilder();
, this results in the following empty Open API document.But to resolve this, simply pass
args
to theCreateBuilder
method. I found that this results in a fully built Open API file.var builder = WebApplication.CreateBuilder(args);