fix: update OpenAPI security scheme and normalize API paths

- Replaced "Authorization" with "x-api-key" in OpenAPI specifications across multiple endpoints.
- Updated the script to convert API path references from slash notation to dot notation to align with the OpenAPI schema.
- Removed redundant slash path aliases, retaining only canonical dot paths in the OpenAPI specification.
This commit is contained in:
Mauricio Siu
2026-03-01 11:33:45 -06:00
parent 8d95754b85
commit b8fa39fc20
3 changed files with 482 additions and 451 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
/**
* Normalizes OpenAPI path references in API docs MDX files.
* Converts dot notation (/tag.operation) to slash notation (/tag/operation)
* to match the OpenAPI schema paths.
* Converts slash notation (/tag/operation) to dot notation (/tag.operation)
* so they match our OpenAPI schema paths and display the real API path.
*/
import { readdirSync, readFileSync, writeFileSync } from "node:fs";
import { join } from "node:path";
@@ -13,15 +13,18 @@ for (const name of readdirSync(API_DOCS_DIR)) {
if (!name.endsWith(".mdx")) continue;
const file = join(API_DOCS_DIR, name);
const content = readFileSync(file, "utf8");
// Match path in both orders: "path":"/x/y" and "path":"/a/b"
const newContent = content.replace(/"path":"(\/[^"]+)"/g, (_, path) => {
if (path.includes(".")) {
// Convert /tag/operation or /tag/op/subop to /tag.operation or /tag.op.subop to match schema
if (path.includes("/") && !path.includes(".")) {
const dotPath = "/" + path.slice(1).replace(/\//g, ".");
totalFixed++;
return `"path":"${path.replace(/\./g, "/")}"`;
return `"path":"${dotPath}"`;
}
return `"path":"${path}"`;
});
if (newContent !== content) writeFileSync(file, newContent);
}
if (totalFixed > 0) {
console.log(`✓ Normalized ${totalFixed} API path(s) in MDX (dot → slash)`);
console.log(`✓ Normalized ${totalFixed} API path(s) in MDX (slash → dot)`);
}

View File

@@ -99,7 +99,25 @@ try {
writeFileSync(openapiPath, JSON.stringify(openapi, null, 2));
if (fixed > 0) console.log(`✓ Fixed ${fixed} empty response schemas`);
if (securityFixed) console.log("✓ Added x-api-key security scheme");
} else {
}
// Keep only canonical paths (dot notation). Remove slash-aliases if present.
let removed = 0;
for (const pathKey of Object.keys(openapi.paths || {})) {
if (pathKey.includes("/") && !pathKey.includes(".")) {
const dotKey = "/" + pathKey.slice(1).replace(/\//g, ".");
if (openapi.paths[dotKey]) {
delete openapi.paths[pathKey];
removed++;
}
}
}
if (removed > 0) {
writeFileSync(openapiPath, JSON.stringify(openapi, null, 2));
console.log(`✓ Removed ${removed} slash path alias(es), keeping dot paths only`);
}
if (!(unwrapped || fixed > 0 || securityFixed) && removed === 0) {
console.log("✓ No fixes needed");
}
} catch (error) {