Swashbuckle.aspnetcore: Error after expanding operation in 5.0.0-RC4

Created on 1 Nov 2019  路  4Comments  路  Source: domaindrivendev/Swashbuckle.AspNetCore

Attempting to expand 2/4 operations in this service causes about 100 of the errors below to appear.

Resolver error at paths./v1/manifest/{dashboardId}/{dataSetId}/{accountId}.post.responses.200.content.application/json.schema.additionalProperties.oneOf.0.properties.children.items.oneOf.0.$ref
Could not resolve reference:
Resolver error at paths./v1/manifest/{dashboardId}/{dataSetId}/{accountId}.post.responses.200.content.application/json.schema.additionalProperties.oneOf.0.properties.children.items.oneOf.1.properties.children.items.oneOf.1.$ref
Could not resolve reference:
Resolver error at paths./v1/manifest/{dashboardId}/{dataSetId}/{accountId}.post.responses.200.content.application/json.schema.additionalProperties.oneOf.0.properties.children.items.oneOf.1.properties.children.items.oneOf.2.properties.children.items.oneOf.2.$ref

This does not occur on 5.0.0-RC2 with the same code base. It is unclear if the issue is related to the UI or the swagger.json that is generated (I attempted to diff but there were a lot of ordering changes).

See attached swagger.json.
swagger.txt

Also when this occurs it looks like the UI is attempting to pull swagger.json a second time, but from an incorrect URL.

image

Initial URL: https://xxxx/reports/dashboard/swagger/v1/swagger.json
Second URL: https://xxxx/reports/dashboard/swagger/swagger/v1/swagger.json

needs investigation

Most helpful comment

I'm having the same issue with 5.0.0-rc4
It returns a 404 error while trying to fetch swagger.json when an operation is expanded. This is the URL requested at this moment:

https://localhost:44329/swagger/v1/v1/swagger.json

And this is the correct URL requested when swagger is accessed, which returns the proper file:

https://localhost:44329/swagger/v1/swagger.json

It seems that when an operation is expanded it's looking for the swagger.json file on a incorrect route, causing the error.

This is my Startup configuration:
app.UseSwagger().UseSwaggerUI(c => c.SwaggerEndpoint("v1/swagger.json", "v1"));

All 4 comments

I'm having the same issue with 5.0.0-rc4
It returns a 404 error while trying to fetch swagger.json when an operation is expanded. This is the URL requested at this moment:

https://localhost:44329/swagger/v1/v1/swagger.json

And this is the correct URL requested when swagger is accessed, which returns the proper file:

https://localhost:44329/swagger/v1/swagger.json

It seems that when an operation is expanded it's looking for the swagger.json file on a incorrect route, causing the error.

This is my Startup configuration:
app.UseSwagger().UseSwaggerUI(c => c.SwaggerEndpoint("v1/swagger.json", "v1"));

Got the same issue when with 5.0.0 stable.

This works for both for an application in the root of the domain, as when running in a subdirectory. Got the idea from #903.

It now both works when hosting in a subdirectory and in the root of the webserver.

return app
    .UseSwagger(options => {
        options.PreSerializeFilters.Add((swaggerDoc, httpRequest) => {
            swaggerDoc.Servers = new List<OpenApiServer> {new OpenApiServer {Url = $"{httpRequest.Scheme}://{httpRequest.Host.Value}/{httpRequest.PathBase}"}};
        });
        options.RouteTemplate = "{documentName}/swagger.json";
    })
    .UseSwaggerUI(options => {
        var appVersion = typeof(Program).Assembly.GetName().Version.ToString(2);
        var appName = typeof(Program).Assembly.GetCustomAttribute<AssemblyProductAttribute>().Product;

        options.SwaggerEndpoint(
            $"../v{appVersion}/swagger.json",
            "My API v" + appVersion
        );
    });

Still actual for the latest stable version 5.2.1
If you need generated schema, I can provide it

This is a dup of #1545. See my comment in that thread for a description of the root cause, why it's in fact an upstream issue with the swagger-ui library, and a potential workaround.

Was this page helpful?
0 / 5 - 0 ratings