OpenAPI: tolerate array schema without items type

This commit is contained in:
Fuma Nama
2025-04-24 14:42:50 +08:00
parent 26257237bc
commit 4dbb7fb7de
4 changed files with 14 additions and 11 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-openapi': patch
---
tolerate array schema without `items` type
+4 -8
View File
@@ -2,11 +2,12 @@ import { mkdir, writeFile } from 'node:fs/promises';
import { dirname, join, parse } from 'node:path';
import fg from 'fast-glob';
import {
generatePages,
generateAll,
type GenerateOptions,
type GeneratePageOutput,
generatePages,
generateTags,
} from './generate';
import { generateAll, generateTags } from './generate';
export interface Config extends GenerateOptions {
/**
@@ -195,12 +196,7 @@ function getOutputPathFromRoute(path: string): string {
}
function getFilename(s: string): string {
return s
.replace(/[A-Z]/g, (match, idx: number) =>
idx === 0 ? match : `-${match.toLowerCase()}`,
)
.replace(/\s+/g, '-')
.toLowerCase();
return s.replace(/\s+/g, '-').toLowerCase();
}
async function write(path: string, content: string): Promise<void> {
+3 -1
View File
@@ -31,7 +31,9 @@ export interface GenerateOptions {
) => Record<string, unknown>;
/**
* Add description to document body
* Add description to document body.
*
* We recommend but don't enable it by default because some OpenAPI schemas have invalid description that breaks MDX syntax.
*
* @defaultValue false
*/
+2 -2
View File
@@ -167,7 +167,7 @@ export function Schema({
const mentionedObjectTypes = [
...(schema.anyOf ?? schema.oneOf ?? []),
...(schema.not ? [schema.not] : []),
...(schema.type === 'array' ? [schema.items] : []),
...(schema.type === 'array' && schema.items ? [schema.items] : []),
].filter((s) => isComplexType(s) && !stack.includes(s));
footer = mentionedObjectTypes.map((s, idx) => {
@@ -240,7 +240,7 @@ function getSchemaType(
if (schema.title) return schema.title;
if (schema.type === 'array')
return `array<${getSchemaType(schema.items, ctx)}>`;
return `array<${schema.items ? getSchemaType(schema.items, ctx) : 'unknown'}>`;
if (schema.oneOf)
return schema.oneOf