fumadocs-openapi 10.0.10 → 10.1.0
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 +6 -5
- package/dist/generate-file.d.ts.map +1 -1
- package/dist/generate-file.js +44 -37
- package/dist/playground/client.d.ts +9 -7
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +7 -7
- package/dist/playground/components/inputs.d.ts +6 -6
- package/dist/playground/components/inputs.d.ts.map +1 -1
- package/dist/playground/components/inputs.js +13 -12
- package/dist/playground/get-default-values.d.ts +2 -2
- package/dist/playground/get-default-values.d.ts.map +1 -1
- package/dist/playground/index.d.ts +1 -2
- package/dist/playground/index.d.ts.map +1 -1
- package/dist/playground/index.js +2 -0
- package/dist/playground/schema.d.ts +22 -8
- package/dist/playground/schema.d.ts.map +1 -1
- package/dist/playground/schema.js +29 -34
- package/dist/requests/generators/index.d.ts +1 -1
- package/dist/requests/generators/index.d.ts.map +1 -1
- package/dist/server/create.d.ts +1 -1
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/source-api.d.ts +5 -3
- package/dist/server/source-api.d.ts.map +1 -1
- package/dist/server/source-api.js +13 -7
- package/dist/types.d.ts +3 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/api-page.d.ts +16 -8
- package/dist/ui/api-page.d.ts.map +1 -1
- package/dist/ui/api-page.js +7 -7
- package/dist/ui/client/index.d.ts +2 -2
- package/dist/ui/client/index.d.ts.map +1 -1
- package/dist/ui/operation/index.d.ts +4 -3
- package/dist/ui/operation/index.d.ts.map +1 -1
- package/dist/ui/operation/index.js +45 -24
- package/dist/ui/operation/request-tabs.d.ts +18 -0
- package/dist/ui/operation/request-tabs.d.ts.map +1 -0
- package/dist/ui/operation/request-tabs.js +143 -0
- package/dist/ui/operation/response-tabs.d.ts +32 -0
- package/dist/ui/operation/response-tabs.d.ts.map +1 -0
- package/dist/ui/operation/response-tabs.js +59 -0
- package/dist/ui/operation/usage-tabs/client.d.ts +23 -0
- package/dist/ui/operation/usage-tabs/client.d.ts.map +1 -0
- package/dist/ui/operation/{example-panel → usage-tabs}/client.js +50 -6
- package/dist/ui/operation/usage-tabs/index.d.ts +26 -0
- package/dist/ui/operation/usage-tabs/index.d.ts.map +1 -0
- package/dist/ui/operation/usage-tabs/index.js +52 -0
- package/dist/ui/operation/usage-tabs/lazy.d.ts +4 -0
- package/dist/ui/operation/usage-tabs/lazy.d.ts.map +1 -0
- package/dist/ui/operation/usage-tabs/lazy.js +5 -0
- package/dist/ui/schema/client.d.ts +1 -3
- package/dist/ui/schema/client.d.ts.map +1 -1
- package/dist/ui/schema/client.js +13 -17
- package/dist/ui/schema/index.d.ts +19 -5
- package/dist/ui/schema/index.d.ts.map +1 -1
- package/dist/ui/schema/index.js +69 -29
- package/dist/utils/deep-equal.d.ts +2 -0
- package/dist/utils/deep-equal.d.ts.map +1 -0
- package/dist/utils/deep-equal.js +27 -0
- package/dist/utils/merge-schema.d.ts +7 -0
- package/dist/utils/merge-schema.d.ts.map +1 -0
- package/dist/utils/merge-schema.js +179 -0
- package/dist/utils/pages/to-body.d.ts.map +1 -1
- package/dist/utils/pages/to-body.js +2 -3
- package/dist/utils/pages/to-text.d.ts.map +1 -1
- package/dist/utils/pages/to-text.js +31 -16
- package/dist/utils/schema-to-string.d.ts.map +1 -1
- package/dist/utils/schema-to-string.js +8 -5
- package/dist/utils/use-query.d.ts +1 -0
- package/dist/utils/use-query.d.ts.map +1 -1
- package/dist/utils/use-query.js +5 -0
- package/package.json +6 -6
- package/dist/ui/contexts/operation.d.ts +0 -20
- package/dist/ui/contexts/operation.d.ts.map +0 -1
- package/dist/ui/contexts/operation.js +0 -48
- package/dist/ui/contexts/operation.lazy.d.ts +0 -2
- package/dist/ui/contexts/operation.lazy.d.ts.map +0 -1
- package/dist/ui/contexts/operation.lazy.js +0 -3
- package/dist/ui/operation/example-panel/client.d.ts +0 -4
- package/dist/ui/operation/example-panel/client.d.ts.map +0 -1
- package/dist/ui/operation/example-panel/index.d.ts +0 -58
- package/dist/ui/operation/example-panel/index.d.ts.map +0 -1
- package/dist/ui/operation/example-panel/index.js +0 -140
- package/dist/ui/operation/example-panel/lazy.d.ts +0 -3
- package/dist/ui/operation/example-panel/lazy.d.ts.map +0 -1
- package/dist/ui/operation/example-panel/lazy.js +0 -4
- package/dist/ui/operation/get-request-data.d.ts +0 -4
- package/dist/ui/operation/get-request-data.d.ts.map +0 -1
- package/dist/ui/operation/get-request-data.js +0 -70
- package/dist/utils/combine-schema.d.ts +0 -6
- package/dist/utils/combine-schema.d.ts.map +0 -1
- package/dist/utils/combine-schema.js +0 -51
|
@@ -7,7 +7,6 @@ export function toText(entry, processed, options = {}) {
|
|
|
7
7
|
case 'operation':
|
|
8
8
|
return generatePage(entry.schemaId, processed, {
|
|
9
9
|
operations: [entry.item],
|
|
10
|
-
hasHead: false,
|
|
11
10
|
}, {
|
|
12
11
|
...options,
|
|
13
12
|
...entry.info,
|
|
@@ -18,7 +17,7 @@ export function toText(entry, processed, options = {}) {
|
|
|
18
17
|
return generatePage(entry.schemaId, processed, {
|
|
19
18
|
operations: entry.operations,
|
|
20
19
|
webhooks: entry.webhooks,
|
|
21
|
-
|
|
20
|
+
showTitle: true,
|
|
22
21
|
}, {
|
|
23
22
|
...options,
|
|
24
23
|
...entry.info,
|
|
@@ -29,7 +28,7 @@ export function toText(entry, processed, options = {}) {
|
|
|
29
28
|
return generatePage(entry.schemaId, processed, {
|
|
30
29
|
operations: entry.operations,
|
|
31
30
|
webhooks: entry.webhooks,
|
|
32
|
-
|
|
31
|
+
showTitle: true,
|
|
33
32
|
}, {
|
|
34
33
|
...options,
|
|
35
34
|
...entry.info,
|
|
@@ -40,7 +39,6 @@ export function toText(entry, processed, options = {}) {
|
|
|
40
39
|
case 'webhook':
|
|
41
40
|
return generatePage(entry.schemaId, processed, {
|
|
42
41
|
webhooks: [entry.item],
|
|
43
|
-
hasHead: false,
|
|
44
42
|
}, {
|
|
45
43
|
...options,
|
|
46
44
|
...entry.info,
|
|
@@ -83,7 +81,13 @@ function generatePage(schemaId, processed, pageProps, options, context) {
|
|
|
83
81
|
const operation = page.operations[0];
|
|
84
82
|
meta = {
|
|
85
83
|
method: operation.method.toUpperCase(),
|
|
86
|
-
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
else if (page.webhooks?.length === 1) {
|
|
87
|
+
const webhook = page.webhooks[0];
|
|
88
|
+
meta = {
|
|
89
|
+
method: webhook.method.toUpperCase(),
|
|
90
|
+
webhook: true,
|
|
87
91
|
};
|
|
88
92
|
}
|
|
89
93
|
const data = generateStaticData(processed.dereferenced, page);
|
|
@@ -111,7 +115,7 @@ function generateStaticData(dereferenced, props) {
|
|
|
111
115
|
const operation = dereferenced.paths?.[item.path]?.[item.method];
|
|
112
116
|
if (!operation)
|
|
113
117
|
continue;
|
|
114
|
-
if (props.
|
|
118
|
+
if (props.showTitle && operation.operationId) {
|
|
115
119
|
const title = operation.summary ??
|
|
116
120
|
(operation.operationId ? idToTitle(operation.operationId) : item.path);
|
|
117
121
|
const id = slugger.slug(title);
|
|
@@ -133,15 +137,26 @@ function generateStaticData(dereferenced, props) {
|
|
|
133
137
|
}
|
|
134
138
|
return { toc, structuredData };
|
|
135
139
|
}
|
|
136
|
-
function pageContent(
|
|
140
|
+
function pageContent({ showTitle, showDescription, document, webhooks, operations, }) {
|
|
141
|
+
const propStrs = [`document={${JSON.stringify(document)}}`];
|
|
137
142
|
// filter extra properties in props
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
143
|
+
if (webhooks) {
|
|
144
|
+
propStrs.push(`webhooks={${JSON.stringify(webhooks.map((item) => ({
|
|
145
|
+
name: item.name,
|
|
146
|
+
method: item.method,
|
|
147
|
+
})))}}`);
|
|
148
|
+
}
|
|
149
|
+
if (operations) {
|
|
150
|
+
propStrs.push(`operations={${JSON.stringify(operations.map((item) => ({
|
|
151
|
+
path: item.path,
|
|
152
|
+
method: item.method,
|
|
153
|
+
})))}}`);
|
|
154
|
+
}
|
|
155
|
+
if (showTitle) {
|
|
156
|
+
propStrs.push(`showTitle={${JSON.stringify(showTitle)}}`);
|
|
157
|
+
}
|
|
158
|
+
if (showDescription) {
|
|
159
|
+
propStrs.push(`showDescription={${JSON.stringify(showDescription)}}`);
|
|
160
|
+
}
|
|
161
|
+
return `<APIPage ${propStrs.join(' ')} />`;
|
|
147
162
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema-to-string.d.ts","sourceRoot":"","sources":["../../src/utils/schema-to-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,oBAAY,WAAW;IACrB,IAAI,IAAI;IACR,QAAQ,IAAS;CAClB;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,cAAc,EACrB,GAAG,CAAC,EAAE,iBAAiB,EACvB,KAAK,GAAE,WAA8B,GACpC,MAAM,
|
|
1
|
+
{"version":3,"file":"schema-to-string.d.ts","sourceRoot":"","sources":["../../src/utils/schema-to-string.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,oBAAY,WAAW;IACrB,IAAI,IAAI;IACR,QAAQ,IAAS;CAClB;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,cAAc,EACrB,GAAG,CAAC,EAAE,iBAAiB,EACvB,KAAK,GAAE,WAA8B,GACpC,MAAM,CA0ER"}
|
|
@@ -39,12 +39,15 @@ export function schemaToString(value, ctx, flags = FormatFlags.None) {
|
|
|
39
39
|
}
|
|
40
40
|
if (schema.type === 'array')
|
|
41
41
|
return `array<${schema.items ? run(schema.items, flags | FormatFlags.UseAlias) : 'unknown'}>`;
|
|
42
|
-
|
|
43
|
-
|
|
42
|
+
const or = schema.oneOf ?? schema.anyOf;
|
|
43
|
+
if (schema.oneOf && schema.anyOf) {
|
|
44
|
+
return `(${union(schema.oneOf, ' | ', flags)}) & (${union(schema.anyOf, ' | ', flags)})`;
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
else if (or) {
|
|
47
|
+
return union(or, ' | ', flags);
|
|
48
|
+
}
|
|
49
|
+
if (schema.allOf) {
|
|
50
|
+
return union(schema.allOf, ' & ', flags);
|
|
48
51
|
}
|
|
49
52
|
if (schema.not)
|
|
50
53
|
return `not ${run(schema.not, flags)}`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-query.d.ts","sourceRoot":"","sources":["../../src/utils/use-query.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAC7C,EAAE,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC9B;IACD,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC7B,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;CACpB,
|
|
1
|
+
{"version":3,"file":"use-query.d.ts","sourceRoot":"","sources":["../../src/utils/use-query.ts"],"names":[],"mappings":"AAEA,wBAAgB,QAAQ,CAAC,CAAC,SAAS,OAAO,EAAE,EAAE,CAAC,EAC7C,EAAE,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,GAC9B;IACD,KAAK,EAAE,CAAC,GAAG,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAC7B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,OAAO,CAAC;CACpB,CAqCA"}
|
package/dist/utils/use-query.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fumadocs-openapi",
|
|
3
|
-
"version": "10.0
|
|
3
|
+
"version": "10.1.0",
|
|
4
4
|
"description": "Generate MDX docs for your OpenAPI spec",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"NextJs",
|
|
@@ -59,7 +59,6 @@
|
|
|
59
59
|
"ajv": "^8.17.1",
|
|
60
60
|
"class-variance-authority": "^0.7.1",
|
|
61
61
|
"github-slugger": "^2.0.0",
|
|
62
|
-
"gray-matter": "^4.0.3",
|
|
63
62
|
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
64
63
|
"js-yaml": "^4.1.1",
|
|
65
64
|
"next-themes": "^0.4.6",
|
|
@@ -67,10 +66,7 @@
|
|
|
67
66
|
"react-hook-form": "^7.66.0",
|
|
68
67
|
"remark": "^15.0.1",
|
|
69
68
|
"remark-rehype": "^11.1.2",
|
|
70
|
-
"
|
|
71
|
-
"xml-js": "^1.6.11",
|
|
72
|
-
"fumadocs-core": "16.0.15",
|
|
73
|
-
"fumadocs-ui": "16.0.15"
|
|
69
|
+
"xml-js": "^1.6.11"
|
|
74
70
|
},
|
|
75
71
|
"devDependencies": {
|
|
76
72
|
"@scalar/api-client-react": "^1.3.50",
|
|
@@ -82,10 +78,14 @@
|
|
|
82
78
|
"openapi-types": "^12.1.3",
|
|
83
79
|
"tailwindcss": "^4.1.17",
|
|
84
80
|
"tsc-alias": "^1.8.16",
|
|
81
|
+
"fumadocs-core": "16.2.0",
|
|
82
|
+
"fumadocs-ui": "16.2.0",
|
|
85
83
|
"eslint-config-custom": "0.0.0",
|
|
86
84
|
"tsconfig": "0.0.0"
|
|
87
85
|
},
|
|
88
86
|
"peerDependencies": {
|
|
87
|
+
"fumadocs-core": "^16.2.0",
|
|
88
|
+
"fumadocs-ui": "^16.2.0",
|
|
89
89
|
"@scalar/api-client-react": "*",
|
|
90
90
|
"@types/react": "*",
|
|
91
91
|
"react": "^19.2.0",
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { type ReactNode } from 'react';
|
|
2
|
-
import type { APIExampleItem } from '../../ui/operation/example-panel/index.js';
|
|
3
|
-
import type { RawRequestData, RequestData } from '../../requests/types.js';
|
|
4
|
-
export type ExampleUpdateListener = (data: RawRequestData, encoded: RequestData) => void;
|
|
5
|
-
export declare function OperationProvider({ route, examples, defaultExampleId, children, }: {
|
|
6
|
-
route: string;
|
|
7
|
-
examples: APIExampleItem[];
|
|
8
|
-
defaultExampleId?: string;
|
|
9
|
-
children: ReactNode;
|
|
10
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
11
|
-
export declare function useOperationContext(): {
|
|
12
|
-
route: string;
|
|
13
|
-
examples: APIExampleItem[];
|
|
14
|
-
example: string | undefined;
|
|
15
|
-
setExample: (id: string) => void;
|
|
16
|
-
setExampleData: (data: RawRequestData, encoded: RequestData) => void;
|
|
17
|
-
addListener: (listener: ExampleUpdateListener) => void;
|
|
18
|
-
removeListener: (listener: ExampleUpdateListener) => void;
|
|
19
|
-
};
|
|
20
|
-
//# sourceMappingURL=operation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/operation.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,SAAS,EAKf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpE,MAAM,MAAM,qBAAqB,GAAG,CAClC,IAAI,EAAE,cAAc,EACpB,OAAO,EAAE,WAAW,KACjB,IAAI,CAAC;AAaV,wBAAgB,iBAAiB,CAAC,EAChC,KAAK,EACL,QAAQ,EACR,gBAAgB,EAChB,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,cAAc,EAAE,CAAC;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,QAAQ,EAAE,SAAS,CAAC;CACrB,2CAwDA;AAED,wBAAgB,mBAAmB;WA9E1B,MAAM;cACH,cAAc,EAAE;aACjB,MAAM,GAAG,SAAS;gBACf,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI;oBAChB,CAAC,IAAI,EAAE,cAAc,EAAE,OAAO,EAAE,WAAW,KAAK,IAAI;iBAEvD,CAAC,QAAQ,EAAE,qBAAqB,KAAK,IAAI;oBACtC,CAAC,QAAQ,EAAE,qBAAqB,KAAK,IAAI;EAyE1D"}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, use, useMemo, useRef, useState, } from 'react';
|
|
4
|
-
const OperationContext = createContext(null);
|
|
5
|
-
export function OperationProvider({ route, examples, defaultExampleId, children, }) {
|
|
6
|
-
const [example, setExample] = useState(() => defaultExampleId ?? examples.at(0)?.id);
|
|
7
|
-
const listeners = useRef([]);
|
|
8
|
-
return (_jsx(OperationContext, { value: useMemo(() => ({
|
|
9
|
-
example,
|
|
10
|
-
route,
|
|
11
|
-
setExample: (newKey) => {
|
|
12
|
-
const example = examples.find((example) => example.id === newKey);
|
|
13
|
-
if (!example)
|
|
14
|
-
return;
|
|
15
|
-
setExample(newKey);
|
|
16
|
-
for (const listener of listeners.current) {
|
|
17
|
-
listener(example.data, example.encoded);
|
|
18
|
-
}
|
|
19
|
-
},
|
|
20
|
-
examples,
|
|
21
|
-
setExampleData: (data, encoded) => {
|
|
22
|
-
for (const item of examples) {
|
|
23
|
-
if (item.id === example) {
|
|
24
|
-
// persistent changes
|
|
25
|
-
item.data = data;
|
|
26
|
-
item.encoded = encoded;
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
for (const listener of listeners.current) {
|
|
31
|
-
listener(data, encoded);
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
removeListener: (listener) => {
|
|
35
|
-
listeners.current = listeners.current.filter((item) => item !== listener);
|
|
36
|
-
},
|
|
37
|
-
addListener: (listener) => {
|
|
38
|
-
// initial call to listeners to ensure their data is the latest
|
|
39
|
-
// this is necessary to avoid race conditions between `useEffect()`
|
|
40
|
-
const active = examples.find((item) => item.id === example);
|
|
41
|
-
listener(active.data, active.encoded);
|
|
42
|
-
listeners.current.push(listener);
|
|
43
|
-
},
|
|
44
|
-
}), [example, route, examples]), children: children }));
|
|
45
|
-
}
|
|
46
|
-
export function useOperationContext() {
|
|
47
|
-
return use(OperationContext);
|
|
48
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"operation.lazy.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/operation.lazy.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,qBAAqB,gDAEjC,CAAC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { CodeUsageGenerator } from './index.js';
|
|
2
|
-
export declare function APIExampleSelector(): import("react/jsx-runtime").JSX.Element | null;
|
|
3
|
-
export declare function APIExampleUsageTab(sample: CodeUsageGenerator): import("react/jsx-runtime").JSX.Element | null;
|
|
4
|
-
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../../src/ui/operation/example-panel/client.tsx"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EAAkB,kBAAkB,EAAE,MAAM,GAAG,CAAC;AAE5D,wBAAgB,kBAAkB,mDAkCjC;AAED,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,kBAAkB,kDAkD5D"}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import type { MethodInformation, RenderContext, ResponseObject } from '../../../types.js';
|
|
2
|
-
import type { ReactNode } from 'react';
|
|
3
|
-
import { type NoReference } from '../../../utils/schema.js';
|
|
4
|
-
import type { RawRequestData, RequestData, SampleGenerator } from '../../../requests/types.js';
|
|
5
|
-
/**
|
|
6
|
-
* Generate code example for given programming language
|
|
7
|
-
*/
|
|
8
|
-
export interface CodeUsageGenerator<T = unknown> {
|
|
9
|
-
id: string;
|
|
10
|
-
lang: string;
|
|
11
|
-
label?: string;
|
|
12
|
-
/**
|
|
13
|
-
* either:
|
|
14
|
-
* - code
|
|
15
|
-
* - a function imported from a file with "use client" directive
|
|
16
|
-
* - false (disabled)
|
|
17
|
-
*/
|
|
18
|
-
source?: string | SampleGenerator<T> | false;
|
|
19
|
-
/**
|
|
20
|
-
* Pass extra context to client-side source generator
|
|
21
|
-
*/
|
|
22
|
-
serverContext?: T;
|
|
23
|
-
}
|
|
24
|
-
export interface APIExampleItem {
|
|
25
|
-
id: string;
|
|
26
|
-
name: string;
|
|
27
|
-
description?: string;
|
|
28
|
-
data: RawRequestData;
|
|
29
|
-
encoded: RequestData;
|
|
30
|
-
}
|
|
31
|
-
export interface ResponseTab {
|
|
32
|
-
/**
|
|
33
|
-
* HTTP response code
|
|
34
|
-
*/
|
|
35
|
-
code: string;
|
|
36
|
-
response: NoReference<ResponseObject>;
|
|
37
|
-
/**
|
|
38
|
-
* media type of response
|
|
39
|
-
*/
|
|
40
|
-
mediaType: string | null;
|
|
41
|
-
examples?: {
|
|
42
|
-
/**
|
|
43
|
-
* generated/defined example data
|
|
44
|
-
*/
|
|
45
|
-
sample: unknown;
|
|
46
|
-
label: string;
|
|
47
|
-
/**
|
|
48
|
-
* description (in Markdown)
|
|
49
|
-
*/
|
|
50
|
-
description?: string;
|
|
51
|
-
}[];
|
|
52
|
-
}
|
|
53
|
-
export declare function getAPIExamples(path: string, method: MethodInformation, ctx: RenderContext): APIExampleItem[];
|
|
54
|
-
export declare function APIExample({ method, ctx, }: {
|
|
55
|
-
method: MethodInformation;
|
|
56
|
-
ctx: RenderContext;
|
|
57
|
-
}): Promise<import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | (string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined)>;
|
|
58
|
-
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/ui/operation/example-panel/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAChF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAAoB,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGpE,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,eAAe,EAChB,MAAM,kBAAkB,CAAC;AAmB1B;;GAEG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC,GAAG,OAAO;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;IAE7C;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,CAAC;CACnB;AAED,MAAM,WAAW,cAAc;IAC7B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,cAAc,CAAC;IACrB,OAAO,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IAEb,QAAQ,EAAE,WAAW,CAAC,cAAc,CAAC,CAAC;IACtC;;OAEG;IACH,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IAEzB,QAAQ,CAAC,EAAE;QACT;;WAEG;QACH,MAAM,EAAE,OAAO,CAAC;QAEhB,KAAK,EAAE,MAAM,CAAC;QAEd;;WAEG;QACH,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,EAAE,CAAC;CACL;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,GAAG,EAAE,aAAa,GACjB,cAAc,EAAE,CA0ClB;AAED,wBAAsB,UAAU,CAAC,EAC/B,MAAM,EACN,GAAG,GACJ,EAAE;IACD,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;CACpB,wUAmEA"}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
-
import { getPreferredType } from '../../../utils/schema.js';
|
|
3
|
-
import { getRequestData } from '../../../ui/operation/get-request-data.js';
|
|
4
|
-
import { sample } from 'openapi-sampler';
|
|
5
|
-
import { defaultSamples } from '../../../requests/generators/index.js';
|
|
6
|
-
import { encodeRequestData } from '../../../requests/media/encode.js';
|
|
7
|
-
import { AccordionContent, AccordionHeader, AccordionItem, Accordions, AccordionTrigger, } from '../../../ui/components/accordion.js';
|
|
8
|
-
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
|
|
9
|
-
import { CodeBlockTab, CodeBlockTabs, CodeBlockTabsList, CodeBlockTabsTrigger, } from 'fumadocs-ui/components/codeblock';
|
|
10
|
-
import { APIExampleSelectorLazy, APIExampleUsageTabLazy } from './lazy.js';
|
|
11
|
-
export function getAPIExamples(path, method, ctx) {
|
|
12
|
-
const media = method.requestBody
|
|
13
|
-
? getPreferredType(method.requestBody.content)
|
|
14
|
-
: null;
|
|
15
|
-
const bodyOfType = media ? method.requestBody?.content[media] : null;
|
|
16
|
-
if (bodyOfType?.examples) {
|
|
17
|
-
const result = [];
|
|
18
|
-
for (const [key, value] of Object.entries(bodyOfType.examples)) {
|
|
19
|
-
const data = getRequestData(path, method, key, ctx);
|
|
20
|
-
result.push({
|
|
21
|
-
id: key,
|
|
22
|
-
name: value.summary ?? key,
|
|
23
|
-
description: value.description,
|
|
24
|
-
data,
|
|
25
|
-
encoded: encodeRequestData(data, ctx.mediaAdapters, method.parameters ?? []),
|
|
26
|
-
});
|
|
27
|
-
}
|
|
28
|
-
if (result.length > 0)
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
const data = getRequestData(path, method, null, ctx);
|
|
32
|
-
return [
|
|
33
|
-
{
|
|
34
|
-
id: '_default',
|
|
35
|
-
name: 'Default',
|
|
36
|
-
description: bodyOfType?.schema?.description,
|
|
37
|
-
data,
|
|
38
|
-
encoded: encodeRequestData(data, ctx.mediaAdapters, method.parameters ?? []),
|
|
39
|
-
},
|
|
40
|
-
];
|
|
41
|
-
}
|
|
42
|
-
export async function APIExample({ method, ctx, }) {
|
|
43
|
-
let { renderAPIExampleUsageTabs, renderAPIExampleLayout } = ctx.content ?? {};
|
|
44
|
-
renderAPIExampleLayout ?? (renderAPIExampleLayout = (slots) => {
|
|
45
|
-
return (_jsxs("div", { className: "prose-no-margin md:sticky md:top-(--fd-api-info-top) xl:w-[400px]", children: [slots.selector, slots.usageTabs, slots.responseTabs] }));
|
|
46
|
-
});
|
|
47
|
-
renderAPIExampleUsageTabs ?? (renderAPIExampleUsageTabs = (generators) => {
|
|
48
|
-
if (generators.length === 0)
|
|
49
|
-
return null;
|
|
50
|
-
return (_jsxs(CodeBlockTabs, { groupId: "fumadocs_openapi_requests", defaultValue: generators[0].id, children: [_jsx(CodeBlockTabsList, { children: generators.map((item) => (_jsx(CodeBlockTabsTrigger, { value: item.id, children: item.label ?? item.lang }, item.id))) }), generators.map((item) => (_jsx(CodeBlockTab, { value: item.id, children: _jsx(APIExampleUsageTabLazy, { ...item }) }, item.id)))] }));
|
|
51
|
-
});
|
|
52
|
-
let generators = [...defaultSamples];
|
|
53
|
-
if (ctx.generateCodeSamples) {
|
|
54
|
-
generators.push(...(await ctx.generateCodeSamples(method)));
|
|
55
|
-
}
|
|
56
|
-
if (method['x-codeSamples']) {
|
|
57
|
-
for (const sample of method['x-codeSamples']) {
|
|
58
|
-
generators.push('id' in sample && typeof sample.id === 'string'
|
|
59
|
-
? sample
|
|
60
|
-
: {
|
|
61
|
-
id: sample.lang,
|
|
62
|
-
...sample,
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
generators = dedupe(generators);
|
|
67
|
-
return renderAPIExampleLayout({
|
|
68
|
-
selector: method['x-exclusiveCodeSample'] ? null : (_jsx(APIExampleSelectorLazy, {})),
|
|
69
|
-
usageTabs: await renderAPIExampleUsageTabs(generators, ctx),
|
|
70
|
-
responseTabs: _jsx(ResponseTabs, { operation: method, ctx: ctx }),
|
|
71
|
-
}, ctx);
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Remove duplicated ids
|
|
75
|
-
*/
|
|
76
|
-
function dedupe(samples) {
|
|
77
|
-
const set = new Set();
|
|
78
|
-
const out = [];
|
|
79
|
-
for (let i = samples.length - 1; i >= 0; i--) {
|
|
80
|
-
const item = samples[i];
|
|
81
|
-
if (set.has(item.id))
|
|
82
|
-
continue;
|
|
83
|
-
set.add(item.id);
|
|
84
|
-
if (item.source !== false)
|
|
85
|
-
out.unshift(item);
|
|
86
|
-
}
|
|
87
|
-
return out;
|
|
88
|
-
}
|
|
89
|
-
function ResponseTabs({ operation, ctx, }) {
|
|
90
|
-
if (!operation.responses)
|
|
91
|
-
return null;
|
|
92
|
-
const tabs = [];
|
|
93
|
-
for (const [code, response] of Object.entries(operation.responses)) {
|
|
94
|
-
const media = response.content ? getPreferredType(response.content) : null;
|
|
95
|
-
const responseOfType = media ? response.content?.[media] : null;
|
|
96
|
-
const tab = {
|
|
97
|
-
code,
|
|
98
|
-
response,
|
|
99
|
-
mediaType: media,
|
|
100
|
-
};
|
|
101
|
-
if (responseOfType?.examples) {
|
|
102
|
-
tab.examples ?? (tab.examples = []);
|
|
103
|
-
for (const [key, sample] of Object.entries(responseOfType.examples)) {
|
|
104
|
-
const title = sample?.summary ?? `Example ${key}`;
|
|
105
|
-
tab.examples.push({
|
|
106
|
-
label: title,
|
|
107
|
-
sample: sample.value,
|
|
108
|
-
description: sample?.description,
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
else if (responseOfType?.example || responseOfType?.schema) {
|
|
113
|
-
tab.examples ?? (tab.examples = []);
|
|
114
|
-
tab.examples.push({
|
|
115
|
-
label: 'Example',
|
|
116
|
-
sample: responseOfType.example ?? sample(responseOfType.schema),
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
tabs.push(tab);
|
|
120
|
-
}
|
|
121
|
-
const { renderResponseTabs = renderResponseTabsDefault } = ctx.content ?? {};
|
|
122
|
-
return renderResponseTabs(tabs, ctx);
|
|
123
|
-
}
|
|
124
|
-
function renderResponseTabsDefault(tabs, ctx) {
|
|
125
|
-
async function renderResponse(tab) {
|
|
126
|
-
const { examples = [] } = tab;
|
|
127
|
-
let slot = 'Empty';
|
|
128
|
-
if (examples.length > 1) {
|
|
129
|
-
slot = (_jsx(Accordions, { type: "single", className: "pt-2", defaultValue: examples[0].label, children: examples.map((example, i) => (_jsxs(AccordionItem, { value: example.label, children: [_jsx(AccordionHeader, { children: _jsx(AccordionTrigger, { children: example.label }) }), _jsxs(AccordionContent, { className: "prose-no-margin", children: [example.description && ctx.renderMarkdown(example.description), ctx.renderCodeBlock('json', JSON.stringify(example.sample, null, 2))] })] }, i))) }));
|
|
130
|
-
}
|
|
131
|
-
else if (examples.length === 1) {
|
|
132
|
-
const example = examples[0];
|
|
133
|
-
slot = (_jsxs(_Fragment, { children: [example.description && ctx.renderMarkdown(example.description), ctx.renderCodeBlock('json', JSON.stringify(example.sample, null, 2))] }));
|
|
134
|
-
}
|
|
135
|
-
return _jsx(Tab, { value: tab.code, children: slot });
|
|
136
|
-
}
|
|
137
|
-
if (tabs.length === 0)
|
|
138
|
-
return null;
|
|
139
|
-
return (_jsx(Tabs, { groupId: "fumadocs_openapi_responses", items: tabs.map((tab) => tab.code), children: tabs.map(renderResponse) }));
|
|
140
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../../../../src/ui/operation/example-panel/lazy.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,sBAAsB,8CAElC,CAAC;AAEF,eAAO,MAAM,sBAAsB,8CAElC,CAAC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { wrapLazy } from '../../../utils/lazy.js';
|
|
3
|
-
export const APIExampleSelectorLazy = wrapLazy(() => import('./client.js').then((mod) => ({ default: mod.APIExampleSelector })));
|
|
4
|
-
export const APIExampleUsageTabLazy = wrapLazy(() => import('./client.js').then((mod) => ({ default: mod.APIExampleUsageTab })));
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { MethodInformation, RenderContext } from '../../types.js';
|
|
2
|
-
import type { RawRequestData } from '../../requests/types.js';
|
|
3
|
-
export declare function getRequestData(path: string, method: MethodInformation, sampleKey: string | null, _ctx: RenderContext): RawRequestData;
|
|
4
|
-
//# sourceMappingURL=get-request-data.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"get-request-data.d.ts","sourceRoot":"","sources":["../../../src/ui/operation/get-request-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAIhE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAEvD,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,IAAI,EAAE,aAAa,GAClB,cAAc,CAwEhB"}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { getPreferredType } from '../../utils/schema.js';
|
|
2
|
-
import { sample } from 'openapi-sampler';
|
|
3
|
-
export function getRequestData(path, method, sampleKey, _ctx) {
|
|
4
|
-
const result = {
|
|
5
|
-
path: {},
|
|
6
|
-
cookie: {},
|
|
7
|
-
header: {},
|
|
8
|
-
query: {},
|
|
9
|
-
method: method.method,
|
|
10
|
-
};
|
|
11
|
-
for (const param of method.parameters ?? []) {
|
|
12
|
-
let schema = param.schema;
|
|
13
|
-
let value;
|
|
14
|
-
if (!schema && param.content) {
|
|
15
|
-
const type = getPreferredType(param.content);
|
|
16
|
-
const content = type ? param.content[type] : undefined;
|
|
17
|
-
if (!content || !content.schema)
|
|
18
|
-
throw new Error(`Cannot find parameter schema for ${param.name} in ${path} ${method.method}`);
|
|
19
|
-
schema = content.schema;
|
|
20
|
-
value = content.example ?? param.example;
|
|
21
|
-
}
|
|
22
|
-
else {
|
|
23
|
-
value = param.example;
|
|
24
|
-
}
|
|
25
|
-
if (param.required) {
|
|
26
|
-
value ?? (value = sample(schema));
|
|
27
|
-
}
|
|
28
|
-
else if (value === undefined) {
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
switch (param.in) {
|
|
32
|
-
case 'cookie':
|
|
33
|
-
result.cookie[param.name] = value;
|
|
34
|
-
break;
|
|
35
|
-
case 'header':
|
|
36
|
-
result.header[param.name] = value;
|
|
37
|
-
break;
|
|
38
|
-
case 'query':
|
|
39
|
-
result.query[param.name] = value;
|
|
40
|
-
break;
|
|
41
|
-
default:
|
|
42
|
-
result.path[param.name] = value;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (method.requestBody) {
|
|
46
|
-
const body = method.requestBody.content;
|
|
47
|
-
const type = getPreferredType(body);
|
|
48
|
-
if (!type)
|
|
49
|
-
throw new Error(`Cannot find body schema for ${path} ${method.method}: missing media type`);
|
|
50
|
-
result.bodyMediaType = type;
|
|
51
|
-
const bodyOfType = body[type];
|
|
52
|
-
if (bodyOfType.examples && sampleKey) {
|
|
53
|
-
result.body = bodyOfType.examples[sampleKey].value;
|
|
54
|
-
}
|
|
55
|
-
else if (bodyOfType.example) {
|
|
56
|
-
result.body = bodyOfType.example;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
result.body = generateBody(method.method, (bodyOfType?.schema ?? {}));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
function generateBody(method, schema) {
|
|
65
|
-
return sample(schema, {
|
|
66
|
-
skipReadOnly: method !== 'GET',
|
|
67
|
-
skipWriteOnly: method === 'GET',
|
|
68
|
-
skipNonRequired: true,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"combine-schema.d.ts","sourceRoot":"","sources":["../../src/utils/combine-schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAEnD;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,YAAY,CAuDlE"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Combine multiple object schemas into one
|
|
3
|
-
*/
|
|
4
|
-
export function combineSchema(schema) {
|
|
5
|
-
let result = {};
|
|
6
|
-
const types = new Set();
|
|
7
|
-
const title = new Set();
|
|
8
|
-
function add(s) {
|
|
9
|
-
if (typeof s === 'boolean') {
|
|
10
|
-
result = s;
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
if (typeof result === 'boolean')
|
|
14
|
-
return;
|
|
15
|
-
if (s.title)
|
|
16
|
-
title.add(s.title);
|
|
17
|
-
if (s.type) {
|
|
18
|
-
for (const v of Array.isArray(s.type) ? s.type : [s.type]) {
|
|
19
|
-
types.add(v);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
for (const key of ['oneOf', 'required', 'enum']) {
|
|
23
|
-
if (!s[key])
|
|
24
|
-
continue;
|
|
25
|
-
result[key] = [...s[key], ...(result[key] ?? [])];
|
|
26
|
-
}
|
|
27
|
-
for (const key of ['properties', 'patternProperties']) {
|
|
28
|
-
if (!s[key])
|
|
29
|
-
continue;
|
|
30
|
-
result[key] ?? (result[key] = {});
|
|
31
|
-
Object.assign(result[key], s[key]);
|
|
32
|
-
}
|
|
33
|
-
if (s.additionalProperties === true) {
|
|
34
|
-
result.additionalProperties = true;
|
|
35
|
-
}
|
|
36
|
-
else if (s.additionalProperties &&
|
|
37
|
-
typeof result.additionalProperties !== 'boolean') {
|
|
38
|
-
result.additionalProperties ?? (result.additionalProperties = {});
|
|
39
|
-
Object.assign(result.additionalProperties, s.additionalProperties);
|
|
40
|
-
}
|
|
41
|
-
(s.allOf ?? s.anyOf)?.forEach(add);
|
|
42
|
-
}
|
|
43
|
-
schema.forEach(add);
|
|
44
|
-
if (title.size > 0)
|
|
45
|
-
result.title = Array.from(title).join(' & ');
|
|
46
|
-
if (types.size > 0) {
|
|
47
|
-
const typeArr = Array.from(types.values());
|
|
48
|
-
result.type = typeArr.length === 1 ? typeArr[0] : typeArr;
|
|
49
|
-
}
|
|
50
|
-
return result;
|
|
51
|
-
}
|