|
23 | 23 | max-width: 100px; |
24 | 24 | } |
25 | 25 |
|
26 | | - .swagger-ui .topbar-wrapper .link img { |
| 26 | + .swagger-ui .topbar-wrapper .link { |
27 | 27 | content: url('logo-light.svg'); |
28 | 28 | } |
29 | 29 | </style> |
|
118 | 118 | const defaultName = versions.find(version => version.default)?.name || versions.slice(-1)[0].name; |
119 | 119 | const selectedName = urlName || defaultName; |
120 | 120 |
|
| 121 | + // if UI is already annotated |
| 122 | + let annotated = false; |
| 123 | + |
121 | 124 | // initialize Swagger UI |
122 | 125 | window.ui = SwaggerUIBundle({ |
123 | 126 | urls: urls, |
|
130 | 133 | SwaggerUIStandalonePreset |
131 | 134 | ], |
132 | 135 | 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; |
154 | 165 | } |
155 | | - } |
| 166 | + }); |
156 | 167 | }; |
157 | 168 | </script> |
158 | 169 |
|
|
0 commit comments