/**
 * Fix ugly module-path tags in openapi.json generated by utoipa.
 * Transforms tags like "crate::agent::provider" -> "agent-provider"
 */
const fs = require('fs');
const path = require('path');

const openapiPath = path.join(__dirname, '..', 'openapi.json');
const json = JSON.parse(fs.readFileSync(openapiPath, 'utf8'));

let fixed = 0;

// Fix operation tags
for (const p in json.paths) {
  for (const m in json.paths[p]) {
    const op = json.paths[p][m];
    if (op.tags) {
      op.tags = op.tags.map(t => {
        const fixed = t.replace(/^crate::/, '').replace(/::/g, '-');
        return fixed;
      });
      fixed++;
    }
  }
}

fs.writeFileSync(openapiPath, JSON.stringify(json, null, 2));
console.log(`Fixed tags in ${fixed} operations`);
