mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
OpenAPI: Improve error message on invalid document props
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-openapi': patch
|
||||
---
|
||||
|
||||
Improve error message on invalid document props
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user