fumadocs-openapi 5.11.8 → 6.0.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/index.d.ts +20 -71
- package/dist/index.js +21 -18
- package/dist/scalar/client-client-DgnHaOQ3.js +93 -0
- package/dist/scalar/index.d.ts +176 -0
- package/dist/scalar/index.js +13 -0
- package/dist/server/index.d.ts +24 -71
- package/dist/server/index.js +218 -212
- package/dist/ui/client-client-CpwKrzlY.js +107 -0
- package/dist/ui/{fetcher-Cc3BieIx.js → fetcher-Cey1qI8X.js} +1 -1
- package/dist/ui/{index-client-DPqAL2w9.js → index-client-CehDtJk-.js} +582 -434
- package/dist/ui/index.d.ts +32 -15
- package/dist/ui/index.js +33 -82
- package/dist/ui/server-select-client-CbFencmM.js +86 -0
- package/package.json +24 -11
- package/dist/ui/client-client-B06fJG48.js +0 -359
- package/dist/ui/server-select-client-CtG30byb.js +0 -101
package/dist/index.d.ts
CHANGED
|
@@ -3,64 +3,10 @@ import Slugger from 'github-slugger';
|
|
|
3
3
|
import { ComponentType, ReactNode } from 'react';
|
|
4
4
|
import { CodeToHastOptionsCommon, CodeOptionsThemes, BuiltinTheme } from 'shiki';
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
interface BaseSchema {
|
|
11
|
-
description?: string;
|
|
12
|
-
isRequired: boolean;
|
|
13
|
-
}
|
|
14
|
-
type PrimitiveRequestField = BaseRequestField & PrimitiveSchema;
|
|
15
|
-
interface PrimitiveSchema extends BaseSchema {
|
|
16
|
-
type: 'boolean' | 'string' | 'number';
|
|
17
|
-
defaultValue: string;
|
|
18
|
-
}
|
|
19
|
-
interface ReferenceSchema extends BaseSchema {
|
|
20
|
-
type: 'ref';
|
|
21
|
-
schema: string;
|
|
22
|
-
}
|
|
23
|
-
interface ArraySchema extends BaseSchema {
|
|
24
|
-
type: 'array';
|
|
25
|
-
/**
|
|
26
|
-
* Reference to item schema or the schema
|
|
27
|
-
*/
|
|
28
|
-
items: string | RequestSchema;
|
|
29
|
-
}
|
|
30
|
-
interface FileSchema extends BaseSchema {
|
|
31
|
-
type: 'file';
|
|
32
|
-
}
|
|
33
|
-
interface ObjectSchema extends BaseSchema {
|
|
34
|
-
type: 'object';
|
|
35
|
-
properties: Record<string, ReferenceSchema>;
|
|
36
|
-
/**
|
|
37
|
-
* Reference to schema, or true if it's `any`
|
|
38
|
-
*/
|
|
39
|
-
additionalProperties?: boolean | string;
|
|
40
|
-
}
|
|
41
|
-
interface SwitcherSchema extends BaseSchema {
|
|
42
|
-
type: 'switcher';
|
|
43
|
-
items: Record<string, ReferenceSchema | RequestSchema>;
|
|
44
|
-
}
|
|
45
|
-
interface NullSchema extends BaseSchema {
|
|
46
|
-
type: 'null';
|
|
47
|
-
}
|
|
48
|
-
type RequestSchema = PrimitiveSchema | ArraySchema | ObjectSchema | SwitcherSchema | NullSchema | FileSchema;
|
|
49
|
-
interface APIPlaygroundProps {
|
|
50
|
-
route: string;
|
|
51
|
-
method: string;
|
|
52
|
-
authorization?: PrimitiveRequestField & {
|
|
53
|
-
authType: string;
|
|
54
|
-
};
|
|
55
|
-
path?: PrimitiveRequestField[];
|
|
56
|
-
query?: PrimitiveRequestField[];
|
|
57
|
-
header?: PrimitiveRequestField[];
|
|
58
|
-
body?: RequestSchema & {
|
|
59
|
-
mediaType: string;
|
|
60
|
-
};
|
|
61
|
-
schemas: Record<string, RequestSchema>;
|
|
62
|
-
proxyUrl?: string;
|
|
63
|
-
}
|
|
6
|
+
type NoReference<T> = T extends (infer I)[] ? NoReference<I>[] : T extends ReferenceObject ? Exclude<T, ReferenceObject> : T extends object ? {
|
|
7
|
+
[K in keyof T]: NoReference<T[K]>;
|
|
8
|
+
} : T;
|
|
9
|
+
type ParsedSchema = OpenAPIV3_1.SchemaObject;
|
|
64
10
|
|
|
65
11
|
interface ResponsesProps {
|
|
66
12
|
items: string[];
|
|
@@ -127,14 +73,13 @@ interface Renderer {
|
|
|
127
73
|
*/
|
|
128
74
|
ObjectCollapsible: ComponentType<ObjectCollapsibleProps>;
|
|
129
75
|
Property: ComponentType<PropertyProps>;
|
|
130
|
-
APIPlayground: ComponentType<
|
|
76
|
+
APIPlayground: ComponentType<{
|
|
77
|
+
path: string;
|
|
78
|
+
method: MethodInformation;
|
|
79
|
+
ctx: RenderContext;
|
|
80
|
+
}>;
|
|
131
81
|
}
|
|
132
82
|
|
|
133
|
-
type NoReference<T> = T extends (infer I)[] ? NoReference<I>[] : T extends ReferenceObject ? Exclude<T, ReferenceObject> : T extends object ? {
|
|
134
|
-
[K in keyof T]: NoReference<T[K]>;
|
|
135
|
-
} : T;
|
|
136
|
-
type ParsedSchema = OpenAPIV3_1.SchemaObject;
|
|
137
|
-
|
|
138
83
|
/**
|
|
139
84
|
* Sample info of endpoint
|
|
140
85
|
*/
|
|
@@ -170,6 +115,13 @@ interface CodeSample {
|
|
|
170
115
|
source: string | ((endpoint: EndpointSample) => string | undefined) | false;
|
|
171
116
|
}
|
|
172
117
|
|
|
118
|
+
type DocumentInput = string | OpenAPIV3_1.Document | OpenAPIV3.Document;
|
|
119
|
+
type ProcessedDocument = {
|
|
120
|
+
document: NoReference<Document>;
|
|
121
|
+
dereferenceMap: DereferenceMap;
|
|
122
|
+
downloaded: Document;
|
|
123
|
+
};
|
|
124
|
+
|
|
173
125
|
type Document = OpenAPIV3_1.Document;
|
|
174
126
|
type OperationObject = OpenAPIV3_1.OperationObject;
|
|
175
127
|
type ParameterObject = OpenAPIV3_1.ParameterObject;
|
|
@@ -194,14 +146,13 @@ interface RenderContext {
|
|
|
194
146
|
*/
|
|
195
147
|
proxyUrl?: string;
|
|
196
148
|
renderer: Renderer;
|
|
197
|
-
/**
|
|
198
|
-
* dereferenced schema
|
|
199
|
-
*/
|
|
200
|
-
document: NoReference<Document>;
|
|
201
149
|
baseUrl: string;
|
|
202
150
|
servers: ServerObject[];
|
|
203
151
|
slugger: Slugger;
|
|
204
|
-
|
|
152
|
+
/**
|
|
153
|
+
* dereferenced schema
|
|
154
|
+
*/
|
|
155
|
+
schema: ProcessedDocument;
|
|
205
156
|
/**
|
|
206
157
|
* Generate TypeScript definitions from response schema.
|
|
207
158
|
*
|
|
@@ -222,8 +173,6 @@ interface RenderContext {
|
|
|
222
173
|
showResponseSchema?: boolean;
|
|
223
174
|
}
|
|
224
175
|
|
|
225
|
-
type DocumentInput = string | OpenAPIV3_1.Document | OpenAPIV3.Document;
|
|
226
|
-
|
|
227
176
|
interface WebhookItem {
|
|
228
177
|
name: string;
|
|
229
178
|
method: OpenAPIV3_1.HttpMethods;
|
package/dist/index.js
CHANGED
|
@@ -158,7 +158,8 @@ const cache = new Map();
|
|
|
158
158
|
});
|
|
159
159
|
const processed = {
|
|
160
160
|
document: dereferenced,
|
|
161
|
-
dereferenceMap
|
|
161
|
+
dereferenceMap,
|
|
162
|
+
downloaded: loaded.specification
|
|
162
163
|
};
|
|
163
164
|
if (!disableCache && typeof document === 'string') {
|
|
164
165
|
cache.set(document, processed);
|
|
@@ -302,24 +303,28 @@ async function generateFiles(options) {
|
|
|
302
303
|
}),
|
|
303
304
|
...urlInputs
|
|
304
305
|
];
|
|
305
|
-
function getOutputPaths(
|
|
306
|
+
function getOutputPaths(result) {
|
|
307
|
+
let file;
|
|
308
|
+
if (result.pathItem.summary) {
|
|
309
|
+
file = getFilename(result.pathItem.summary);
|
|
310
|
+
} else if (result.type === 'operation') {
|
|
311
|
+
file = result.operation.operationId ? getFilename(result.operation.operationId) : join(getOutputPathFromRoute(result.item.path), result.item.method.toLowerCase());
|
|
312
|
+
} else {
|
|
313
|
+
file = getFilename(result.item.name);
|
|
314
|
+
}
|
|
306
315
|
const outPaths = [];
|
|
307
316
|
if (groupBy === 'tag') {
|
|
308
317
|
const tags = result.operation.tags;
|
|
309
318
|
if (tags && tags.length > 0) {
|
|
310
319
|
for (const tag of tags){
|
|
311
|
-
outPaths.push(join(outputDir, getFilename(tag), `${
|
|
320
|
+
outPaths.push(join(outputDir, getFilename(tag), `${file}.mdx`));
|
|
312
321
|
}
|
|
313
322
|
} else {
|
|
314
|
-
outPaths.push(result.type === 'operation' ? join(outputDir, `${
|
|
323
|
+
outPaths.push(result.type === 'operation' ? join(outputDir, `${file}.mdx`) : join(outputDir, 'webhooks', `${file}.mdx`));
|
|
315
324
|
}
|
|
316
325
|
}
|
|
317
|
-
if (groupBy === 'route') {
|
|
318
|
-
|
|
319
|
-
outPaths.push(join(outputDir, dir, `${getFilename(name)}.mdx`));
|
|
320
|
-
}
|
|
321
|
-
if (groupBy === 'none') {
|
|
322
|
-
outPaths.push(join(outputDir, `${getFilename(name)}.mdx`));
|
|
326
|
+
if (groupBy === 'route' || groupBy === 'none') {
|
|
327
|
+
outPaths.push(join(outputDir, `${file}.mdx`));
|
|
323
328
|
}
|
|
324
329
|
return outPaths;
|
|
325
330
|
}
|
|
@@ -336,19 +341,17 @@ async function generateFiles(options) {
|
|
|
336
341
|
const metaFiles = new Set();
|
|
337
342
|
const results = await generatePages(pathOrUrl, options);
|
|
338
343
|
for (const result of results){
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
for (const outPath of getOutputPaths(
|
|
344
|
+
const meta = JSON.stringify({
|
|
345
|
+
title: result.pathItem.summary
|
|
346
|
+
}, null, 2);
|
|
347
|
+
for (const outPath of getOutputPaths(result)){
|
|
343
348
|
await write(outPath, result.content);
|
|
344
349
|
console.log(`Generated: ${outPath}`);
|
|
345
350
|
if (groupBy === 'route') {
|
|
346
351
|
const metaFile = join(dirname(outPath), 'meta.json');
|
|
347
352
|
if (!result.pathItem.summary || metaFiles.has(metaFile)) continue;
|
|
348
353
|
metaFiles.add(metaFile);
|
|
349
|
-
await write(metaFile,
|
|
350
|
-
title: result.pathItem.summary
|
|
351
|
-
}, null, 2));
|
|
354
|
+
await write(metaFile, meta);
|
|
352
355
|
console.log(`Generated Meta: ${metaFile}`);
|
|
353
356
|
}
|
|
354
357
|
}
|
|
@@ -370,7 +373,7 @@ async function generateFiles(options) {
|
|
|
370
373
|
function isUrl(input) {
|
|
371
374
|
return input.startsWith('https://') || input.startsWith('http://');
|
|
372
375
|
}
|
|
373
|
-
function
|
|
376
|
+
function getOutputPathFromRoute(path) {
|
|
374
377
|
return path.replaceAll('.', '/').split('/').filter((v)=>!v.startsWith('{') && !v.endsWith('}')).at(-1) ?? '';
|
|
375
378
|
}
|
|
376
379
|
function getFilename(s) {
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
+
import { cn } from 'fumadocs-ui/components/api';
|
|
4
|
+
import { buttonVariants } from 'fumadocs-ui/components/ui/button';
|
|
5
|
+
import { ApiClientModalProvider, useApiClientModal } from '@scalar/api-client-react';
|
|
6
|
+
import { cva } from 'class-variance-authority';
|
|
7
|
+
import { useTheme } from 'next-themes';
|
|
8
|
+
import { useState, useEffect } from 'react';
|
|
9
|
+
|
|
10
|
+
const variants = cva('font-mono font-medium', {
|
|
11
|
+
variants: {
|
|
12
|
+
color: {
|
|
13
|
+
green: 'text-green-600 dark:text-green-400',
|
|
14
|
+
yellow: 'text-yellow-600 dark:text-yellow-400',
|
|
15
|
+
red: 'text-red-600 dark:text-red-400',
|
|
16
|
+
blue: 'text-blue-600 dark:text-blue-400',
|
|
17
|
+
orange: 'text-orange-600 dark:text-orange-400'
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
function getBadgeColor(method) {
|
|
22
|
+
switch(method.toUpperCase()){
|
|
23
|
+
case 'PUT':
|
|
24
|
+
return 'yellow';
|
|
25
|
+
case 'PATCH':
|
|
26
|
+
return 'orange';
|
|
27
|
+
case 'POST':
|
|
28
|
+
return 'blue';
|
|
29
|
+
case 'DELETE':
|
|
30
|
+
return 'red';
|
|
31
|
+
default:
|
|
32
|
+
return 'green';
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
function MethodLabel({ children, ...props }) {
|
|
36
|
+
return /*#__PURE__*/ jsx("span", {
|
|
37
|
+
...props,
|
|
38
|
+
className: cn(variants({
|
|
39
|
+
color: getBadgeColor(children)
|
|
40
|
+
}), props.className),
|
|
41
|
+
children: children.toUpperCase()
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function ScalarPlayground({ path, method, spec }) {
|
|
46
|
+
const { resolvedTheme } = useTheme();
|
|
47
|
+
const [mounted, setMounted] = useState(false);
|
|
48
|
+
useEffect(()=>{
|
|
49
|
+
setMounted(true);
|
|
50
|
+
}, []);
|
|
51
|
+
return /*#__PURE__*/ jsxs("div", {
|
|
52
|
+
className: cn('flex flex-row items-center gap-2.5 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose', mounted ? `${resolvedTheme}-mode` : null),
|
|
53
|
+
children: [
|
|
54
|
+
/*#__PURE__*/ jsx(MethodLabel, {
|
|
55
|
+
className: "text-xs",
|
|
56
|
+
children: method
|
|
57
|
+
}),
|
|
58
|
+
/*#__PURE__*/ jsx("code", {
|
|
59
|
+
className: "flex-1 overflow-auto text-nowrap text-[13px] text-fd-muted-foreground",
|
|
60
|
+
children: path
|
|
61
|
+
}),
|
|
62
|
+
/*#__PURE__*/ jsx(ApiClientModalProvider, {
|
|
63
|
+
configuration: {
|
|
64
|
+
themeId: 'moon',
|
|
65
|
+
spec: {
|
|
66
|
+
content: spec
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
children: /*#__PURE__*/ jsx(Trigger, {
|
|
70
|
+
path: path,
|
|
71
|
+
method: method
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
]
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
function Trigger({ path, method }) {
|
|
78
|
+
const client = useApiClientModal();
|
|
79
|
+
return /*#__PURE__*/ jsx("button", {
|
|
80
|
+
type: "submit",
|
|
81
|
+
className: cn(buttonVariants({
|
|
82
|
+
color: 'primary',
|
|
83
|
+
size: 'sm'
|
|
84
|
+
}), 'px-3 py-1.5'),
|
|
85
|
+
onClick: ()=>client?.open({
|
|
86
|
+
path,
|
|
87
|
+
method
|
|
88
|
+
}),
|
|
89
|
+
children: "Test"
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export { ScalarPlayground as default };
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { OpenAPIV3_1 } from 'openapi-types';
|
|
3
|
+
import Slugger from 'github-slugger';
|
|
4
|
+
import { ComponentType, ReactNode } from 'react';
|
|
5
|
+
import { CodeToHastOptionsCommon, CodeOptionsThemes, BuiltinTheme } from 'shiki';
|
|
6
|
+
|
|
7
|
+
type NoReference<T> = T extends (infer I)[] ? NoReference<I>[] : T extends ReferenceObject ? Exclude<T, ReferenceObject> : T extends object ? {
|
|
8
|
+
[K in keyof T]: NoReference<T[K]>;
|
|
9
|
+
} : T;
|
|
10
|
+
type ParsedSchema = OpenAPIV3_1.SchemaObject;
|
|
11
|
+
|
|
12
|
+
interface ResponsesProps {
|
|
13
|
+
items: string[];
|
|
14
|
+
children: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
interface ResponseProps {
|
|
17
|
+
value: string;
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
}
|
|
20
|
+
interface APIInfoProps {
|
|
21
|
+
method: string;
|
|
22
|
+
route: string;
|
|
23
|
+
head: ReactNode;
|
|
24
|
+
children: ReactNode;
|
|
25
|
+
}
|
|
26
|
+
interface PropertyProps {
|
|
27
|
+
name: string;
|
|
28
|
+
type: string;
|
|
29
|
+
required?: boolean;
|
|
30
|
+
deprecated?: boolean;
|
|
31
|
+
children?: ReactNode;
|
|
32
|
+
}
|
|
33
|
+
interface ObjectCollapsibleProps {
|
|
34
|
+
name: string;
|
|
35
|
+
children: ReactNode;
|
|
36
|
+
}
|
|
37
|
+
interface RequestProps {
|
|
38
|
+
language: string;
|
|
39
|
+
name: string;
|
|
40
|
+
code: string;
|
|
41
|
+
}
|
|
42
|
+
interface ResponseTypeProps {
|
|
43
|
+
lang: string;
|
|
44
|
+
code: string;
|
|
45
|
+
label: string;
|
|
46
|
+
}
|
|
47
|
+
interface RootProps {
|
|
48
|
+
baseUrl?: string;
|
|
49
|
+
servers: ServerObject[];
|
|
50
|
+
children: ReactNode;
|
|
51
|
+
}
|
|
52
|
+
interface Renderer {
|
|
53
|
+
Root: ComponentType<RootProps>;
|
|
54
|
+
API: ComponentType<{
|
|
55
|
+
children: ReactNode;
|
|
56
|
+
}>;
|
|
57
|
+
APIInfo: ComponentType<APIInfoProps>;
|
|
58
|
+
APIExample: ComponentType<{
|
|
59
|
+
children: ReactNode;
|
|
60
|
+
}>;
|
|
61
|
+
Responses: ComponentType<ResponsesProps>;
|
|
62
|
+
Response: ComponentType<ResponseProps>;
|
|
63
|
+
Requests: ComponentType<{
|
|
64
|
+
items: string[];
|
|
65
|
+
children: ReactNode;
|
|
66
|
+
}>;
|
|
67
|
+
Request: ComponentType<RequestProps>;
|
|
68
|
+
ResponseTypes: ComponentType<{
|
|
69
|
+
children: ReactNode;
|
|
70
|
+
}>;
|
|
71
|
+
ResponseType: ComponentType<ResponseTypeProps>;
|
|
72
|
+
/**
|
|
73
|
+
* Collapsible to show object schemas
|
|
74
|
+
*/
|
|
75
|
+
ObjectCollapsible: ComponentType<ObjectCollapsibleProps>;
|
|
76
|
+
Property: ComponentType<PropertyProps>;
|
|
77
|
+
APIPlayground: ComponentType<{
|
|
78
|
+
path: string;
|
|
79
|
+
method: MethodInformation;
|
|
80
|
+
ctx: RenderContext;
|
|
81
|
+
}>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Sample info of endpoint
|
|
86
|
+
*/
|
|
87
|
+
interface EndpointSample {
|
|
88
|
+
/**
|
|
89
|
+
* Request URL, including path and query parameters
|
|
90
|
+
*/
|
|
91
|
+
url: string;
|
|
92
|
+
method: string;
|
|
93
|
+
body?: {
|
|
94
|
+
schema: ParsedSchema;
|
|
95
|
+
mediaType: string;
|
|
96
|
+
sample: unknown;
|
|
97
|
+
};
|
|
98
|
+
responses: Record<string, ResponseSample>;
|
|
99
|
+
parameters: ParameterSample[];
|
|
100
|
+
}
|
|
101
|
+
interface ResponseSample {
|
|
102
|
+
mediaType: string;
|
|
103
|
+
sample: unknown;
|
|
104
|
+
schema: ParsedSchema;
|
|
105
|
+
}
|
|
106
|
+
interface ParameterSample {
|
|
107
|
+
name: string;
|
|
108
|
+
in: string;
|
|
109
|
+
schema: ParsedSchema;
|
|
110
|
+
sample: unknown;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
interface CodeSample {
|
|
114
|
+
lang: string;
|
|
115
|
+
label: string;
|
|
116
|
+
source: string | ((endpoint: EndpointSample) => string | undefined) | false;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
type ProcessedDocument = {
|
|
120
|
+
document: NoReference<Document>;
|
|
121
|
+
dereferenceMap: DereferenceMap;
|
|
122
|
+
downloaded: Document;
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
type Document = OpenAPIV3_1.Document;
|
|
126
|
+
type OperationObject = OpenAPIV3_1.OperationObject;
|
|
127
|
+
type ReferenceObject = OpenAPIV3_1.ReferenceObject;
|
|
128
|
+
type ServerObject = NoReference<OpenAPIV3_1.ServerObject>;
|
|
129
|
+
type MethodInformation = NoReference<OperationObject> & {
|
|
130
|
+
method: string;
|
|
131
|
+
};
|
|
132
|
+
type Awaitable<T> = T | Promise<T>;
|
|
133
|
+
/**
|
|
134
|
+
* Dereferenced value and its original `$ref` value
|
|
135
|
+
*/
|
|
136
|
+
type DereferenceMap = Map<unknown, string>;
|
|
137
|
+
interface RenderContext {
|
|
138
|
+
/**
|
|
139
|
+
* The url of proxy to avoid CORS issues
|
|
140
|
+
*/
|
|
141
|
+
proxyUrl?: string;
|
|
142
|
+
renderer: Renderer;
|
|
143
|
+
baseUrl: string;
|
|
144
|
+
servers: ServerObject[];
|
|
145
|
+
slugger: Slugger;
|
|
146
|
+
/**
|
|
147
|
+
* dereferenced schema
|
|
148
|
+
*/
|
|
149
|
+
schema: ProcessedDocument;
|
|
150
|
+
/**
|
|
151
|
+
* Generate TypeScript definitions from response schema.
|
|
152
|
+
*
|
|
153
|
+
* Pass `false` to disable it.
|
|
154
|
+
*
|
|
155
|
+
* @param endpoint - the API endpoint
|
|
156
|
+
* @param code - status code
|
|
157
|
+
*/
|
|
158
|
+
generateTypeScriptSchema?: ((endpoint: EndpointSample, code: string) => Awaitable<string>) | false;
|
|
159
|
+
/**
|
|
160
|
+
* Generate code samples for endpoint.
|
|
161
|
+
*/
|
|
162
|
+
generateCodeSamples?: (endpoint: EndpointSample) => Awaitable<CodeSample[]>;
|
|
163
|
+
shikiOptions?: Omit<CodeToHastOptionsCommon, 'lang'> & CodeOptionsThemes<BuiltinTheme>;
|
|
164
|
+
/**
|
|
165
|
+
* Show full response schema instead of only example response & Typescript definitions
|
|
166
|
+
*/
|
|
167
|
+
showResponseSchema?: boolean;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
declare function APIPlayground({ path, method, ctx, }: {
|
|
171
|
+
path: string;
|
|
172
|
+
method: MethodInformation;
|
|
173
|
+
ctx: RenderContext;
|
|
174
|
+
}): react_jsx_runtime.JSX.Element;
|
|
175
|
+
|
|
176
|
+
export { APIPlayground };
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import dynamic from 'next/dynamic';
|
|
3
|
+
|
|
4
|
+
const Client = dynamic(()=>import('./client-client-DgnHaOQ3.js'));
|
|
5
|
+
function APIPlayground({ path, method, ctx }) {
|
|
6
|
+
return /*#__PURE__*/ jsx(Client, {
|
|
7
|
+
method: method.method,
|
|
8
|
+
path: path,
|
|
9
|
+
spec: ctx.schema.downloaded
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { APIPlayground };
|
package/dist/server/index.d.ts
CHANGED
|
@@ -5,64 +5,10 @@ import { CodeToHastOptionsCommon, CodeOptionsThemes, BuiltinTheme } from 'shiki'
|
|
|
5
5
|
import { NextRequest } from 'next/server';
|
|
6
6
|
import { BuildPageTreeOptions } from 'fumadocs-core/source';
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
interface BaseSchema {
|
|
13
|
-
description?: string;
|
|
14
|
-
isRequired: boolean;
|
|
15
|
-
}
|
|
16
|
-
type PrimitiveRequestField = BaseRequestField & PrimitiveSchema;
|
|
17
|
-
interface PrimitiveSchema extends BaseSchema {
|
|
18
|
-
type: 'boolean' | 'string' | 'number';
|
|
19
|
-
defaultValue: string;
|
|
20
|
-
}
|
|
21
|
-
interface ReferenceSchema extends BaseSchema {
|
|
22
|
-
type: 'ref';
|
|
23
|
-
schema: string;
|
|
24
|
-
}
|
|
25
|
-
interface ArraySchema extends BaseSchema {
|
|
26
|
-
type: 'array';
|
|
27
|
-
/**
|
|
28
|
-
* Reference to item schema or the schema
|
|
29
|
-
*/
|
|
30
|
-
items: string | RequestSchema;
|
|
31
|
-
}
|
|
32
|
-
interface FileSchema extends BaseSchema {
|
|
33
|
-
type: 'file';
|
|
34
|
-
}
|
|
35
|
-
interface ObjectSchema extends BaseSchema {
|
|
36
|
-
type: 'object';
|
|
37
|
-
properties: Record<string, ReferenceSchema>;
|
|
38
|
-
/**
|
|
39
|
-
* Reference to schema, or true if it's `any`
|
|
40
|
-
*/
|
|
41
|
-
additionalProperties?: boolean | string;
|
|
42
|
-
}
|
|
43
|
-
interface SwitcherSchema extends BaseSchema {
|
|
44
|
-
type: 'switcher';
|
|
45
|
-
items: Record<string, ReferenceSchema | RequestSchema>;
|
|
46
|
-
}
|
|
47
|
-
interface NullSchema extends BaseSchema {
|
|
48
|
-
type: 'null';
|
|
49
|
-
}
|
|
50
|
-
type RequestSchema = PrimitiveSchema | ArraySchema | ObjectSchema | SwitcherSchema | NullSchema | FileSchema;
|
|
51
|
-
interface APIPlaygroundProps {
|
|
52
|
-
route: string;
|
|
53
|
-
method: string;
|
|
54
|
-
authorization?: PrimitiveRequestField & {
|
|
55
|
-
authType: string;
|
|
56
|
-
};
|
|
57
|
-
path?: PrimitiveRequestField[];
|
|
58
|
-
query?: PrimitiveRequestField[];
|
|
59
|
-
header?: PrimitiveRequestField[];
|
|
60
|
-
body?: RequestSchema & {
|
|
61
|
-
mediaType: string;
|
|
62
|
-
};
|
|
63
|
-
schemas: Record<string, RequestSchema>;
|
|
64
|
-
proxyUrl?: string;
|
|
65
|
-
}
|
|
8
|
+
type NoReference<T> = T extends (infer I)[] ? NoReference<I>[] : T extends ReferenceObject ? Exclude<T, ReferenceObject> : T extends object ? {
|
|
9
|
+
[K in keyof T]: NoReference<T[K]>;
|
|
10
|
+
} : T;
|
|
11
|
+
type ParsedSchema = OpenAPIV3_1.SchemaObject;
|
|
66
12
|
|
|
67
13
|
interface ResponsesProps {
|
|
68
14
|
items: string[];
|
|
@@ -129,14 +75,13 @@ interface Renderer {
|
|
|
129
75
|
*/
|
|
130
76
|
ObjectCollapsible: ComponentType<ObjectCollapsibleProps>;
|
|
131
77
|
Property: ComponentType<PropertyProps>;
|
|
132
|
-
APIPlayground: ComponentType<
|
|
78
|
+
APIPlayground: ComponentType<{
|
|
79
|
+
path: string;
|
|
80
|
+
method: MethodInformation;
|
|
81
|
+
ctx: RenderContext;
|
|
82
|
+
}>;
|
|
133
83
|
}
|
|
134
84
|
|
|
135
|
-
type NoReference<T> = T extends (infer I)[] ? NoReference<I>[] : T extends ReferenceObject ? Exclude<T, ReferenceObject> : T extends object ? {
|
|
136
|
-
[K in keyof T]: NoReference<T[K]>;
|
|
137
|
-
} : T;
|
|
138
|
-
type ParsedSchema = OpenAPIV3_1.SchemaObject;
|
|
139
|
-
|
|
140
85
|
/**
|
|
141
86
|
* Sample info of endpoint
|
|
142
87
|
*/
|
|
@@ -172,9 +117,20 @@ interface CodeSample {
|
|
|
172
117
|
source: string | ((endpoint: EndpointSample) => string | undefined) | false;
|
|
173
118
|
}
|
|
174
119
|
|
|
120
|
+
type DocumentInput = string | OpenAPIV3_1.Document | OpenAPIV3.Document;
|
|
121
|
+
type ProcessedDocument = {
|
|
122
|
+
document: NoReference<Document>;
|
|
123
|
+
dereferenceMap: DereferenceMap;
|
|
124
|
+
downloaded: Document;
|
|
125
|
+
};
|
|
126
|
+
|
|
175
127
|
type Document = OpenAPIV3_1.Document;
|
|
128
|
+
type OperationObject = OpenAPIV3_1.OperationObject;
|
|
176
129
|
type ReferenceObject = OpenAPIV3_1.ReferenceObject;
|
|
177
130
|
type ServerObject = NoReference<OpenAPIV3_1.ServerObject>;
|
|
131
|
+
type MethodInformation = NoReference<OperationObject> & {
|
|
132
|
+
method: string;
|
|
133
|
+
};
|
|
178
134
|
type Awaitable<T> = T | Promise<T>;
|
|
179
135
|
/**
|
|
180
136
|
* Dereferenced value and its original `$ref` value
|
|
@@ -186,14 +142,13 @@ interface RenderContext {
|
|
|
186
142
|
*/
|
|
187
143
|
proxyUrl?: string;
|
|
188
144
|
renderer: Renderer;
|
|
189
|
-
/**
|
|
190
|
-
* dereferenced schema
|
|
191
|
-
*/
|
|
192
|
-
document: NoReference<Document>;
|
|
193
145
|
baseUrl: string;
|
|
194
146
|
servers: ServerObject[];
|
|
195
147
|
slugger: Slugger;
|
|
196
|
-
|
|
148
|
+
/**
|
|
149
|
+
* dereferenced schema
|
|
150
|
+
*/
|
|
151
|
+
schema: ProcessedDocument;
|
|
197
152
|
/**
|
|
198
153
|
* Generate TypeScript definitions from response schema.
|
|
199
154
|
*
|
|
@@ -214,8 +169,6 @@ interface RenderContext {
|
|
|
214
169
|
showResponseSchema?: boolean;
|
|
215
170
|
}
|
|
216
171
|
|
|
217
|
-
type DocumentInput = string | OpenAPIV3_1.Document | OpenAPIV3.Document;
|
|
218
|
-
|
|
219
172
|
type ApiPageContextProps = Pick<Partial<RenderContext>, 'shikiOptions' | 'generateTypeScriptSchema' | 'generateCodeSamples' | 'proxyUrl' | 'showResponseSchema'>;
|
|
220
173
|
interface ApiPageProps extends ApiPageContextProps {
|
|
221
174
|
document: DocumentInput;
|