mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
OpenAPI: Add getSchema() to virtual pages
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-openapi': patch
|
||||
---
|
||||
|
||||
Add `getSchema()` to virtual pages
|
||||
@@ -1,7 +1,6 @@
|
||||
import { MethodLabel } from '@/ui/components/method-label';
|
||||
import type {
|
||||
LoaderPlugin,
|
||||
MetaData,
|
||||
PageData,
|
||||
PageTreeTransformer,
|
||||
Source,
|
||||
@@ -10,9 +9,9 @@ import type {
|
||||
import type { OpenAPIServer } from '@/server/create';
|
||||
import type { SchemaToPagesOptions } from '@/utils/pages/preset-auto';
|
||||
import type { ApiPageProps } from '@/ui/api-page';
|
||||
import { toStaticData } from '@/utils/pages/to-static-data';
|
||||
import type { StructuredData } from 'fumadocs-core/mdx-plugins';
|
||||
import type { TOCItemType } from 'fumadocs-core/toc';
|
||||
import type { ProcessedDocument } from '@/utils/process-document';
|
||||
|
||||
declare module 'fumadocs-core/source' {
|
||||
export interface PageData {
|
||||
@@ -72,6 +71,7 @@ export function openapiPlugin(): LoaderPlugin {
|
||||
|
||||
interface OpenAPIPageData extends PageData {
|
||||
getAPIPageProps: () => ApiPageProps;
|
||||
getSchema: () => { id: string } & ProcessedDocument;
|
||||
structuredData: StructuredData;
|
||||
toc: TOCItemType[];
|
||||
}
|
||||
@@ -86,7 +86,7 @@ export async function openapiSource(
|
||||
} = {},
|
||||
): Promise<
|
||||
Source<{
|
||||
metaData: MetaData;
|
||||
metaData: never;
|
||||
pageData: OpenAPIPageData;
|
||||
}>
|
||||
> {
|
||||
@@ -94,14 +94,15 @@ export async function openapiSource(
|
||||
const { createAutoPreset } = await import('@/utils/pages/preset-auto');
|
||||
const { fromServer } = await import('@/utils/pages/builder');
|
||||
const { toBody } = await import('@/utils/pages/to-body');
|
||||
const { toStaticData } = await import('@/utils/pages/to-static-data');
|
||||
const files: VirtualFile<{
|
||||
pageData: OpenAPIPageData;
|
||||
metaData: MetaData;
|
||||
metaData: never;
|
||||
}>[] = [];
|
||||
|
||||
const entries = await fromServer(server, createAutoPreset(options));
|
||||
for (const [schemaId, list] of Object.entries(entries)) {
|
||||
const dereferenced = (await server.getSchema(schemaId)).dereferenced;
|
||||
const processed = await server.getSchema(schemaId);
|
||||
for (const entry of list) {
|
||||
const props = toBody(entry);
|
||||
props.showDescription ??= true;
|
||||
@@ -114,7 +115,13 @@ export async function openapiSource(
|
||||
getAPIPageProps() {
|
||||
return props;
|
||||
},
|
||||
...toStaticData(props, dereferenced),
|
||||
getSchema() {
|
||||
return {
|
||||
id: schemaId,
|
||||
...processed,
|
||||
};
|
||||
},
|
||||
...toStaticData(props, processed.dereferenced),
|
||||
_openapi: {
|
||||
method:
|
||||
entry.type === 'operation' || entry.type === 'webhook'
|
||||
|
||||
@@ -14,7 +14,7 @@ export type ProcessedDocument = {
|
||||
_internal_idToSchema: () => Map<string, object>;
|
||||
|
||||
/**
|
||||
* Get raw object from dereference object
|
||||
* Get raw object from dereferenced object
|
||||
*/
|
||||
getRawRef: (obj: object) => string | undefined;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user