Swashbuckle.AspNetCore: Swagger file generated in cli missing paths, components (Swashbuckle.AspNetCore.Cli 5.1.0)
During 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?
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 9
- Comments: 15 (4 by maintainers)
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);
I am having the same issue. Any work-arounds for this?