fumadocs-openapi 8.0.3 → 8.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generate-file.d.ts.map +1 -1
- package/dist/generate-file.js +3 -9
- package/dist/generate.d.ts +3 -1
- package/dist/generate.d.ts.map +1 -1
- package/dist/playground/client.js +1 -1
- package/dist/render/codeblock.d.ts +3 -3
- package/dist/render/codeblock.d.ts.map +1 -1
- package/dist/render/codeblock.js +3 -2
- package/dist/render/operation/api-example.d.ts.map +1 -1
- package/dist/render/operation/api-example.js +11 -25
- package/dist/render/operation/index.d.ts +1 -1
- package/dist/render/operation/index.d.ts.map +1 -1
- package/dist/render/operation/index.js +29 -23
- package/dist/render/renderer.d.ts.map +1 -1
- package/dist/render/renderer.js +2 -2
- package/dist/render/schema.d.ts +7 -13
- package/dist/render/schema.d.ts.map +1 -1
- package/dist/render/schema.js +14 -19
- package/dist/types.d.ts +2 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +10 -9
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-file.d.ts","sourceRoot":"","sources":["../src/generate-file.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,eAAe,
|
|
1
|
+
{"version":3,"file":"generate-file.d.ts","sourceRoot":"","sources":["../src/generate-file.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,eAAe,EAIrB,MAAM,YAAY,CAAC;AAEpB,MAAM,WAAW,MAAO,SAAQ,eAAe;IAC7C;;OAEG;IACH,KAAK,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAEzB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;;;;OAMG;IACH,GAAG,CAAC,EAAE,KAAK,GAAG,MAAM,GAAG,WAAW,CAAC;IAEnC;;OAEG;IACH,IAAI,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;IAEtD;;;;;OAKG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;IAExB;;;;OAIG;IACH,OAAO,CAAC,EAAE,KAAK,GAAG,OAAO,GAAG,MAAM,CAAC;CACpC;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CA+HlE"}
|
package/dist/generate-file.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
2
|
import { dirname, join, parse } from 'node:path';
|
|
3
3
|
import fg from 'fast-glob';
|
|
4
|
-
import { generatePages, } from './generate.js';
|
|
5
|
-
import { generateAll, generateTags } from './generate.js';
|
|
4
|
+
import { generateAll, generatePages, generateTags, } from './generate.js';
|
|
6
5
|
export async function generateFiles(options) {
|
|
7
6
|
const { input, output, name: nameFn, per = 'operation', groupBy = 'none', cwd = process.cwd(), } = options;
|
|
8
7
|
const outputDir = join(cwd, output);
|
|
@@ -29,9 +28,7 @@ export async function generateFiles(options) {
|
|
|
29
28
|
file = getFilename(result.pathItem.summary);
|
|
30
29
|
}
|
|
31
30
|
else if (result.type === 'operation') {
|
|
32
|
-
file = result.
|
|
33
|
-
? getFilename(result.operation.operationId)
|
|
34
|
-
: join(getOutputPathFromRoute(result.item.path), result.item.method.toLowerCase());
|
|
31
|
+
file = join(getOutputPathFromRoute(result.item.path), result.item.method.toLowerCase());
|
|
35
32
|
}
|
|
36
33
|
else {
|
|
37
34
|
file = getFilename(result.item.name);
|
|
@@ -109,10 +106,7 @@ function getOutputPathFromRoute(path) {
|
|
|
109
106
|
.at(-1) ?? '');
|
|
110
107
|
}
|
|
111
108
|
function getFilename(s) {
|
|
112
|
-
return s
|
|
113
|
-
.replace(/[A-Z]/g, (match, idx) => idx === 0 ? match : `-${match.toLowerCase()}`)
|
|
114
|
-
.replace(/\s+/g, '-')
|
|
115
|
-
.toLowerCase();
|
|
109
|
+
return s.replace(/\s+/g, '-').toLowerCase();
|
|
116
110
|
}
|
|
117
111
|
async function write(path, content) {
|
|
118
112
|
await mkdir(dirname(path), { recursive: true });
|
package/dist/generate.d.ts
CHANGED
|
@@ -18,7 +18,9 @@ export interface GenerateOptions {
|
|
|
18
18
|
*/
|
|
19
19
|
frontmatter?: (title: string, description: string | undefined, context: DocumentContext) => Record<string, unknown>;
|
|
20
20
|
/**
|
|
21
|
-
* Add description to document body
|
|
21
|
+
* Add description to document body.
|
|
22
|
+
*
|
|
23
|
+
* We recommend but don't enable it by default because some OpenAPI schemas have invalid description that breaks MDX syntax.
|
|
22
24
|
*
|
|
23
25
|
* @defaultValue false
|
|
24
26
|
*/
|
package/dist/generate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,eAAe,EAErB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,KAAK,aAAa,EAAmB,MAAM,0BAA0B,CAAC;AAE/E,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,OAAO,CAAC,EAAE;QACR,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd,EAAE,CAAC;IAEJ;;;;OAIG;IACH,WAAW,CAAC,EAAE,CACZ,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,OAAO,EAAE,eAAe,KACrB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE7B
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../src/generate.ts"],"names":[],"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,CAAC,CAAC;IAExC,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAgBN,wBAAsB,WAAW,CAC/B,cAAc,EAAE,aAAa,EAC7B,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,MAAM,CAAC,CAoBjB;AAED,wBAAsB,aAAa,CACjC,cAAc,EAAE,aAAa,EAC7B,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAiE/B;AAED,wBAAsB,YAAY,CAChC,cAAc,EAAE,aAAa,EAC7B,OAAO,GAAE,eAAoB,GAC5B,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAsC9B"}
|
|
@@ -209,7 +209,7 @@ function usePersistentAuthInfo(authorization) {
|
|
|
209
209
|
};
|
|
210
210
|
}
|
|
211
211
|
function CollapsiblePanel({ title, children, ...props }) {
|
|
212
|
-
return (_jsxs(Collapsible, { ...props, className: "border-b last:border-b-0", children: [_jsxs(CollapsibleTrigger, { className: "group w-full flex items-center gap-2 p-3 text-sm font-medium", children: [title, _jsx(ChevronDown, { className: "ms-auto size-3.5 text-fd-muted-foreground group-data-[state=open]:rotate-180" })] }), _jsx(CollapsibleContent, { children: _jsx("div", { className: "flex flex-col gap-3 p-
|
|
212
|
+
return (_jsxs(Collapsible, { ...props, className: "border-b last:border-b-0", children: [_jsxs(CollapsibleTrigger, { className: "group w-full flex items-center gap-2 p-3 text-sm font-medium", children: [title, _jsx(ChevronDown, { className: "ms-auto size-3.5 text-fd-muted-foreground group-data-[state=open]:rotate-180" })] }), _jsx(CollapsibleContent, { children: _jsx("div", { className: "flex flex-col gap-3 p-3 pt-1", children: children }) })] }));
|
|
213
213
|
}
|
|
214
214
|
function writeAuthHeader(authorization, input, header, query, cookie) {
|
|
215
215
|
if (authorization.type === 'apiKey') {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { type HTMLAttributes } from 'react';
|
|
2
2
|
import type { RenderContext } from '../types.js';
|
|
3
|
-
export
|
|
3
|
+
export interface CodeBlockProps extends HTMLAttributes<HTMLElement> {
|
|
4
4
|
code: string;
|
|
5
5
|
lang: string;
|
|
6
6
|
ctx: RenderContext;
|
|
7
|
-
}
|
|
8
|
-
export declare function CodeBlock({ code, lang, ctx, ...rest }: CodeBlockProps): Promise<
|
|
7
|
+
}
|
|
8
|
+
export declare function CodeBlock({ code, lang, ctx, ...rest }: CodeBlockProps): Promise<import("react/jsx-runtime").JSX.Element>;
|
|
9
9
|
//# sourceMappingURL=codeblock.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"codeblock.d.ts","sourceRoot":"","sources":["../../src/render/codeblock.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"codeblock.d.ts","sourceRoot":"","sources":["../../src/render/codeblock.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAI7C,MAAM,WAAW,cAAe,SAAQ,cAAc,CAAC,WAAW,CAAC;IACjE,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,aAAa,CAAC;CACpB;AAED,wBAAsB,SAAS,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,EAAE,cAAc,oDAc3E"}
|
package/dist/render/codeblock.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import * as Base from 'fumadocs-ui/components/codeblock';
|
|
3
3
|
import { highlight } from 'fumadocs-core/highlight';
|
|
4
|
+
import { cn } from 'fumadocs-ui/utils/cn';
|
|
4
5
|
export async function CodeBlock({ code, lang, ctx, ...rest }) {
|
|
5
6
|
const rendered = await highlight(code, {
|
|
6
7
|
lang,
|
|
7
8
|
...ctx.shikiOptions,
|
|
8
9
|
components: {
|
|
9
|
-
pre: (props) => _jsx(Base.Pre, { ...props
|
|
10
|
+
pre: (props) => _jsx(Base.Pre, { ...props }),
|
|
10
11
|
},
|
|
11
12
|
});
|
|
12
|
-
return _jsx(Base.CodeBlock, { className:
|
|
13
|
+
return (_jsx(Base.CodeBlock, { className: cn('my-0', rest.className), children: rendered }));
|
|
13
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-example.d.ts","sourceRoot":"","sources":["../../../src/render/operation/api-example.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"api-example.d.ts","sourceRoot":"","sources":["../../../src/render/operation/api-example.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAS3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAqBtD,UAAU,cAAc;IACtB,eAAe,CAAC,EAAE,UAAU,EAAE,CAAC;IAC/B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,UAAU,eAAe;IACvB,GAAG,EAAE,MAAM,CAAC;IAEZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,MAAM,EAAE,iBAAiB,GAAG,cAAc,CAAC;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;CACrB,2CAeA;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,GAAG,EAAE,aAAa,GACjB,eAAe,EAAE,CA8BnB;AAED,wBAAsB,UAAU,CAAC,EAC/B,MAAM,EACN,QAAQ,EACR,GAAG,GACJ,EAAE;IACD,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,MAAM,EAAE,iBAAiB,GAAG,cAAc,CAAC;IAC3C,GAAG,EAAE,aAAa,CAAC;CACpB,oDAmCA"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Markdown } from '../../render/markdown.js';
|
|
3
|
-
import { getTypescriptSchema } from '../../utils/get-typescript-schema.js';
|
|
4
3
|
import { CodeBlock } from '../../render/codeblock.js';
|
|
5
4
|
import { CodeExample, CodeExampleProvider, } from '../../ui/contexts/code-example.lazy.js';
|
|
6
5
|
import { getPreferredType } from '../../utils/schema.js';
|
|
@@ -86,40 +85,27 @@ function dedupe(samples) {
|
|
|
86
85
|
return out;
|
|
87
86
|
}
|
|
88
87
|
function ResponseTabs({ operation, ctx, }) {
|
|
89
|
-
const { renderer
|
|
88
|
+
const { renderer } = ctx;
|
|
90
89
|
if (!operation.responses)
|
|
91
90
|
return null;
|
|
92
91
|
async function renderResponse(code) {
|
|
93
|
-
const response = operation.responses
|
|
94
|
-
|
|
95
|
-
: null;
|
|
96
|
-
const media = getPreferredType(response?.content ?? {});
|
|
92
|
+
const response = operation.responses?.[code];
|
|
93
|
+
const media = response?.content ? getPreferredType(response.content) : null;
|
|
97
94
|
const responseOfType = media ? response?.content?.[media] : null;
|
|
98
|
-
|
|
99
|
-
responseOfType?.schema?.description ??
|
|
100
|
-
'';
|
|
101
|
-
let ts;
|
|
102
|
-
if (generateTypeScriptSchema) {
|
|
103
|
-
ts = await generateTypeScriptSchema(operation, code);
|
|
104
|
-
}
|
|
105
|
-
else if (generateTypeScriptSchema === undefined &&
|
|
106
|
-
responseOfType?.schema) {
|
|
107
|
-
ts = await getTypescriptSchema(responseOfType?.schema, schema.dereferenceMap);
|
|
108
|
-
}
|
|
109
|
-
const values = [];
|
|
110
|
-
let exampleSlot;
|
|
95
|
+
let slot = 'Empty';
|
|
111
96
|
if (responseOfType?.examples) {
|
|
112
|
-
|
|
113
|
-
|
|
97
|
+
const values = [];
|
|
98
|
+
const children = Object.entries(responseOfType.examples).map(([key, sample]) => {
|
|
99
|
+
const title = sample?.summary ?? `Example ${key}`;
|
|
114
100
|
values.push(title);
|
|
115
|
-
return (_jsxs(renderer.ResponseType, { label: title, children: [sample?.description
|
|
101
|
+
return (_jsxs(renderer.ResponseType, { label: title, children: [sample?.description && _jsx(Markdown, { text: sample.description }), _jsx(CodeBlock, { lang: "json", code: JSON.stringify(sample.value, null, 2), ctx: ctx })] }, key));
|
|
116
102
|
});
|
|
103
|
+
slot = (_jsx(renderer.ResponseTypes, { defaultValue: values[0], children: children }));
|
|
117
104
|
}
|
|
118
105
|
else if (responseOfType?.example || responseOfType?.schema) {
|
|
119
|
-
|
|
120
|
-
exampleSlot = (_jsx(renderer.ResponseType, { label: "Response", children: _jsx(CodeBlock, { lang: "json", code: JSON.stringify(responseOfType.example ?? sample(responseOfType.schema), null, 2), ctx: ctx }) }));
|
|
106
|
+
slot = (_jsx(CodeBlock, { lang: "json", code: JSON.stringify(responseOfType.example ?? sample(responseOfType.schema), null, 2), ctx: ctx }));
|
|
121
107
|
}
|
|
122
|
-
return (
|
|
108
|
+
return _jsx(renderer.Response, { value: code, children: slot });
|
|
123
109
|
}
|
|
124
110
|
const codes = Object.keys(operation.responses);
|
|
125
111
|
if (codes.length === 0)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ReactElement } from 'react';
|
|
2
2
|
import type { MethodInformation, RenderContext } from '../../types.js';
|
|
3
|
-
import { RequestData } from '../../requests/_shared.js';
|
|
3
|
+
import { type RequestData } from '../../requests/_shared.js';
|
|
4
4
|
export interface CodeSample {
|
|
5
5
|
lang: string;
|
|
6
6
|
label: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/render/operation/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EAEV,iBAAiB,EAEjB,aAAa,EAEd,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/render/operation/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EAEV,iBAAiB,EAEjB,aAAa,EAEd,MAAM,SAAS,CAAC;AAejB,OAAO,EAAE,KAAK,WAAW,EAAuB,MAAM,oBAAoB,CAAC;AAK3E,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EACH,MAAM,GACN,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,MAAM,GAAG,SAAS,CAAC,GACxD,KAAK,CAAC;CACX;AASD,wBAAgB,SAAS,CAAC,EACxB,IAAkB,EAClB,IAAI,EACJ,MAAM,EACN,GAAG,EACH,OAAO,EACP,YAAgB,GACjB,EAAE;IACD,IAAI,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;IAEnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,YAAY,CAgLf"}
|
|
@@ -11,6 +11,9 @@ import { methodKeys } from '../../build-routes.js';
|
|
|
11
11
|
import { APIExample, APIExampleProvider, getAPIExamples, } from '../../render/operation/api-example.js';
|
|
12
12
|
import { MethodLabel } from '../../ui/components/method-label.js';
|
|
13
13
|
import { supportedMediaTypes } from '../../requests/_shared.js';
|
|
14
|
+
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
|
|
15
|
+
import { CodeBlock } from '../../render/codeblock.js';
|
|
16
|
+
import { getTypescriptSchema } from '../../utils/get-typescript-schema.js';
|
|
14
17
|
const ParamTypes = {
|
|
15
18
|
path: 'Path Parameters',
|
|
16
19
|
query: 'Query Parameters',
|
|
@@ -34,31 +37,15 @@ export function Operation({ type = 'operation', path, method, ctx, hasHead, head
|
|
|
34
37
|
if (!type ||
|
|
35
38
|
!supportedMediaTypes.includes(String(type)))
|
|
36
39
|
throw new Error(`No supported media type for body content: ${path}, received: ${type}`);
|
|
37
|
-
bodyNode = (_jsxs(_Fragment, { children: [heading(headingLevel, 'Request Body', ctx), _jsxs("div", { className: "mb-8 flex flex-row items-center justify-between gap-2", children: [_jsx("code", { children: type }), _jsx("span", { children: body.required ? 'Required' : 'Optional' })] }), body.description ? _jsx(Markdown, { text: body.description }) : null, _jsx(Schema, { name: "body", schema: body.content[type].schema ?? {}, ctx: {
|
|
40
|
+
bodyNode = (_jsxs(_Fragment, { children: [heading(headingLevel, 'Request Body', ctx), _jsxs("div", { className: "mb-8 flex flex-row items-center justify-between gap-2", children: [_jsx("code", { children: type }), _jsx("span", { children: body.required ? 'Required' : 'Optional' })] }), body.description ? _jsx(Markdown, { text: body.description }) : null, _jsx(Schema, { name: "body", schema: body.content[type].schema ?? {}, required: body.required, ctx: {
|
|
38
41
|
readOnly: method.method === 'GET',
|
|
39
42
|
writeOnly: method.method !== 'GET',
|
|
40
|
-
required: body.required ?? false,
|
|
41
43
|
render: ctx,
|
|
42
|
-
allowFile: type === 'multipart/form-data',
|
|
43
44
|
} })] }));
|
|
44
45
|
}
|
|
45
|
-
if (method.responses && ctx.showResponseSchema) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return;
|
|
49
|
-
const mediaType = getPreferredType(response.content);
|
|
50
|
-
if (!mediaType)
|
|
51
|
-
return null;
|
|
52
|
-
const content = response.content[mediaType];
|
|
53
|
-
if (!content.schema)
|
|
54
|
-
return null;
|
|
55
|
-
return (_jsxs(Fragment, { children: [heading(headingLevel + 1, status, ctx), _jsx(Markdown, { text: response.description }), _jsx(Schema, { name: "response", schema: content.schema, ctx: {
|
|
56
|
-
render: ctx,
|
|
57
|
-
writeOnly: false,
|
|
58
|
-
readOnly: true,
|
|
59
|
-
required: true,
|
|
60
|
-
} })] }, status));
|
|
61
|
-
})] }));
|
|
46
|
+
if (method.responses && ctx.showResponseSchema !== false) {
|
|
47
|
+
const statuses = Object.keys(method.responses);
|
|
48
|
+
responseNode = (_jsxs(_Fragment, { children: [heading(headingLevel, 'Response Body', ctx), _jsx(Tabs, { items: statuses, groupId: "fumadocs_openapi_responses", className: "bg-transparent", children: statuses.map((status) => (_jsx(ResponseTab, { status: status, operation: method, ctx: ctx }, status))) })] }));
|
|
62
49
|
}
|
|
63
50
|
const parameterNode = Object.entries(ParamTypes).map(([type, title]) => {
|
|
64
51
|
const params = method.parameters?.filter((param) => param.in === type);
|
|
@@ -69,11 +56,9 @@ export function Operation({ type = 'operation', path, method, ctx, hasHead, head
|
|
|
69
56
|
description: param.description ?? param.schema?.description,
|
|
70
57
|
deprecated: (param.deprecated ?? false) ||
|
|
71
58
|
(param.schema?.deprecated ?? false),
|
|
72
|
-
}, ctx: {
|
|
73
|
-
parseObject: false,
|
|
59
|
+
}, parseObject: false, required: param.required, ctx: {
|
|
74
60
|
readOnly: method.method === 'GET',
|
|
75
61
|
writeOnly: method.method !== 'GET',
|
|
76
|
-
required: param.required ?? false,
|
|
77
62
|
render: ctx,
|
|
78
63
|
} }, param.name))) })] }, type));
|
|
79
64
|
});
|
|
@@ -92,6 +77,27 @@ export function Operation({ type = 'operation', path, method, ctx, hasHead, head
|
|
|
92
77
|
return info;
|
|
93
78
|
}
|
|
94
79
|
}
|
|
80
|
+
async function ResponseTab({ status, operation, ctx, }) {
|
|
81
|
+
const response = operation.responses[status];
|
|
82
|
+
const { generateTypeScriptSchema, schema } = ctx;
|
|
83
|
+
const mediaType = response.content
|
|
84
|
+
? getPreferredType(response.content)
|
|
85
|
+
: null;
|
|
86
|
+
const responseOfType = mediaType ? response.content?.[mediaType] : null;
|
|
87
|
+
const description = responseOfType?.schema?.description ?? response.description ?? '';
|
|
88
|
+
let ts;
|
|
89
|
+
if (generateTypeScriptSchema) {
|
|
90
|
+
ts = await generateTypeScriptSchema(operation, status);
|
|
91
|
+
}
|
|
92
|
+
else if (generateTypeScriptSchema === undefined && responseOfType?.schema) {
|
|
93
|
+
ts = await getTypescriptSchema(responseOfType?.schema, schema.dereferenceMap);
|
|
94
|
+
}
|
|
95
|
+
return (_jsxs(Tab, { value: status, children: [_jsx(Markdown, { text: description }), responseOfType?.schema && (_jsx(Schema, { name: "response", schema: responseOfType.schema, required: true, ctx: {
|
|
96
|
+
render: ctx,
|
|
97
|
+
writeOnly: false,
|
|
98
|
+
readOnly: true,
|
|
99
|
+
} })), ts && _jsx(CodeBlock, { lang: "ts", code: ts, ctx: ctx, className: "mt-4" })] }));
|
|
100
|
+
}
|
|
95
101
|
function WebhookCallback({ callback, ctx, headingLevel, }) {
|
|
96
102
|
return Object.entries(callback).map(([path, pathItem]) => {
|
|
97
103
|
const pathNodes = methodKeys.map((method) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/render/renderer.tsx"],"names":[],"mappings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
2
2
|
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
|
|
3
3
|
import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
|
|
4
|
-
import { API,
|
|
4
|
+
import { API, APIExample, APIInfo, ObjectCollapsible, Property, Root, } from '../ui/index.js';
|
|
5
5
|
import { APIPlayground } from '../playground/index.js';
|
|
6
6
|
import { CodeExampleSelector } from '../ui/contexts/code-example.lazy.js';
|
|
7
7
|
export function createRenders(shikiOptions) {
|
|
@@ -10,7 +10,7 @@ export function createRenders(shikiOptions) {
|
|
|
10
10
|
API,
|
|
11
11
|
APIInfo: ({ children, head }) => (_jsxs(APIInfo, { children: [head, children] })),
|
|
12
12
|
APIExample,
|
|
13
|
-
Responses: Tabs,
|
|
13
|
+
Responses: (props) => (_jsx(Tabs, { ...props, groupId: "fumadocs_openapi_responses" })),
|
|
14
14
|
Response: Tab,
|
|
15
15
|
ResponseTypes: (props) => (_jsx(Accordions, { type: "single", className: "!-m-4 border-none pt-2", defaultValue: props.defaultValue, children: props.children })),
|
|
16
16
|
ResponseType: (props) => (_jsx(Accordion, { title: props.label, children: props.children })),
|
package/dist/render/schema.d.ts
CHANGED
|
@@ -4,25 +4,19 @@ import type { RenderContext } from '../types.js';
|
|
|
4
4
|
interface Context {
|
|
5
5
|
readOnly: boolean;
|
|
6
6
|
writeOnly: boolean;
|
|
7
|
-
|
|
7
|
+
stack?: ParsedSchema[];
|
|
8
|
+
render: RenderContext;
|
|
9
|
+
}
|
|
10
|
+
export declare function Schema({ name, schema, required, parseObject, ctx, }: {
|
|
11
|
+
name: string;
|
|
12
|
+
required?: boolean;
|
|
13
|
+
schema: NoReference<ParsedSchema>;
|
|
8
14
|
/**
|
|
9
15
|
* Render the full object
|
|
10
16
|
*
|
|
11
17
|
* @defaultValue true
|
|
12
18
|
* */
|
|
13
19
|
parseObject?: boolean;
|
|
14
|
-
/**
|
|
15
|
-
* Parse binary format string to be files
|
|
16
|
-
*
|
|
17
|
-
* @defaultValue false
|
|
18
|
-
*/
|
|
19
|
-
allowFile?: boolean;
|
|
20
|
-
stack?: ParsedSchema[];
|
|
21
|
-
render: RenderContext;
|
|
22
|
-
}
|
|
23
|
-
export declare function Schema({ name, schema, ctx, }: {
|
|
24
|
-
name: string;
|
|
25
|
-
schema: NoReference<ParsedSchema>;
|
|
26
20
|
ctx: Context;
|
|
27
21
|
}): ReactNode;
|
|
28
22
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/render/schema.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAc,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAgB7C,UAAU,OAAO;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/render/schema.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAc,WAAW,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAgB7C,UAAU,OAAO;IACf,QAAQ,EAAE,OAAO,CAAC;IAClB,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;IAEvB,MAAM,EAAE,aAAa,CAAC;CACvB;AAUD,wBAAgB,MAAM,CAAC,EACrB,IAAI,EACJ,MAAM,EACN,QAAgB,EAChB,WAAkB,EAClB,GAAG,GACJ,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;IAElC;;;;SAIK;IACL,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB,GAAG,EAAE,OAAO,CAAC;CACd,GAAG,SAAS,CAmKZ"}
|
package/dist/render/schema.js
CHANGED
|
@@ -16,13 +16,11 @@ function isObject(schema) {
|
|
|
16
16
|
schema.properties !== undefined ||
|
|
17
17
|
schema.additionalProperties !== undefined);
|
|
18
18
|
}
|
|
19
|
-
export function Schema({ name, schema, ctx, }) {
|
|
19
|
+
export function Schema({ name, schema, required = false, parseObject = true, ctx, }) {
|
|
20
20
|
if ((schema.readOnly === true && !ctx.readOnly) ||
|
|
21
21
|
(schema.writeOnly === true && !ctx.writeOnly))
|
|
22
22
|
return null;
|
|
23
|
-
const
|
|
24
|
-
const stack = ctx.stack ?? [];
|
|
25
|
-
const { renderer } = ctx.render;
|
|
23
|
+
const { render: { renderer }, stack = [], } = ctx;
|
|
26
24
|
// object type
|
|
27
25
|
if (isObject(schema) &&
|
|
28
26
|
parseObject &&
|
|
@@ -34,25 +32,26 @@ export function Schema({ name, schema, ctx, }) {
|
|
|
34
32
|
footer = _jsx(renderer.Property, { name: "[key: string]", type: "any" });
|
|
35
33
|
}
|
|
36
34
|
else if (additionalProperties) {
|
|
37
|
-
footer = (_jsx(Schema, { name: "[key: string]", schema: additionalProperties, ctx: {
|
|
35
|
+
footer = (_jsx(Schema, { name: "[key: string]", schema: additionalProperties, parseObject: false, ctx: {
|
|
38
36
|
...ctx,
|
|
39
|
-
|
|
40
|
-
parseObject: false,
|
|
37
|
+
stack: [schema, ...stack],
|
|
41
38
|
} }));
|
|
42
39
|
}
|
|
43
40
|
if (properties) {
|
|
44
41
|
body = Object.entries(properties).map(([key, value]) => {
|
|
45
|
-
return (_jsx(Schema, { name: key, schema: value, ctx: {
|
|
42
|
+
return (_jsx(Schema, { name: key, schema: value, parseObject: false, required: schema.required?.includes(key) ?? false, ctx: {
|
|
46
43
|
...ctx,
|
|
47
|
-
|
|
48
|
-
parseObject: false,
|
|
44
|
+
stack: [schema, ...stack],
|
|
49
45
|
} }, key));
|
|
50
46
|
});
|
|
51
47
|
}
|
|
52
48
|
return (_jsxs("div", { className: "flex flex-col gap-4", children: [body, footer] }));
|
|
53
49
|
}
|
|
54
50
|
if (schema.allOf && parseObject) {
|
|
55
|
-
return (_jsx(Schema, { name: name, schema: combineSchema(schema.allOf), ctx:
|
|
51
|
+
return (_jsx(Schema, { name: name, schema: combineSchema(schema.allOf), ctx: {
|
|
52
|
+
...ctx,
|
|
53
|
+
stack: [schema, ...stack],
|
|
54
|
+
} }));
|
|
56
55
|
}
|
|
57
56
|
let footer;
|
|
58
57
|
const fields = [];
|
|
@@ -73,8 +72,6 @@ export function Schema({ name, schema, ctx, }) {
|
|
|
73
72
|
if (isObject(schema) && !parseObject && !stack.includes(schema)) {
|
|
74
73
|
footer = (_jsx(renderer.ObjectCollapsible, { name: "Show Attributes", children: _jsx(Schema, { name: name, schema: schema, ctx: {
|
|
75
74
|
...ctx,
|
|
76
|
-
parseObject: true,
|
|
77
|
-
required: false,
|
|
78
75
|
stack: [schema, ...stack],
|
|
79
76
|
} }) }));
|
|
80
77
|
}
|
|
@@ -82,7 +79,7 @@ export function Schema({ name, schema, ctx, }) {
|
|
|
82
79
|
const mentionedObjectTypes = [
|
|
83
80
|
...(schema.anyOf ?? schema.oneOf ?? []),
|
|
84
81
|
...(schema.not ? [schema.not] : []),
|
|
85
|
-
...(schema.type === 'array' ? [schema.items] : []),
|
|
82
|
+
...(schema.type === 'array' && schema.items ? [schema.items] : []),
|
|
86
83
|
].filter((s) => isComplexType(s) && !stack.includes(s));
|
|
87
84
|
footer = mentionedObjectTypes.map((s, idx) => {
|
|
88
85
|
return (_jsx(renderer.ObjectCollapsible, { name: s.title ??
|
|
@@ -91,12 +88,10 @@ export function Schema({ name, schema, ctx, }) {
|
|
|
91
88
|
: `Object ${idx + 1}`), children: _jsx(Schema, { name: "element", schema: s, ctx: {
|
|
92
89
|
...ctx,
|
|
93
90
|
stack: [schema, ...stack],
|
|
94
|
-
parseObject: true,
|
|
95
|
-
required: false,
|
|
96
91
|
} }) }, idx));
|
|
97
92
|
});
|
|
98
93
|
}
|
|
99
|
-
return (_jsxs(renderer.Property, { name: name, type: getSchemaType(schema, ctx), required:
|
|
94
|
+
return (_jsxs(renderer.Property, { name: name, type: getSchemaType(schema, ctx), required: required, deprecated: schema.deprecated, children: [schema.description ? _jsx(Markdown, { text: schema.description }) : null, fields.length > 0 ? (_jsx("div", { className: "flex flex-col gap-2", children: fields.map((field) => (_jsxs("span", { children: [field.key, ": ", _jsx("code", { children: field.value })] }, field.key))) })) : null, footer] }));
|
|
100
95
|
}
|
|
101
96
|
/**
|
|
102
97
|
* Check if the schema needs another collapsible to explain
|
|
@@ -115,7 +110,7 @@ function getSchemaType(schema, ctx, isRoot = true) {
|
|
|
115
110
|
if (schema.title)
|
|
116
111
|
return schema.title;
|
|
117
112
|
if (schema.type === 'array')
|
|
118
|
-
return `array<${getSchemaType(schema.items, ctx)}>`;
|
|
113
|
+
return `array<${schema.items ? getSchemaType(schema.items, ctx) : 'unknown'}>`;
|
|
119
114
|
if (schema.oneOf)
|
|
120
115
|
return schema.oneOf
|
|
121
116
|
.map((one) => getSchemaType(one, ctx, false))
|
|
@@ -141,7 +136,7 @@ function getSchemaType(schema, ctx, isRoot = true) {
|
|
|
141
136
|
}
|
|
142
137
|
// otherwise unknown
|
|
143
138
|
}
|
|
144
|
-
if (schema.type === 'string' && schema.format === 'binary'
|
|
139
|
+
if (schema.type === 'string' && schema.format === 'binary')
|
|
145
140
|
return 'file';
|
|
146
141
|
if (schema.type && Array.isArray(schema.type)) {
|
|
147
142
|
const nonNullTypes = schema.type.filter((v) => v !== 'null');
|
package/dist/types.d.ts
CHANGED
|
@@ -56,6 +56,8 @@ export interface RenderContext {
|
|
|
56
56
|
shikiOptions?: Omit<CodeToHastOptionsCommon, 'lang'> & CodeOptionsThemes<BuiltinTheme>;
|
|
57
57
|
/**
|
|
58
58
|
* Show full response schema instead of only example response & Typescript definitions
|
|
59
|
+
*
|
|
60
|
+
* @default true
|
|
59
61
|
*/
|
|
60
62
|
showResponseSchema?: boolean;
|
|
61
63
|
}
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;AACrC,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;AACnD,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;AACnD,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,yBAAyB,CAAC;AACvE,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,CAAC;AAC7D,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;AACnD,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;AACjD,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;AACvC,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAC1D,MAAM,MAAM,cAAc,GAAG,WAAW,C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AC;IAElB,QAAQ,EAAE,QAAQ,CAAC;IAEnB;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,YAAY,EAAE,CAAC;IAExB,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,MAAM,EAAE,iBAAiB,CAAC;IAE1B;;;;;;;OAOG;IACH,wBAAwB,CAAC,EACrB,CAAC,CACC,MAAM,EAAE,WAAW,CAAC,iBAAiB,CAAC,EACtC,UAAU,EAAE,MAAM,KACf,SAAS,CAAC,MAAM,CAAC,CAAC,GACvB,KAAK,CAAC;IAEV;;OAEG;IACH,mBAAmB,CAAC,EAAE,CACpB,MAAM,EAAE,WAAW,CAAC,iBAAiB,CAAC,KACnC,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC;IAE7B,YAAY,CAAC,EAAE,IAAI,CAAC,uBAAuB,EAAE,MAAM,CAAC,GAClD,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAElC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-openapi",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.1.1",
|
|
4
4
|
"description": "Generate MDX docs for your OpenAPI spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"import": "./dist/index.js",
|
|
17
17
|
"types": "./dist/index.d.ts"
|
|
18
18
|
},
|
|
19
|
+
"./css/*": "./css/*",
|
|
19
20
|
"./ui": {
|
|
20
21
|
"import": "./dist/ui/index.js",
|
|
21
22
|
"types": "./dist/ui/index.d.ts"
|
|
@@ -44,8 +45,8 @@
|
|
|
44
45
|
],
|
|
45
46
|
"dependencies": {
|
|
46
47
|
"@fumari/json-schema-to-typescript": "^1.1.3",
|
|
47
|
-
"@radix-ui/react-dialog": "^1.1.
|
|
48
|
-
"@radix-ui/react-select": "^2.
|
|
48
|
+
"@radix-ui/react-dialog": "^1.1.10",
|
|
49
|
+
"@radix-ui/react-select": "^2.2.2",
|
|
49
50
|
"@radix-ui/react-slot": "^1.2.0",
|
|
50
51
|
"@scalar/openapi-parser": "0.10.16",
|
|
51
52
|
"ajv-draft-04": "^1.0.0",
|
|
@@ -54,19 +55,19 @@
|
|
|
54
55
|
"github-slugger": "^2.0.0",
|
|
55
56
|
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
56
57
|
"js-yaml": "^4.1.0",
|
|
57
|
-
"lucide-react": "^0.
|
|
58
|
+
"lucide-react": "^0.503.0",
|
|
58
59
|
"next-themes": "^0.4.6",
|
|
59
60
|
"openapi-sampler": "^1.6.1",
|
|
60
|
-
"react-hook-form": "^7.
|
|
61
|
+
"react-hook-form": "^7.56.0",
|
|
61
62
|
"remark": "^15.0.1",
|
|
62
63
|
"remark-rehype": "^11.1.2",
|
|
63
|
-
"shiki": "^3.
|
|
64
|
+
"shiki": "^3.3.0",
|
|
64
65
|
"xml-js": "^1.6.11",
|
|
65
|
-
"fumadocs-core": "15.2.
|
|
66
|
-
"fumadocs-ui": "15.2.
|
|
66
|
+
"fumadocs-core": "15.2.10",
|
|
67
|
+
"fumadocs-ui": "15.2.10"
|
|
67
68
|
},
|
|
68
69
|
"devDependencies": {
|
|
69
|
-
"@scalar/api-client-react": "^1.2.
|
|
70
|
+
"@scalar/api-client-react": "^1.2.23",
|
|
70
71
|
"@types/js-yaml": "^4.0.9",
|
|
71
72
|
"@types/node": "22.14.1",
|
|
72
73
|
"@types/openapi-sampler": "^1.0.3",
|