UNPKG

@apistudio/apim-cli

Version:

CLI for API Management Products

83 lines (69 loc) 2.81 kB
// Schema Test - Tests the getSchema functionality from runtimeInventory import { runtimeInventory } from './dist/index.js'; console.log('=== Testing JSON imports and schema retrieval ===\n'); // Get the embedded JSON data from runtimeInventory const defaultVersions = runtimeInventory.getDefaultVersions(); const combinedSource = runtimeInventory.schemaDefinitions || {}; // Display information about the embedded JSON data console.log('Default Versions:'); console.log(`- Total entries: ${Object.keys(defaultVersions).length}`); console.log('- Sample entries:'); Object.entries(defaultVersions).slice(0, 3).forEach(([key, value]) => { console.log(` - ${key}: ${value}`); }); console.log('\nCombined Source:'); console.log(`- Total entries: ${Object.keys(combinedSource).length}`); console.log('- Sample keys:'); Object.keys(combinedSource).slice(0, 3).forEach(key => { console.log(` - ${key}`); }); // Use the getSchema function from runtimeInventory function getSchema(name, version) { return runtimeInventory.getSchema(name, version); } function getLintRules(name, version) { return runtimeInventory.getLintRuleset(name, version); } // Test cases const tests = [ { name: 'API', version: 'api.ibm.com/v1', description: 'Explicit version' }, { name: 'API', description: 'Default version' }, { name: 'Plan', description: 'Another schema' }, { name: 'AuthorizeUser', version: 'api.ibm.com/v1', description: 'Another valid schema' }, { name: 'nonexistent', version: '1.0.0', description: 'Non-existent name' } ]; // Run tests console.log('\n=== Test Results ==='); tests.forEach((test, index) => { console.log(`\n${index + 1}. ${test.description}: getSchema('${test.name}'${test.version ? `, '${test.version}'` : ''})`); try { const schema = getSchema(test.name, test.version); if (schema) { console.log('✅ Schema found!'); console.log(' Type:', typeof schema); // Show a sample of the schema const sampleText = typeof schema === 'string' ? schema.substring(0, 80) : JSON.stringify(schema).substring(0, 80); console.log(` Sample: ${sampleText}...`); } else { console.log('❌ Schema not found'); } const rules= getLintRules(test.name, test.version) if (rules) { console.log('✅ rules found!'); console.log(' Type:', typeof rules); console.log('Rule: '+ rules.toString()); // Show a sample of the schema const sampleText = typeof rules === 'string' ? rules.substring(0, 80) : JSON.stringify(rules).substring(0, 80); console.log(` Sample: ${sampleText}...`); } else { console.log('❌ rules not found'); } } catch (error) { console.error(' Error:', error.message); } }); // Made with Bob