OpenAPI: Improve error message on invalid document props

This commit is contained in:
Fuma Nama
2025-12-13 18:00:55 +08:00
parent fb3440cabb
commit ddeeb74d0f
3 changed files with 17 additions and 1 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-openapi': patch
---
Improve error message on invalid document props
+11
View File
@@ -35,6 +35,7 @@ export interface OpenAPIOptions {
export interface OpenAPIServer {
createProxy: typeof createProxy;
getSchemas: () => Promise<ProcessedSchemaMap>;
getSchema: (document: string) => Promise<ProcessedDocument>;
readonly options: OpenAPIOptions;
}
@@ -65,6 +66,16 @@ export function createOpenAPI(options: OpenAPIOptions = {}): OpenAPIServer {
return {
options,
createProxy,
async getSchema(document) {
const schemas = await getSchemas();
if (document in schemas) return schemas[document];
console.warn(
`[Fumadocs OpenAPI] the document "${document}" is not listed in the input array, this may not be expected.`,
);
// do not cache unlisted documents
return processDocument(document);
},
async getSchemas() {
if (disableCache) return getSchemas();
+1 -1
View File
@@ -253,7 +253,7 @@ export function createAPIPage(
return async function APIPageWrapper({ document, ...props }) {
let processed: ProcessedDocument;
if (typeof document === 'string') {
processed = (await server.getSchemas())[document];
processed = await server.getSchema(document);
} else {
processed = await document;
}