Spaces:
Sleeping
Sleeping
const axios = require('axios'); | |
const yaml = require('js-yaml'); | |
async function testUrl(apiUrl) { | |
try { | |
const result = await axios.get(apiUrl); | |
console.log(`SUCCESS: FETCH ${apiUrl}`); | |
let schemaText = result.data; | |
console.log(`SUCCESS: READ DATA from ${apiUrl}`); | |
let parsedSchema; | |
if (apiUrl.endsWith('.yaml') || apiUrl.endsWith('.yml')) { | |
parsedSchema = yaml.load(schemaText); | |
console.log(`SUCCESS: RESOLVE FROM YAML ${apiUrl}`); | |
} else { | |
if (typeof schemaText === 'string') { | |
try { | |
schemaText = JSON.parse(schemaText); | |
console.log(`SUCCESS: PARSE JSON from ${apiUrl}`); | |
} catch (error) { | |
console.error(`FAILURE: PARSE JSON from ${apiUrl} with error = ${error}`); | |
throw error; | |
} | |
} | |
parsedSchema = schemaText; | |
console.log(`SUCCESS: RESOLVE FROM JSON ${apiUrl}`); | |
} | |
console.log(`Parsed schema from ${apiUrl}:`, parsedSchema); | |
} catch (error) { | |
console.error(`Failed to load spec from ${apiUrl}`, error); | |
} | |
} | |
// Replace with the URL you want to test | |
testUrl('https:api.elevenlabs.io/openapi.json'); | |
testUrl('https:api.replicate.com/openapi.json'); | |