OpenAPI: Fix root schema manipulation with TypeScript definition generation

This commit is contained in:
Fuma Nama
2025-06-06 22:09:10 +08:00
parent 6f31a8d765
commit 77461e55e5
3 changed files with 13 additions and 20 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-openapi': patch
---
Fix root schema manipulation with TypeScript definition generation
@@ -125,11 +125,6 @@ function writeReferences(
for (const key in output[name]) {
output[name][key] = writeReferences(output[name][key], ctx, stack);
}
continue;
default:
if (typeof output[name] === 'object' && !Array.isArray(output[name])) {
output[name] = { ...output[name] };
}
}
}
@@ -5,19 +5,12 @@ export async function getTypescriptSchema(
schema: object,
dereferenceMap: DereferenceMap,
): Promise<string | undefined> {
return compile(
// re-running on the same schema results in error
// because it uses `defineProperty` to define internal references
// we clone the schema to fix this problem
schema,
'Response',
{
$refOptions: false,
schemaToId: dereferenceMap,
bannerComment: '',
additionalProperties: false,
format: true,
enableConstEnums: false,
},
);
const cloned = structuredClone({ schema, dereferenceMap });
return compile(cloned.schema, 'Response', {
$refOptions: false,
schemaToId: cloned.dereferenceMap,
bannerComment: '',
additionalProperties: false,
enableConstEnums: false,
});
}