fumadocs-openapi 12.6.9 → 12.6.11
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/css/generated/shared.css +1 -1
- package/dist/_virtual/_rolldown/runtime.js +8 -6
- package/dist/generate-file.js +9 -25
- package/dist/i18n.d.ts +1 -1
- package/dist/index.browser.d.ts +1 -1
- package/dist/index.browser.js +1 -1
- package/dist/operation.d.ts +1 -1
- package/dist/operation.js +16 -9
- package/dist/packages/shared-api/dist/auto-anchor/index.js +1 -1
- package/dist/packages/shared-api/dist/components/badge.js +1 -1
- package/dist/packages/shared-api/dist/components/collapsible.js +1 -1
- package/dist/packages/shared-api/dist/components/copy-typescript.js +3 -3
- package/dist/packages/shared-api/dist/components/defaults.d.ts +1 -1
- package/dist/packages/shared-api/dist/components/defaults.js +1 -1
- package/dist/packages/shared-api/dist/components/dialog.js +4 -4
- package/dist/packages/shared-api/dist/components/example.js +4 -4
- package/dist/packages/shared-api/dist/components/playground/fields.js +11 -11
- package/dist/packages/shared-api/dist/components/playground/json-editor.js +1 -1
- package/dist/packages/shared-api/dist/components/playground/panels.js +6 -6
- package/dist/packages/shared-api/dist/components/playground/param-input.js +1 -1
- package/dist/packages/shared-api/dist/components/playground/result.js +3 -3
- package/dist/packages/shared-api/dist/components/playground/schema.js +1 -1
- package/dist/packages/shared-api/dist/components/playground/server-select.js +5 -5
- package/dist/packages/shared-api/dist/components/schema/client.js +11 -6
- package/dist/packages/shared-api/dist/components/schema/index.js +2 -2
- package/dist/packages/shared-api/dist/components/segmented.js +1 -1
- package/dist/packages/shared-api/dist/components/select-tab.js +1 -1
- package/dist/packages/shared-api/dist/components/select.js +3 -3
- package/dist/packages/shared-api/dist/components/spinner.js +1 -1
- package/dist/packages/shared-api/dist/source.js +40 -24
- package/dist/packages/shared-api/dist/utils/use-server-store.js +1 -1
- package/dist/playground/auth.d.ts +4 -3
- package/dist/playground/auth.js +65 -49
- package/dist/playground/fetcher.js +1 -1
- package/dist/playground/use-playground.d.ts +2 -2
- package/dist/playground/use-playground.js +3 -3
- package/dist/press.d.ts +2 -2
- package/dist/requests/generators/csharp.js +2 -1
- package/dist/requests/generators/curl.js +3 -2
- package/dist/requests/generators/index.js +1 -1
- package/dist/requests/media/adapter.d.ts +2 -0
- package/dist/requests/media/adapter.js +6 -4
- package/dist/requests/media/encode.js +4 -11
- package/dist/requests/string-utils.js +3 -3
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.js +37 -32
- package/dist/ui/base.d.ts +1 -1
- package/dist/ui/components/schema.js +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +1 -1
- package/dist/ui/operation/index.js +9 -8
- package/dist/ui/operation/usage-tabs.js +4 -4
- package/dist/ui/playground/client.d.ts +2 -2
- package/dist/ui/playground/client.js +7 -7
- package/dist/ui/playground/components/auth.js +6 -6
- package/dist/ui/playground/components/request-panel.d.ts +2 -2
- package/dist/ui/playground/components/request-panel.js +4 -4
- package/dist/ui/playground/components/response-panel.js +3 -3
- package/dist/ui/playground/components/result-display.d.ts +1 -1
- package/dist/ui/playground/components/result-display.js +3 -3
- package/dist/ui/playground/components/server-select.js +1 -1
- package/dist/ui/scalar/client.js +5 -5
- package/dist/utils/create-page.d.ts +3 -3
- package/dist/utils/create-page.js +3 -3
- package/dist/utils/get-example-requests.js +5 -5
- package/dist/utils/pages/builder.js +1 -1
- package/dist/utils/pages/preset-auto.js +3 -3
- package/dist/utils/pages/to-static-data.d.ts +1 -1
- package/dist/utils/pages/to-static-data.js +14 -12
- package/dist/utils/pages/to-text.js +1 -1
- package/dist/utils/schema.js +6 -3
- package/dist/utils/use-server.d.ts +1 -1
- package/dist/utils/use-server.js +1 -1
- package/package.json +13 -13
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cn } from "../utils/cn.js";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
2
|
import { Loader2Icon } from "lucide-react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
4
|
// ../shared-api/dist/components/spinner.js
|
|
5
5
|
function Spinner({ className, ...props }) {
|
|
6
6
|
return /* @__PURE__ */ jsx(Loader2Icon, {
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import * as path from "node:path";
|
|
2
2
|
import { PathUtils } from "fumadocs-core/source";
|
|
3
3
|
// ../shared-api/dist/source.js
|
|
4
|
-
/** convert output entries into
|
|
5
|
-
function toVirtualFiles(entries, { baseDir = ""
|
|
6
|
-
const { folderStyle = "folder" } = typeof meta === "object" ? meta : {};
|
|
4
|
+
/** convert output entries into pages for `loader()` */
|
|
5
|
+
function toVirtualFiles(entries, { baseDir = "" }, toPage) {
|
|
7
6
|
const files = [];
|
|
8
|
-
function scan(entries
|
|
7
|
+
function scan(entries) {
|
|
9
8
|
for (const entry of entries) {
|
|
10
9
|
if (entry.type === "group") {
|
|
11
|
-
scan(entry.entries
|
|
10
|
+
scan(entry.entries);
|
|
12
11
|
continue;
|
|
13
12
|
}
|
|
14
13
|
files.push({
|
|
@@ -18,32 +17,49 @@ function toVirtualFiles(entries, { baseDir = "", meta = false }, toPage) {
|
|
|
18
17
|
locale: "$"
|
|
19
18
|
});
|
|
20
19
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
}
|
|
21
|
+
scan(entries);
|
|
22
|
+
return files;
|
|
23
|
+
}
|
|
24
|
+
/** the `meta.json` of each folder, from the output entries of each schema */
|
|
25
|
+
function toMetaFiles(schemas, { baseDir = "", meta = false }) {
|
|
26
|
+
if (!meta) return [];
|
|
27
|
+
const { folderStyle = "folder" } = typeof meta === "object" ? meta : {};
|
|
28
|
+
const folders = /* @__PURE__ */ new Map();
|
|
29
|
+
function scan(entries, group) {
|
|
30
|
+
const dir = group?.path ?? "";
|
|
31
|
+
let folder = folders.get(dir);
|
|
32
|
+
if (!folder) folders.set(dir, folder = {
|
|
33
|
+
group,
|
|
34
|
+
entries: /* @__PURE__ */ new Map()
|
|
35
|
+
});
|
|
36
|
+
for (const entry of entries) {
|
|
37
|
+
if (!folder.entries.has(entry.path)) folder.entries.set(entry.path, entry);
|
|
38
|
+
if (entry.type === "group") scan(entry.entries, entry);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
for (const entries of schemas) scan(entries);
|
|
42
|
+
const files = [];
|
|
43
|
+
for (const [dir, { group, entries }] of folders) {
|
|
44
|
+
const pages = [];
|
|
45
|
+
for (const entry of entries.values()) {
|
|
46
|
+
const relativePath = PathUtils.slash(dir ? path.relative(dir, entry.path) : entry.path);
|
|
47
|
+
if (entry.type !== "group") pages.push(relativePath.slice(0, -path.extname(entry.path).length));
|
|
48
|
+
else if (folderStyle === "folder") pages.push(relativePath);
|
|
49
|
+
else pages.push(`---${entry.info.title}---`, `...${relativePath}`);
|
|
50
|
+
}
|
|
51
|
+
if (pages.length === 0) continue;
|
|
24
52
|
files.push({
|
|
25
53
|
type: "meta",
|
|
26
|
-
path: path.join(baseDir,
|
|
54
|
+
path: path.join(baseDir, dir, "meta.json"),
|
|
27
55
|
data: {
|
|
28
|
-
title:
|
|
29
|
-
description:
|
|
56
|
+
title: group?.info.title,
|
|
57
|
+
description: group?.info.description,
|
|
30
58
|
pages
|
|
31
59
|
},
|
|
32
60
|
locale: "$"
|
|
33
61
|
});
|
|
34
62
|
}
|
|
35
|
-
scan(entries);
|
|
36
63
|
return files;
|
|
37
64
|
}
|
|
38
|
-
|
|
39
|
-
function getMetaPages(entries, parent, folderStyle) {
|
|
40
|
-
const pages = [];
|
|
41
|
-
for (const entry of entries) {
|
|
42
|
-
const relativePath = PathUtils.slash(parent ? path.relative(parent.path, entry.path) : entry.path);
|
|
43
|
-
if (entry.type !== "group") pages.push(relativePath.slice(0, -path.extname(entry.path).length));
|
|
44
|
-
else if (folderStyle === "folder") pages.push(relativePath);
|
|
45
|
-
else pages.push(`---${entry.info.title}---`, `...${relativePath}`);
|
|
46
|
-
}
|
|
47
|
-
return pages;
|
|
48
|
-
}
|
|
49
|
-
export { getMetaPages, toVirtualFiles };
|
|
65
|
+
export { toMetaFiles, toVirtualFiles };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { isPlainObject } from "./is-plain-object.js";
|
|
3
2
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
3
|
+
import { isPlainObject } from "./is-plain-object.js";
|
|
4
4
|
// ../shared-api/dist/utils/use-server-store.js
|
|
5
5
|
/**
|
|
6
6
|
* The selected server of an API page, persisted in `localStorage`.
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { RawRequestData } from "../requests/types.js";
|
|
1
|
+
import "../utils/create-page.js";
|
|
3
2
|
import { FC, ReactNode } from "react";
|
|
4
|
-
import { JsonSchema } from "@fumadocs/json-schema";
|
|
5
3
|
import { DataEngine, FieldKey, Stf } from "@fumari/stf";
|
|
4
|
+
import { JsonSchema } from "@fumadocs/json-schema";
|
|
5
|
+
import { OAuthFlows, OperationObject, SecuritySchemeObject } from "../types.js";
|
|
6
|
+
import { RawRequestData } from "../requests/types.js";
|
|
6
7
|
/** how token requests authenticate the client */
|
|
7
8
|
interface OAuthClient {
|
|
8
9
|
client_id: string;
|
package/dist/playground/auth.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useOpenAPI } from "../utils/create-page.js";
|
|
3
3
|
import { useServer } from "../utils/use-server.js";
|
|
4
|
-
import { useOperation } from "../operation.js";
|
|
5
|
-
import { proxied } from "./fetcher.js";
|
|
6
4
|
import { use, useCallback, useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
7
|
-
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
8
5
|
import { DataEngine, useListener } from "@fumari/stf";
|
|
9
6
|
import { arrayStartsWith, objectGet } from "@fumari/stf/lib/utils";
|
|
7
|
+
import { useOperation } from "../operation.js";
|
|
8
|
+
import { proxied } from "./fetcher.js";
|
|
9
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
10
10
|
// src/playground/auth.tsx
|
|
11
11
|
const pendingFlowKey = "fumadocs-openapi-flow";
|
|
12
12
|
function leavePage(url, flow, redirectUrl) {
|
|
@@ -427,56 +427,72 @@ function getAuthScheme(scheme) {
|
|
|
427
427
|
if (scheme.type !== "http" || !scheme.scheme) return "Bearer";
|
|
428
428
|
return `${scheme.scheme[0].toUpperCase()}${scheme.scheme.slice(1)}`;
|
|
429
429
|
}
|
|
430
|
+
/** the security requirements of an operation, and the one selected first */
|
|
431
|
+
function getRequirements({ dereferenced, resolve }, operation) {
|
|
432
|
+
const requirements = [];
|
|
433
|
+
const schemes = dereferenced.components?.securitySchemes ?? {};
|
|
434
|
+
for (const map of operation?.security ?? dereferenced.security ?? []) {
|
|
435
|
+
const list = [];
|
|
436
|
+
for (const [id, scopes] of Object.entries(map)) {
|
|
437
|
+
const scheme = resolve(schemes[id]);
|
|
438
|
+
if (scheme) list.push({
|
|
439
|
+
id,
|
|
440
|
+
scopes,
|
|
441
|
+
scheme
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
if (list.length > 0) requirements.push(list);
|
|
445
|
+
}
|
|
446
|
+
const idx = requirements.findIndex((req) => req.every((item) => !item.scheme.deprecated));
|
|
447
|
+
return {
|
|
448
|
+
requirements,
|
|
449
|
+
selected: idx === -1 && requirements.length > 0 ? 0 : idx
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
function createAuthFields(requirement, storageKeyPrefix, { providers, transform }) {
|
|
453
|
+
if (!requirement) return [];
|
|
454
|
+
const out = requirement.map((item) => ({
|
|
455
|
+
schemeId: item.id,
|
|
456
|
+
scheme: item.scheme,
|
|
457
|
+
scopes: item.scopes,
|
|
458
|
+
fieldName: ["auth", item.id],
|
|
459
|
+
storageKey: `${storageKeyPrefix}auth-${item.id}`,
|
|
460
|
+
defaultValue: getDefaultValue(item.scheme),
|
|
461
|
+
provider: findProvider(providers, item)
|
|
462
|
+
}));
|
|
463
|
+
return transform ? transform(out) : out;
|
|
464
|
+
}
|
|
465
|
+
/** replace the values with `********`, for code usages */
|
|
466
|
+
function mask(value) {
|
|
467
|
+
if (value === void 0) return value;
|
|
468
|
+
return JSON.parse(JSON.stringify(value), (_, v) => typeof v === "string" && v ? "********" : v);
|
|
469
|
+
}
|
|
470
|
+
/**
|
|
471
|
+
* Encode the default values of the auth fields into request data like code usages, what playgrounds start with.
|
|
472
|
+
*/
|
|
473
|
+
function getDefaultAuth({ doc, storageKeyPrefix }, options) {
|
|
474
|
+
const { requirements, selected } = getRequirements(doc, options.operation);
|
|
475
|
+
const fields = createAuthFields(requirements[selected], storageKeyPrefix, options);
|
|
476
|
+
return (data) => {
|
|
477
|
+
const out = structuredClone(data);
|
|
478
|
+
for (const field of fields) field.provider.onRequest(out, mask(field.defaultValue), field);
|
|
479
|
+
return out;
|
|
480
|
+
};
|
|
481
|
+
}
|
|
430
482
|
/**
|
|
431
483
|
* The auth fields of an API playground: the values it persists, and the request data they encode into.
|
|
432
484
|
*/
|
|
433
485
|
function useAuthFields(engine, { operation, providers, transform } = {}) {
|
|
434
486
|
const page = usePlaygroundAuth().stf.dataEngine;
|
|
435
487
|
const { storageKeyPrefix, doc } = useOpenAPI();
|
|
436
|
-
const {
|
|
437
|
-
const
|
|
438
|
-
const
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
const scheme = resolve(schemes[id]);
|
|
445
|
-
if (scheme) list.push({
|
|
446
|
-
id,
|
|
447
|
-
scopes,
|
|
448
|
-
scheme
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
if (list.length > 0) out.push(list);
|
|
452
|
-
}
|
|
453
|
-
return out;
|
|
454
|
-
}, [
|
|
455
|
-
dereferenced.security,
|
|
456
|
-
operation?.security,
|
|
457
|
-
resolve,
|
|
458
|
-
schemes
|
|
459
|
-
]);
|
|
460
|
-
const [selected, select] = useState(() => {
|
|
461
|
-
if (requirements.length === 0) return -1;
|
|
462
|
-
const idx = requirements.findIndex((req) => req.every((item) => !item.scheme.deprecated));
|
|
463
|
-
return idx !== -1 ? idx : 0;
|
|
464
|
-
});
|
|
465
|
-
const requirement = selected === -1 ? null : requirements[selected];
|
|
466
|
-
const fields = useMemo(() => {
|
|
467
|
-
if (!requirement) return [];
|
|
468
|
-
const out = requirement.map((item) => ({
|
|
469
|
-
schemeId: item.id,
|
|
470
|
-
scheme: item.scheme,
|
|
471
|
-
scopes: item.scopes,
|
|
472
|
-
fieldName: ["auth", item.id],
|
|
473
|
-
storageKey: `${storageKeyPrefix}auth-${item.id}`,
|
|
474
|
-
defaultValue: getDefaultValue(item.scheme),
|
|
475
|
-
provider: findProvider(providers, item)
|
|
476
|
-
}));
|
|
477
|
-
return transform ? transform(out) : out;
|
|
478
|
-
}, [
|
|
479
|
-
requirement,
|
|
488
|
+
const { requirements, selected: initial } = useMemo(() => getRequirements(doc, operation), [doc, operation]);
|
|
489
|
+
const [selected, select] = useState(initial);
|
|
490
|
+
const fields = useMemo(() => createAuthFields(requirements[selected], storageKeyPrefix, {
|
|
491
|
+
providers,
|
|
492
|
+
transform
|
|
493
|
+
}), [
|
|
494
|
+
requirements,
|
|
495
|
+
selected,
|
|
480
496
|
storageKeyPrefix,
|
|
481
497
|
providers,
|
|
482
498
|
transform
|
|
@@ -502,7 +518,7 @@ function useAuthFields(engine, { operation, providers, transform } = {}) {
|
|
|
502
518
|
const auth = page.get(["auth"]) ?? {};
|
|
503
519
|
const cloned = structuredClone({
|
|
504
520
|
...values,
|
|
505
|
-
auth: masked ?
|
|
521
|
+
auth: masked ? mask(auth) : auth
|
|
506
522
|
});
|
|
507
523
|
const data = cloned;
|
|
508
524
|
for (const field of fields) field.provider.onRequest(data, objectGet(data, field.fieldName), field);
|
|
@@ -522,4 +538,4 @@ function useAuthFields(engine, { operation, providers, transform } = {}) {
|
|
|
522
538
|
}, [page, fields])
|
|
523
539
|
};
|
|
524
540
|
}
|
|
525
|
-
export { finishOAuthFlow, requestOAuthToken, useAuthFields, useAuthRedirect, useOpenIdConnectFlows, usePlaygroundAuth };
|
|
541
|
+
export { finishOAuthFlow, getDefaultAuth, requestOAuthToken, useAuthFields, useAuthRedirect, useOpenIdConnectFlows, usePlaygroundAuth };
|
|
@@ -25,7 +25,7 @@ function createBrowserFetcher(adapters, { proxyUrl, proxyForwardCookie = true, r
|
|
|
25
25
|
const param = data.header[key];
|
|
26
26
|
headers.append(key, param.value);
|
|
27
27
|
}
|
|
28
|
-
if (data.bodyMediaType && data.body) {
|
|
28
|
+
if (data.bodyMediaType && data.body !== void 0) {
|
|
29
29
|
const adapter = resolveMediaAdapter(data.bodyMediaType, adapters);
|
|
30
30
|
if (!adapter) return {
|
|
31
31
|
type: "client_error",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
+
import { Stf } from "@fumari/stf";
|
|
2
|
+
import { JsonSchema } from "@fumadocs/json-schema";
|
|
1
3
|
import { AuthField, AuthProvider, AuthRequirement, OAuthFlowInput, OAuthFlowType } from "./auth.js";
|
|
2
4
|
import { BrowserFetcherOptions, FetchResult } from "./fetcher.js";
|
|
3
|
-
import { JsonSchema } from "@fumadocs/json-schema";
|
|
4
|
-
import { Stf } from "@fumari/stf";
|
|
5
5
|
export interface PlaygroundOptions {
|
|
6
6
|
/** handle security schemes, before the built-in providers */
|
|
7
7
|
authProviders?: AuthProvider[];
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useEffect, useEffectEvent, useMemo, useState } from "react";
|
|
3
|
+
import { DataEngine } from "@fumari/stf";
|
|
2
4
|
import { useExampleRequests, useOperation } from "../operation.js";
|
|
3
5
|
import { pathnameFromRequest } from "../requests/generators/index.js";
|
|
4
6
|
import { encodeRequestData } from "../requests/media/encode.js";
|
|
@@ -7,8 +9,6 @@ import { getPreferredType } from "../utils/schema.js";
|
|
|
7
9
|
import { useServer } from "../utils/use-server.js";
|
|
8
10
|
import { requestOAuthToken, useAuthFields, usePlaygroundAuth } from "./auth.js";
|
|
9
11
|
import { createBrowserFetcher } from "./fetcher.js";
|
|
10
|
-
import { useEffect, useEffectEvent, useMemo, useState } from "react";
|
|
11
|
-
import { DataEngine } from "@fumari/stf";
|
|
12
12
|
// src/playground/use-playground.tsx
|
|
13
13
|
/** the form of a playground, its `auth` is the auth values of page */
|
|
14
14
|
var PlaygroundForm = class extends DataEngine {
|
|
@@ -69,7 +69,7 @@ function usePlayground({ authProviders, transformAuthInputs, fetchOptions } = {}
|
|
|
69
69
|
query: data?.query ?? {},
|
|
70
70
|
header: data?.header ?? {},
|
|
71
71
|
cookie: data?.cookie ?? {},
|
|
72
|
-
body: data?.body
|
|
72
|
+
body: data?.body === void 0 ? {} : data.body
|
|
73
73
|
};
|
|
74
74
|
}, [examples, selected]);
|
|
75
75
|
const stf = useMemo(() => ({ dataEngine: new PlaygroundForm(defaultValues, page.stf.dataEngine) }), [defaultValues, page.stf.dataEngine]);
|
package/dist/press.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { Plugin } from "fumadocs-core/framework/plugin";
|
|
2
|
+
import { ComponentType } from "react";
|
|
1
3
|
import { OpenAPIServer } from "./server/index.js";
|
|
2
4
|
import { Awaitable } from "./types.js";
|
|
3
5
|
import { CreateProxyOptions, Proxy } from "./server/proxy.js";
|
|
4
6
|
import { OpenAPIPageProps } from "./utils/pages/builder.js";
|
|
5
|
-
import { ComponentType } from "react";
|
|
6
|
-
import { Plugin } from "fumadocs-core/framework/plugin";
|
|
7
7
|
export interface OpenAPIPluginOptions {
|
|
8
8
|
/** created with `createOpenAPI()` */
|
|
9
9
|
server: OpenAPIServer;
|
|
@@ -12,7 +12,8 @@ const csharp = {
|
|
|
12
12
|
]);
|
|
13
13
|
const body = generateBodyExample(data, mediaAdapters, {
|
|
14
14
|
lang: "csharp",
|
|
15
|
-
addImport: (name) => imports.add(name)
|
|
15
|
+
addImport: (name) => imports.add(name),
|
|
16
|
+
bodyMediaType: data.bodyMediaType
|
|
16
17
|
});
|
|
17
18
|
const s = Array.from(imports, (name) => `using ${name};`);
|
|
18
19
|
s.push("");
|
|
@@ -7,12 +7,13 @@ const curl = {
|
|
|
7
7
|
lang: "bash",
|
|
8
8
|
generate(data, { mediaAdapters }) {
|
|
9
9
|
const s = [];
|
|
10
|
-
|
|
10
|
+
const method = data.method.toUpperCase();
|
|
11
|
+
s.push(`curl ${method === "HEAD" ? "--head" : `-X ${method}`} ${shellQuote(data.url)}`);
|
|
11
12
|
for (const header in data.header) s.push(`-H ${shellQuote(`${header}: ${data.header[header].value}`)}`);
|
|
12
13
|
for (const k in data.cookie) s.push(`--cookie ${shellQuote(`${k}=${data.cookie[k].value}`)}`);
|
|
13
14
|
const type = data.bodyMediaType && resolveMediaType(data.bodyMediaType, mediaAdapters);
|
|
14
15
|
if (data.body && type === "multipart/form-data") for (const [key, value] of formFields(data.body)) s.push(`-F ${shellQuote(`${key}=${value}`)}`);
|
|
15
|
-
else if (data.body
|
|
16
|
+
else if (type && type !== "multipart/form-data" && data.body !== void 0) {
|
|
16
17
|
s.push(`-H 'Content-Type: ${data.bodyMediaType}'`);
|
|
17
18
|
s.push(`-d ${shellQuote(inputToString(data.body, type))}`);
|
|
18
19
|
}
|
|
@@ -3,7 +3,7 @@ import { createCodeUsageGeneratorRegistry as createCodeUsageGeneratorRegistry$1
|
|
|
3
3
|
function pathnameFromRequest(pathname, { path, query }) {
|
|
4
4
|
for (const key in path) {
|
|
5
5
|
const param = path[key];
|
|
6
|
-
pathname = pathname.
|
|
6
|
+
pathname = pathname.replaceAll(`{${key}}`, () => param.value);
|
|
7
7
|
}
|
|
8
8
|
const [pathPart, existingQueryString] = pathname.split("?", 2);
|
|
9
9
|
const searchParams = new URLSearchParams(existingQueryString || "");
|
|
@@ -19,6 +19,8 @@ interface JavaContext extends BaseContext {
|
|
|
19
19
|
interface CSharpContext extends BaseContext {
|
|
20
20
|
lang: 'csharp';
|
|
21
21
|
addImport: (specifier: string) => void;
|
|
22
|
+
/** the declared media type, like `application/merge-patch+json` */
|
|
23
|
+
bodyMediaType: string;
|
|
22
24
|
}
|
|
23
25
|
export type MediaContext = JavaContext | GoContext | JavaScriptContext | CSharpContext | (BaseContext & {
|
|
24
26
|
lang: string;
|
|
@@ -27,8 +27,7 @@ const defaultAdapters = {
|
|
|
27
27
|
},
|
|
28
28
|
"application/x-ndjson": {
|
|
29
29
|
encode(data) {
|
|
30
|
-
|
|
31
|
-
return JSON.stringify(data.body);
|
|
30
|
+
return inputToString(data.body, "application/x-ndjson");
|
|
32
31
|
},
|
|
33
32
|
generateExample(data, ctx) {
|
|
34
33
|
return str(data.body, "application/x-ndjson", ctx);
|
|
@@ -117,7 +116,7 @@ const defaultAdapters = {
|
|
|
117
116
|
* Generate the code that inits a `body` variable for the request body, `undefined` when unsupported.
|
|
118
117
|
*/
|
|
119
118
|
function generateBodyExample(data, adapters, ctx) {
|
|
120
|
-
if (
|
|
119
|
+
if (data.body === void 0 || !data.bodyMediaType) return;
|
|
121
120
|
return resolveMediaAdapter(data.bodyMediaType, adapters)?.generateExample(data, ctx);
|
|
122
121
|
}
|
|
123
122
|
function str(init, mediaType, ctx) {
|
|
@@ -132,7 +131,10 @@ function str(init, mediaType, ctx) {
|
|
|
132
131
|
case "java":
|
|
133
132
|
ctx.addImport("java.net.http.HttpRequest.BodyPublishers");
|
|
134
133
|
return `var body = BodyPublishers.ofString(${javaTextBlock(text)});`;
|
|
135
|
-
case "csharp":
|
|
134
|
+
case "csharp": {
|
|
135
|
+
const [type] = ctx.bodyMediaType.split(";", 1);
|
|
136
|
+
return `var body = new StringContent(${csharpRawString(text)}, Encoding.UTF8, "${type.trim()}");`;
|
|
137
|
+
}
|
|
136
138
|
case "rust": return `let body = ${rustString(text)};`;
|
|
137
139
|
case "ruby": return `body = ${rubyString(text)}`;
|
|
138
140
|
}
|
|
@@ -96,21 +96,14 @@ function serializePathParameter(field, value, output) {
|
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
function serializeQueryParameter(field, value, output) {
|
|
99
|
-
const { style, explode =
|
|
100
|
-
|
|
101
|
-
output[field.name] = { values: [value.join(" ")] };
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if (style === "pipeDelimited" && !explode && Array.isArray(value)) {
|
|
105
|
-
output[field.name] = { values: [value.join("|")] };
|
|
106
|
-
return;
|
|
107
|
-
}
|
|
99
|
+
const { style = "form", explode = style === "form" } = field;
|
|
100
|
+
const delimiter = style === "pipeDelimited" ? "|" : style === "spaceDelimited" ? " " : ",";
|
|
108
101
|
if (style === "deepObject" && !Array.isArray(value) && typeof value === "object") {
|
|
109
102
|
for (const [k, v] of Object.entries(value)) output[`${field.name}[${k}]`] = { values: Array.isArray(v) ? v : [String(v)] };
|
|
110
103
|
return;
|
|
111
104
|
}
|
|
112
105
|
if (Array.isArray(value)) {
|
|
113
|
-
output[field.name] = { values: explode ? value : [value.join(
|
|
106
|
+
output[field.name] = { values: explode ? value : [value.join(delimiter)] };
|
|
114
107
|
return;
|
|
115
108
|
}
|
|
116
109
|
if (typeof value === "object" && explode) {
|
|
@@ -118,7 +111,7 @@ function serializeQueryParameter(field, value, output) {
|
|
|
118
111
|
return;
|
|
119
112
|
}
|
|
120
113
|
if (typeof value === "object") {
|
|
121
|
-
output[field.name] = { values: [Object.entries(value).flat().join(
|
|
114
|
+
output[field.name] = { values: [Object.entries(value).flat().join(delimiter)] };
|
|
122
115
|
return;
|
|
123
116
|
}
|
|
124
117
|
output[field.name] = { values: [String(value)] };
|
|
@@ -3,11 +3,11 @@ import { require_js2xml } from "../node_modules/.pnpm/xml-js@1.6.11/node_modules
|
|
|
3
3
|
// src/requests/string-utils.ts
|
|
4
4
|
var import_js2xml = /* @__PURE__ */ __toESM(require_js2xml(), 1);
|
|
5
5
|
/**
|
|
6
|
-
* The text of a body value in the format of a media type
|
|
6
|
+
* The text of a body value in the format of a media type. Non-JSON strings are already serialized.
|
|
7
7
|
*/
|
|
8
8
|
function inputToString(value, format = "application/json") {
|
|
9
|
-
if (typeof value === "string") return value;
|
|
10
|
-
if (format === "application/x-ndjson") return Array.isArray(value) ? value.map((v) => JSON.stringify(v)).join("\n") : JSON.stringify(value
|
|
9
|
+
if (typeof value === "string" && format !== "application/json") return value;
|
|
10
|
+
if (format === "application/x-ndjson") return Array.isArray(value) ? value.map((v) => JSON.stringify(v)).join("\n") : JSON.stringify(value);
|
|
11
11
|
if (format === "application/x-www-form-urlencoded") return toSearchParams(value).toString();
|
|
12
12
|
if (format === "application/xml") return (0, import_js2xml.default)(value, {
|
|
13
13
|
compact: true,
|
package/dist/server/index.d.ts
CHANGED
|
@@ -2,13 +2,13 @@ import { CreateProxyOptions, Proxy, createProxy } from "./proxy.js";
|
|
|
2
2
|
import { OpenAPIPageProps_Preloaded, OpenAPIPageProps_Spec } from "../utils/pages/builder.js";
|
|
3
3
|
import { OAuthHandlerOptions, createOAuthHandler } from "./oauth.js";
|
|
4
4
|
import { Awaitable, Document } from "../types.js";
|
|
5
|
+
import { DynamicSource, LoaderPlugin, MetaData, Page, PageData, Source } from "fumadocs-core/source";
|
|
5
6
|
import { InternalOpenAPIMeta } from "../utils/pages/to-static-data.js";
|
|
6
7
|
import { SourceOptions } from "../packages/shared-api/dist/source.js";
|
|
7
8
|
import "../ui/index.js";
|
|
8
|
-
import { SchemaToPagesOptions } from "../utils/pages/preset-auto.js";
|
|
9
|
-
import { DynamicSource, LoaderPlugin, MetaData, Page, PageData, Source } from "fumadocs-core/source";
|
|
10
|
-
import { TOCItemType } from "fumadocs-core/toc";
|
|
11
9
|
import { StructuredData } from "fumadocs-core/mdx-plugins/remark-structure";
|
|
10
|
+
import { TOCItemType } from "fumadocs-core/toc";
|
|
11
|
+
import { SchemaToPagesOptions } from "../utils/pages/preset-auto.js";
|
|
12
12
|
/**
|
|
13
13
|
* schema ID -> file path, URL, downloaded schema object, or a function returning them
|
|
14
14
|
*/
|
package/dist/server/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { createOAuthHandler } from "./oauth.js";
|
|
|
3
3
|
import { loadDocument } from "../utils/document/load.js";
|
|
4
4
|
import { fromSchema, getPageProps } from "../utils/pages/builder.js";
|
|
5
5
|
import { toStaticData } from "../utils/pages/to-static-data.js";
|
|
6
|
-
import { toVirtualFiles } from "../packages/shared-api/dist/source.js";
|
|
6
|
+
import { toMetaFiles, toVirtualFiles } from "../packages/shared-api/dist/source.js";
|
|
7
7
|
import { createAutoPreset } from "../utils/pages/preset-auto.js";
|
|
8
8
|
import { MethodLabel } from "../ui/components/method-label.js";
|
|
9
9
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -30,44 +30,49 @@ function createOpenAPI(options = {}) {
|
|
|
30
30
|
return Object.fromEntries(entries);
|
|
31
31
|
}
|
|
32
32
|
async function getVirtualFiles(server, options, docFilesCache) {
|
|
33
|
+
const entries = [];
|
|
33
34
|
const files = [];
|
|
34
35
|
for (const [id, schema] of Object.entries(await server.getSchemas())) {
|
|
35
|
-
|
|
36
|
-
if (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
return {
|
|
43
|
-
...entry.info,
|
|
44
|
-
full: true,
|
|
45
|
-
getOpenAPIPageProps() {
|
|
36
|
+
let output = docFilesCache?.get(schema);
|
|
37
|
+
if (!output) {
|
|
38
|
+
const docEntries = fromSchema(id, schema.bundled, createAutoPreset(options));
|
|
39
|
+
output = {
|
|
40
|
+
entries: docEntries,
|
|
41
|
+
files: toVirtualFiles(docEntries, options, (entry) => {
|
|
42
|
+
const props = getPageProps(entry);
|
|
46
43
|
return {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
...entry.info,
|
|
45
|
+
full: true,
|
|
46
|
+
getOpenAPIPageProps() {
|
|
47
|
+
return {
|
|
48
|
+
payload: {
|
|
49
|
+
...includeDocument && { bundled: schema.bundled },
|
|
50
|
+
proxyUrl: server.options.proxyUrl
|
|
51
|
+
},
|
|
52
|
+
...props
|
|
53
|
+
};
|
|
50
54
|
},
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
getSchema() {
|
|
56
|
+
return {
|
|
57
|
+
id,
|
|
58
|
+
bundled: schema.bundled
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
...toStaticData(props, schema.bundled),
|
|
62
|
+
_openapi: {
|
|
63
|
+
method: entry.type === "operation" || entry.type === "webhook" ? entry.item.method : void 0,
|
|
64
|
+
webhook: entry.type === "webhook",
|
|
65
|
+
deprecated: entry.info.deprecated
|
|
66
|
+
}
|
|
58
67
|
};
|
|
59
|
-
}
|
|
60
|
-
...toStaticData(props, schema.bundled),
|
|
61
|
-
_openapi: {
|
|
62
|
-
method: entry.type === "operation" || entry.type === "webhook" ? entry.item.method : void 0,
|
|
63
|
-
webhook: entry.type === "webhook",
|
|
64
|
-
deprecated: entry.info.deprecated
|
|
65
|
-
}
|
|
68
|
+
})
|
|
66
69
|
};
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
docFilesCache?.set(schema, output);
|
|
71
|
+
}
|
|
72
|
+
entries.push(output.entries);
|
|
73
|
+
files.push(...output.files);
|
|
70
74
|
}
|
|
75
|
+
files.push(...toMetaFiles(entries, options));
|
|
71
76
|
return files;
|
|
72
77
|
}
|
|
73
78
|
return {
|
package/dist/ui/base.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OpenAPIPageProps } from "../utils/pages/builder.js";
|
|
2
|
-
import { CreateOpenAPIPageOptions } from "./index.js";
|
|
3
2
|
import { FC } from "react";
|
|
3
|
+
import { CreateOpenAPIPageOptions } from "./index.js";
|
|
4
4
|
/**
|
|
5
5
|
* Create `<OpenAPIPage />` (a client component) without the full Shiki bundle.
|
|
6
6
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { useMemo } from "react";
|
|
2
3
|
import { useAnchorId } from "../../packages/shared-api/dist/auto-anchor/index.js";
|
|
3
4
|
import { useComponents, useRenderContext } from "../../utils/create-page.js";
|
|
4
|
-
import { useMemo } from "react";
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
6
|
// src/ui/components/schema.tsx
|
|
7
7
|
/**
|
package/dist/ui/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { FC } from "react";
|
|
1
2
|
import { CreateOpenAPIRendererOptions } from "../utils/create-page.js";
|
|
2
3
|
import { OpenAPIPageProps, OpenAPIPageProps_Preloaded, OpenAPIPageProps_Spec } from "../utils/pages/builder.js";
|
|
3
|
-
import { FC } from "react";
|
|
4
4
|
export interface CreateOpenAPIPageOptions extends Omit<CreateOpenAPIRendererOptions, 'components'> {
|
|
5
5
|
/**
|
|
6
6
|
* Replace parts of the UI, e.g. the ones installed with Fumadocs CLI.
|
package/dist/ui/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { createOpenAPIPageBase } from "./base.js";
|
|
3
2
|
import { defaultShikiFactory } from "fumadocs-core/highlight/shiki/full";
|
|
3
|
+
import { createOpenAPIPageBase } from "./base.js";
|
|
4
4
|
// src/ui/index.tsx
|
|
5
5
|
/**
|
|
6
6
|
* Create `<OpenAPIPage />` (a client component).
|
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
"use client";
|
|
2
|
+
import { Fragment, Suspense, lazy, useState } from "react";
|
|
3
|
+
import { Dialog } from "@base-ui/react/dialog";
|
|
2
4
|
import { RequestTabs, UsageTabs } from "./usage-tabs.js";
|
|
3
5
|
import { MethodLabel } from "../components/method-label.js";
|
|
4
6
|
import { SchemaUI } from "../components/schema.js";
|
|
5
7
|
import { Badge } from "../../packages/shared-api/dist/components/badge.js";
|
|
6
8
|
import { useOpenAPI, useRenderContext } from "../../utils/create-page.js";
|
|
7
9
|
import { OperationProvider, useOperation } from "../../operation.js";
|
|
10
|
+
import { useTranslations } from "@fuma-translate/react";
|
|
8
11
|
import { cn } from "../../utils/cn.js";
|
|
9
12
|
import { SelectTab, SelectTabTrigger, SelectTabs } from "../../packages/shared-api/dist/components/select-tab.js";
|
|
13
|
+
import { Callout } from "fumadocs-ui/components/callout";
|
|
10
14
|
import { AnchorSection, useAnchorLink } from "../../packages/shared-api/dist/auto-anchor/index.js";
|
|
11
15
|
import { Heading } from "../components/heading.js";
|
|
12
16
|
import { Markdown } from "../components/markdown.js";
|
|
17
|
+
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
18
|
+
import { ChevronRight, Plus, X } from "lucide-react";
|
|
13
19
|
import { CopyTypeScript } from "../../packages/shared-api/dist/components/copy-typescript.js";
|
|
14
20
|
import { EndpointBar } from "../components/endpoint.js";
|
|
15
21
|
import { Segmented, SegmentedList, SegmentedPanel } from "../../packages/shared-api/dist/components/segmented.js";
|
|
16
22
|
import { DialogPopup } from "../../packages/shared-api/dist/components/dialog.js";
|
|
17
|
-
import { Fragment, Suspense, lazy, useState } from "react";
|
|
18
23
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
19
|
-
import { useTranslations } from "@fuma-translate/react";
|
|
20
|
-
import { ChevronRight, Plus, X } from "lucide-react";
|
|
21
|
-
import { buttonVariants } from "fumadocs-ui/components/ui/button";
|
|
22
|
-
import { Dialog } from "@base-ui/react/dialog";
|
|
23
|
-
import { Callout } from "fumadocs-ui/components/callout";
|
|
24
24
|
// src/ui/operation/index.tsx
|
|
25
25
|
const PlaygroundClient = lazy(() => import("../playground/client.js"));
|
|
26
26
|
function Operation({ type, path, method, operation, pathItem, ...props }) {
|
|
@@ -113,8 +113,9 @@ function OperationContent({ showTitle, showDescription, headingLevel = 2 }) {
|
|
|
113
113
|
children: /* @__PURE__ */ jsx("div", {
|
|
114
114
|
className: "rounded-xl border bg-fd-card px-3",
|
|
115
115
|
children: items.map((param) => {
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
const raw = param.schema ?? resolve(Object.values(param.content ?? {})[0])?.schema;
|
|
117
|
+
if (raw == null) return;
|
|
118
|
+
const schema = resolve(raw);
|
|
118
119
|
return /* @__PURE__ */ jsx(SchemaUI, {
|
|
119
120
|
client: {
|
|
120
121
|
name: param.name,
|