fumadocs-openapi 6.3.0 → 7.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/playground/client.d.ts +11 -11
- package/dist/playground/client.d.ts.map +1 -1
- package/dist/playground/client.js +124 -119
- package/dist/playground/fetcher.d.ts +6 -22
- package/dist/playground/fetcher.d.ts.map +1 -1
- package/dist/playground/fetcher.js +44 -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 +3 -2
- package/dist/playground/index.d.ts.map +1 -1
- package/dist/playground/index.js +6 -11
- 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/scalar/client.js +1 -1
- 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/generate-document.js +1 -1
- 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 +9 -9
- 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
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"}
|
package/dist/requests/curl.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare function getSampleRequest(
|
|
1
|
+
import { type RequestData } from '../requests/_shared.js';
|
|
2
|
+
export declare function getSampleRequest(url: string, data: RequestData): string;
|
|
3
3
|
//# sourceMappingURL=curl.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../src/requests/curl.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../src/requests/curl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE9D,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,CAqCvE"}
|
package/dist/requests/curl.js
CHANGED
|
@@ -1,28 +1,27 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import { inputToString } from '../utils/input-to-string.js';
|
|
2
|
-
|
|
3
|
+
import { getUrl } from '../requests/_shared.js';
|
|
4
|
+
export function getSampleRequest(url, data) {
|
|
3
5
|
const s = [];
|
|
4
|
-
s.push(`curl -X ${
|
|
5
|
-
for (const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
s.push(`--cookie ${cookie}`);
|
|
13
|
-
}
|
|
6
|
+
s.push(`curl -X ${data.method} "${getUrl(url, data)}"`);
|
|
7
|
+
for (const header in data.header) {
|
|
8
|
+
const value = `${header}: ${data.header[header]}`;
|
|
9
|
+
s.push(`-H "${value}"`);
|
|
10
|
+
}
|
|
11
|
+
for (const cookie in data.cookie) {
|
|
12
|
+
const value = JSON.stringify(`${cookie}=${data.cookie[cookie]}`);
|
|
13
|
+
s.push(`--cookie ${value}`);
|
|
14
14
|
}
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
for (const [key, value] of Object.entries(sample)) {
|
|
15
|
+
if (data.bodyMediaType === 'multipart/form-data') {
|
|
16
|
+
if (data.body && typeof data.body === 'object') {
|
|
17
|
+
for (const [key, value] of Object.entries(data.body)) {
|
|
19
18
|
s.push(`-F ${key}=${inputToString(value)}`);
|
|
20
19
|
}
|
|
21
20
|
}
|
|
22
21
|
}
|
|
23
|
-
else if (
|
|
24
|
-
s.push(`-H "Content-Type: ${
|
|
25
|
-
s.push(`-d ${inputToString(
|
|
22
|
+
else if (data.body) {
|
|
23
|
+
s.push(`-H "Content-Type: ${data.bodyMediaType}"`);
|
|
24
|
+
s.push(`-d ${inputToString(data.body, data.bodyMediaType, 'single-quote')}`);
|
|
26
25
|
}
|
|
27
26
|
return s
|
|
28
27
|
.flatMap((v, i) => v
|
package/dist/requests/go.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare function getSampleRequest(
|
|
1
|
+
import { type RequestData } from '../requests/_shared.js';
|
|
2
|
+
export declare function getSampleRequest(url: string, data: RequestData): string;
|
|
3
3
|
//# sourceMappingURL=go.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"go.d.ts","sourceRoot":"","sources":["../../src/requests/go.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"go.d.ts","sourceRoot":"","sources":["../../src/requests/go.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE9D,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,CAwEvE"}
|
package/dist/requests/go.js
CHANGED
|
@@ -1,32 +1,33 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import { inputToString } from '../utils/input-to-string.js';
|
|
2
|
-
|
|
3
|
+
import { getUrl } from '../requests/_shared.js';
|
|
4
|
+
export function getSampleRequest(url, data) {
|
|
3
5
|
const imports = ['fmt', 'net/http', 'io/ioutil'];
|
|
4
6
|
const headers = new Map();
|
|
5
7
|
const variables = new Map();
|
|
8
|
+
variables.set('url', JSON.stringify(getUrl(url, data)));
|
|
6
9
|
// additional lines before initializing request
|
|
7
10
|
const additional = [];
|
|
8
|
-
for (const
|
|
9
|
-
|
|
10
|
-
headers.set(p.name, JSON.stringify(p.sample));
|
|
11
|
+
for (const header in data.header) {
|
|
12
|
+
headers.set(header, JSON.stringify(data.header[header]));
|
|
11
13
|
}
|
|
12
|
-
const cookies =
|
|
13
|
-
variables.set('url', JSON.stringify(endpoint.url));
|
|
14
|
+
const cookies = Object.keys(data.cookie);
|
|
14
15
|
if (cookies.length > 0)
|
|
15
|
-
headers.set('Cookie', JSON.stringify(cookies.map((p) => `${p
|
|
16
|
-
if (
|
|
17
|
-
headers.set('Content-Type', `"${
|
|
18
|
-
if (
|
|
19
|
-
typeof
|
|
16
|
+
headers.set('Cookie', JSON.stringify(cookies.map((p) => `${p}=${data.cookie[p]}`).join('; ')));
|
|
17
|
+
if (data.body) {
|
|
18
|
+
headers.set('Content-Type', `"${data.bodyMediaType}"`);
|
|
19
|
+
if (data.bodyMediaType === 'multipart/form-data' &&
|
|
20
|
+
typeof data.body === 'object') {
|
|
20
21
|
imports.push('mime/multipart', 'bytes');
|
|
21
22
|
variables.set('payload', `new(bytes.Buffer)`);
|
|
22
23
|
variables.set('mp', 'multipart.NewWriter(payload)');
|
|
23
|
-
for (const [key, value] of Object.entries(
|
|
24
|
+
for (const [key, value] of Object.entries(data.body)) {
|
|
24
25
|
additional.push(`mp.WriteField("${key}", ${inputToString(value, undefined, 'backtick')})`);
|
|
25
26
|
}
|
|
26
27
|
}
|
|
27
28
|
else {
|
|
28
29
|
imports.push('strings');
|
|
29
|
-
variables.set('payload', `strings.NewReader(${inputToString(
|
|
30
|
+
variables.set('payload', `strings.NewReader(${inputToString(data.body, data.bodyMediaType, 'backtick').replaceAll('\n', '\n ')})`);
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
return `package main
|
|
@@ -40,7 +41,7 @@ ${Array.from(variables.entries())
|
|
|
40
41
|
.map(([k, v]) => ` ${k} := ${v}`)
|
|
41
42
|
.join('\n')}
|
|
42
43
|
${additional.join('\n ')}
|
|
43
|
-
req, _ := http.NewRequest("${
|
|
44
|
+
req, _ := http.NewRequest("${data.method}", url, ${variables.has('payload') ? 'payload' : 'nil'})
|
|
44
45
|
${Array.from(headers.entries())
|
|
45
46
|
.map(([key, value]) => `req.Header.Add("${key}", ${value})`)
|
|
46
47
|
.join('\n ')}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/requests/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAMrD,eAAO,MAAM,cAAc,EAAE,UAAU,EAqBtC,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as CURL from '../requests/curl.js';
|
|
2
|
+
import * as JS from '../requests/javascript.js';
|
|
3
|
+
import * as Go from '../requests/go.js';
|
|
4
|
+
import * as Python from '../requests/python.js';
|
|
5
|
+
export const defaultSamples = [
|
|
6
|
+
{
|
|
7
|
+
label: 'cURL',
|
|
8
|
+
source: CURL.getSampleRequest,
|
|
9
|
+
lang: 'bash',
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
label: 'JavaScript',
|
|
13
|
+
source: JS.getSampleRequest,
|
|
14
|
+
lang: 'js',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
label: 'Go',
|
|
18
|
+
source: Go.getSampleRequest,
|
|
19
|
+
lang: 'go',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
label: 'Python',
|
|
23
|
+
source: Python.getSampleRequest,
|
|
24
|
+
lang: 'python',
|
|
25
|
+
},
|
|
26
|
+
];
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare function getSampleRequest(
|
|
1
|
+
import { type RequestData } from '../requests/_shared.js';
|
|
2
|
+
export declare function getSampleRequest(url: string, data: RequestData): string;
|
|
3
3
|
//# sourceMappingURL=javascript.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"javascript.d.ts","sourceRoot":"","sources":["../../src/requests/javascript.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"javascript.d.ts","sourceRoot":"","sources":["../../src/requests/javascript.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE9D,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,CAmDvE"}
|
|
@@ -1,49 +1,42 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import { inputToString } from '../utils/input-to-string.js';
|
|
2
|
-
|
|
3
|
+
import { getUrl } from '../requests/_shared.js';
|
|
4
|
+
export function getSampleRequest(url, data) {
|
|
3
5
|
const s = [];
|
|
4
6
|
const options = new Map();
|
|
5
|
-
const headers =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
if (param.in === 'header') {
|
|
9
|
-
headers.set(param.name, param.sample);
|
|
10
|
-
}
|
|
11
|
-
if (param.in === 'cookie') {
|
|
12
|
-
cookies.set(param.name, param.sample);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
if (cookies.size > 0) {
|
|
16
|
-
headers.set('cookie', Array.from(cookies.entries())
|
|
7
|
+
const headers = { ...data.header };
|
|
8
|
+
if (Object.keys(data.cookie).length > 0) {
|
|
9
|
+
headers['cookie'] = Object.entries(data.cookie)
|
|
17
10
|
.map(([key, value]) => `${key}=${value}`)
|
|
18
|
-
.join('; ')
|
|
11
|
+
.join('; ');
|
|
19
12
|
}
|
|
20
|
-
if (headers.
|
|
21
|
-
options.set('headers', JSON.stringify(
|
|
13
|
+
if (Object.keys(headers).length > 0) {
|
|
14
|
+
options.set('headers', JSON.stringify(headers, null, 2).replaceAll('\n', '\n '));
|
|
22
15
|
}
|
|
23
|
-
if (
|
|
24
|
-
typeof
|
|
25
|
-
|
|
16
|
+
if (data.bodyMediaType === 'multipart/form-data' &&
|
|
17
|
+
typeof data.body === 'object' &&
|
|
18
|
+
data.body) {
|
|
26
19
|
s.push(`const formData = new FormData();`);
|
|
27
|
-
for (const [key, value] of Object.entries(
|
|
20
|
+
for (const [key, value] of Object.entries(data.body))
|
|
28
21
|
s.push(`formData.set(${key}, ${inputToString(value)})`);
|
|
29
22
|
options.set('body', 'formData');
|
|
30
23
|
}
|
|
31
|
-
else if (
|
|
24
|
+
else if (data.body) {
|
|
32
25
|
let code;
|
|
33
|
-
if (
|
|
26
|
+
if (data.bodyMediaType === 'application/json') {
|
|
34
27
|
code =
|
|
35
|
-
typeof
|
|
36
|
-
? inputToString(
|
|
37
|
-
: `JSON.stringify(${JSON.stringify(
|
|
28
|
+
typeof data.body === 'string'
|
|
29
|
+
? inputToString(data.body, data.bodyMediaType, 'backtick')
|
|
30
|
+
: `JSON.stringify(${JSON.stringify(data.body, null, 2)})`;
|
|
38
31
|
}
|
|
39
32
|
else {
|
|
40
|
-
code = inputToString(
|
|
33
|
+
code = inputToString(data.body, data.bodyMediaType, 'backtick');
|
|
41
34
|
}
|
|
42
35
|
options.set('body', code.replaceAll('\n', '\n '));
|
|
43
36
|
}
|
|
44
37
|
const optionsStr = Array.from(options.entries())
|
|
45
38
|
.map(([k, v]) => ` ${k}: ${v}`)
|
|
46
39
|
.join(',\n');
|
|
47
|
-
s.push(`fetch(${JSON.stringify(
|
|
40
|
+
s.push(`fetch(${JSON.stringify(getUrl(url, data))}, {\n${optionsStr}\n});`);
|
|
48
41
|
return s.join('\n\n');
|
|
49
42
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare function getSampleRequest(
|
|
1
|
+
import { type RequestData } from '../requests/_shared.js';
|
|
2
|
+
export declare function getSampleRequest(url: string, data: RequestData): string;
|
|
3
3
|
//# sourceMappingURL=python.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../src/requests/python.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"python.d.ts","sourceRoot":"","sources":["../../src/requests/python.ts"],"names":[],"mappings":"AAEA,OAAO,EAAU,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE9D,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,CA8CvE"}
|
package/dist/requests/python.js
CHANGED
|
@@ -1,41 +1,37 @@
|
|
|
1
|
+
'use client';
|
|
1
2
|
import { inputToString } from '../utils/input-to-string.js';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const cookies = new Map();
|
|
3
|
+
import { getUrl } from '../requests/_shared.js';
|
|
4
|
+
export function getSampleRequest(url, data) {
|
|
5
5
|
const variables = new Map();
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (param.in === 'cookie')
|
|
10
|
-
cookies.set(param.name, param.sample);
|
|
11
|
-
}
|
|
12
|
-
if (endpoint.body) {
|
|
13
|
-
switch (endpoint.body.mediaType) {
|
|
6
|
+
const headers = { ...data.header };
|
|
7
|
+
if (data.body) {
|
|
8
|
+
switch (data.bodyMediaType) {
|
|
14
9
|
case 'application/json':
|
|
15
|
-
variables.set('json', JSON.stringify(
|
|
10
|
+
variables.set('json', JSON.stringify(data.body, null, 2));
|
|
16
11
|
break;
|
|
17
12
|
case 'multipart/form-data':
|
|
18
|
-
headers
|
|
19
|
-
variables.set('data', JSON.stringify(
|
|
13
|
+
headers['Content-Type'] = data.bodyMediaType;
|
|
14
|
+
variables.set('data', JSON.stringify(data.body, null, 2));
|
|
20
15
|
break;
|
|
21
16
|
default:
|
|
22
|
-
|
|
23
|
-
|
|
17
|
+
if (data.bodyMediaType)
|
|
18
|
+
headers['Content-Type'] = data.bodyMediaType;
|
|
19
|
+
variables.set('data', inputToString(data.body, data.bodyMediaType, 'python'));
|
|
24
20
|
}
|
|
25
21
|
}
|
|
26
|
-
if (headers.
|
|
27
|
-
variables.set('headers', JSON.stringify(
|
|
22
|
+
if (Object.keys(headers).length > 0) {
|
|
23
|
+
variables.set('headers', JSON.stringify(headers, null, 2));
|
|
28
24
|
}
|
|
29
|
-
if (
|
|
30
|
-
variables.set('cookies', JSON.stringify(
|
|
25
|
+
if (Object.keys(data.cookie).length > 0) {
|
|
26
|
+
variables.set('cookies', JSON.stringify(data.cookie, null, 2));
|
|
31
27
|
}
|
|
32
28
|
return `import requests
|
|
33
29
|
|
|
34
|
-
url = ${JSON.stringify(
|
|
30
|
+
url = ${JSON.stringify(getUrl(url, data))}
|
|
35
31
|
${Array.from(variables.entries())
|
|
36
32
|
.map(([k, v]) => `${k} = ${v}`)
|
|
37
33
|
.join('\n')}
|
|
38
|
-
response = requests.request("${
|
|
34
|
+
response = requests.request("${data.method}", url${variables.size > 0
|
|
39
35
|
? `, ${Array.from(variables.keys())
|
|
40
36
|
.map((k) => `${k}=${k}`)
|
|
41
37
|
.join(', ')}`
|
package/dist/scalar/client.js
CHANGED
|
@@ -13,7 +13,7 @@ export default function ScalarPlayground({ path, method, spec, }) {
|
|
|
13
13
|
setMounted(true);
|
|
14
14
|
}, []);
|
|
15
15
|
return (_jsxs("div", { 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), children: [_jsx(MethodLabel, { className: "text-xs", children: method }), _jsx("code", { className: "flex-1 overflow-auto text-nowrap text-[13px] text-fd-muted-foreground", children: path }), _jsx(ApiClientModalProvider, { configuration: {
|
|
16
|
-
|
|
16
|
+
theme: 'moon',
|
|
17
17
|
spec: {
|
|
18
18
|
content: spec,
|
|
19
19
|
},
|
package/dist/server/api-page.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import Slugger from 'github-slugger';
|
|
3
|
-
import { Operation } from '../render/operation.js';
|
|
3
|
+
import { Operation } from '../render/operation/index.js';
|
|
4
4
|
import { createMethod } from '../server/create-method.js';
|
|
5
5
|
import { createRenders } from '../render/renderer.js';
|
|
6
6
|
import { processDocument, } from '../utils/process-document.js';
|
package/dist/types.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { OpenAPIV3_1 as V3_1 } from 'openapi-types';
|
|
2
2
|
import type { default as Slugger } from 'github-slugger';
|
|
3
3
|
import { type Renderer } from './render/renderer.js';
|
|
4
|
-
import type {
|
|
5
|
-
import type { CodeSample } from './render/operation.js';
|
|
4
|
+
import type { CodeSample } from './render/operation/index.js';
|
|
6
5
|
import type { BuiltinTheme, CodeOptionsThemes, CodeToHastOptionsCommon } from 'shiki';
|
|
7
6
|
import type { NoReference } from './utils/schema.js';
|
|
8
7
|
import type { ProcessedDocument } from './utils/process-document.js';
|
|
@@ -46,14 +45,14 @@ export interface RenderContext {
|
|
|
46
45
|
*
|
|
47
46
|
* Pass `false` to disable it.
|
|
48
47
|
*
|
|
49
|
-
* @param
|
|
50
|
-
* @param
|
|
48
|
+
* @param method - the operation object
|
|
49
|
+
* @param statusCode - status code
|
|
51
50
|
*/
|
|
52
|
-
generateTypeScriptSchema?: ((
|
|
51
|
+
generateTypeScriptSchema?: ((method: NoReference<MethodInformation>, statusCode: string) => Awaitable<string>) | false;
|
|
53
52
|
/**
|
|
54
53
|
* Generate code samples for endpoint.
|
|
55
54
|
*/
|
|
56
|
-
generateCodeSamples?: (
|
|
55
|
+
generateCodeSamples?: (method: NoReference<MethodInformation>) => Awaitable<CodeSample[]>;
|
|
57
56
|
shikiOptions?: Omit<CodeToHastOptionsCommon, 'lang'> & CodeOptionsThemes<BuiltinTheme>;
|
|
58
57
|
/**
|
|
59
58
|
* Show full response schema instead of only example response & Typescript definitions
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EACV,YAAY,EACZ,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAElE,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;AACrC,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;AACnD,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;AACnD,MAAM,MAAM,yBAAyB,GAAG,IAAI,CAAC,yBAAyB,CAAC;AACvE,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,CAAC;AAC7D,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;AACnD,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;AACjD,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;AACvC,MAAM,MAAM,YAAY,GAAG,WAAW,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;AAC1D,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;AAE9D,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,eAAe,CAAC,GAAG;IAC7D,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AAEnC;;GAEG;AACH,MAAM,MAAM,cAAc,GAAG,GAAG,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAElD,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,QAAQ,EAAE,QAAQ,CAAC;IAEnB;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAE5B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,YAAY,EAAE,CAAC;IAExB,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,MAAM,EAAE,iBAAiB,CAAC;IAE1B;;;;;;;OAOG;IACH,wBAAwB,CAAC,EACrB,CAAC,CACC,MAAM,EAAE,WAAW,CAAC,iBAAiB,CAAC,EACtC,UAAU,EAAE,MAAM,KACf,SAAS,CAAC,MAAM,CAAC,CAAC,GACvB,KAAK,CAAC;IAEV;;OAEG;IACH,mBAAmB,CAAC,EAAE,CACpB,MAAM,EAAE,WAAW,CAAC,iBAAiB,CAAC,KACnC,SAAS,CAAC,UAAU,EAAE,CAAC,CAAC;IAE7B,YAAY,CAAC,EAAE,IAAI,CAAC,uBAAuB,EAAE,MAAM,CAAC,GAClD,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAElC;;OAEG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B"}
|
package/dist/ui/client.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
export declare const Sample: import("react").ComponentType<import("../render/renderer.js").SampleProps>;
|
|
1
|
+
export { ClientLazy as APIPlayground } from '../playground/client.lazy.js';
|
|
3
2
|
//# sourceMappingURL=client.d.ts.map
|
package/dist/ui/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/ui/client.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/ui/client.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,IAAI,aAAa,EAAE,MAAM,0BAA0B,CAAC"}
|
package/dist/ui/client.js
CHANGED
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
|
|
3
|
-
export const Samples = dynamic(() => import('./sample-select.js').then((mod) => mod.Samples));
|
|
4
|
-
export const Sample = dynamic(() => import('./sample-select.js').then((mod) => mod.Sample));
|
|
2
|
+
export { ClientLazy as APIPlayground } from '../playground/client.lazy.js';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type VariantProps } from 'class-variance-authority';
|
|
2
2
|
import type { HTMLAttributes } from 'react';
|
|
3
3
|
export declare const badgeVariants: (props?: ({
|
|
4
|
-
color?: "
|
|
4
|
+
color?: "green" | "yellow" | "red" | "blue" | "orange" | null | undefined;
|
|
5
5
|
} & import("class-variance-authority/types").ClassProp) | undefined) => string;
|
|
6
6
|
export declare function Badge({ className, color, ...props }: Omit<HTMLAttributes<HTMLSpanElement>, 'color'> & VariantProps<typeof badgeVariants>): import("react/jsx-runtime").JSX.Element;
|
|
7
7
|
export declare function MethodLabel({ children, ...props }: Omit<HTMLAttributes<HTMLSpanElement>, 'children'> & {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type ReactNode
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
2
|
import type { RenderContext, ServerObject } from '../../types.js';
|
|
3
3
|
export interface ApiProviderProps {
|
|
4
4
|
/**
|
|
@@ -9,13 +9,11 @@ export interface ApiProviderProps {
|
|
|
9
9
|
shikiOptions: RenderContext['shikiOptions'];
|
|
10
10
|
children?: ReactNode;
|
|
11
11
|
}
|
|
12
|
-
interface SelectedServer {
|
|
12
|
+
export interface SelectedServer {
|
|
13
13
|
url: string;
|
|
14
14
|
variables: Record<string, string>;
|
|
15
15
|
}
|
|
16
|
-
|
|
17
|
-
serverRef: RefObject<SelectedServer | null>;
|
|
18
|
-
}
|
|
16
|
+
type ApiContextType = Omit<ApiProviderProps, 'children' | 'defaultBaseUrl'>;
|
|
19
17
|
interface ServerSelectType {
|
|
20
18
|
server: SelectedServer | null;
|
|
21
19
|
setServer: (value: string) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/api.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/api.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,SAAS,EAKf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE3D,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IAE5C,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,KAAK,cAAc,GAAG,IAAI,CAAC,gBAAgB,EAAE,UAAU,GAAG,gBAAgB,CAAC,CAAC;AAE5E,UAAU,gBAAgB;IACxB,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CAC7D;AAOD,wBAAgB,aAAa,IAAI,cAAc,CAK9C;AAED,wBAAgB,sBAAsB,IAAI,gBAAgB,CAKzD;AAED,wBAAgB,WAAW,CAAC,EAC1B,cAAc,EACd,QAAQ,EACR,GAAG,KAAK,EACT,EAAE,gBAAgB,2CA+DlB"}
|
package/dist/ui/contexts/api.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createContext, useContext, useEffect, useMemo,
|
|
3
|
+
import { createContext, useContext, useEffect, useMemo, useState, } from 'react';
|
|
4
4
|
const ApiContext = createContext(undefined);
|
|
5
5
|
const ServerSelectContext = createContext(undefined);
|
|
6
6
|
export function useApiContext() {
|
|
@@ -27,8 +27,6 @@ export function ApiProvider({ defaultBaseUrl, children, ...props }) {
|
|
|
27
27
|
}
|
|
28
28
|
: null;
|
|
29
29
|
});
|
|
30
|
-
const serverRef = useRef(server);
|
|
31
|
-
serverRef.current = server;
|
|
32
30
|
useEffect(() => {
|
|
33
31
|
const cached = localStorage.getItem('apiBaseUrl');
|
|
34
32
|
if (!cached)
|
|
@@ -43,10 +41,7 @@ export function ApiProvider({ defaultBaseUrl, children, ...props }) {
|
|
|
43
41
|
// ignore
|
|
44
42
|
}
|
|
45
43
|
}, []);
|
|
46
|
-
return (_jsx(ApiContext.Provider, { value: useMemo(() => ({
|
|
47
|
-
...props,
|
|
48
|
-
serverRef,
|
|
49
|
-
}), [props]), children: _jsx(ServerSelectContext.Provider, { value: useMemo(() => ({
|
|
44
|
+
return (_jsx(ApiContext.Provider, { value: props, children: _jsx(ServerSelectContext.Provider, { value: useMemo(() => ({
|
|
50
45
|
server,
|
|
51
46
|
setServerVariables(variables) {
|
|
52
47
|
setServer((prev) => {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { CodeSample } from '../../render/operation/index.js';
|
|
2
|
+
import type { SamplesProps } from '../../render/renderer.js';
|
|
3
|
+
import type { RequestData } from '../../requests/_shared.js';
|
|
4
|
+
export declare function CodeExampleProvider({ route, examples, initialKey, children, }: {
|
|
5
|
+
route: string;
|
|
6
|
+
examples: {
|
|
7
|
+
key: string;
|
|
8
|
+
data: RequestData;
|
|
9
|
+
}[];
|
|
10
|
+
initialKey?: string;
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function CodeExample(props: CodeSample): import("react/jsx-runtime").JSX.Element | null;
|
|
14
|
+
export declare function CodeExampleSelector({ items }: SamplesProps): import("react/jsx-runtime").JSX.Element;
|
|
15
|
+
export declare function useRequestData(): {
|
|
16
|
+
/**
|
|
17
|
+
* initial request data
|
|
18
|
+
*/
|
|
19
|
+
data: RequestData;
|
|
20
|
+
/**
|
|
21
|
+
* Save changes to request data, it won't trigger re-render on the component itself, which makes it safe to call in an effect with `data` as dep
|
|
22
|
+
*/
|
|
23
|
+
saveData: (data: RequestData) => void;
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=code-example.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code-example.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/code-example.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAUtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAqBtD,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,WAAW,CAAC;KACnB,EAAE,CAAC;IACJ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,2CAqDA;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,kDAsC5C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,EAAE,YAAY,2CAoB1D;AAgBD,wBAAgB,cAAc;IAaxB;;OAEG;;IAEH;;OAEG;qBAZgC,WAAW;EAiBnD"}
|