Skip to content

Commit

Permalink
fix(plugin): allow Topbar plugin to read url param on load (#8168)
Browse files Browse the repository at this point in the history
* fix(plugin): allow Topbar plugin to read url param on load

* fix(plugin): add cypress tests for topbar w/o query config
  • Loading branch information
chadknight-wf committed Sep 21, 2022
1 parent 424d704 commit 94c70e2
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/plugins/topbar/topbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export default class Topbar extends React.Component {

if(urls && urls.length) {
var targetIndex = this.state.selectedIndex
let primaryName = configs["urls.primaryName"]
let search = parseSearch()
let primaryName = search["urls.primaryName"] || configs["urls.primaryName"]
if(primaryName)
{
urls.forEach((spec, i) => {
Expand Down
80 changes: 80 additions & 0 deletions test/e2e-cypress/static/pages/multiple-urls/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<!-- HTML for dev server -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Swagger UI</title>
<link rel="stylesheet" type="text/css" href="/swagger-ui.css" >
<link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32" />
<link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16" />
<style>
html
{
box-sizing: border-box;
overflow: -moz-scrollbars-vertical;
overflow-y: scroll;
}
*,
*:before,
*:after
{
box-sizing: inherit;
}
body {
margin:0;
background: #fafafa;
}
</style>
</head>

<body>

<div id="swagger-ui"></div>

<script src="/swagger-ui-bundle.js" charset="UTF-8"> </script>
<script src="/swagger-ui-standalone-preset.js" charset="UTF-8"> </script>
<script>
window.onload = function() {
window["SwaggerUIBundle"] = window["swagger-ui-bundle"]
window["SwaggerUIStandalonePreset"] = window["swagger-ui-standalone-preset"]
// Build a system
const ui = SwaggerUIBundle({
urls: [
{ name: "Petstore OAS", url: "/documents/petstore-expanded.openapi.yaml" },
{ name: "Petstore Swagger", url: "/documents/petstore.swagger.yaml" }
],
dom_id: '#swagger-ui',
presets: [
SwaggerUIBundle.presets.apis,
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout",
onComplete: () => {
if(window.completeCount) {
window.completeCount++
} else {
window.completeCount = 1
}
},
queryConfigEnabled: false,
})

window.ui = ui

ui.initOAuth({
clientId: "your-client-id",
clientSecret: "your-client-secret-if-required",
realm: "your-realms",
appName: "your-app-name",
scopeSeparator: " ",
additionalQueryStringParams: {}
})
}
</script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
describe("Loading specs by url.primaryName param", () => {
describe("with no param", () => {
it("should load the default spec", () => {
cy.visit("/pages/multiple-urls/index.html")
.get("span.url")
.contains("/documents/petstore-expanded.openapi.yaml")
})
})
describe("with an invalid param", () => {
it("should fall back to the default spec", () => {
cy.visit("/pages/multiple-urls/index.html?urls.primaryName=undefinedUrlName")
.get("span.url")
.contains("/documents/petstore-expanded.openapi.yaml")
})
})
describe("with a valid url.primaryName param", () => {
it("should render the requested spec", () => {
cy.visit("/pages/multiple-urls/index.html?urls.primaryName=Petstore Swagger")
.get("span.url")
.contains("/documents/petstore.swagger.yaml")
})
})
})

0 comments on commit 94c70e2

Please sign in to comment.