fumadocs-openapi 6.3.0 → 7.0.0-beta.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/playground/client.d.ts +4 -3
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +109 -102
- package/dist/playground/fetcher.d.ts +6 -22
- package/dist/playground/fetcher.d.ts.map +1 -1
- package/dist/playground/fetcher.js +25 -85
- package/dist/playground/get-default-values.d.ts +2 -3
- package/dist/playground/get-default-values.d.ts.map +1 -1
- package/dist/playground/get-default-values.js +8 -4
- package/dist/playground/index.d.ts +0 -1
- package/dist/playground/index.d.ts.map +1 -1
- package/dist/playground/index.js +0 -1
- package/dist/playground/inputs.d.ts.map +1 -1
- package/dist/playground/inputs.js +46 -32
- package/dist/render/operation/api-example.d.ts +18 -4
- package/dist/render/operation/api-example.d.ts.map +1 -1
- package/dist/render/operation/api-example.js +68 -72
- package/dist/render/operation/get-request-data.d.ts +5 -0
- package/dist/render/operation/get-request-data.d.ts.map +1 -0
- package/dist/render/operation/get-request-data.js +71 -0
- package/dist/render/{operation.d.ts → operation/index.d.ts} +4 -4
- package/dist/render/operation/index.d.ts.map +1 -0
- package/dist/render/{operation.js → operation/index.js} +14 -15
- package/dist/render/renderer.d.ts +1 -9
- package/dist/render/renderer.d.ts.map +1 -1
- package/dist/render/renderer.js +3 -5
- package/dist/requests/_shared.d.ts +11 -0
- package/dist/requests/_shared.d.ts.map +1 -0
- package/dist/requests/_shared.js +4 -0
- package/dist/requests/curl.d.ts +2 -2
- package/dist/requests/curl.d.ts.map +1 -1
- package/dist/requests/curl.js +17 -18
- package/dist/requests/go.d.ts +2 -2
- package/dist/requests/go.d.ts.map +1 -1
- package/dist/requests/go.js +15 -14
- package/dist/requests/index.d.ts +3 -0
- package/dist/requests/index.d.ts.map +1 -0
- package/dist/requests/index.js +26 -0
- package/dist/requests/javascript.d.ts +2 -2
- package/dist/requests/javascript.d.ts.map +1 -1
- package/dist/requests/javascript.js +20 -27
- package/dist/requests/python.d.ts +2 -2
- package/dist/requests/python.d.ts.map +1 -1
- package/dist/requests/python.js +18 -22
- package/dist/server/api-page.js +1 -1
- package/dist/types.d.ts +5 -6
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/client.d.ts +1 -2
- package/dist/ui/client.d.ts.map +1 -1
- package/dist/ui/client.js +1 -3
- package/dist/ui/components/method-label.d.ts +1 -1
- package/dist/ui/contexts/api.d.ts +3 -5
- package/dist/ui/contexts/api.d.ts.map +1 -1
- package/dist/ui/contexts/api.js +2 -7
- package/dist/ui/contexts/code-example.d.ts +25 -0
- package/dist/ui/contexts/code-example.d.ts.map +1 -0
- package/dist/ui/contexts/code-example.js +104 -0
- package/dist/ui/contexts/code-example.lazy.d.ts +12 -0
- package/dist/ui/contexts/code-example.lazy.d.ts.map +1 -0
- package/dist/ui/contexts/code-example.lazy.js +5 -0
- package/dist/ui/server-select.d.ts +6 -1
- package/dist/ui/server-select.d.ts.map +1 -1
- package/dist/ui/server-select.js +6 -7
- package/dist/utils/get-pathname-from-input.d.ts +2 -0
- package/dist/utils/get-pathname-from-input.d.ts.map +1 -0
- package/dist/utils/get-pathname-from-input.js +15 -0
- package/dist/utils/get-typescript-schema.d.ts +2 -3
- package/dist/utils/get-typescript-schema.d.ts.map +1 -1
- package/dist/utils/get-typescript-schema.js +13 -16
- package/package.json +6 -6
- package/dist/render/operation.d.ts.map +0 -1
- package/dist/ui/sample-select.d.ts +0 -4
- package/dist/ui/sample-select.d.ts.map +0 -1
- package/dist/ui/sample-select.js +0 -19
- package/dist/utils/generate-sample.d.ts +0 -40
- package/dist/utils/generate-sample.d.ts.map +0 -1
- package/dist/utils/generate-sample.js +0 -109
|
@@ -17,19 +17,18 @@ export function ObjectInput({ field, fieldName, ...props }) {
|
|
|
17
17
|
return (_jsxs("div", { ...props, className: cn('flex flex-col gap-6', props.className), children: [Object.entries(field.properties).map(([key, child]) => (_jsx(FieldSet, { name: key, field: resolve(child, references), fieldName: `${fieldName}.${key}` }, key))), field.additionalProperties ? (_jsx(AdditionalProperties, { fieldName: fieldName, type: field.additionalProperties })) : null] }));
|
|
18
18
|
}
|
|
19
19
|
function AdditionalProperties({ fieldName, type, }) {
|
|
20
|
-
const { control, setValue } = useFormContext();
|
|
21
|
-
const { references
|
|
20
|
+
const { control, setValue, getValues } = useFormContext();
|
|
21
|
+
const { references } = useSchemaContext();
|
|
22
22
|
const [nextName, setNextName] = useState('');
|
|
23
23
|
const [properties, setProperties] = useState(() => {
|
|
24
|
-
const
|
|
25
|
-
if (
|
|
26
|
-
return
|
|
24
|
+
const value = getValues(fieldName);
|
|
25
|
+
if (value)
|
|
26
|
+
return Object.keys(value);
|
|
27
27
|
return [];
|
|
28
28
|
});
|
|
29
|
-
|
|
30
|
-
type
|
|
31
|
-
|
|
32
|
-
});
|
|
29
|
+
const types = typeof type === 'string'
|
|
30
|
+
? resolveDynamicTypes(references[type], references)
|
|
31
|
+
: anyFields;
|
|
33
32
|
const onAppend = () => {
|
|
34
33
|
const name = nextName.trim();
|
|
35
34
|
if (name.length === 0)
|
|
@@ -37,17 +36,14 @@ function AdditionalProperties({ fieldName, type, }) {
|
|
|
37
36
|
setProperties((p) => {
|
|
38
37
|
if (p.includes(name))
|
|
39
38
|
return p;
|
|
40
|
-
setValue(`${fieldName}.${name}`,
|
|
39
|
+
setValue(`${fieldName}.${name}`, getDefaultValue(Object.values(types)[0], references));
|
|
41
40
|
setNextName('');
|
|
42
41
|
return [...p, name];
|
|
43
42
|
});
|
|
44
43
|
};
|
|
45
|
-
const types = typeof type === 'string'
|
|
46
|
-
? resolveDynamicTypes(references[type], references)
|
|
47
|
-
: undefined;
|
|
48
44
|
return (_jsxs(_Fragment, { children: [properties.map((item) => (_jsx(FieldSet, { name: item, field: {
|
|
49
45
|
type: 'switcher',
|
|
50
|
-
items: types
|
|
46
|
+
items: types,
|
|
51
47
|
isRequired: false,
|
|
52
48
|
}, fieldName: `${fieldName}.${item}`, toolbar: _jsx("button", { type: "button", "aria-label": "Remove Item", className: cn(buttonVariants({
|
|
53
49
|
color: 'secondary',
|
|
@@ -76,17 +72,14 @@ const anyFields = {
|
|
|
76
72
|
string: {
|
|
77
73
|
type: 'string',
|
|
78
74
|
isRequired: false,
|
|
79
|
-
defaultValue: '',
|
|
80
75
|
},
|
|
81
76
|
boolean: {
|
|
82
77
|
type: 'boolean',
|
|
83
78
|
isRequired: false,
|
|
84
|
-
defaultValue: '',
|
|
85
79
|
},
|
|
86
80
|
number: {
|
|
87
81
|
type: 'number',
|
|
88
82
|
isRequired: false,
|
|
89
|
-
defaultValue: '',
|
|
90
83
|
},
|
|
91
84
|
object: {
|
|
92
85
|
type: 'object',
|
|
@@ -114,41 +107,62 @@ export function FieldInput({ field, fieldName, ...props }) {
|
|
|
114
107
|
if (field.type === 'array') {
|
|
115
108
|
return (_jsx(ArrayInput, { fieldName: fieldName, field: field, ...props, className: cn('rounded-lg border border-fd-primary/20 bg-fd-background p-3 shadow-sm', props.className) }));
|
|
116
109
|
}
|
|
117
|
-
if (field.type === 'file'
|
|
118
|
-
return (_jsx(Controller, { control: control, name: fieldName, render: ({ field: { value, onChange, ...restField } }) =>
|
|
110
|
+
if (field.type === 'file') {
|
|
111
|
+
return (_jsx(Controller, { control: control, name: fieldName, render: ({ field: { value: _, onChange, ...restField } }) => (_jsx("input", { id: fieldName, type: "file", multiple: false, onChange: (e) => {
|
|
119
112
|
if (!e.target.files)
|
|
120
113
|
return;
|
|
121
114
|
onChange(e.target.files.item(0));
|
|
122
|
-
}, ...props, ...restField }))
|
|
115
|
+
}, ...props, ...restField })) }));
|
|
116
|
+
}
|
|
117
|
+
if (field.type === 'boolean') {
|
|
118
|
+
return (_jsx(Controller, { control: control, name: fieldName, render: ({ field: { value, onChange, ...restField } }) => (_jsxs(Select, { value: String(value), onValueChange: (value) => onChange(value === 'null' ? null : value === 'true'), disabled: restField.disabled, children: [_jsx(SelectTrigger, { id: fieldName, className: props.className, ...restField, children: _jsx(SelectValue, {}) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: "true", children: "True" }), _jsx(SelectItem, { value: "false", children: "False" }), field.isRequired ? null : (_jsx(SelectItem, { value: "null", children: "Null" }))] })] })) }));
|
|
123
119
|
}
|
|
124
|
-
return (_jsx(Input, { id: fieldName, placeholder: "Enter value", type: field.type === 'string' ? 'text' : 'number', ...register(fieldName
|
|
120
|
+
return (_jsx(Input, { id: fieldName, placeholder: "Enter value", type: field.type === 'string' ? 'text' : 'number', ...register(fieldName, {
|
|
121
|
+
valueAsNumber: field.type === 'number',
|
|
122
|
+
}), ...props }));
|
|
125
123
|
}
|
|
126
124
|
export function FieldSet({ field, fieldName, toolbar, name, ...props }) {
|
|
125
|
+
const form = useFormContext();
|
|
127
126
|
const { references, dynamic } = useSchemaContext();
|
|
128
|
-
const [
|
|
127
|
+
const [type, setType] = useState(() => {
|
|
129
128
|
if (field.type !== 'switcher')
|
|
130
129
|
return '';
|
|
131
130
|
const d = dynamic.current.get(fieldName);
|
|
132
131
|
const items = Object.keys(field.items);
|
|
133
132
|
if (d?.type === 'field') {
|
|
134
|
-
// schemas are passed from server components,
|
|
133
|
+
// schemas are passed from server components, object references are maintained
|
|
135
134
|
const cached = items.find((item) => d.schema === field.items[item]);
|
|
136
135
|
if (cached)
|
|
137
136
|
return cached;
|
|
138
137
|
}
|
|
139
|
-
|
|
138
|
+
const value = form.getValues(fieldName);
|
|
139
|
+
let type = typeof value;
|
|
140
|
+
if (Array.isArray(value)) {
|
|
141
|
+
type = 'array';
|
|
142
|
+
}
|
|
143
|
+
else if (value instanceof File) {
|
|
144
|
+
type = 'file';
|
|
145
|
+
}
|
|
146
|
+
else if (value === null) {
|
|
147
|
+
type = 'null';
|
|
148
|
+
}
|
|
149
|
+
return items.find((item) => field.items[item].type === type) ?? items[0];
|
|
140
150
|
});
|
|
141
151
|
if (field.type === 'null')
|
|
142
152
|
return null;
|
|
143
|
-
if (value && field.type === 'switcher') {
|
|
144
|
-
dynamic.current.set(fieldName, {
|
|
145
|
-
type: 'field',
|
|
146
|
-
schema: field.items[value],
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
153
|
if (field.type === 'switcher') {
|
|
150
|
-
const child = resolve(field.items[
|
|
151
|
-
return (_jsxs("fieldset", { ...props, className: cn('flex flex-col gap-1.5', props.className), children: [_jsxs(FieldHeader, { name: name, htmlFor: fieldName, required: field.isRequired, children: [_jsx("select", { value:
|
|
154
|
+
const child = resolve(field.items[type], references);
|
|
155
|
+
return (_jsxs("fieldset", { ...props, className: cn('flex flex-col gap-1.5', props.className), children: [_jsxs(FieldHeader, { name: name, htmlFor: fieldName, required: field.isRequired, children: [_jsx("select", { value: type, onChange: (e) => {
|
|
156
|
+
const value = e.target.value;
|
|
157
|
+
if (value === type)
|
|
158
|
+
return;
|
|
159
|
+
setType(value);
|
|
160
|
+
dynamic.current.set(fieldName, {
|
|
161
|
+
type: 'field',
|
|
162
|
+
schema: field.items[value],
|
|
163
|
+
});
|
|
164
|
+
form.setValue(fieldName, getDefaultValue(field.items[value], references));
|
|
165
|
+
}, className: "text-xs", children: Object.keys(field.items).map((item) => (_jsx("option", { value: item, children: item }, item))) }), toolbar] }), _jsx("p", { className: "text-xs text-fd-muted-foreground", children: field.description }), child.type === 'switcher' ? (_jsx(FieldSet, { field: child, fieldName: fieldName })) : (_jsx(FieldInput, { field: child, fieldName: fieldName }))] }));
|
|
152
166
|
}
|
|
153
167
|
return (_jsxs("fieldset", { ...props, className: cn('flex flex-col gap-1.5', props.className), children: [_jsx(FieldHeader, { htmlFor: fieldName, name: name, required: field.isRequired, type: field.type, children: toolbar }), _jsx(FieldInput, { field: field, fieldName: fieldName })] }));
|
|
154
168
|
}
|
|
@@ -1,14 +1,28 @@
|
|
|
1
1
|
import type { MethodInformation, RenderContext } from '../../types.js';
|
|
2
|
-
import type
|
|
3
|
-
import { type CodeSample } from '../../render/operation.js';
|
|
2
|
+
import { type ReactNode } from 'react';
|
|
3
|
+
import { type CodeSample } from '../../render/operation/index.js';
|
|
4
|
+
import type { RequestData } from '../../requests/_shared.js';
|
|
4
5
|
interface CustomProperty {
|
|
5
6
|
'x-codeSamples'?: CodeSample[];
|
|
6
7
|
'x-selectedCodeSample'?: string;
|
|
7
8
|
'x-exclusiveCodeSample'?: string;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
+
interface CodeExampleItem {
|
|
11
|
+
key: string;
|
|
12
|
+
name: string;
|
|
13
|
+
description?: string;
|
|
14
|
+
data: RequestData;
|
|
15
|
+
}
|
|
16
|
+
export declare function APIExampleProvider({ examples, method, children, route, }: {
|
|
17
|
+
examples: CodeExampleItem[];
|
|
18
|
+
method: MethodInformation & CustomProperty;
|
|
19
|
+
route: string;
|
|
20
|
+
children: ReactNode;
|
|
21
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
22
|
+
export declare function getAPIExamples(path: string, method: MethodInformation, ctx: RenderContext): CodeExampleItem[];
|
|
23
|
+
export declare function APIExample({ method, examples, ctx, }: {
|
|
24
|
+
examples: CodeExampleItem[];
|
|
10
25
|
method: MethodInformation & CustomProperty;
|
|
11
|
-
endpoint: EndpointSample;
|
|
12
26
|
ctx: RenderContext;
|
|
13
27
|
}): Promise<import("react/jsx-runtime").JSX.Element>;
|
|
14
28
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-example.d.ts","sourceRoot":"","sources":["../../../src/render/operation/api-example.tsx"],"names":[],"mappings":"
|
|
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;AAU3D,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,84 +1,75 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import * as CURL from '../../requests/curl.js';
|
|
3
|
-
import * as JS from '../../requests/javascript.js';
|
|
4
|
-
import * as Go from '../../requests/go.js';
|
|
5
|
-
import * as Python from '../../requests/python.js';
|
|
6
2
|
import { Markdown } from '../../render/markdown.js';
|
|
7
3
|
import { getTypescriptSchema } from '../../utils/get-typescript-schema.js';
|
|
8
4
|
import { CodeBlock } from '../../render/codeblock.js';
|
|
5
|
+
import { CodeExample, CodeExampleProvider, } from '../../ui/contexts/code-example.lazy.js';
|
|
6
|
+
import { getPreferredType } from '../../utils/schema.js';
|
|
7
|
+
import { getRequestData } from '../../render/operation/get-request-data.js';
|
|
8
|
+
import { sample } from 'openapi-sampler';
|
|
9
9
|
const defaultSamples = [
|
|
10
10
|
{
|
|
11
11
|
label: 'cURL',
|
|
12
|
-
source: CURL.getSampleRequest,
|
|
13
12
|
lang: 'bash',
|
|
14
13
|
},
|
|
15
14
|
{
|
|
16
15
|
label: 'JavaScript',
|
|
17
|
-
source: JS.getSampleRequest,
|
|
18
16
|
lang: 'js',
|
|
19
17
|
},
|
|
20
18
|
{
|
|
21
19
|
label: 'Go',
|
|
22
|
-
source: Go.getSampleRequest,
|
|
23
20
|
lang: 'go',
|
|
24
21
|
},
|
|
25
22
|
{
|
|
26
23
|
label: 'Python',
|
|
27
|
-
source: Python.getSampleRequest,
|
|
28
24
|
lang: 'python',
|
|
29
25
|
},
|
|
30
26
|
];
|
|
31
|
-
export
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
if (result === undefined)
|
|
55
|
-
return [];
|
|
56
|
-
return {
|
|
57
|
-
...sample,
|
|
58
|
-
source: result,
|
|
59
|
-
};
|
|
60
|
-
}),
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
function renderRequest(sample) {
|
|
64
|
-
return (_jsx(renderer.Requests, { items: sample.samples.map((s) => s.label), children: sample.samples.map((s) => (_jsx(renderer.Request, { name: s.label, code: s.source, language: s.lang }, s.label))) }));
|
|
65
|
-
}
|
|
66
|
-
const exclusiveCodeSamples = method['x-exclusiveCodeSample'];
|
|
67
|
-
if ((samples.size === 1 && samples.has('_default')) ||
|
|
68
|
-
(exclusiveCodeSamples && samples.has(exclusiveCodeSamples))) {
|
|
69
|
-
// if exclusiveSampleKey is present, we don't use tabs
|
|
70
|
-
// if only the fallback or non described openapi legacy example is present, we don't use tabs
|
|
71
|
-
children = renderRequest(samples.get(exclusiveCodeSamples ?? '_default'));
|
|
72
|
-
}
|
|
73
|
-
else if (samples.size > 0) {
|
|
74
|
-
const entries = Array.from(samples.entries());
|
|
75
|
-
children = (_jsx(renderer.Samples, { items: entries.map(([key, sample]) => ({
|
|
76
|
-
title: sample.title,
|
|
77
|
-
description: sample.description ? (_jsx(Markdown, { text: sample.description })) : null,
|
|
78
|
-
value: key,
|
|
79
|
-
})), defaultValue: exclusiveCodeSamples, children: entries.map(([key, sample]) => (_jsx(renderer.Sample, { value: key, children: renderRequest(sample) }, key))) }));
|
|
27
|
+
export function APIExampleProvider({ examples, method, children, route, }) {
|
|
28
|
+
const exclusiveSampleKey = method['x-exclusiveCodeSample'];
|
|
29
|
+
return (_jsx(CodeExampleProvider, { initialKey: exclusiveSampleKey, route: route, examples: examples.map((example) => ({
|
|
30
|
+
key: example.key,
|
|
31
|
+
data: example.data,
|
|
32
|
+
})), children: children }));
|
|
33
|
+
}
|
|
34
|
+
export function getAPIExamples(path, method, ctx) {
|
|
35
|
+
const media = method.requestBody
|
|
36
|
+
? getPreferredType(method.requestBody.content)
|
|
37
|
+
: null;
|
|
38
|
+
const bodyOfType = media ? method.requestBody?.content[media] : null;
|
|
39
|
+
if (bodyOfType?.examples) {
|
|
40
|
+
const result = [];
|
|
41
|
+
for (const [key, value] of Object.entries(bodyOfType.examples)) {
|
|
42
|
+
result.push({
|
|
43
|
+
key,
|
|
44
|
+
name: value.summary ?? key,
|
|
45
|
+
description: value.description,
|
|
46
|
+
data: getRequestData(path, method, key, ctx),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
80
50
|
}
|
|
81
|
-
return
|
|
51
|
+
return [
|
|
52
|
+
{
|
|
53
|
+
key: '_default',
|
|
54
|
+
name: 'Default',
|
|
55
|
+
description: bodyOfType?.schema?.description,
|
|
56
|
+
data: getRequestData(path, method, null, ctx),
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
}
|
|
60
|
+
export async function APIExample({ method, examples, ctx, }) {
|
|
61
|
+
const renderer = ctx.renderer;
|
|
62
|
+
const generators = dedupe([
|
|
63
|
+
...defaultSamples,
|
|
64
|
+
...(ctx.generateCodeSamples ? await ctx.generateCodeSamples(method) : []),
|
|
65
|
+
...(method['x-codeSamples'] ?? []),
|
|
66
|
+
]).filter((generator) => generator.source !== false);
|
|
67
|
+
const exclusiveSampleKey = method['x-exclusiveCodeSample'];
|
|
68
|
+
return (_jsxs(renderer.APIExample, { children: [examples.length > 1 && !exclusiveSampleKey && (_jsx(renderer.CodeExampleSelector, { items: examples.map((sample) => ({
|
|
69
|
+
title: sample.name,
|
|
70
|
+
description: sample.description ? (_jsx(Markdown, { text: sample.description })) : null,
|
|
71
|
+
value: sample.key,
|
|
72
|
+
})) })), generators.length > 0 && (_jsx(renderer.Requests, { items: generators.map((s) => s.label), children: generators.map((generator) => (_jsx(renderer.Request, { name: generator.label, children: _jsx(CodeExample, { ...generator }) }, generator.label))) })), _jsx(ResponseTabs, { operation: method, ctx: ctx })] }));
|
|
82
73
|
}
|
|
83
74
|
/**
|
|
84
75
|
* Remove duplicated labels
|
|
@@ -94,35 +85,40 @@ function dedupe(samples) {
|
|
|
94
85
|
}
|
|
95
86
|
return out;
|
|
96
87
|
}
|
|
97
|
-
function ResponseTabs({
|
|
88
|
+
function ResponseTabs({ operation, ctx: { renderer, generateTypeScriptSchema, schema }, }) {
|
|
98
89
|
if (!operation.responses)
|
|
99
90
|
return null;
|
|
100
91
|
async function renderResponse(code) {
|
|
101
|
-
const response =
|
|
92
|
+
const response = operation.responses && code in operation.responses
|
|
93
|
+
? operation.responses[code]
|
|
94
|
+
: null;
|
|
95
|
+
const media = getPreferredType(response?.content ?? {});
|
|
96
|
+
const responseOfType = media ? response?.content?.[media] : null;
|
|
102
97
|
const description = operation.responses?.[code].description ??
|
|
103
|
-
|
|
98
|
+
responseOfType?.schema?.description ??
|
|
104
99
|
'';
|
|
105
100
|
let ts;
|
|
106
101
|
if (generateTypeScriptSchema) {
|
|
107
|
-
ts = await generateTypeScriptSchema(
|
|
102
|
+
ts = await generateTypeScriptSchema(operation, code);
|
|
108
103
|
}
|
|
109
|
-
else if (generateTypeScriptSchema === undefined
|
|
110
|
-
|
|
104
|
+
else if (generateTypeScriptSchema === undefined &&
|
|
105
|
+
responseOfType?.schema) {
|
|
106
|
+
ts = await getTypescriptSchema(responseOfType?.schema, schema.dereferenceMap);
|
|
111
107
|
}
|
|
112
108
|
const values = [];
|
|
113
109
|
let exampleSlot;
|
|
114
|
-
if (
|
|
115
|
-
|
|
116
|
-
exampleSlot = (_jsx(renderer.ResponseType, { label: "Response", children: _jsx(CodeBlock, { lang: "json", code: JSON.stringify(endpoint.responses[code].samples._default, null, 2) }) }));
|
|
117
|
-
}
|
|
118
|
-
else if (response) {
|
|
119
|
-
exampleSlot = Object.entries(response.samples).map(([key, sample], i) => {
|
|
110
|
+
if (responseOfType?.examples) {
|
|
111
|
+
exampleSlot = Object.entries(responseOfType.examples).map(([key, sample], i) => {
|
|
120
112
|
const title = sample?.summary ?? `Example ${i + 1}`;
|
|
121
113
|
values.push(title);
|
|
122
|
-
return (_jsxs(renderer.ResponseType, { label: title, children: [sample?.description ? (_jsx(Markdown, { text: sample.description })) : null, _jsx(CodeBlock, { lang: "json", code: JSON.stringify(sample, null, 2) })] }, key));
|
|
114
|
+
return (_jsxs(renderer.ResponseType, { label: title, children: [sample?.description ? (_jsx(Markdown, { text: sample.description })) : null, _jsx(CodeBlock, { lang: "json", code: JSON.stringify(sample.value, null, 2) })] }, key));
|
|
123
115
|
});
|
|
124
116
|
}
|
|
125
|
-
|
|
117
|
+
else if (responseOfType?.example || responseOfType?.schema) {
|
|
118
|
+
values.push('Response');
|
|
119
|
+
exampleSlot = (_jsx(renderer.ResponseType, { label: "Response", children: _jsx(CodeBlock, { lang: "json", code: JSON.stringify(responseOfType.example ?? sample(responseOfType.schema), null, 2) }) }));
|
|
120
|
+
}
|
|
121
|
+
return (_jsxs(renderer.Response, { value: code, children: [description ? _jsx(Markdown, { text: description }) : null, exampleSlot ? (_jsxs(renderer.ResponseTypes, { defaultValue: values[0], children: [exampleSlot, ts ? (_jsx(renderer.ResponseType, { label: "TypeScript", children: _jsx(CodeBlock, { code: ts, lang: "ts" }) })) : null] })) : null] }));
|
|
126
122
|
}
|
|
127
123
|
const codes = Object.keys(operation.responses);
|
|
128
124
|
if (codes.length === 0)
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { MethodInformation, RenderContext } from '../../types.js';
|
|
2
|
+
import type { NoReference } from '../../utils/schema.js';
|
|
3
|
+
import type { RequestData } from '../../requests/_shared.js';
|
|
4
|
+
export declare function getRequestData(path: string, method: NoReference<MethodInformation>, sampleKey: string | null, { schema: { document } }: RenderContext): RequestData;
|
|
5
|
+
//# sourceMappingURL=get-request-data.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-request-data.d.ts","sourceRoot":"","sources":["../../../src/render/operation/get-request-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAKlD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,CAAC,iBAAiB,CAAC,EACtC,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,aAAa,GACtC,WAAW,CAqEb"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { sample } from 'openapi-sampler';
|
|
2
|
+
import { getPreferredType } from '../../utils/schema.js';
|
|
3
|
+
import { getSecurities, getSecurityPrefix } from '../../utils/get-security.js';
|
|
4
|
+
export function getRequestData(path, method, sampleKey, { schema: { document } }) {
|
|
5
|
+
const result = {
|
|
6
|
+
path: {},
|
|
7
|
+
cookie: {},
|
|
8
|
+
header: {},
|
|
9
|
+
query: {},
|
|
10
|
+
method: method.method,
|
|
11
|
+
};
|
|
12
|
+
for (const param of method.parameters ?? []) {
|
|
13
|
+
let schema = param.schema;
|
|
14
|
+
let value;
|
|
15
|
+
if (!schema && param.content) {
|
|
16
|
+
const type = getPreferredType(param.content);
|
|
17
|
+
const content = type ? param.content[type] : undefined;
|
|
18
|
+
if (!content)
|
|
19
|
+
throw new Error(`Cannot find parameter schema for ${param.name} in ${path} ${method.method}`);
|
|
20
|
+
schema = content.schema;
|
|
21
|
+
value = content.example ?? param.example ?? sample(schema);
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
value = param.example ?? sample(schema);
|
|
25
|
+
}
|
|
26
|
+
if (param.in === 'cookie') {
|
|
27
|
+
result.cookie[param.name] = value;
|
|
28
|
+
}
|
|
29
|
+
else if (param.in === 'header') {
|
|
30
|
+
result.header[param.name] = value;
|
|
31
|
+
}
|
|
32
|
+
else if (param.in === 'query') {
|
|
33
|
+
result.query[param.name] = value;
|
|
34
|
+
}
|
|
35
|
+
else if (param.in === 'path') {
|
|
36
|
+
result.path[param.name] = value;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const requirements = method.security ?? document.security;
|
|
40
|
+
if (requirements && requirements.length > 0) {
|
|
41
|
+
for (const security of getSecurities(requirements[0], document)) {
|
|
42
|
+
const prefix = getSecurityPrefix(security);
|
|
43
|
+
const name = security.type === 'apiKey' ? security.name : 'Authorization';
|
|
44
|
+
result.header[name] = prefix ? `${prefix} <token>` : '<token>';
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
if (method.requestBody) {
|
|
48
|
+
const body = method.requestBody.content;
|
|
49
|
+
const type = getPreferredType(body);
|
|
50
|
+
if (!type)
|
|
51
|
+
throw new Error(`Cannot find body schema for ${path} ${method.method}: missing media type`);
|
|
52
|
+
result.bodyMediaType = type;
|
|
53
|
+
const bodyOfType = body[type];
|
|
54
|
+
if (bodyOfType.examples && sampleKey) {
|
|
55
|
+
result.body = bodyOfType.examples[sampleKey].value;
|
|
56
|
+
}
|
|
57
|
+
else if (bodyOfType.example) {
|
|
58
|
+
result.body = bodyOfType.example;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
result.body = generateBody(method.method, bodyOfType?.schema ?? {});
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
function generateBody(method, schema) {
|
|
67
|
+
return sample(schema, {
|
|
68
|
+
skipReadOnly: method !== 'GET',
|
|
69
|
+
skipWriteOnly: method === 'GET',
|
|
70
|
+
});
|
|
71
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type ReactElement } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
2
|
+
import type { MethodInformation, RenderContext } from '../../types.js';
|
|
3
|
+
import type { RequestData } from '../../requests/_shared.js';
|
|
4
4
|
export interface CodeSample {
|
|
5
5
|
lang: string;
|
|
6
6
|
label: string;
|
|
7
|
-
source
|
|
7
|
+
source?: string | ((url: string, data: RequestData) => string | undefined) | false;
|
|
8
8
|
}
|
|
9
9
|
export declare function Operation({ type, path, method, ctx, hasHead, headingLevel, }: {
|
|
10
10
|
type?: 'webhook' | 'operation';
|
|
@@ -14,4 +14,4 @@ export declare function Operation({ type, path, method, ctx, hasHead, headingLev
|
|
|
14
14
|
hasHead?: boolean;
|
|
15
15
|
headingLevel?: number;
|
|
16
16
|
}): ReactElement;
|
|
17
|
-
//# sourceMappingURL=
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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;AAgBjB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,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,CAkLf"}
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Fragment } from 'react';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { MethodLabel } from '../ui/components/method-label.js';
|
|
3
|
+
import { getPreferredType } from '../../utils/schema.js';
|
|
4
|
+
import { getSecurities, getSecurityPrefix } from '../../utils/get-security.js';
|
|
5
|
+
import { idToTitle } from '../../utils/id-to-title.js';
|
|
6
|
+
import { Markdown } from '../markdown.js';
|
|
7
|
+
import { heading } from '../heading.js';
|
|
8
|
+
import { Schema } from '../schema.js';
|
|
9
|
+
import { createMethod } from '../../server/create-method.js';
|
|
10
|
+
import { methodKeys } from '../../build-routes.js';
|
|
11
|
+
import { APIExample, APIExampleProvider, getAPIExamples, } from '../../render/operation/api-example.js';
|
|
12
|
+
import { MethodLabel } from '../../ui/components/method-label.js';
|
|
14
13
|
const ParamTypes = {
|
|
15
14
|
path: 'Path Parameters',
|
|
16
15
|
query: 'Query Parameters',
|
|
@@ -60,10 +59,9 @@ export function Operation({ type = 'operation', path, method, ctx, hasHead, head
|
|
|
60
59
|
} })] }, status));
|
|
61
60
|
})] }));
|
|
62
61
|
}
|
|
63
|
-
const endpoint = generateSample(path, method, ctx);
|
|
64
62
|
const parameterNode = Object.entries(ParamTypes).map(([type, title]) => {
|
|
65
|
-
const params =
|
|
66
|
-
if (params.length === 0)
|
|
63
|
+
const params = method.parameters?.filter((param) => param.in === type);
|
|
64
|
+
if (!params || params.length === 0)
|
|
67
65
|
return;
|
|
68
66
|
return (_jsxs(Fragment, { children: [heading(headingLevel, title, ctx), _jsx("div", { className: "flex flex-col gap-4", children: params.map((param) => (_jsx(Schema, { name: param.name, schema: {
|
|
69
67
|
...param.schema,
|
|
@@ -83,7 +81,8 @@ export function Operation({ type = 'operation', path, method, ctx, hasHead, head
|
|
|
83
81
|
}
|
|
84
82
|
const info = (_jsxs(ctx.renderer.APIInfo, { head: headNode, method: method.method, route: path, children: [type === 'operation' ? (ctx.disablePlayground ? (_jsxs("div", { className: "flex flex-row items-center gap-2.5 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose", children: [_jsx(MethodLabel, { className: "text-xs", children: method.method }), _jsx("code", { className: "flex-1 overflow-auto text-nowrap text-[13px] text-fd-muted-foreground", children: path })] })) : (_jsx(ctx.renderer.APIPlayground, { path: path, method: method, ctx: ctx }))) : null, security && Object.keys(security).length > 0 ? (_jsxs(_Fragment, { children: [heading(headingLevel, 'Authorization', ctx), _jsx(AuthSection, { requirements: security, ctx: ctx })] })) : null, bodyNode, parameterNode, responseNode, callbacksNode] }));
|
|
85
83
|
if (type === 'operation') {
|
|
86
|
-
|
|
84
|
+
const examples = getAPIExamples(path, method, ctx);
|
|
85
|
+
return (_jsx(ctx.renderer.API, { children: _jsxs(APIExampleProvider, { route: path, examples: examples, method: method, children: [info, _jsx(APIExample, { examples: examples, method: method, ctx: ctx })] }) }));
|
|
87
86
|
}
|
|
88
87
|
else {
|
|
89
88
|
return info;
|
|
@@ -27,12 +27,7 @@ export interface ObjectCollapsibleProps {
|
|
|
27
27
|
children: ReactNode;
|
|
28
28
|
}
|
|
29
29
|
export interface RequestProps {
|
|
30
|
-
language: string;
|
|
31
30
|
name: string;
|
|
32
|
-
code: string;
|
|
33
|
-
}
|
|
34
|
-
export interface SampleProps {
|
|
35
|
-
value: string;
|
|
36
31
|
children: ReactNode;
|
|
37
32
|
}
|
|
38
33
|
export interface SamplesProps {
|
|
@@ -41,8 +36,6 @@ export interface SamplesProps {
|
|
|
41
36
|
description?: ReactNode;
|
|
42
37
|
value: string;
|
|
43
38
|
}[];
|
|
44
|
-
children: ReactNode;
|
|
45
|
-
defaultValue?: string;
|
|
46
39
|
}
|
|
47
40
|
export interface ResponseTypeProps {
|
|
48
41
|
label: string;
|
|
@@ -65,8 +58,7 @@ export interface Renderer {
|
|
|
65
58
|
}>;
|
|
66
59
|
Responses: ComponentType<ResponsesProps>;
|
|
67
60
|
Response: ComponentType<ResponseProps>;
|
|
68
|
-
|
|
69
|
-
Samples: ComponentType<SamplesProps>;
|
|
61
|
+
CodeExampleSelector: ComponentType<SamplesProps>;
|
|
70
62
|
Requests: ComponentType<{
|
|
71
63
|
items: string[];
|
|
72
64
|
children: ReactNode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/render/renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/render/renderer.tsx"],"names":[],"mappings":"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"}
|
package/dist/render/renderer.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
|
|
3
3
|
import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
|
|
4
|
-
import { CodeBlock } from '../render/codeblock.js';
|
|
5
4
|
import { API, Root, APIInfo, APIExample, Property, ObjectCollapsible, } from '../ui/index.js';
|
|
6
5
|
import { APIPlayground } from '../playground/index.js';
|
|
7
|
-
import {
|
|
6
|
+
import { CodeExampleSelector } from '../ui/contexts/code-example.lazy.js';
|
|
8
7
|
export function createRenders(shikiOptions) {
|
|
9
8
|
return {
|
|
10
9
|
Root: (props) => (_jsx(Root, { shikiOptions: shikiOptions, ...props, children: props.children })),
|
|
@@ -18,9 +17,8 @@ export function createRenders(shikiOptions) {
|
|
|
18
17
|
Property,
|
|
19
18
|
ObjectCollapsible,
|
|
20
19
|
Requests: (props) => (_jsx(Tabs, { groupId: "fumadocs_openapi_requests", ...props })),
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Request: (props) => (_jsx(Tab, { value: props.name, children: _jsx(CodeBlock, { lang: props.language, code: props.code, options: shikiOptions }) })),
|
|
20
|
+
CodeExampleSelector,
|
|
21
|
+
Request: (props) => _jsx(Tab, { value: props.name, children: props.children }),
|
|
24
22
|
APIPlayground,
|
|
25
23
|
};
|
|
26
24
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export interface RequestData {
|
|
2
|
+
method: string;
|
|
3
|
+
path: Record<string, string>;
|
|
4
|
+
query: Record<string, string>;
|
|
5
|
+
header: Record<string, string>;
|
|
6
|
+
cookie: Record<string, string>;
|
|
7
|
+
body?: unknown;
|
|
8
|
+
bodyMediaType?: 'multipart/form-data' | 'application/json' | 'application/xml';
|
|
9
|
+
}
|
|
10
|
+
export declare function getUrl(url: string, data: RequestData): string;
|
|
11
|
+
//# sourceMappingURL=_shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"_shared.d.ts","sourceRoot":"","sources":["../../src/requests/_shared.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IAEf,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf,aAAa,CAAC,EACV,qBAAqB,GACrB,kBAAkB,GAClB,iBAAiB,CAAC;CACvB;AAED,wBAAgB,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,CAE7D"}
|