OpenAPI: Fix self-referencing schema types

This commit is contained in:
fuma-nama
2024-08-08 21:12:07 +08:00
parent 4e0f9e53c9
commit 444af277f1
4 changed files with 15 additions and 9 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-openapi': patch
---
Fix self-referencing schema types
+1
View File
@@ -24,4 +24,5 @@ export const { getPage, getPages, pageTree } = loader({
export const openapi = createOpenAPI({
documentOrPath: path.resolve('./unkey.json'),
generateTypeScriptSchema: false,
});
@@ -89,7 +89,6 @@ export function Operation({
required: body.required ?? false,
render: ctx,
allowFile: type === 'multipart/form-data',
stack: [],
}}
/>
</Fragment>,
@@ -130,8 +129,6 @@ export function Operation({
writeOnly: method.method !== 'GET',
required: param.required ?? false,
render: ctx,
allowFile: false,
stack: [],
}}
/>,
);
+9 -6
View File
@@ -28,10 +28,12 @@ interface Context {
/**
* Parse binary format string to be files
*
* @defaultValue false
*/
allowFile: boolean;
allowFile?: boolean;
stack: OpenAPI.SchemaObject[];
stack?: OpenAPI.SchemaObject[];
render: RenderContext;
}
@@ -58,6 +60,9 @@ export function Schema({
(schema.writeOnly === true && !ctx.writeOnly)
)
return null;
ctx.allowFile ??= true;
const stack = ctx.stack ?? [];
const { renderer } = ctx.render;
const child: ReactNode[] = [];
@@ -169,9 +174,7 @@ export function Schema({
...(schema.type === 'array' ? [schema.items] : []),
]
.map(noRef)
.filter((s) => isComplexType(s) && !ctx.stack.includes(s));
ctx.stack.push(schema);
.filter((s) => isComplexType(s) && !stack.includes(s));
const renderedMentionedTypes = mentionedObjectTypes.map((s, idx) => {
return (
@@ -184,6 +187,7 @@ export function Schema({
schema={noRef(s)}
ctx={{
...ctx,
stack: [schema, ...stack],
parseObject: true,
required: false,
}}
@@ -193,7 +197,6 @@ export function Schema({
});
child.push(...renderedMentionedTypes);
ctx.stack.pop();
}
return (