Skip to content

Commit e726639

Browse files
committed
fix: rendering of API Navigator with updated SwaggerUI
1 parent e06f992 commit e726639

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

public/index.html

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
max-width: 100px;
2424
}
2525

26-
.swagger-ui .topbar-wrapper .link img {
26+
.swagger-ui .topbar-wrapper .link {
2727
content: url('logo-light.svg');
2828
}
2929
</style>
@@ -118,6 +118,9 @@
118118
const defaultName = versions.find(version => version.default)?.name || versions.slice(-1)[0].name;
119119
const selectedName = urlName || defaultName;
120120

121+
// if UI is already annotated
122+
let annotated = false;
123+
121124
// initialize Swagger UI
122125
window.ui = SwaggerUIBundle({
123126
urls: urls,
@@ -130,29 +133,37 @@
130133
SwaggerUIStandalonePreset
131134
],
132135
layout: "StandaloneLayout",
133-
});
134-
135-
// handle "home" click
136-
const logo = document.querySelectorAll('.swagger-ui .topbar-wrapper .link')[0];
137-
logo.addEventListener('click', () => {
138-
window.location.href = window.location.href.split('?')[0];
139-
})
140-
141-
// attach custom labels
142-
for (const version of versions) {
143-
const option = document.querySelector(`#swagger-ui .topbar-wrapper select option[value="${version.file}"]`);
144-
const text = option.text;
145-
146-
if (version.environments.length) {
147-
option.text = `${text} - deployed on ${version.environments.join(', ')}`;
148-
continue;
149-
}
150-
151-
if (version.label) {
152-
option.text = `${text} - ${version.label}`;
153-
continue;
136+
onComplete: function() {
137+
if (annotated) {
138+
return;
139+
}
140+
141+
// handle "home" click
142+
const logo = document.querySelectorAll('.swagger-ui .topbar-wrapper .link')[0];
143+
144+
logo.addEventListener('click', () => {
145+
window.location.href = window.location.href.split('?')[0];
146+
});
147+
148+
// attach custom labels
149+
for (const version of versions) {
150+
const option = document.querySelector(`#swagger-ui .topbar-wrapper select option[value="${version.file}"]`);
151+
const text = option.text;
152+
153+
if (version.environments.length) {
154+
option.text = `${text} - deployed on ${version.environments.join(', ')}`;
155+
continue;
156+
}
157+
158+
if (version.label) {
159+
option.text = `${text} - ${version.label}`;
160+
continue;
161+
}
162+
}
163+
164+
annotated = true;
154165
}
155-
}
166+
});
156167
};
157168
</script>
158169

0 commit comments

Comments
 (0)