fumadocs-openapi 9.7.3 → 10.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generate-file.d.ts +3 -4
- package/dist/generate-file.d.ts.map +1 -1
- package/dist/generate-file.js +4 -34
- package/dist/playground/client.d.ts +43 -22
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +68 -63
- package/dist/playground/{inputs.d.ts → components/inputs.d.ts} +1 -1
- package/dist/playground/components/inputs.d.ts.map +1 -0
- package/dist/playground/{inputs.js → components/inputs.js} +7 -7
- package/dist/playground/components/oauth-dialog.d.ts.map +1 -0
- package/dist/playground/components/server-select.d.ts.map +1 -0
- package/dist/{ui → playground/components}/server-select.js +6 -7
- package/dist/playground/index.d.ts +1 -4
- package/dist/playground/index.d.ts.map +1 -1
- package/dist/playground/index.js +5 -3
- package/dist/playground/lazy.d.ts +2 -0
- package/dist/playground/lazy.d.ts.map +1 -0
- package/dist/playground/lazy.js +3 -0
- package/dist/requests/generators/index.d.ts +2 -2
- package/dist/requests/generators/index.d.ts.map +1 -1
- package/dist/requests/generators/index.js +6 -0
- package/dist/requests/media/adapter.d.ts +0 -6
- package/dist/requests/media/adapter.d.ts.map +1 -1
- package/dist/scalar/client.d.ts +1 -0
- package/dist/scalar/client.d.ts.map +1 -1
- package/dist/scalar/client.js +2 -3
- package/dist/scalar/index.d.ts +7 -6
- package/dist/scalar/index.d.ts.map +1 -1
- package/dist/scalar/index.js +17 -1
- package/dist/server/create.d.ts +11 -59
- package/dist/server/create.d.ts.map +1 -1
- package/dist/server/create.js +5 -14
- package/dist/server/source-api.d.ts +1 -1
- package/dist/server/source-api.d.ts.map +1 -1
- package/dist/server/source-api.js +1 -1
- package/dist/types.d.ts +12 -4
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/api-page.d.ts +145 -0
- package/dist/ui/api-page.d.ts.map +1 -0
- package/dist/ui/api-page.js +120 -0
- package/dist/ui/client/index.d.ts +29 -0
- package/dist/ui/client/index.d.ts.map +1 -0
- package/dist/ui/client/index.js +4 -0
- package/dist/ui/client/storage-key.d.ts +9 -0
- package/dist/ui/client/storage-key.d.ts.map +1 -0
- package/dist/ui/client/storage-key.js +12 -0
- package/dist/ui/components/method-label.d.ts +1 -1
- package/dist/ui/contexts/api.d.ts +12 -10
- package/dist/ui/contexts/api.d.ts.map +1 -1
- package/dist/ui/contexts/api.js +53 -37
- package/dist/ui/contexts/api.lazy.d.ts +2 -0
- package/dist/ui/contexts/api.lazy.d.ts.map +1 -0
- package/dist/ui/contexts/api.lazy.js +3 -0
- package/dist/ui/contexts/operation.d.ts +20 -0
- package/dist/ui/contexts/operation.d.ts.map +1 -0
- package/dist/ui/contexts/operation.js +48 -0
- package/dist/ui/contexts/operation.lazy.d.ts +2 -0
- package/dist/ui/contexts/operation.lazy.d.ts.map +1 -0
- package/dist/ui/contexts/operation.lazy.js +3 -0
- package/dist/ui/index.d.ts +1 -8
- package/dist/ui/index.d.ts.map +1 -1
- package/dist/ui/index.js +1 -26
- package/dist/ui/{select-tabs.d.ts → operation/client.d.ts} +5 -2
- package/dist/ui/operation/client.d.ts.map +1 -0
- package/dist/ui/{client.js → operation/client.js} +18 -1
- package/dist/ui/operation/example-panel/client.d.ts +4 -0
- package/dist/ui/operation/example-panel/client.d.ts.map +1 -0
- package/dist/ui/operation/example-panel/client.js +50 -0
- package/dist/ui/operation/example-panel/index.d.ts +58 -0
- package/dist/ui/operation/example-panel/index.d.ts.map +1 -0
- package/dist/ui/operation/example-panel/index.js +140 -0
- package/dist/ui/operation/example-panel/lazy.d.ts +3 -0
- package/dist/ui/operation/example-panel/lazy.d.ts.map +1 -0
- package/dist/ui/operation/example-panel/lazy.js +4 -0
- package/dist/ui/operation/get-request-data.d.ts.map +1 -0
- package/dist/ui/operation/index.d.ts +11 -0
- package/dist/ui/operation/index.d.ts.map +1 -0
- package/dist/{render → ui}/operation/index.js +50 -24
- package/dist/ui/schema/client.d.ts +11 -0
- package/dist/ui/schema/client.d.ts.map +1 -0
- package/dist/{render → ui}/schema/client.js +22 -12
- package/dist/{render/schema/server.d.ts → ui/schema/index.d.ts} +5 -4
- package/dist/ui/schema/index.d.ts.map +1 -0
- package/dist/{render/schema/server.js → ui/schema/index.js} +11 -5
- package/dist/ui/schema/lazy.d.ts +2 -0
- package/dist/ui/schema/lazy.d.ts.map +1 -0
- package/dist/ui/schema/lazy.js +3 -0
- package/dist/utils/get-typescript-schema.d.ts +3 -2
- package/dist/utils/get-typescript-schema.d.ts.map +1 -1
- package/dist/utils/get-typescript-schema.js +12 -7
- package/dist/utils/lazy.d.ts +5 -0
- package/dist/utils/lazy.d.ts.map +1 -0
- package/dist/utils/lazy.js +12 -0
- package/dist/utils/pages/builder.d.ts +1 -1
- package/dist/utils/pages/builder.d.ts.map +1 -1
- package/dist/utils/pages/to-body.d.ts +2 -3
- package/dist/utils/pages/to-body.d.ts.map +1 -1
- package/dist/utils/pages/to-body.js +7 -7
- package/dist/utils/pages/to-text.d.ts.map +1 -1
- package/dist/utils/process-document.d.ts +1 -0
- package/dist/utils/process-document.d.ts.map +1 -1
- package/dist/utils/process-document.js +7 -2
- package/package.json +20 -16
- package/dist/playground/auth/oauth-dialog.d.ts.map +0 -1
- package/dist/playground/inputs.d.ts.map +0 -1
- package/dist/render/api-page.d.ts +0 -33
- package/dist/render/api-page.d.ts.map +0 -1
- package/dist/render/api-page.js +0 -59
- package/dist/render/codeblock.d.ts +0 -9
- package/dist/render/codeblock.d.ts.map +0 -1
- package/dist/render/codeblock.js +0 -14
- package/dist/render/heading.d.ts +0 -4
- package/dist/render/heading.d.ts.map +0 -1
- package/dist/render/heading.js +0 -6
- package/dist/render/markdown.d.ts +0 -5
- package/dist/render/markdown.d.ts.map +0 -1
- package/dist/render/markdown.js +0 -31
- package/dist/render/operation/api-example.d.ts +0 -30
- package/dist/render/operation/api-example.d.ts.map +0 -1
- package/dist/render/operation/api-example.js +0 -103
- package/dist/render/operation/get-request-data.d.ts.map +0 -1
- package/dist/render/operation/index.d.ts +0 -27
- package/dist/render/operation/index.d.ts.map +0 -1
- package/dist/render/renderer.d.ts +0 -79
- package/dist/render/renderer.d.ts.map +0 -1
- package/dist/render/renderer.js +0 -25
- package/dist/render/schema/client.d.ts +0 -18
- package/dist/render/schema/client.d.ts.map +0 -1
- package/dist/render/schema/index.d.ts +0 -7
- package/dist/render/schema/index.d.ts.map +0 -1
- package/dist/render/schema/index.js +0 -11
- package/dist/render/schema/server.d.ts.map +0 -1
- package/dist/render/schema/ui.d.ts +0 -16
- package/dist/render/schema/ui.d.ts.map +0 -1
- package/dist/render/schema/ui.js +0 -14
- package/dist/ui/client.d.ts +0 -4
- package/dist/ui/client.d.ts.map +0 -1
- package/dist/ui/contexts/code-example.d.ts +0 -24
- package/dist/ui/contexts/code-example.d.ts.map +0 -1
- package/dist/ui/contexts/code-example.js +0 -97
- package/dist/ui/lazy.d.ts +0 -16
- package/dist/ui/lazy.d.ts.map +0 -1
- package/dist/ui/lazy.js +0 -22
- package/dist/ui/select-tabs.d.ts.map +0 -1
- package/dist/ui/select-tabs.js +0 -20
- package/dist/ui/server-select.d.ts.map +0 -1
- /package/dist/playground/{auth → components}/oauth-dialog.d.ts +0 -0
- /package/dist/playground/{auth → components}/oauth-dialog.js +0 -0
- /package/dist/{ui → playground/components}/server-select.d.ts +0 -0
- /package/dist/{render → ui}/operation/get-request-data.d.ts +0 -0
- /package/dist/{render → ui}/operation/get-request-data.js +0 -0
package/dist/generate-file.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type PagesToTextOptions } from './utils/pages/to-text.js';
|
|
2
|
-
import {
|
|
2
|
+
import type { ProcessedDocument } from './utils/process-document.js';
|
|
3
3
|
import type { OpenAPIServer } from './server/index.js';
|
|
4
4
|
import { type SchemaToPagesOptions } from './utils/pages/preset-auto.js';
|
|
5
5
|
export interface OutputFile {
|
|
@@ -31,11 +31,10 @@ interface IndexItem {
|
|
|
31
31
|
only?: (string | OutputFile)[];
|
|
32
32
|
}
|
|
33
33
|
interface GenerateFilesConfig extends PagesToTextOptions {
|
|
34
|
-
cwd?: string;
|
|
35
34
|
/**
|
|
36
|
-
*
|
|
35
|
+
* the OpenAPI server object
|
|
37
36
|
*/
|
|
38
|
-
input:
|
|
37
|
+
input: OpenAPIServer;
|
|
39
38
|
/**
|
|
40
39
|
* Output directory
|
|
41
40
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-file.d.ts","sourceRoot":"","sources":["../src/generate-file.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate-file.d.ts","sourceRoot":"","sources":["../src/generate-file.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,kBAAkB,EAExB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG9C,OAAO,EAEL,KAAK,oBAAoB,EAC1B,MAAM,2BAA2B,CAAC;AAGnC,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,WAAW;IACnB,KAAK,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,WAAW,KAAK,SAAS,EAAE,CAAC,CAAC;IAEzD;;OAEG;IACH,GAAG,EACC,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC,GAC9B;QACE,OAAO,EAAE,MAAM,CAAC;QAChB;;WAEG;QACH,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACP;AAED,UAAU,SAAS;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,UAAU,CAAC,EAAE,CAAC;CAChC;AAED,UAAU,mBAAoB,SAAQ,kBAAkB;IACtD;;OAEG;IACH,KAAK,EAAE,aAAa,CAAC;IAErB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;OAEG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC;IAEpB;;QAEI;IACJ,WAAW,CAAC,EAAE,CACZ,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,UAAU,EAAE,KAChB,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3B;AAED,MAAM,MAAM,MAAM,GAAG,oBAAoB,GAAG,mBAAmB,CAAC;AAEhE,UAAU,WAAW;IACnB,KAAK,EAAE,UAAU,EAAE,CAAC;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;IACjD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC;CACvD;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAalE;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAAC,mBAAmB,EAAE,QAAQ,CAAC,GAClE,OAAO,CAAC,UAAU,EAAE,CAAC,CAiCvB"}
|
package/dist/generate-file.js
CHANGED
|
@@ -1,53 +1,23 @@
|
|
|
1
1
|
import { mkdir, writeFile } from 'node:fs/promises';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
|
-
import { glob } from 'tinyglobby';
|
|
4
3
|
import { generateDocument, toText, } from './utils/pages/to-text.js';
|
|
5
|
-
import { processDocumentCached, } from './utils/process-document.js';
|
|
6
4
|
import { createGetUrl, getSlugs } from 'fumadocs-core/source';
|
|
7
5
|
import matter from 'gray-matter';
|
|
8
6
|
import { createAutoPreset, } from './utils/pages/preset-auto.js';
|
|
9
|
-
import { isUrl } from './utils/url.js';
|
|
10
7
|
import { fromSchema } from './utils/pages/builder.js';
|
|
11
8
|
export async function generateFiles(options) {
|
|
12
9
|
const files = await generateFilesOnly(options);
|
|
13
|
-
const { output
|
|
14
|
-
const baseDir = path.join(cwd, output);
|
|
10
|
+
const { output } = options;
|
|
15
11
|
await Promise.all(files.map(async (file) => {
|
|
16
|
-
const filePath = path.join(
|
|
12
|
+
const filePath = path.join(output, file.path);
|
|
17
13
|
await mkdir(path.dirname(filePath), { recursive: true });
|
|
18
14
|
await writeFile(filePath, file.content);
|
|
19
15
|
console.log(`Generated: ${filePath}`);
|
|
20
16
|
}));
|
|
21
17
|
}
|
|
22
18
|
export async function generateFilesOnly(options) {
|
|
23
|
-
const {
|
|
24
|
-
const
|
|
25
|
-
let schemas = {};
|
|
26
|
-
async function resolveInput(item) {
|
|
27
|
-
if (isUrl(item)) {
|
|
28
|
-
schemas[item] = await processDocumentCached(item);
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
const resolved = await glob(item, { cwd, absolute: true });
|
|
32
|
-
if (resolved.length > 1) {
|
|
33
|
-
console.warn('glob patterns in `input` are deprecated, please specify your schemas explicitly.');
|
|
34
|
-
for (let i = 0; i < resolved.length; i++) {
|
|
35
|
-
schemas[`${item}[${i}]`] = await processDocumentCached(item);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
else if (resolved.length === 1) {
|
|
39
|
-
schemas[item] = await processDocumentCached(resolved[0]);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
throw new Error(`input not found: ${item}`);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (Array.isArray(input)) {
|
|
46
|
-
await Promise.all(input.map(resolveInput));
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
schemas = await input.getSchemas();
|
|
50
|
-
}
|
|
19
|
+
const { beforeWrite } = options;
|
|
20
|
+
const schemas = await options.input.getSchemas();
|
|
51
21
|
const generated = {};
|
|
52
22
|
const files = [];
|
|
53
23
|
const entries = Object.entries(schemas);
|
|
@@ -1,28 +1,20 @@
|
|
|
1
|
-
import { type FC, type HTMLAttributes, type
|
|
2
|
-
import type {
|
|
1
|
+
import { type FC, type HTMLAttributes, type ReactNode } from 'react';
|
|
2
|
+
import type { FieldPath, UseControllerProps, UseControllerReturn } from 'react-hook-form';
|
|
3
3
|
import type { FetchResult } from '../playground/fetcher.js';
|
|
4
4
|
import type { ParameterField, RequestSchema, SecurityEntry } from '../playground/index.js';
|
|
5
5
|
import type { RequestData } from '../requests/types.js';
|
|
6
|
-
interface FormValues {
|
|
6
|
+
export interface FormValues {
|
|
7
7
|
path: Record<string, unknown>;
|
|
8
8
|
query: Record<string, unknown>;
|
|
9
9
|
header: Record<string, unknown>;
|
|
10
10
|
cookie: Record<string, unknown>;
|
|
11
11
|
body: unknown;
|
|
12
|
+
/**
|
|
13
|
+
* Store the cached encoded request data, do not modify it.
|
|
14
|
+
*/
|
|
12
15
|
_encoded?: RequestData;
|
|
13
16
|
}
|
|
14
|
-
export interface
|
|
15
|
-
render: (props: {
|
|
16
|
-
/**
|
|
17
|
-
* Field Info
|
|
18
|
-
*/
|
|
19
|
-
info: Info;
|
|
20
|
-
field: ControllerRenderProps<FormValues, TName>;
|
|
21
|
-
fieldState: ControllerFieldState;
|
|
22
|
-
formState: UseFormStateReturn<FormValues>;
|
|
23
|
-
}) => ReactElement;
|
|
24
|
-
}
|
|
25
|
-
export interface ClientProps extends HTMLAttributes<HTMLFormElement> {
|
|
17
|
+
export interface PlaygroundClientProps extends HTMLAttributes<HTMLFormElement> {
|
|
26
18
|
route: string;
|
|
27
19
|
method: string;
|
|
28
20
|
parameters?: ParameterField[];
|
|
@@ -36,21 +28,50 @@ export interface ClientProps extends HTMLAttributes<HTMLFormElement> {
|
|
|
36
28
|
*/
|
|
37
29
|
references: Record<string, RequestSchema>;
|
|
38
30
|
proxyUrl?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface PlaygroundClientOptions {
|
|
33
|
+
/**
|
|
34
|
+
* transform fields for auth-specific parameters (e.g. header)
|
|
35
|
+
*/
|
|
36
|
+
transformAuthInputs?: (fields: AuthField[]) => AuthField[];
|
|
39
37
|
/**
|
|
40
38
|
* Request timeout in seconds (default: 10s)
|
|
41
39
|
*/
|
|
42
40
|
requestTimeout?: number;
|
|
43
|
-
fields?: {
|
|
44
|
-
parameter?: CustomField<`${ParameterField['in']}.${string}`, ParameterField>;
|
|
45
|
-
auth?: CustomField<FieldPath<FormValues>, RequestSchema>;
|
|
46
|
-
body?: CustomField<'body', RequestSchema>;
|
|
47
|
-
};
|
|
48
41
|
components?: Partial<{
|
|
49
42
|
ResultDisplay: FC<{
|
|
50
43
|
data: FetchResult;
|
|
51
44
|
}>;
|
|
52
45
|
}>;
|
|
46
|
+
/**
|
|
47
|
+
* render the paremeter inputs of API endpoint.
|
|
48
|
+
*
|
|
49
|
+
* It uses `react-hook-form`, you can use either:
|
|
50
|
+
* - the library itself, with types from `fumadocs-openapi/playground/client`.
|
|
51
|
+
* - the `Custom.useController()` from `fumadocs-openapi/playground/client`.
|
|
52
|
+
*
|
|
53
|
+
* Recommended types packages: `json-schema-typed`, `openapi-types`.
|
|
54
|
+
*/
|
|
55
|
+
renderParameterField?: (fieldName: FieldPath<FormValues>, param: ParameterField) => ReactNode;
|
|
56
|
+
/**
|
|
57
|
+
* render the input for API endpoint body.
|
|
58
|
+
*
|
|
59
|
+
* @see renderParameterField for customisation tips
|
|
60
|
+
*/
|
|
61
|
+
renderBodyField?: (fieldName: 'body', info: {
|
|
62
|
+
schema: RequestSchema;
|
|
63
|
+
mediaType: string;
|
|
64
|
+
}) => ReactNode;
|
|
65
|
+
}
|
|
66
|
+
export default function PlaygroundClient({ route, method, securities, parameters, body, references, proxyUrl, ...rest }: PlaygroundClientProps): import("react/jsx-runtime").JSX.Element;
|
|
67
|
+
export interface AuthField {
|
|
68
|
+
fieldName: string;
|
|
69
|
+
defaultValue: unknown;
|
|
70
|
+
original?: SecurityEntry;
|
|
71
|
+
children: ReactNode;
|
|
72
|
+
mapOutput?: (values: unknown) => unknown;
|
|
53
73
|
}
|
|
54
|
-
export
|
|
55
|
-
|
|
74
|
+
export declare const Custom: {
|
|
75
|
+
useController<TName extends FieldPath<FormValues> = "path" | "query" | "header" | "cookie" | "body" | "_encoded" | `path.${string}` | `query.${string}` | `header.${string}` | `cookie.${string}` | "_encoded.method" | "_encoded.path" | "_encoded.query" | "_encoded.header" | "_encoded.cookie" | "_encoded.body" | "_encoded.bodyMediaType" | `_encoded.path.${string}` | `_encoded.query.${string}` | `_encoded.header.${string}` | `_encoded.cookie.${string}`, TTransformedValues = FormValues>(props: UseControllerProps<FormValues, TName, TTransformedValues>): UseControllerReturn<FormValues, TName>;
|
|
76
|
+
};
|
|
56
77
|
//# sourceMappingURL=client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/playground/client.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EAAE,EAEP,KAAK,cAAc,EAEnB,KAAK,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/playground/client.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,EAAE,EAEP,KAAK,cAAc,EAEnB,KAAK,SAAS,EAKf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,SAAS,EACT,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,iBAAiB,CAAC;AAUzB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAOxD,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,aAAa,EACd,MAAM,oBAAoB,CAAC;AAmC5B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAIpD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,IAAI,EAAE,OAAO,CAAC;IAEd;;OAEG;IACH,QAAQ,CAAC,EAAE,WAAW,CAAC;CACxB;AAED,MAAM,WAAW,qBAAsB,SAAQ,cAAc,CAAC,eAAe,CAAC;IAC5E,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAC9B,UAAU,EAAE,aAAa,EAAE,EAAE,CAAC;IAC9B,IAAI,CAAC,EAAE;QACL,MAAM,EAAE,aAAa,CAAC;QACtB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF;;OAEG;IACH,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC;IAC1C,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,mBAAmB,CAAC,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,SAAS,EAAE,CAAC;IAE3D;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,UAAU,CAAC,EAAE,OAAO,CAAC;QACnB,aAAa,EAAE,EAAE,CAAC;YAAE,IAAI,EAAE,WAAW,CAAA;SAAE,CAAC,CAAC;KAC1C,CAAC,CAAC;IAEH;;;;;;;;OAQG;IACH,oBAAoB,CAAC,EAAE,CACrB,SAAS,EAAE,SAAS,CAAC,UAAU,CAAC,EAChC,KAAK,EAAE,cAAc,KAClB,SAAS,CAAC;IAEf;;;;OAIG;IACH,eAAe,CAAC,EAAE,CAChB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE;QACJ,MAAM,EAAE,aAAa,CAAC;QACtB,SAAS,EAAE,MAAM,CAAC;KACnB,KACE,SAAS,CAAC;CAChB;AAaD,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EACvC,KAAK,EACL,MAAc,EACd,UAAU,EACV,UAAe,EACf,IAAI,EACJ,UAAU,EACV,QAAQ,EACR,GAAG,IAAI,EACR,EAAE,qBAAqB,2CA8LvB;AA8LD,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,OAAO,CAAC;IAEtB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,QAAQ,EAAE,SAAS,CAAC;IAEpB,SAAS,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,OAAO,CAAC;CAC1C;AAoQD,eAAO,MAAM,MAAM;kBAEf,KAAK,SAAS,SAAS,CAAC,UAAU,CAAC,qZACnC,kBAAkB,sBAEX,kBAAkB,CAAC,UAAU,EAAE,KAAK,EAAE,kBAAkB,CAAC,GAC/D,mBAAmB,CAAC,UAAU,EAAE,KAAK,CAAC;CAG1C,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { Fragment, lazy, useEffect, useMemo, useState, } from 'react';
|
|
4
|
-
import {
|
|
5
|
-
import { useApiContext
|
|
6
|
-
import { FieldInput, FieldSet, JsonInput, ObjectInput } from './inputs.js';
|
|
3
|
+
import { Fragment, lazy, useEffect, useMemo, useState, useEffectEvent, } from 'react';
|
|
4
|
+
import { FormProvider, get, set, useController, useForm, useFormContext, } from 'react-hook-form';
|
|
5
|
+
import { useApiContext } from '../ui/contexts/api.js';
|
|
6
|
+
import { FieldInput, FieldSet, JsonInput, ObjectInput, } from './components/inputs.js';
|
|
7
7
|
import { getStatusInfo } from './status-info.js';
|
|
8
8
|
import { joinURL, resolveRequestData, resolveServerUrl, withBase, } from '../utils/url.js';
|
|
9
9
|
import { DynamicCodeBlock } from 'fumadocs-ui/components/dynamic-codeblock';
|
|
@@ -15,40 +15,44 @@ import { encodeRequestData } from '../requests/media/encode.js';
|
|
|
15
15
|
import { buttonVariants } from 'fumadocs-ui/components/ui/button';
|
|
16
16
|
import { cn } from 'fumadocs-ui/utils/cn';
|
|
17
17
|
import { SchemaProvider, useResolvedSchema, } from '../playground/schema.js';
|
|
18
|
-
import {
|
|
19
|
-
import { useEffectEvent } from 'fumadocs-core/utils/use-effect-event';
|
|
18
|
+
import { useOperationContext } from '../ui/contexts/operation.js';
|
|
20
19
|
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../ui/components/select.js';
|
|
21
20
|
import { labelVariants } from '../ui/components/input.js';
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const OauthDialog = lazy(() => import('./
|
|
21
|
+
import ServerSelect from './components/server-select.js';
|
|
22
|
+
import { useStorageKey } from '../ui/client/storage-key.js';
|
|
23
|
+
const OauthDialog = lazy(() => import('./components/oauth-dialog.js').then((mod) => ({
|
|
25
24
|
default: mod.OauthDialog,
|
|
26
25
|
})));
|
|
27
|
-
const OauthDialogTrigger = lazy(() => import('./
|
|
26
|
+
const OauthDialogTrigger = lazy(() => import('./components/oauth-dialog.js').then((mod) => ({
|
|
28
27
|
default: mod.OauthDialogTrigger,
|
|
29
28
|
})));
|
|
30
|
-
export default function
|
|
31
|
-
const {
|
|
32
|
-
const
|
|
33
|
-
const updater = useRequestDataUpdater();
|
|
29
|
+
export default function PlaygroundClient({ route, method = 'GET', securities, parameters = [], body, references, proxyUrl, ...rest }) {
|
|
30
|
+
const { example: exampleId, examples, setExampleData, } = useOperationContext();
|
|
31
|
+
const storageKeys = useStorageKey();
|
|
34
32
|
const fieldInfoMap = useMemo(() => new Map(), []);
|
|
35
|
-
const { mediaAdapters } = useApiContext();
|
|
33
|
+
const { mediaAdapters, serverRef, client: { playground: { components: { ResultDisplay = DefaultResultDisplay } = {}, requestTimeout = 10, transformAuthInputs, } = {}, }, } = useApiContext();
|
|
36
34
|
const [securityId, setSecurityId] = useState(0);
|
|
37
|
-
const { inputs, mapInputs } = useAuthInputs(securities[securityId]);
|
|
38
|
-
const defaultValues = useMemo(() =>
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
const { inputs, mapInputs, initAuthValues } = useAuthInputs(securities[securityId], transformAuthInputs);
|
|
36
|
+
const defaultValues = useMemo(() => {
|
|
37
|
+
const requestData = examples.find((example) => example.id === exampleId)?.data;
|
|
38
|
+
return {
|
|
39
|
+
path: requestData?.path ?? {},
|
|
40
|
+
query: requestData?.query ?? {},
|
|
41
|
+
header: requestData?.header ?? {},
|
|
42
|
+
body: requestData?.body ?? {},
|
|
43
|
+
cookie: requestData?.cookie ?? {},
|
|
44
|
+
};
|
|
45
|
+
}, [examples, exampleId]);
|
|
45
46
|
const form = useForm({
|
|
46
47
|
defaultValues,
|
|
47
48
|
});
|
|
48
49
|
const testQuery = useQuery(async (input) => {
|
|
50
|
+
const targetServer = serverRef.current;
|
|
49
51
|
const fetcher = await import('./fetcher.js').then((mod) => mod.createBrowserFetcher(mediaAdapters, requestTimeout));
|
|
50
52
|
input._encoded ?? (input._encoded = encodeRequestData({ ...mapInputs(input), method, bodyMediaType: body?.mediaType }, mediaAdapters, parameters));
|
|
51
|
-
return fetcher.fetch(joinURL(withBase(
|
|
53
|
+
return fetcher.fetch(joinURL(withBase(targetServer
|
|
54
|
+
? resolveServerUrl(targetServer.url, targetServer.variables)
|
|
55
|
+
: '/', window.location.origin), resolveRequestData(route, input._encoded)), {
|
|
52
56
|
proxyUrl,
|
|
53
57
|
...input._encoded,
|
|
54
58
|
});
|
|
@@ -57,7 +61,7 @@ export default function Client({ route, method = 'GET', securities, parameters =
|
|
|
57
61
|
for (const item of inputs) {
|
|
58
62
|
const value = get(values, item.fieldName);
|
|
59
63
|
if (value) {
|
|
60
|
-
localStorage.setItem(
|
|
64
|
+
localStorage.setItem(storageKeys.AuthField(item), JSON.stringify(value));
|
|
61
65
|
}
|
|
62
66
|
}
|
|
63
67
|
const data = {
|
|
@@ -66,7 +70,7 @@ export default function Client({ route, method = 'GET', securities, parameters =
|
|
|
66
70
|
bodyMediaType: body?.mediaType,
|
|
67
71
|
};
|
|
68
72
|
values._encoded ?? (values._encoded = encodeRequestData(data, mediaAdapters, parameters));
|
|
69
|
-
|
|
73
|
+
setExampleData(data, values._encoded);
|
|
70
74
|
});
|
|
71
75
|
useEffect(() => {
|
|
72
76
|
let timer = null;
|
|
@@ -86,7 +90,12 @@ export default function Client({ route, method = 'GET', securities, parameters =
|
|
|
86
90
|
// eslint-disable-next-line react-hooks/exhaustive-deps -- mounted once only
|
|
87
91
|
}, []);
|
|
88
92
|
useEffect(() => {
|
|
89
|
-
form.reset(
|
|
93
|
+
form.reset(initAuthValues(defaultValues));
|
|
94
|
+
return () => fieldInfoMap.clear();
|
|
95
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- ignore other parts
|
|
96
|
+
}, [defaultValues]);
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
form.reset((values) => initAuthValues(values));
|
|
90
99
|
return () => {
|
|
91
100
|
form.reset((values) => {
|
|
92
101
|
for (const item of inputs) {
|
|
@@ -95,19 +104,12 @@ export default function Client({ route, method = 'GET', securities, parameters =
|
|
|
95
104
|
return values;
|
|
96
105
|
});
|
|
97
106
|
};
|
|
98
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps --
|
|
107
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- ignore other parts
|
|
99
108
|
}, [inputs]);
|
|
100
|
-
useEffect(() => {
|
|
101
|
-
return () => {
|
|
102
|
-
fieldInfoMap.clear();
|
|
103
|
-
form.reset(initAuthValues(defaultValues, inputs));
|
|
104
|
-
};
|
|
105
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps -- for on change
|
|
106
|
-
}, [requestDataKey]);
|
|
107
109
|
const onSubmit = form.handleSubmit((value) => {
|
|
108
110
|
testQuery.start(mapInputs(value));
|
|
109
111
|
});
|
|
110
|
-
return (_jsx(FormProvider, { ...form, children: _jsx(SchemaProvider, { fieldInfoMap: fieldInfoMap, references: references, children: _jsxs("form", { ...rest, className: cn('not-prose flex flex-col rounded-xl border shadow-md overflow-hidden bg-fd-card text-fd-card-foreground', rest.className), onSubmit: onSubmit, children: [_jsx(ServerSelect, {}), _jsxs("div", { className: "flex flex-row items-center gap-2 text-sm p-3 pb-0", children: [_jsx(MethodLabel, { children: method }), _jsx(Route, { route: route, className: "flex-1" }), _jsx("button", { type: "submit", className: cn(buttonVariants({ color: 'primary', size: 'sm' }), 'px-3 py-1.5'), disabled: testQuery.isLoading, children: testQuery.isLoading ? (_jsx(LoaderCircle, { className: "size-4 animate-spin" })) : ('Send') })] }), securities.length > 0 && (_jsx(SecurityTabs, { securities: securities, securityId: securityId, setSecurityId: setSecurityId, children: inputs.map((input) => (_jsx(Fragment, { children: input.children }, input.fieldName))) })), _jsx(FormBody, { body: body,
|
|
112
|
+
return (_jsx(FormProvider, { ...form, children: _jsx(SchemaProvider, { fieldInfoMap: fieldInfoMap, references: references, children: _jsxs("form", { ...rest, className: cn('not-prose flex flex-col rounded-xl border shadow-md overflow-hidden bg-fd-card text-fd-card-foreground', rest.className), onSubmit: onSubmit, children: [_jsx(ServerSelect, {}), _jsxs("div", { className: "flex flex-row items-center gap-2 text-sm p-3 not-last:pb-0", children: [_jsx(MethodLabel, { children: method }), _jsx(Route, { route: route, className: "flex-1" }), _jsx("button", { type: "submit", className: cn(buttonVariants({ color: 'primary', size: 'sm' }), 'px-3 py-1.5'), disabled: testQuery.isLoading, children: testQuery.isLoading ? (_jsx(LoaderCircle, { className: "size-4 animate-spin" })) : ('Send') })] }), securities.length > 0 && (_jsx(SecurityTabs, { securities: securities, securityId: securityId, setSecurityId: setSecurityId, children: inputs.map((input) => (_jsx(Fragment, { children: input.children }, input.fieldName))) })), _jsx(FormBody, { body: body, parameters: parameters }), testQuery.data ? _jsx(ResultDisplay, { data: testQuery.data }) : null] }) }) }));
|
|
111
113
|
}
|
|
112
114
|
function SecurityTabs({ securities, setSecurityId, securityId, children, }) {
|
|
113
115
|
const [open, setOpen] = useState(false);
|
|
@@ -129,7 +131,8 @@ function SecurityTabs({ securities, setSecurityId, securityId, children, }) {
|
|
|
129
131
|
return result;
|
|
130
132
|
}
|
|
131
133
|
const ParamTypes = ['path', 'header', 'cookie', 'query'];
|
|
132
|
-
function FormBody({ parameters = [],
|
|
134
|
+
function FormBody({ parameters = [], body, }) {
|
|
135
|
+
const { renderParameterField, renderBodyField } = useApiContext().client.playground ?? {};
|
|
133
136
|
const panels = useMemo(() => {
|
|
134
137
|
return ParamTypes.map((type) => {
|
|
135
138
|
const items = parameters.filter((v) => v.in === type);
|
|
@@ -142,17 +145,17 @@ function FormBody({ parameters = [], fields = {}, body, }) {
|
|
|
142
145
|
path: 'Path',
|
|
143
146
|
}[type], children: items.map((field) => {
|
|
144
147
|
const fieldName = `${type}.${field.name}`;
|
|
148
|
+
if (renderParameterField) {
|
|
149
|
+
return renderParameterField(fieldName, field);
|
|
150
|
+
}
|
|
145
151
|
const schema = (field.content
|
|
146
152
|
? field.content[Object.keys(field.content)[0]].schema
|
|
147
153
|
: field.schema);
|
|
148
|
-
if (fields?.parameter) {
|
|
149
|
-
return renderCustomField(fieldName, schema, fields.parameter, field.name);
|
|
150
|
-
}
|
|
151
154
|
return (_jsx(FieldSet, { name: field.name, fieldName: fieldName, field: schema }, fieldName));
|
|
152
155
|
}) }, type));
|
|
153
156
|
});
|
|
154
|
-
}, [
|
|
155
|
-
return (_jsxs(_Fragment, { children: [panels, body && (_jsx(CollapsiblePanel, { title: "Body", children:
|
|
157
|
+
}, [parameters, renderParameterField]);
|
|
158
|
+
return (_jsxs(_Fragment, { children: [panels, body && (_jsx(CollapsiblePanel, { title: "Body", children: renderBodyField ? (renderBodyField('body', body)) : (_jsx(BodyInput, { field: body.schema })) }))] }));
|
|
156
159
|
}
|
|
157
160
|
function BodyInput({ field: _field }) {
|
|
158
161
|
const field = useResolvedSchema(_field);
|
|
@@ -171,7 +174,8 @@ function BodyInput({ field: _field }) {
|
|
|
171
174
|
className: 'p-2',
|
|
172
175
|
})), onClick: () => setIsJson(true), children: "Open JSON Editor" }) }));
|
|
173
176
|
}
|
|
174
|
-
function useAuthInputs(securities) {
|
|
177
|
+
function useAuthInputs(securities, transform) {
|
|
178
|
+
const storageKeys = useStorageKey();
|
|
175
179
|
const inputs = useMemo(() => {
|
|
176
180
|
const result = [];
|
|
177
181
|
if (!securities)
|
|
@@ -254,8 +258,8 @@ function useAuthInputs(securities) {
|
|
|
254
258
|
});
|
|
255
259
|
}
|
|
256
260
|
}
|
|
257
|
-
return result;
|
|
258
|
-
}, [securities]);
|
|
261
|
+
return transform ? transform(result) : result;
|
|
262
|
+
}, [securities, transform]);
|
|
259
263
|
const mapInputs = (values) => {
|
|
260
264
|
const cloned = structuredClone(values);
|
|
261
265
|
for (const item of inputs) {
|
|
@@ -265,26 +269,21 @@ function useAuthInputs(securities) {
|
|
|
265
269
|
}
|
|
266
270
|
return cloned;
|
|
267
271
|
};
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
continue;
|
|
272
|
+
const initAuthValues = (values) => {
|
|
273
|
+
for (const item of inputs) {
|
|
274
|
+
const stored = localStorage.getItem(storageKeys.AuthField(item));
|
|
275
|
+
if (stored) {
|
|
276
|
+
const parsed = JSON.parse(stored);
|
|
277
|
+
if (typeof parsed === typeof item.defaultValue) {
|
|
278
|
+
set(values, item.fieldName, parsed);
|
|
279
|
+
continue;
|
|
280
|
+
}
|
|
278
281
|
}
|
|
282
|
+
set(values, item.fieldName, item.defaultValue);
|
|
279
283
|
}
|
|
280
|
-
|
|
281
|
-
}
|
|
282
|
-
return
|
|
283
|
-
}
|
|
284
|
-
function renderCustomField(fieldName, info, field, key) {
|
|
285
|
-
return (_jsx(Controller, {
|
|
286
|
-
// @ts-expect-error we use string here
|
|
287
|
-
render: (props) => field.render({ ...props, info }), name: fieldName }, key));
|
|
284
|
+
return values;
|
|
285
|
+
};
|
|
286
|
+
return { inputs, mapInputs, initAuthValues };
|
|
288
287
|
}
|
|
289
288
|
function Route({ route, ...props }) {
|
|
290
289
|
return (_jsx("div", { ...props, className: cn('flex flex-row items-center gap-0.5 overflow-auto text-nowrap', props.className), children: route.split('/').map((part, index) => (_jsxs(Fragment, { children: [index > 0 && _jsx("span", { className: "text-fd-muted-foreground", children: "/" }), part.startsWith('{') && part.endsWith('}') ? (_jsx("code", { className: "bg-fd-primary/10 text-fd-primary", children: part })) : (_jsx("code", { className: "text-fd-foreground", children: part }))] }, index))) }));
|
|
@@ -301,3 +300,9 @@ function DefaultResultDisplay({ data }) {
|
|
|
301
300
|
function CollapsiblePanel({ title, children, ...props }) {
|
|
302
301
|
return (_jsxs(Collapsible, { ...props, className: "border-b last:border-b-0", children: [_jsxs(CollapsibleTrigger, { className: "group w-full flex items-center gap-2 p-3 text-sm font-medium", children: [title, _jsx(ChevronDown, { className: "ms-auto size-3.5 text-fd-muted-foreground group-data-[state=open]:rotate-180" })] }), _jsx(CollapsibleContent, { children: _jsx("div", { className: "flex flex-col gap-3 p-3 pt-1", children: children }) })] }));
|
|
303
302
|
}
|
|
303
|
+
// exports for customisations
|
|
304
|
+
export const Custom = {
|
|
305
|
+
useController(props) {
|
|
306
|
+
return useController(props);
|
|
307
|
+
},
|
|
308
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ComponentProps, type HTMLAttributes, type ReactNode } from 'react';
|
|
2
|
-
import type { RequestSchema } from '
|
|
2
|
+
import type { RequestSchema } from '../../playground/index.js';
|
|
3
3
|
export declare function ObjectInput({ field: _field, fieldName, ...props }: {
|
|
4
4
|
field: Exclude<RequestSchema, boolean>;
|
|
5
5
|
fieldName: string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../../src/playground/components/inputs.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,SAAS,EAGf,MAAM,OAAO,CAAC;AAef,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAkDxD,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EAAE,MAAM,EACb,SAAS,EACT,GAAG,KAAK,EACT,EAAE;IACD,KAAK,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACvC,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,cAAc,CAAC,KAAK,CAAC,uDAwCxB;AAED,wBAAgB,SAAS,CAAC,EAAE,SAAS,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,2CA8B7D;AA6FD,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,SAAS,EACT,UAAU,EACV,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG;IAC/B,KAAK,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,uDAoGA;AAED,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EAAE,MAAM,EACb,SAAS,EACT,OAAO,EACP,IAAI,EACJ,UAAU,EACV,KAAS,EACT,QAAQ,EACR,WAAkB,EAClB,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,aAAa,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,kDA4KA"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
3
3
|
import { useMemo, useState, } from 'react';
|
|
4
|
-
import { ChevronDown, Plus, Trash2, X } from '
|
|
4
|
+
import { ChevronDown, Plus, Trash2, X } from '../../icons.js';
|
|
5
5
|
import { set, useController, useFieldArray, useFormContext, } from 'react-hook-form';
|
|
6
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '
|
|
7
|
-
import { Input, labelVariants } from '
|
|
8
|
-
import { getDefaultValue } from '
|
|
6
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../../ui/components/select.js';
|
|
7
|
+
import { Input, labelVariants } from '../../ui/components/input.js';
|
|
8
|
+
import { getDefaultValue } from '../get-default-values.js';
|
|
9
9
|
import { cn } from 'fumadocs-ui/utils/cn';
|
|
10
10
|
import { buttonVariants } from 'fumadocs-ui/components/ui/button';
|
|
11
|
-
import { combineSchema } from '
|
|
12
|
-
import { FormatFlags, schemaToString } from '
|
|
13
|
-
import { anyFields, useFieldInfo, useResolvedSchema, } from '
|
|
11
|
+
import { combineSchema } from '../../utils/combine-schema.js';
|
|
12
|
+
import { FormatFlags, schemaToString } from '../../utils/schema-to-string.js';
|
|
13
|
+
import { anyFields, useFieldInfo, useResolvedSchema, } from '../../playground/schema.js';
|
|
14
14
|
function FieldLabel(props) {
|
|
15
15
|
return (_jsx("label", { ...props, className: cn('w-full inline-flex items-center gap-0.5', props.className), children: props.children }));
|
|
16
16
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"oauth-dialog.d.ts","sourceRoot":"","sources":["../../../src/playground/components/oauth-dialog.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAIjD,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAa5D,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,WAAW,CAAC,oBAAoB,CAAC;IACzC,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,EAAE,SAAS,CAAC;CACrB;AAuCD,wBAAgB,WAAW,CAAC,EAC1B,MAAM,EACN,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,OAAO,GACR,EAAE,eAAe,2CAwSjB;AAED,eAAO,MAAM,kBAAkB,mJAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server-select.d.ts","sourceRoot":"","sources":["../../../src/playground/components/server-select.tsx"],"names":[],"mappings":"AAUA,OAAO,EACL,KAAK,cAAc,EAIpB,MAAM,OAAO,CAAC;AAef,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,KAAK,EAAE,cAAc,CAAC,cAAc,CAAC,uDAwDzE"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
-
import { useApiContext, useServerSelectContext } from '
|
|
4
|
-
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '
|
|
5
|
-
import { Input, labelVariants } from '
|
|
6
|
-
import { useEffect, useState } from 'react';
|
|
3
|
+
import { useApiContext, useServerSelectContext } from '../../ui/contexts/api.js';
|
|
4
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../../ui/components/select.js';
|
|
5
|
+
import { Input, labelVariants } from '../../ui/components/input.js';
|
|
6
|
+
import { useEffect, useState, useEffectEvent, } from 'react';
|
|
7
7
|
import { cn } from 'fumadocs-ui/utils/cn';
|
|
8
|
-
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from '
|
|
9
|
-
import { resolveServerUrl, withBase } from '
|
|
8
|
+
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from '../../ui/components/dialog.js';
|
|
9
|
+
import { resolveServerUrl, withBase } from '../../utils/url.js';
|
|
10
10
|
import { FormProvider, useController, useForm } from 'react-hook-form';
|
|
11
|
-
import { useEffectEvent } from 'fumadocs-core/utils/use-effect-event';
|
|
12
11
|
export default function ServerSelect(props) {
|
|
13
12
|
const { servers } = useApiContext();
|
|
14
13
|
const { server, setServer, setServerVariables } = useServerSelectContext();
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { MethodInformation, ParameterObject, RenderContext, SecuritySchemeObject } from '../types.js';
|
|
2
2
|
import { type NoReference, type ParsedSchema } from '../utils/schema.js';
|
|
3
|
-
import { type ClientProps } from './client.js';
|
|
4
3
|
export type ParameterField = NoReference<ParameterObject> & {
|
|
5
4
|
schema: ParsedSchema;
|
|
6
5
|
in: 'cookie' | 'header' | 'query' | 'path';
|
|
@@ -10,12 +9,10 @@ export interface APIPlaygroundProps {
|
|
|
10
9
|
path: string;
|
|
11
10
|
method: MethodInformation;
|
|
12
11
|
ctx: RenderContext;
|
|
13
|
-
client?: Partial<ClientProps>;
|
|
14
12
|
}
|
|
15
|
-
export type { ClientProps, CustomField } from './client.js';
|
|
16
13
|
export type SecurityEntry = SecuritySchemeObject & {
|
|
17
14
|
scopes: string[];
|
|
18
15
|
id: string;
|
|
19
16
|
};
|
|
20
|
-
export declare function APIPlayground({ path, method, ctx
|
|
17
|
+
export declare function APIPlayground({ path, method, ctx }: APIPlaygroundProps): Promise<string | number | bigint | boolean | Iterable<import("react").ReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined>;
|
|
21
18
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/playground/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,oBAAoB,EACrB,MAAM,SAAS,CAAC;AACjB,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/playground/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,oBAAoB,EACrB,MAAM,SAAS,CAAC;AACjB,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,gBAAgB,CAAC;AAIxB,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,eAAe,CAAC,GAAG;IAC1D,MAAM,EAAE,YAAY,CAAC;IACrB,EAAE,EAAE,QAAQ,GAAG,QAAQ,GAAG,OAAO,GAAG,MAAM,CAAC;CAC5C,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,YAAY,CAAC;AAQzC,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;CACpB;AAED,MAAM,MAAM,aAAa,GAAG,oBAAoB,GAAG;IACjD,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,EAAE,EAAE,MAAM,CAAC;CACZ,CAAC;AAEF,wBAAsB,aAAa,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,EAAE,kBAAkB,kJAqC5E"}
|
package/dist/playground/index.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { getPreferredType, } from '../utils/schema.js';
|
|
3
|
-
import { ClientLazy } from '
|
|
4
|
-
export async function APIPlayground({ path, method, ctx
|
|
3
|
+
import { ClientLazy } from './lazy.js';
|
|
4
|
+
export async function APIPlayground({ path, method, ctx }) {
|
|
5
|
+
if (ctx.playground?.render) {
|
|
6
|
+
return ctx.playground.render({ path, method, ctx });
|
|
7
|
+
}
|
|
5
8
|
let currentId = 0;
|
|
6
9
|
const bodyContent = method.requestBody?.content;
|
|
7
10
|
const mediaType = bodyContent ? getPreferredType(bodyContent) : undefined;
|
|
@@ -25,7 +28,6 @@ export async function APIPlayground({ path, method, ctx, client, }) {
|
|
|
25
28
|
: undefined,
|
|
26
29
|
references: context.references,
|
|
27
30
|
proxyUrl: ctx.proxyUrl,
|
|
28
|
-
...client,
|
|
29
31
|
};
|
|
30
32
|
return _jsx(ClientLazy, { ...props });
|
|
31
33
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lazy.d.ts","sourceRoot":"","sources":["../../src/playground/lazy.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,UAAU,mCAAqC,CAAC"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const defaultSamples:
|
|
1
|
+
import type { CodeUsageGenerator } from '../../ui/operation/example-panel/index.js';
|
|
2
|
+
export declare const defaultSamples: CodeUsageGenerator[];
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/requests/generators/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/requests/generators/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,eAAO,MAAM,cAAc,EAAE,kBAAkB,EAqC9C,CAAC"}
|
|
@@ -6,31 +6,37 @@ import * as Java from './java.js';
|
|
|
6
6
|
import * as CSharp from './csharp.js';
|
|
7
7
|
export const defaultSamples = [
|
|
8
8
|
{
|
|
9
|
+
id: 'curl',
|
|
9
10
|
label: 'cURL',
|
|
10
11
|
source: CURL.generator,
|
|
11
12
|
lang: 'bash',
|
|
12
13
|
},
|
|
13
14
|
{
|
|
15
|
+
id: 'js',
|
|
14
16
|
label: 'JavaScript',
|
|
15
17
|
source: JS.generator,
|
|
16
18
|
lang: 'js',
|
|
17
19
|
},
|
|
18
20
|
{
|
|
21
|
+
id: 'go',
|
|
19
22
|
label: 'Go',
|
|
20
23
|
source: Go.generator,
|
|
21
24
|
lang: 'go',
|
|
22
25
|
},
|
|
23
26
|
{
|
|
27
|
+
id: 'python',
|
|
24
28
|
label: 'Python',
|
|
25
29
|
source: Python.generator,
|
|
26
30
|
lang: 'python',
|
|
27
31
|
},
|
|
28
32
|
{
|
|
33
|
+
id: 'java',
|
|
29
34
|
label: 'Java',
|
|
30
35
|
source: Java.generator,
|
|
31
36
|
lang: 'java',
|
|
32
37
|
},
|
|
33
38
|
{
|
|
39
|
+
id: 'csharp',
|
|
34
40
|
label: 'C#',
|
|
35
41
|
source: CSharp.generator,
|
|
36
42
|
lang: 'csharp',
|