fix: enhance OpenAPI schema handling in fix-openapi script

- Added logic to unwrap nested OpenAPI specifications from migrated APIs, improving compatibility with various API structures.
- Updated the condition for writing the fixed schema to include unwrapped status, ensuring all necessary changes are saved.
This commit is contained in:
Mauricio Siu
2026-02-24 01:03:44 -06:00
parent f89b3b07f2
commit aa524f56e5

View File

@@ -6,7 +6,15 @@ const openapiPath = join(process.cwd(), "public", "openapi.json");
console.log("Fixing OpenAPI schema..."); console.log("Fixing OpenAPI schema...");
try { try {
const openapi = JSON.parse(readFileSync(openapiPath, "utf8")); let openapi = JSON.parse(readFileSync(openapiPath, "utf8"));
let unwrapped = false;
// If the spec is nested (e.g. result.data.json from a migrated/source API), use the inner spec
if (openapi.result?.data?.json && typeof openapi.result.data.json === "object") {
openapi = openapi.result.data.json;
unwrapped = true;
console.log("✓ Unwrapped nested OpenAPI spec (result.data.json)");
}
let fixed = 0; let fixed = 0;
let securityFixed = false; let securityFixed = false;
@@ -87,7 +95,7 @@ try {
} }
} }
if (fixed > 0 || securityFixed) { if (unwrapped || fixed > 0 || securityFixed) {
writeFileSync(openapiPath, JSON.stringify(openapi, null, 2)); writeFileSync(openapiPath, JSON.stringify(openapi, null, 2));
if (fixed > 0) console.log(`✓ Fixed ${fixed} empty response schemas`); if (fixed > 0) console.log(`✓ Fixed ${fixed} empty response schemas`);
if (securityFixed) console.log("✓ Added x-api-key security scheme"); if (securityFixed) console.log("✓ Added x-api-key security scheme");