fix(openapi): reduce package size

This commit is contained in:
Fuma Nama
2026-06-03 21:00:02 +08:00
parent 9335822490
commit 2771e34d70
7 changed files with 36 additions and 32 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-openapi': patch
---
Reduce package size
+3 -6
View File
@@ -64,9 +64,9 @@
"tailwind-merge": "^3.6.0"
},
"devDependencies": {
"@apidevtools/json-schema-ref-parser": "^15.3.5",
"@fastify/deepmerge": "^3.2.1",
"@scalar/api-client-react": "2.0.20",
"@scalar/json-magic": "^0.12.14",
"@scalar/openapi-upgrader": "^0.2.8",
"@tailwindcss/oxide": "^4.3.0",
"@types/js-yaml": "^4.0.9",
@@ -103,17 +103,14 @@
}
},
"inlinedDependencies": {
"@apidevtools/json-schema-ref-parser": "15.3.5",
"@fastify/deepmerge": "3.2.1",
"@scalar/helpers": "0.8.0",
"@scalar/json-magic": "0.12.14",
"@scalar/openapi-upgrader": "0.2.8",
"ajv": "8.20.0",
"fast-content-type-parse": "3.0.0",
"fast-deep-equal": "3.1.3",
"fast-uri": "3.1.0",
"json-schema-traverse": "1.0.0",
"pathe": "2.0.3",
"xml-js": "1.6.11",
"yaml": "2.9.0"
"xml-js": "1.6.11"
}
}
-1
View File
@@ -1,7 +1,6 @@
import type { OpenAPIV3_2, OpenAPIV3 } from './_openapi/types';
import type { NoReference } from '@/utils/schema';
import type { DereferencedDocument } from '@/utils/document/dereference';
import type { MediaAdapter } from '@/requests/media/adapter';
import type { OpenAPIOptions } from '@/server';
import type { CreateAPIPageOptions } from './ui/base';
import type { InlineCodeUsageGenerator } from './requests/generators';
+9 -17
View File
@@ -1,8 +1,7 @@
import type { Document } from '@/types';
import { bundle } from '@scalar/json-magic/bundle';
import { upgrade } from '@scalar/openapi-upgrader';
import { fetchUrls, readFiles } from '@scalar/json-magic/bundle/plugins/node';
import { dereferenceDocument, type DereferencedDocument } from './dereference';
import { bundle } from '@apidevtools/json-schema-ref-parser';
export type ProcessedDocument = DereferencedDocument;
@@ -10,20 +9,13 @@ export type ProcessedDocument = DereferencedDocument;
* process & reference input document to a Fumadocs OpenAPI compatible format
*/
export async function processDocument(input: string | Document): Promise<ProcessedDocument> {
const bundled: Document = await bundle(input, {
plugins: [fetchUrls(), readFiles()],
treeShake: true,
hooks: {
onResolveError(node) {
throw new Error(`Failed to resolve ${node.$ref}`);
},
},
})
.then((v) => upgrade(v as never, '3.2') as Document)
.catch((e) => {
throw new Error(`[OpenAPI] Failed to resolve input: ${input}`, {
cause: e,
});
try {
let bundled: Document = await bundle(input);
bundled = upgrade(bundled, '3.2') as Document;
return dereferenceDocument(bundled);
} catch (e) {
throw new Error(`[OpenAPI] Failed to resolve input: ${input}`, {
cause: e,
});
return dereferenceDocument(bundled);
}
}
+3
View File
@@ -2,12 +2,15 @@ import { RenderContext } from '@/types';
import { processDocument } from '@/utils/document/process';
import { defaultShikiFactory } from 'fumadocs-core/highlight/shiki/full';
import * as ClientBoundary from '@/ui/client/boundary.lazy';
import { createCodeUsageGeneratorRegistry } from '@/requests/generators';
import { registerDefault } from '@/requests/generators/all';
export async function renderContextFrom(input: string): Promise<RenderContext> {
const schema = await processDocument(input);
return {
mediaAdapters: {},
codeUsages: registerDefault(createCodeUsageGeneratorRegistry()),
generateTypeScriptDefinitions() {
return '';
},
+2 -5
View File
@@ -31,10 +31,7 @@ export default defineConfig({
'fast-content-type-parse',
'@fastify/deepmerge',
'@scalar/json-magic',
'pathe',
'yaml',
'@scalar/helpers',
'@apidevtools/json-schema-ref-parser',
'@scalar/openapi-upgrader',
// for Vite RSC compatibility
@@ -44,7 +41,7 @@ export default defineConfig({
'json-schema-traverse',
'fast-uri',
],
neverBundle: [/^node:/, /ajv(.+)\.d\.ts/],
neverBundle: [/^node:/, 'fs', /ajv(.+)\.d\.ts/],
},
exports: {
enabled: true,
+14 -3
View File
@@ -2794,15 +2794,15 @@ importers:
specifier: ^3.6.0
version: 3.6.0
devDependencies:
'@apidevtools/json-schema-ref-parser':
specifier: ^15.3.5
version: 15.3.5(@types/[email protected])
'@fastify/deepmerge':
specifier: ^3.2.1
version: 3.2.1
'@scalar/api-client-react':
specifier: 2.0.20
version: 2.0.20([email protected])([email protected])([email protected])([email protected])
'@scalar/json-magic':
specifier: ^0.12.14
version: 0.12.14
'@scalar/openapi-upgrader':
specifier: ^0.2.8
version: 0.2.8
@@ -3701,6 +3701,12 @@ packages:
'@antfu/[email protected]':
resolution: {integrity: sha512-MGQsmw10ZyI+EJo45CdSER4zEb+p31LpDAFp2Z3gkSd1yqVZGi0Ebx++YTEMonJy4oChEMLsxZ64j8FH6sSqtQ==}
'@apidevtools/[email protected]':
resolution: {integrity: sha512-orNOYXw3hYXxxisXMldjzjBzqqTLBPbwOtHg7ovBPvfBHDue1qM9YJENZ3W2BQuS+7z4ThogMbEzEsov57Itkg==}
engines: {node: '>=20'}
peerDependencies:
'@types/json-schema': ^7.0.15
'@architect/[email protected]':
resolution: {integrity: sha512-oJjYDranGTCkp21bziF/fIxJfLTucitqg/ar5mmLPHyroNG3XF3SUIMvuNd1GNIe4oy40wvGEXvTToKYvUeOLA==}
engines: {node: '>=16'}
@@ -15706,6 +15712,11 @@ snapshots:
package-manager-detector: 1.6.0
tinyexec: 1.2.2
'@apidevtools/[email protected](@types/[email protected])':
dependencies:
'@types/json-schema': 7.0.15
js-yaml: 4.1.1
'@architect/[email protected]':
dependencies:
'@aws-lite/client': 0.21.10