flatten.ts 1.1 KB

12345678910111213141516171819202122232425262728
  1. import { dereferenceJsonSchema } from '../lib/helper.js';
  2. import { jsonNavigatorOutputSchema } from '../lib/json_schema.js';
  3. /**
  4. * This example demonstrates how to flatten the jsonNavigatorOutputSchema
  5. * by dereferencing all $ref fields and removing the $defs section.
  6. */
  7. // Flatten the schema by dereferencing all references
  8. console.log('Flattening jsonNavigatorOutputSchema...');
  9. const flattenedSchema = dereferenceJsonSchema(jsonNavigatorOutputSchema);
  10. // Pretty print the flattened schema
  11. console.log('Flattened Schema:');
  12. console.log(JSON.stringify(flattenedSchema, null, 2));
  13. // You can also see the size difference
  14. const originalSize = JSON.stringify(jsonNavigatorOutputSchema).length;
  15. const flattenedSize = JSON.stringify(flattenedSchema).length;
  16. console.log('\nSize comparison:');
  17. console.log(`Original schema size: ${originalSize} bytes`);
  18. console.log(`Flattened schema size: ${flattenedSize} bytes`);
  19. console.log(
  20. `Difference: ${flattenedSize - originalSize} bytes (${((flattenedSize / originalSize) * 100).toFixed(2)}% of original)`,
  21. );
  22. // Note: The flattened schema is typically larger because references are replaced with their full definitions