OpenAPI: Fix TypeScript schema generation

This commit is contained in:
fuma-nama
2024-09-18 19:06:12 +08:00
parent 87063eb83a
commit 42c9701c99
24 changed files with 869 additions and 832 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'fumadocs-openapi': patch
---
Fix TypeScript schema generation
+12 -12
View File
@@ -14,13 +14,13 @@
"start": "next start"
},
"dependencies": {
"@next/env": "^14.2.11",
"@next/env": "^14.2.12",
"@radix-ui/react-popover": "^1.1.1",
"@radix-ui/react-slot": "^1.1.0",
"@radix-ui/react-tooltip": "^1.1.2",
"@resvg/resvg-js": "^2.6.2",
"@shikijs/transformers": "^1.17.5",
"algoliasearch": "^4.24.0",
"@shikijs/transformers": "^1.17.7",
"algoliasearch": "4.24.0",
"class-variance-authority": "^0.7.0",
"fumadocs-core": "workspace:*",
"fumadocs-docgen": "workspace:^",
@@ -33,31 +33,31 @@
"hast-util-to-jsx-runtime": "^2.3.0",
"katex": "^0.16.11",
"lucide-react": "^0.441.0",
"next": "^14.2.11",
"next": "^14.2.12",
"phenomenon": "^1.6.0",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"rehype-katex": "^7.0.1",
"remark-math": "^6.0.0",
"satori": "^0.11.0",
"shiki": "^1.17.5",
"satori": "^0.11.1",
"shiki": "^1.17.7",
"tailwind-merge": "^2.5.2",
"zod": "^3.23.8"
},
"devDependencies": {
"@next/bundle-analyzer": "^14.2.11",
"@next/eslint-plugin-next": "^14.2.11",
"@next/bundle-analyzer": "^14.2.12",
"@next/eslint-plugin-next": "^14.2.12",
"@types/mdx": "^2.0.13",
"@types/node": "22.5.4",
"@types/react": "^18.3.5",
"@types/node": "22.5.5",
"@types/react": "^18.3.7",
"@types/react-dom": "^18.3.0",
"autoprefixer": "^10.4.20",
"eslint-config-custom": "workspace:*",
"fumadocs": "workspace:*",
"glslify": "^7.1.1",
"glslx": "^0.3.0",
"postcss": "^8.4.45",
"tailwindcss": "^3.4.11",
"postcss": "^8.4.47",
"tailwindcss": "^3.4.12",
"tailwindcss-animate": "^1.0.7",
"tsconfig": "workspace:*",
"tsx": "^4.19.1",
+2 -2
View File
@@ -11,7 +11,7 @@
"@fumadocs/content-collections": "workspace:*",
"fumadocs-core": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "^14.2.11",
"next": "^14.2.12",
"react": "18.3.1",
"react-dom": "18.3.1"
},
@@ -20,7 +20,7 @@
"@content-collections/mdx": "^0.1.5",
"@content-collections/next": "^0.2.1",
"@types/mdx": "^2.0.13",
"@types/react": "^18.3.5",
"@types/react": "^18.3.7",
"@types/react-dom": "^18.3.0",
"typescript": "^5.6.2"
}
+4 -4
View File
@@ -8,18 +8,18 @@
"start": "next start"
},
"dependencies": {
"@orama/stopwords": "^2.1.0",
"@orama/tokenizers": "^2.1.0",
"@orama/stopwords": "^2.1.1",
"@orama/tokenizers": "^2.1.1",
"fumadocs-core": "workspace:*",
"fumadocs-mdx": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "^14.2.11",
"next": "^14.2.12",
"react": "18.3.1",
"react-dom": "18.3.1"
},
"devDependencies": {
"@types/mdx": "^2.0.13",
"@types/react": "^18.3.5",
"@types/react": "^18.3.7",
"@types/react-dom": "^18.3.0",
"typescript": "^5.6.2"
}
+2 -2
View File
@@ -11,13 +11,13 @@
"fumadocs-core": "workspace:*",
"fumadocs-mdx": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "^14.2.11",
"next": "^14.2.12",
"react": "18.3.1",
"react-dom": "18.3.1"
},
"devDependencies": {
"@types/mdx": "^2.0.13",
"@types/react": "^18.3.5",
"@types/react": "^18.3.7",
"@types/react-dom": "^18.3.0",
"typescript": "^5.6.2"
}
+4 -4
View File
@@ -13,16 +13,16 @@
"fumadocs-mdx": "workspace:*",
"fumadocs-openapi": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "^14.2.11",
"postcss": "^8.4.45",
"next": "^14.2.12",
"postcss": "^8.4.47",
"react": "18.3.1",
"react-dom": "18.3.1",
"tailwindcss": "^3.4.11",
"tailwindcss": "^3.4.12",
"zod": "^3.23.8"
},
"devDependencies": {
"@types/mdx": "^2.0.13",
"@types/react": "^18.3.5",
"@types/react": "^18.3.7",
"@types/react-dom": "^18.3.0",
"rimraf": "^6.0.1",
"typescript": "^5.6.2"
+2 -2
View File
@@ -11,13 +11,13 @@
"@fumadocs/mdx-remote": "workspace:*",
"fumadocs-core": "workspace:*",
"fumadocs-ui": "workspace:*",
"next": "^14.2.11",
"next": "^14.2.12",
"react": "18.3.1",
"react-dom": "18.3.1"
},
"devDependencies": {
"@types/mdx": "^2.0.13",
"@types/react": "^18.3.5",
"@types/react": "^18.3.7",
"@types/react-dom": "^18.3.0",
"typescript": "^5.6.2"
}
+3 -3
View File
@@ -19,8 +19,8 @@
"prettier": "@vercel/style-guide/prettier",
"devDependencies": {
"@changesets/cli": "^2.27.8",
"@typescript-eslint/eslint-plugin": "^8.5.0",
"@typescript-eslint/parser": "^8.5.0",
"@typescript-eslint/eslint-plugin": "^8.6.0",
"@typescript-eslint/parser": "^8.6.0",
"@vercel/style-guide": "^6.0.0",
"concurrently": "^9.0.1",
"eslint": "^8.57.0",
@@ -30,7 +30,7 @@
"tsup": "8.3.0",
"turbo": "2.1.2",
"typescript": "^5.6.2",
"vitest": "^2.1.0"
"vitest": "^2.1.1"
},
"packageManager": "[email protected]",
"engines": {
+1 -1
View File
@@ -36,7 +36,7 @@
},
"devDependencies": {
"@types/cross-spawn": "^6.0.6",
"@types/node": "22.5.4",
"@types/node": "22.5.5",
"eslint-config-custom": "workspace:*",
"fast-glob": "^3.3.1",
"tsconfig": "workspace:*",
+1 -1
View File
@@ -47,7 +47,7 @@
"devDependencies": {
"@content-collections/core": "^0.7.0",
"@content-collections/mdx": "^0.1.5",
"@types/node": "22.5.4",
"@types/node": "22.5.5",
"eslint-config-custom": "workspace:*",
"fumadocs-core": "workspace:*",
"tsconfig": "workspace:*",
+8 -8
View File
@@ -77,9 +77,9 @@
},
"dependencies": {
"@formatjs/intl-localematcher": "^0.5.4",
"@orama/orama": "^2.1.0",
"@shikijs/rehype": "^1.17.5",
"@shikijs/transformers": "^1.17.5",
"@orama/orama": "^2.1.1",
"@shikijs/rehype": "^1.17.7",
"@shikijs/transformers": "^1.17.7",
"github-slugger": "^2.0.0",
"image-size": "^1.1.1",
"negotiator": "^0.6.3",
@@ -87,7 +87,7 @@
"remark": "^15.0.0",
"remark-gfm": "^4.0.0",
"scroll-into-view-if-needed": "^3.1.0",
"shiki": "^1.17.5",
"shiki": "^1.17.7",
"unist-util-visit": "^5.0.0"
},
"devDependencies": {
@@ -97,14 +97,14 @@
"@types/hast": "^3.0.4",
"@types/mdast": "^4.0.3",
"@types/negotiator": "^0.6.3",
"@types/node": "22.5.4",
"@types/react": "^18.3.5",
"@types/node": "22.5.5",
"@types/react": "^18.3.7",
"@types/react-dom": "^18.3.0",
"algoliasearch": "^4.24.0",
"algoliasearch": "4.24.0",
"eslint-config-custom": "workspace:*",
"mdast-util-mdx-jsx": "^3.1.3",
"mdast-util-mdxjs-esm": "^2.0.1",
"next": "^14.2.11",
"next": "^14.2.12",
"remark-mdx": "^3.0.1",
"tsconfig": "workspace:*",
"unified": "^11.0.5"
+16 -10
View File
@@ -211,13 +211,16 @@ function buildFolderNode(
defaultOpen: metadata?.defaultOpen,
index,
children,
$ref: !ctx.options.noRef
? {
metaFile: meta?.file.path,
}
: undefined,
};
if (!ctx.options.noRef)
Object.defineProperty(node, '$ref', {
value: {
metaFile: meta?.file.path,
} as PageTree.Folder['$ref'],
enumerable: false,
});
return removeUndefined(
ctx.options.attachFolder?.(node, folder, meta) ?? node,
);
@@ -246,13 +249,16 @@ function buildFileNode(
name: localized.data.data.title,
icon: ctx.options.resolveIcon?.(localized.data.data.icon),
url: ctx.options.getUrl(localized.data.slugs, urlLocale),
$ref: !ctx.options.noRef
? {
file: localized.file.path,
}
: undefined,
};
if (!ctx.options.noRef)
Object.defineProperty(item, '$ref', {
value: {
file: localized.file.path,
} as PageTree.Item['$ref'],
enumerable: false,
});
return removeUndefined(ctx.options.attachFile?.(item, file) ?? item);
}
+14
View File
@@ -7,6 +7,7 @@ import {
type SourceConfig,
} from '@/source/loader';
import { parseFilePath } from '@/source';
import { PageTree } from '../dist/server';
test('get slugs', () => {
expect(getSlugs(parseFilePath('index.mdx'))).toStrictEqual([]);
@@ -253,6 +254,16 @@ test('Internationalized Routing', () => {
source: i18nSource,
});
expect(
result.getNodePage(result.pageTree['en'].children[0] as PageTree.Item),
).toEqual(
expect.objectContaining({
data: {
title: 'Hello',
},
}),
);
expect(result.pageTree['en'], 'Page Tree').toMatchInlineSnapshot(`
{
"children": [
@@ -313,6 +324,9 @@ test('Internationalized Routing: Hide Prefix', () => {
defaultLanguage: 'en',
hideLocale: 'default-locale',
},
pageTree: {
noRef: true,
},
source: i18nSource,
});
+5 -5
View File
@@ -9,15 +9,15 @@
"@content-collections/mdx": "^0.1.5",
"@content-collections/next": "^0.2.1",
"@types/mdx": "^2.0.13",
"@types/node": "22.5.4",
"@types/react": "^18.3.5",
"@types/node": "22.5.5",
"@types/react": "^18.3.7",
"@types/react-dom": "^18.3.0",
"autoprefixer": "^10.4.20",
"next": "^14.2.11",
"postcss": "^8.4.45",
"next": "^14.2.12",
"postcss": "^8.4.47",
"react": "^18.3.1",
"react-dom": "^18.3.1",
"tailwindcss": "^3.4.11",
"tailwindcss": "^3.4.12",
"typescript": "^5.6.2"
}
}
+1 -1
View File
@@ -33,7 +33,7 @@
},
"devDependencies": {
"@types/cross-spawn": "^6.0.6",
"@types/node": "22.5.4",
"@types/node": "22.5.5",
"eslint-config-custom": "workspace:*",
"fast-glob": "^3.3.1",
"tsconfig": "workspace:*"
+2 -2
View File
@@ -36,10 +36,10 @@
},
"devDependencies": {
"@mdx-js/mdx": "^3.0.1",
"@types/estree": "^1.0.5",
"@types/estree": "^1.0.6",
"@types/hast": "^3.0.4",
"@types/mdast": "^4.0.3",
"@types/node": "22.5.4",
"@types/node": "22.5.5",
"eslint-config-custom": "workspace:*",
"remark": "^15.0.0",
"tsconfig": "workspace:*",
+3 -3
View File
@@ -72,12 +72,12 @@
"devDependencies": {
"@types/mdx": "^2.0.13",
"@types/micromatch": "^4.0.9",
"@types/node": "22.5.4",
"@types/react": "^18.3.5",
"@types/node": "22.5.5",
"@types/react": "^18.3.7",
"@types/ws": "^8.5.12",
"eslint-config-custom": "workspace:*",
"fumadocs-core": "workspace:*",
"next": "^14.2.11",
"next": "^14.2.12",
"tsconfig": "workspace:*",
"unified": "^11.0.5",
"vfile": "^6.0.3"
+2 -2
View File
@@ -66,10 +66,10 @@
"@types/mdast": "^4.0.3",
"@types/mdx": "^2.0.13",
"@types/micromatch": "^4.0.9",
"@types/react": "^18.3.5",
"@types/react": "^18.3.7",
"eslint-config-custom": "workspace:*",
"fumadocs-core": "workspace:*",
"next": "^14.2.11",
"next": "^14.2.12",
"tsconfig": "workspace:*",
"unified": "^11.0.5",
"webpack": "^5.90.3"
+5 -5
View File
@@ -52,7 +52,7 @@
},
"dependencies": {
"@apidevtools/json-schema-ref-parser": "^11.7.0",
"@fumari/json-schema-to-typescript": "^1.1.0",
"@fumari/json-schema-to-typescript": "^1.1.1",
"@radix-ui/react-select": "^2.1.1",
"@radix-ui/react-slot": "^1.1.0",
"class-variance-authority": "^0.7.0",
@@ -67,17 +67,17 @@
"react-hook-form": "^7.53.0",
"remark": "^15.0.1",
"remark-rehype": "^11.1.0",
"shiki": "^1.17.5",
"shiki": "^1.17.7",
"swr": "^2.2.5"
},
"devDependencies": {
"@types/js-yaml": "^4.0.9",
"@types/node": "22.5.4",
"@types/node": "22.5.5",
"@types/openapi-sampler": "^1.0.3",
"@types/react": "^18.3.5",
"@types/react": "^18.3.7",
"bunchee": "^5.4.0",
"eslint-config-custom": "workspace:*",
"next": "^14.2.11",
"next": "^14.2.12",
"openapi-types": "^12.1.3",
"tsconfig": "workspace:*"
},
@@ -7,6 +7,7 @@ export async function getTypescriptSchema(
): Promise<string | undefined> {
if (code in endpoint.responses) {
return compile(endpoint.responses[code].schema, 'Response', {
$refOptions: false,
bannerComment: '',
additionalProperties: false,
format: true,
+6 -6
View File
@@ -37,7 +37,7 @@
},
"dependencies": {
"@radix-ui/react-popover": "^1.1.1",
"@shikijs/twoslash": "^1.17.5",
"@shikijs/twoslash": "^1.17.7",
"mdast-util-from-markdown": "^2.0.1",
"mdast-util-gfm": "^3.0.0",
"mdast-util-to-hast": "^13.2.0",
@@ -46,14 +46,14 @@
"devDependencies": {
"@types/hast": "^3.0.4",
"@types/mdast": "^4.0.3",
"@types/node": "22.5.4",
"@types/react": "^18.3.5",
"@types/node": "22.5.5",
"@types/react": "^18.3.7",
"eslint-config-custom": "workspace:*",
"fumadocs-ui": "workspace:*",
"postcss": "^8.4.45",
"postcss": "^8.4.47",
"postcss-lightningcss": "^1.0.1",
"shiki": "^1.17.5",
"tailwindcss": "^3.4.11",
"shiki": "^1.17.7",
"tailwindcss": "^3.4.12",
"tsconfig": "workspace:*"
},
"peerDependencies": {
+2 -2
View File
@@ -49,10 +49,10 @@
"mdast-util-to-hast": "^13.2.0"
},
"devDependencies": {
"@types/estree": "^1.0.5",
"@types/estree": "^1.0.6",
"@types/hast": "^3.0.4",
"@types/mdast": "^4.0.3",
"@types/react": "18.3.5",
"@types/react": "18.3.7",
"@types/react-dom": "18.3.0",
"eslint-config-custom": "workspace:*",
"fumadocs-ui": "workspace:*",
+5 -5
View File
@@ -81,17 +81,17 @@
},
"devDependencies": {
"@algolia/client-search": "^4.24.0",
"@next/eslint-plugin-next": "^14.2.11",
"@types/react": "^18.3.5",
"@next/eslint-plugin-next": "^14.2.12",
"@types/react": "^18.3.7",
"@types/react-dom": "^18.3.0",
"algoliasearch": "^4.24.0",
"eslint-config-custom": "workspace:*",
"lucide-react": "^0.441.0",
"next": "^14.2.11",
"postcss": "^8.4.45",
"next": "^14.2.12",
"postcss": "^8.4.47",
"postcss-cli": "^11.0.0",
"postcss-lightningcss": "^1.0.1",
"tailwindcss": "^3.4.11",
"tailwindcss": "^3.4.12",
"tsconfig": "workspace:*"
},
"peerDependencies": {
+763 -752
View File
File diff suppressed because it is too large Load Diff