Created
April 17, 2026 12:15
-
-
Save freddi301/b4a3a605aa1410b704c01c72d83c529a to your computer and use it in GitHub Desktop.
Download all liferay open api specs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { writeFile, mkdir } from 'fs/promises'; | |
| import { dirname, join } from 'path'; | |
| const BASE_URL = 'http://localhost:8080'; | |
| const AUTH = 'Basic ' + Buffer.from('test@test.it:password').toString('base64'); | |
| const OUT_DIR = './openapi-specs'; | |
| console.log('Fetching API list...'); | |
| const res = await fetch(`${BASE_URL}/o/openapi`, { headers: { Authorization: AUTH } }); | |
| const data = await res.json(); | |
| console.log('Response:', JSON.stringify(data, null, 2)); | |
| // Extract all openapi.json URLs from the response | |
| const urls = Object.values(data).flat().filter(url => typeof url === 'string' && url.includes('openapi.yaml')); | |
| console.log(`Found ${urls.length} specs`); | |
| await Promise.all(urls.map(async url => { | |
| const name = url.replace(BASE_URL, ""); | |
| const file = join(OUT_DIR, name); | |
| console.log(`Downloading ${url} → ${file}`); | |
| await mkdir(dirname(file), { recursive: true }); | |
| await writeFile(file, await (await fetch(url, { headers: { Authorization: AUTH } })).text()); | |
| })) | |
| console.log(`Done! Specs saved to ${OUT_DIR}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment