Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Swashbuckle.AspNetCore.SwaggerUI/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ window.onload = function () {
// Workaround for https://github.com/swagger-api/swagger-ui/issues/5945
configObject.urls.forEach(function (item) {
if (item.url.startsWith("http") || item.url.startsWith("/")) return;
item.url = window.location.href.replace("index.html", item.url).split('#')[0];
item.url = window.location.href.split(/[?#]/)[0].replace("index.html", item.url).split('#')[0];
});

// If validatorUrl is not explicitly provided, disable the feature by setting to null
Expand Down
17 changes: 17 additions & 0 deletions test/Swashbuckle.AspNetCore.IntegrationTests/UITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,25 @@ await fixture.VerifyPage(application.ServerUrl, async (page) =>
});
}

[Fact]
public async Task Relative_Document_Url_Does_Not_Inherit_Query_String_From_Page_Url()
{
await using var application = new RelativeDocumentUrlFixture();
var url = new Uri(new Uri(application.ServerUrl), "swagger/index.html?foo=bar");

await fixture.VerifyPage(url.ToString(), async (page) =>
{
var link = await page.WaitForSelectorAsync(".info .url");
var documentUrl = (await link.TextContentAsync())?.Trim();

Assert.EndsWith("/swagger/v1.json", documentUrl);
});
}

private sealed class RedocFixture : HttpApplicationFixture<ReDocApp.Program>;

private sealed class SwaggerUIFixture : HttpApplicationFixture<Basic.Startup>;

private sealed class RelativeDocumentUrlFixture : HttpApplicationFixture<TopLevelSwaggerDoc.Program>;
}
#endif