UNPKG

@apistudio/apim-cli

Version:

CLI for API Management Products

105 lines (86 loc) 3.71 kB
// Schema Test - Tests the schema functionality from wmgw_runtimeinventry import { LWGWRuntimeInventory } from './dist/index.js'; // Import the combined source directly for testing import fs from 'fs'; import path from 'path'; console.log('=== Testing LWGWRuntimeInventory Schema Functionality ===\n'); // Create an instance of LWGWRuntimeInventory const inventory = new LWGWRuntimeInventory(); // Load the combined-source.json file directly for testing const combinedSourcePath = path.resolve('./generated/combined-source.json'); const combinedSource = JSON.parse(fs.readFileSync(combinedSourcePath, 'utf8')); console.log(`Combined Source loaded: ${Object.keys(combinedSource).length} schemas available`); console.log('Sample schema keys:'); Object.keys(combinedSource).slice(0, 3).forEach(key => { console.log(`- ${key}`); }); // Extract the kinds from the schemas for testing const schemaKinds = []; Object.entries(combinedSource).forEach(([key, schema]) => { if (schema.properties && schema.properties.kind && schema.properties.kind.enum) { schemaKinds.push(schema.properties.kind.enum[0]); } }); console.log(`\nExtracted ${schemaKinds.length} schema kinds: ${schemaKinds.join(', ')}`); // Test accessing schemas through the LWGWRuntimeInventory instance console.log('\n=== Testing LWGWRuntimeInventory Methods ==='); // Test the policy sequence types console.log('\n1. Testing getPolicySequenceType()'); try { const sequenceTypes = inventory.getPolicySequenceType(); console.log(`✅ Policy Sequence Types: ${JSON.stringify(sequenceTypes)}`); } catch (error) { console.error('❌ Error getting policy sequence types:', error.message); } // Test if we can access the schema definitions console.log('\n2. Testing internal schema definitions'); try { // Access the internal schemaDefinitions property (this is a hack for testing) const instance = inventory; const schemaDefinitions = instance._schemaDefinitions || instance.schemaDefinitions; if (schemaDefinitions && Object.keys(schemaDefinitions).length > 0) { console.log(`✅ Schema definitions found: ${Object.keys(schemaDefinitions).length} entries`); console.log(' Sample keys:'); Object.keys(schemaDefinitions).slice(0, 3).forEach(key => { console.log(` - ${key}`); }); } else { console.log('❌ Schema definitions not accessible or empty'); } } catch (error) { console.error('❌ Error accessing schema definitions:', error.message); } // Test the getSchema method with the extracted kinds console.log('\n3. Testing getSchema() with extracted kinds'); schemaKinds.forEach((kind, index) => { console.log(`\n ${index + 1}. Testing getSchema for kind: ${kind}`); try { // Try different version formats const versions = [ `wm_1.0.0`, `api.ibm.com-v1`, undefined // Let it use default version ]; let schemaFound = false; for (const version of versions) { const schema = inventory.getSchema(kind, version); if (schema) { schemaFound = true; console.log(` ✅ Schema found with version: ${version || 'default'}`); 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}...`); break; } } if (!schemaFound) { console.log(` ❌ Schema not found for kind: ${kind}`); } } catch (error) { console.error(` ❌ Error getting schema for ${kind}:`, error.message); } }); console.log('\n=== Test Complete ===');