File size: 1,198 Bytes
74bd902
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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');