Skip to content

Commit d919af0

Browse files
committed
fix: Use buildSpecUrl for initial spec URL in swagger-ui.html
- Removed adjustSpecPath() function that was keeping URLs as relative paths - Now buildSpecUrl() is used to convert relative paths to GitHub tag URLs based on version parameter - This fixes the issue where opening index.html locally would show 'Service Specification Not Available' error - Swagger UI now correctly loads specs from GitHub tags when version parameter is provided
1 parent e3e8934 commit d919af0

1 file changed

Lines changed: 7 additions & 18 deletions

File tree

docs/swagger-ui.html

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -386,35 +386,25 @@ <h1>AAS API Documentation - Swagger UI</h1>
386386
<script>
387387
// Get URL parameter or default
388388
const urlParams = new URLSearchParams(window.location.search);
389-
let specUrl = urlParams.get('url') || '../Entire-API-Collection/V3.2.yaml';
390389
const version = urlParams.get('version') || 'v3.2.0';
390+
const rawUrl = urlParams.get('url') || '../Entire-API-Collection/V3.2.yaml';
391391

392-
// Adjust path based on environment
393-
function adjustSpecPath(url) {
394-
// If it's already a full GitHub URL, return as-is
395-
if (url.startsWith('http://') || url.startsWith('https://')) {
396-
return url;
397-
}
398-
399-
// For local relative paths (../), keep them as-is
400-
// This allows Swagger UI to properly resolve $ref references
401-
// that are also relative in the YAML files
402-
return url;
403-
}
392+
// Build the actual spec URL based on version
393+
const specUrl = buildSpecUrl(version, rawUrl);
404394

405395
// Initialize Swagger UI
406396
function initSwaggerUI(url) {
407-
const adjustedUrl = adjustSpecPath(url);
397+
// URL is already built by buildSpecUrl, use it directly
408398

409399
// First check if the spec file exists
410-
fetch(adjustedUrl, { method: 'HEAD' })
400+
fetch(url, { method: 'HEAD' })
411401
.then(response => {
412402
if (!response.ok) {
413403
throw new Error('Spec not found');
414404
}
415405
// File exists, initialize Swagger UI
416406
window.ui = SwaggerUIBundle({
417-
url: adjustedUrl,
407+
url: url,
418408
dom_id: '#swagger-ui',
419409
deepLinking: true,
420410
presets: [
@@ -505,8 +495,7 @@ <h3 style="color: #856404; margin-top: 0; display: flex; align-items: center; ga
505495

506496
// Set dropdown to current spec
507497
const select = document.getElementById('specSelect');
508-
const adjustedSpecUrl = adjustSpecPath(specUrl);
509-
select.value = adjustedSpecUrl;
498+
select.value = specUrl;
510499

511500
// Handle spec changes
512501
select.addEventListener('change', function(e) {

0 commit comments

Comments
 (0)