Skip to content

Commit 6df9707

Browse files
committed
fix: handle multi-segment API path by passing base URL from data attributes
Signed-off-by: Yash-Raj-5424 <myash3499@gmail.com>
1 parent 96ce9d9 commit 6df9707

2 files changed

Lines changed: 5 additions & 6 deletions

File tree

layouts/partials/rest-apis/viewer.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ <h3 id="server-urls-{{ $operationId }}">Try this endpoint</h3>
404404
{{ range $server := $servers }}
405405
{{ $serverUrl := index $server "url" | default "" }}
406406
{{ $serverDescription := index $server "description" | default "Layer5 Cloud URL" }}
407-
<div class="rest-api-try-item">
407+
<div class="rest-api-try-item" data-base-url="{{ $serverUrl }}">
408408
<p class="rest-api-try-item__label">{{ $serverDescription }}</p>
409409
<code class="rest-api-try-item__url">{{ printf "%s%s" $serverUrl $operationPath }}</code>
410410
</div>

static/js/rest-api-executor.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -180,11 +180,10 @@ class RESTAPIExecutor {
180180
if (!trySection) return ['https://cloud.layer5.io'];
181181

182182
const servers = [];
183-
const urlElements = trySection.querySelectorAll('.rest-api-try-item__url');
184-
urlElements.forEach(el => {
185-
const url = el.textContent.trim();
186-
const baseUrl = url.replace(/\/[^/]*$/, ''); // Remove path, keep base
187-
if (!servers.includes(baseUrl)) {
183+
const tryItems = trySection.querySelectorAll('.rest-api-try-item');
184+
tryItems.forEach(item => {
185+
const baseUrl = item.dataset.baseUrl;
186+
if (baseUrl && !servers.includes(baseUrl)) {
188187
servers.push(baseUrl);
189188
}
190189
});

0 commit comments

Comments
 (0)