New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Swagger file generated in cli missing paths, components (Swashbuckle.AspNetCore.Cli 5.1.0) #1580
Comments
I've no idea why this might happen - could you create a minimal project that repro's the issue and post to github. Without a simple repro, it's hard for me to troubleshoot. |
I created an example project and uploaded it here: https://github.com/kepalas/Swashbuckle.Repro |
Same issue with |
I've taken a quick look and I don't think the root cause lies in the Swashbuckle library. I believe it's related to the custom So, it might be worth digging deeper into this component. @commonsensesoftware any ideas on what might be going on here? |
@domaindrivendev, I don't fully know or understand the initialization steps that the CLI code path takes. Based on what @kepalas has demonstrated, things definitely went all the way through the I'll try to keep this succinct, but I think it's worth clarifying what happens on the API Versioning side for OData. Ultimately, it's a consequence of OData's design. The normal setup expects the following to happen in app.UseMvc(routes => routes.MapVersionedODataRoutes("odata", null, builder.GetEdmModels())); OData provides no intrinsic way to track or otherwise know which routes have been registered. In particular, there needs to be a way to know the pairing of route, EDM, and API version in order to support API exploration. API Versioning adds a service called IODataRouteCollection, which contains ODataRouteMapping instances. This collection is appended after every call to ActionDescriptor instances are required to build ApiDescription instances (as you know). The default OData implementation excludes all actions from Sooo ... long explanation, not so short... If Hopefully, that provides context and we can start whittling down to where the source of the problem lies. |
I am having the same issue. Any work-arounds for this? |
@kepalas @manisha201301 @commonsensesoftware revisiting this issue ... I just cracked open the repro project again, and even used the following approach (https://github.com/domaindrivendev/Swashbuckle.AspNetCore#use-the-cli-tool-with-a-custom-host-configuration) to ensure the CLI tool runs in an identical host setup to the application itself, but still the same issue. Have to say, I'm completely stumped at this point!!! So, any assistance to dig deeper and try figure it out would be greatly appreciated. |
Without walking through all of the code myself, it's hard to be sure. I spent some time looking at all the moving parts and it looks right. A couple of questions:
I couldn't find exactly where the code is (anymore), but I know that the If I have time, I'll try to dive in deeper. If That's my observations so far. I hope that helps. |
@commonsensesoftware a combination of your insights above and another unrelated-but-actually-related issue (see #1957) are leading me to the root cause ... With it's current implementation, the CLI tool builds an |
@domaindrivendev excellent! My recommendation as a starting point would be to checkout the Test Host. You can probably use it in its entirety, but if not, it should provide a lot of good pointers on hosting without hosting. The TestServer doesn't actually host any endpoints. |
Hello, I'm not sure if it will help, but let's give it a try. I had a similar problem, but with custom {
"openapi": "3.0.1",
"info": {
"title": "(...)",
"version": "v1"
},
"paths": { },
"components": {
"securitySchemes": {
"Bearer": {
"type": "http",
"description": "Bearer token for the API to authenticate incoming requests.",
"scheme": "bearer"
}
}
},
"security": [
{
"Bearer": [ ]
}
]
} Everything worked just fine:
(...)
var host = SwaggerHostFactory.CreateHost();
var swaggerProvider = host.Services.GetRequiredService<ISwaggerProvider>();
(...) To resolve this issue I had to set a value for application name, so finally my /// <summary>
/// Custom <see cref="IHost"/> factory used for API client generation.
/// </summary>
public class SwaggerHostFactory
{
public static IHost CreateHost()
{
var builder = WebApplication.CreateBuilder(new WebApplicationOptions
{
ApplicationName = typeof(SwaggerHostFactory).Namespace // without it, actions won't be added to swagger file
});
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSynergySwaggerGen(options =>
{
options.SwaggerDoc("v1", new() { Title = "...", Version = "v1" });
(...)
});
var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint(...);
(...)
});
app.MapControllers();
return app;
}
} Problem might be related to private static ApplicationPartManager GetApplicationPartManager(IServiceCollection services, IWebHostEnvironment? environment)
{
var manager = GetServiceFromCollection<ApplicationPartManager>(services);
if (manager == null)
{
manager = new ApplicationPartManager();
var entryAssemblyName = environment?.ApplicationName;
if (string.IsNullOrEmpty(entryAssemblyName))
{
return manager;
}
manager.PopulateDefaultParts(entryAssemblyName);
}
return manager;
} Why do I think so? var partManager = app.Services.GetRequiredService<ApplicationPartManager>();
var feature = new ControllerFeature();
partManager.PopulateFeature(feature); During normal runtime, Cheers, |
This also seems to solve my problem. As far as I see, you need to set the |
I ran across this when using {
"openapi": "3.0.1",
"info": {
"title": "My API",
"version": "V1"
},
"paths": { },
"components": { }
} But to resolve this, simply pass
|
This is still a problem in 6.5.0 |
Same here, I'm using .net 7 with minimal API's. |
facing the same issue with |
Duplicate of #1957 |
During the build process we are trying to generate the
swagger.json
file.We are using the following command:
The output that gets generated:
As you can see, the
paths
andcomponents
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 relevantpaths
andcomponents
.Can you please clarify how can we achieve the same output in CLI as from the web service?
The text was updated successfully, but these errors were encountered: