Skip to content

Commit aa524f5

Browse files
committed
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.
1 parent f89b3b0 commit aa524f5

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

apps/docs/scripts/fix-openapi.mjs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@ const openapiPath = join(process.cwd(), "public", "openapi.json");
66
console.log("Fixing OpenAPI schema...");
77

88
try {
9-
const openapi = JSON.parse(readFileSync(openapiPath, "utf8"));
9+
let openapi = JSON.parse(readFileSync(openapiPath, "utf8"));
10+
11+
let unwrapped = false;
12+
// If the spec is nested (e.g. result.data.json from a migrated/source API), use the inner spec
13+
if (openapi.result?.data?.json && typeof openapi.result.data.json === "object") {
14+
openapi = openapi.result.data.json;
15+
unwrapped = true;
16+
console.log("✓ Unwrapped nested OpenAPI spec (result.data.json)");
17+
}
1018

1119
let fixed = 0;
1220
let securityFixed = false;
@@ -87,7 +95,7 @@ try {
8795
}
8896
}
8997

90-
if (fixed > 0 || securityFixed) {
98+
if (unwrapped || fixed > 0 || securityFixed) {
9199
writeFileSync(openapiPath, JSON.stringify(openapi, null, 2));
92100
if (fixed > 0) console.log(`✓ Fixed ${fixed} empty response schemas`);
93101
if (securityFixed) console.log("✓ Added x-api-key security scheme");

0 commit comments

Comments
 (0)