fumadocs-openapi 12.5.5 → 12.5.7
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/.translations/index.d.ts +6 -3
- package/dist/.translations/keys.js +6 -2
- package/dist/_virtual/_rolldown/runtime.js +1 -2
- package/dist/generate-file.d.ts +1 -3
- package/dist/generate-file.js +3 -3
- package/dist/i18n.d.ts +1 -3
- package/dist/i18n.js +1 -2
- package/dist/index.browser.d.ts +0 -2
- package/dist/index.browser.js +1 -2
- package/dist/node_modules/.pnpm/fast-content-type-parse@4.0.1/node_modules/fast-content-type-parse/index.js +1 -2
- package/dist/node_modules/.pnpm/xml-js@1.6.11/node_modules/xml-js/lib/array-helper.js +1 -2
- package/dist/node_modules/.pnpm/xml-js@1.6.11/node_modules/xml-js/lib/js2xml.js +1 -2
- package/dist/node_modules/.pnpm/xml-js@1.6.11/node_modules/xml-js/lib/options-helper.js +1 -2
- package/dist/operation.d.ts +1 -3
- package/dist/operation.js +3 -4
- package/dist/packages/shared-api/dist/.translations/index.d.ts +2 -5
- package/dist/packages/shared-api/dist/.translations/keys.js +2 -2
- package/dist/packages/shared-api/dist/auto-anchor/index.js +1 -2
- package/dist/packages/shared-api/dist/codegen.d.ts +0 -3
- package/dist/packages/shared-api/dist/codegen.js +1 -2
- package/dist/packages/shared-api/dist/components/badge.js +1 -2
- package/dist/packages/shared-api/dist/components/collapsible.js +1 -2
- package/dist/packages/shared-api/dist/components/copy-typescript.js +1 -2
- package/dist/packages/shared-api/dist/components/defaults.d.ts +1 -4
- package/dist/packages/shared-api/dist/components/defaults.js +1 -2
- package/dist/packages/shared-api/dist/components/dialog.js +1 -2
- package/dist/packages/shared-api/dist/components/example.js +3 -3
- package/dist/packages/shared-api/dist/components/playground/fields.js +28 -10
- package/dist/packages/shared-api/dist/components/playground/json-editor.js +1 -2
- package/dist/packages/shared-api/dist/components/playground/panels.js +2 -3
- package/dist/packages/shared-api/dist/components/playground/param-input.js +1 -2
- package/dist/packages/shared-api/dist/components/playground/result.js +1 -2
- package/dist/packages/shared-api/dist/components/playground/schema.js +1 -2
- package/dist/packages/shared-api/dist/components/playground/server-select.js +2 -3
- package/dist/packages/shared-api/dist/components/schema/client.d.ts +1 -4
- package/dist/packages/shared-api/dist/components/schema/client.js +3 -2
- package/dist/packages/shared-api/dist/components/schema/index.d.ts +0 -3
- package/dist/packages/shared-api/dist/components/schema/index.js +1 -2
- package/dist/packages/shared-api/dist/components/segmented.js +1 -2
- package/dist/packages/shared-api/dist/components/select-tab.js +1 -2
- package/dist/packages/shared-api/dist/components/select.js +1 -2
- package/dist/packages/shared-api/dist/components/spinner.js +1 -2
- package/dist/packages/shared-api/dist/i18n.js +1 -2
- package/dist/packages/shared-api/dist/source.d.ts +1 -4
- package/dist/packages/shared-api/dist/source.js +1 -2
- package/dist/packages/shared-api/dist/utils/document-cache.js +1 -2
- package/dist/packages/shared-api/dist/utils/id-to-title.js +1 -2
- package/dist/packages/shared-api/dist/utils/is-plain-object.js +1 -2
- package/dist/packages/shared-api/dist/utils/url.js +1 -2
- package/dist/packages/shared-api/dist/utils/use-query.js +1 -2
- package/dist/packages/shared-api/dist/utils/use-server-store.js +1 -2
- package/dist/playground/auth.d.ts +8 -8
- package/dist/playground/auth.js +90 -59
- package/dist/playground/fetcher.d.ts +1 -3
- package/dist/playground/fetcher.js +1 -2
- package/dist/playground/use-playground.d.ts +1 -3
- package/dist/playground/use-playground.js +3 -4
- package/dist/requests/generators/all.d.ts +1 -3
- package/dist/requests/generators/all.js +1 -2
- package/dist/requests/generators/csharp.d.ts +1 -3
- package/dist/requests/generators/csharp.js +1 -2
- package/dist/requests/generators/curl.d.ts +1 -3
- package/dist/requests/generators/curl.js +1 -2
- package/dist/requests/generators/go.d.ts +1 -3
- package/dist/requests/generators/go.js +1 -2
- package/dist/requests/generators/index.d.ts +1 -3
- package/dist/requests/generators/index.js +1 -2
- package/dist/requests/generators/java.d.ts +1 -3
- package/dist/requests/generators/java.js +1 -2
- package/dist/requests/generators/javascript.d.ts +1 -3
- package/dist/requests/generators/javascript.js +1 -2
- package/dist/requests/generators/python.d.ts +1 -3
- package/dist/requests/generators/python.js +1 -2
- package/dist/requests/generators/rust.d.ts +1 -3
- package/dist/requests/generators/rust.js +1 -2
- package/dist/requests/media/adapter.d.ts +0 -2
- package/dist/requests/media/adapter.js +1 -2
- package/dist/requests/media/encode.d.ts +1 -3
- package/dist/requests/media/encode.js +1 -2
- package/dist/requests/media/resolve-adapter.d.ts +1 -3
- package/dist/requests/media/resolve-adapter.js +1 -2
- package/dist/requests/string-utils.js +1 -2
- package/dist/requests/types.d.ts +1 -3
- package/dist/server/index.d.ts +0 -2
- package/dist/server/index.js +1 -2
- package/dist/server/oauth.d.ts +1 -3
- package/dist/server/oauth.js +7 -11
- package/dist/server/proxy.d.ts +0 -2
- package/dist/server/proxy.js +8 -4
- package/dist/types/openapi.d.ts +1 -3
- package/dist/types.d.ts +1 -3
- package/dist/ui/base.d.ts +1 -3
- package/dist/ui/base.js +1 -2
- package/dist/ui/components/codeblock.js +1 -2
- package/dist/ui/components/endpoint.js +1 -2
- package/dist/ui/components/heading.js +1 -2
- package/dist/ui/components/markdown.js +1 -2
- package/dist/ui/components/method-label.js +1 -2
- package/dist/ui/components/schema.js +1 -2
- package/dist/ui/index.d.ts +0 -2
- package/dist/ui/index.js +1 -2
- package/dist/ui/operation/index.js +29 -16
- package/dist/ui/operation/usage-tabs.js +13 -6
- package/dist/ui/playground/client.d.ts +5 -4
- package/dist/ui/playground/client.js +5 -6
- package/dist/ui/playground/components/auth.js +4 -5
- package/dist/ui/playground/components/request-panel.d.ts +8 -0
- package/dist/ui/playground/components/request-panel.js +17 -11
- package/dist/ui/playground/components/response-panel.js +1 -2
- package/dist/ui/playground/components/result-display.d.ts +1 -3
- package/dist/ui/playground/components/result-display.js +1 -2
- package/dist/ui/playground/components/server-select.js +1 -2
- package/dist/ui/playground/components/url-bar.js +1 -2
- package/dist/ui/scalar/client.js +1 -2
- package/dist/ui/scalar/index.d.ts +1 -3
- package/dist/ui/scalar/index.js +1 -2
- package/dist/utils/create-page.d.ts +1 -3
- package/dist/utils/create-page.js +2 -4
- package/dist/utils/document/dereference.d.ts +1 -3
- package/dist/utils/document/dereference.js +1 -2
- package/dist/utils/document/load.js +1 -2
- package/dist/utils/get-example-requests.js +2 -3
- package/dist/utils/pages/builder.d.ts +0 -2
- package/dist/utils/pages/builder.js +1 -2
- package/dist/utils/pages/preset-auto.d.ts +0 -2
- package/dist/utils/pages/preset-auto.js +1 -2
- package/dist/utils/pages/to-static-data.d.ts +1 -3
- package/dist/utils/pages/to-static-data.js +1 -2
- package/dist/utils/pages/to-text.d.ts +1 -3
- package/dist/utils/pages/to-text.js +1 -2
- package/dist/utils/schema.js +1 -2
- package/dist/utils/use-server.d.ts +2 -4
- package/dist/utils/use-server.js +3 -3
- package/package.json +3 -3
package/dist/playground/auth.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { useServer } from "../utils/use-server.js";
|
|
3
|
-
import {
|
|
3
|
+
import { useOpenAPI } from "../utils/create-page.js";
|
|
4
4
|
import { useOperation } from "../operation.js";
|
|
5
5
|
import { proxied } from "./fetcher.js";
|
|
6
|
-
import {
|
|
7
|
-
import { createContext, use, useCallback, useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
6
|
+
import { use, useCallback, useEffect, useMemo, useState, useSyncExternalStore } from "react";
|
|
8
7
|
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
9
|
-
import {
|
|
8
|
+
import { DataEngine, useListener } from "@fumari/stf";
|
|
10
9
|
import { arrayStartsWith, objectGet } from "@fumari/stf/lib/utils";
|
|
11
|
-
|
|
10
|
+
// src/playground/auth.tsx
|
|
12
11
|
const pendingFlowKey = "fumadocs-openapi-flow";
|
|
13
12
|
function leavePage(url, flow, redirectUrl) {
|
|
14
13
|
sessionStorage.setItem(pendingFlowKey, JSON.stringify(flow));
|
|
15
|
-
if (redirectUrl)
|
|
14
|
+
if (redirectUrl) sessionStorage.setItem("fumadocs-openapi-oauth", window.location.pathname);
|
|
16
15
|
window.location.replace(url);
|
|
17
16
|
}
|
|
18
17
|
/**
|
|
@@ -256,63 +255,96 @@ function endReturnedFlow(flow) {
|
|
|
256
255
|
}
|
|
257
256
|
/** returned OAuth flows the page is finishing */
|
|
258
257
|
const finishing = /* @__PURE__ */ new WeakSet();
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
258
|
+
/** the auth of a page, created by its first playground */
|
|
259
|
+
var PageAuth = class {
|
|
260
|
+
constructor() {
|
|
261
|
+
this.stf = { dataEngine: new DataEngine({ auth: {} }) };
|
|
262
|
+
this.state = {
|
|
263
|
+
isLoading: false,
|
|
264
|
+
store: {}
|
|
265
|
+
};
|
|
266
|
+
this.listeners = /* @__PURE__ */ new Set();
|
|
267
|
+
this.getState = () => this.state;
|
|
268
|
+
this.subscribe = (listener) => {
|
|
269
|
+
this.listeners.add(listener);
|
|
270
|
+
const returned = getReturnedFlow();
|
|
271
|
+
if (returned?.oauth && !finishing.has(returned)) {
|
|
272
|
+
finishing.add(returned);
|
|
273
|
+
this.finish(returned);
|
|
274
|
+
}
|
|
275
|
+
return () => {
|
|
276
|
+
this.listeners.delete(listener);
|
|
277
|
+
};
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
set(state) {
|
|
281
|
+
this.state = state;
|
|
282
|
+
for (const listener of this.listeners) listener();
|
|
283
|
+
}
|
|
284
|
+
async finish(flow) {
|
|
285
|
+
this.set({
|
|
286
|
+
isLoading: true,
|
|
287
|
+
store: {}
|
|
288
|
+
});
|
|
274
289
|
try {
|
|
290
|
+
const result = finishOAuthFlow(flow.url, flow.data);
|
|
291
|
+
if (result !== void 0) window.history.replaceState(null, "", window.location.pathname);
|
|
275
292
|
const token = await result;
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
293
|
+
const store = {};
|
|
294
|
+
if (token !== void 0) {
|
|
295
|
+
this.stf.dataEngine.update(["auth", flow.scheme], token);
|
|
296
|
+
const { client_id, client_secret, client_auth } = flow.data;
|
|
297
|
+
store[flow.scheme] = typeof result === "string" ? {
|
|
298
|
+
type: "implicit",
|
|
299
|
+
client_id,
|
|
300
|
+
token
|
|
301
|
+
} : {
|
|
302
|
+
type: "authorization_code",
|
|
303
|
+
client_id,
|
|
304
|
+
client_secret,
|
|
305
|
+
client_auth,
|
|
306
|
+
token
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
this.set({
|
|
310
|
+
isLoading: false,
|
|
311
|
+
store
|
|
312
|
+
});
|
|
313
|
+
} catch (error) {
|
|
314
|
+
this.set({
|
|
315
|
+
isLoading: false,
|
|
316
|
+
error,
|
|
317
|
+
store: {}
|
|
318
|
+
});
|
|
291
319
|
} finally {
|
|
292
320
|
endReturnedFlow(flow);
|
|
293
321
|
}
|
|
294
|
-
});
|
|
295
|
-
if (returned?.oauth && !finishing.has(returned)) {
|
|
296
|
-
finishing.add(returned);
|
|
297
|
-
query.start(returned);
|
|
298
322
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
323
|
+
};
|
|
324
|
+
const pages = /* @__PURE__ */ new WeakMap();
|
|
325
|
+
/**
|
|
326
|
+
* The auth of page: the values of security schemes, and the flow that returned to it.
|
|
327
|
+
*/
|
|
328
|
+
function usePlaygroundAuth() {
|
|
329
|
+
const runtime = useOpenAPI();
|
|
330
|
+
let page = pages.get(runtime);
|
|
331
|
+
if (!page) {
|
|
332
|
+
page = new PageAuth();
|
|
333
|
+
pages.set(runtime, page);
|
|
334
|
+
}
|
|
335
|
+
const returned = useSyncExternalStore(subscribeNever, getReturnedFlow, () => void 0);
|
|
336
|
+
const state = useSyncExternalStore(page.subscribe, page.getState, page.getState);
|
|
337
|
+
const { stf } = page;
|
|
338
|
+
return useMemo(() => ({
|
|
339
|
+
...state,
|
|
340
|
+
stf,
|
|
341
|
+
returned,
|
|
342
|
+
origin: returned?.origin
|
|
343
|
+
}), [
|
|
344
|
+
state,
|
|
345
|
+
stf,
|
|
346
|
+
returned
|
|
347
|
+
]);
|
|
316
348
|
}
|
|
317
349
|
const builtinProviders = [
|
|
318
350
|
{
|
|
@@ -470,5 +502,4 @@ function useAuthFields(engine, { operation, providers, transform } = {}) {
|
|
|
470
502
|
}, [page, fields])
|
|
471
503
|
};
|
|
472
504
|
}
|
|
473
|
-
|
|
474
|
-
export { PlaygroundAuthProvider, finishOAuthFlow, requestOAuthToken, useAuthFields, useAuthRedirect, useOpenIdConnectFlows, usePlaygroundAuth };
|
|
505
|
+
export { finishOAuthFlow, requestOAuthToken, useAuthFields, useAuthRedirect, useOpenIdConnectFlows, usePlaygroundAuth };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { RequestData } from "../requests/types.js";
|
|
2
2
|
import { MediaAdapter } from "../requests/media/adapter.js";
|
|
3
3
|
import { Awaitable } from "../types.js";
|
|
4
|
-
//#region src/playground/fetcher.d.ts
|
|
5
4
|
export type FetchResult = FetchResponseResult | FetchErrorResult;
|
|
6
5
|
export interface FetchErrorResult {
|
|
7
6
|
type: 'client_error';
|
|
@@ -48,5 +47,4 @@ export interface BrowserFetcherOptions {
|
|
|
48
47
|
*/
|
|
49
48
|
onRequestInit?: (requestInit: RequestInit) => Awaitable<RequestInit>;
|
|
50
49
|
}
|
|
51
|
-
export declare function createBrowserFetcher(adapters: Record<string, MediaAdapter>, { proxyUrl, proxyForwardCookie, requestTimeout, onRequestInit }?: BrowserFetcherOptions): Fetcher;
|
|
52
|
-
//#endregion
|
|
50
|
+
export declare function createBrowserFetcher(adapters: Record<string, MediaAdapter>, { proxyUrl, proxyForwardCookie, requestTimeout, onRequestInit }?: BrowserFetcherOptions): Fetcher;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveMediaAdapter } from "../requests/media/resolve-adapter.js";
|
|
2
2
|
import { require_fast_content_type_parse } from "../node_modules/.pnpm/fast-content-type-parse@4.0.1/node_modules/fast-content-type-parse/index.js";
|
|
3
|
-
|
|
3
|
+
// src/playground/fetcher.ts
|
|
4
4
|
var import_fast_content_type_parse = require_fast_content_type_parse();
|
|
5
5
|
/**
|
|
6
6
|
* The URL requesting `url` through the proxy of `createProxy()`, `url` itself without a proxy.
|
|
@@ -90,5 +90,4 @@ function getFileName(headers) {
|
|
|
90
90
|
}
|
|
91
91
|
return name?.replace(/^.*[/\\]/, "") || void 0;
|
|
92
92
|
}
|
|
93
|
-
//#endregion
|
|
94
93
|
export { createBrowserFetcher, proxied };
|
|
@@ -2,7 +2,6 @@ import { BrowserFetcherOptions, FetchResult } from "./fetcher.js";
|
|
|
2
2
|
import { AuthField, AuthProvider, AuthRequirement, OAuthFlowInput, OAuthFlowType } from "./auth.js";
|
|
3
3
|
import { JsonSchema } from "@fumadocs/json-schema";
|
|
4
4
|
import { Stf } from "@fumari/stf";
|
|
5
|
-
//#region src/playground/use-playground.d.ts
|
|
6
5
|
export interface PlaygroundOptions {
|
|
7
6
|
/** handle security schemes, before the built-in providers */
|
|
8
7
|
authProviders?: AuthProvider[];
|
|
@@ -60,5 +59,4 @@ export interface Playground {
|
|
|
60
59
|
*
|
|
61
60
|
* Edits are synced to the example request, so code usages follow them.
|
|
62
61
|
*/
|
|
63
|
-
export declare function usePlayground({ authProviders, transformAuthInputs, fetchOptions }?: PlaygroundOptions): Playground;
|
|
64
|
-
//#endregion
|
|
62
|
+
export declare function usePlayground({ authProviders, transformAuthInputs, fetchOptions }?: PlaygroundOptions): Playground;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { pathnameFromRequest } from "../requests/generators/index.js";
|
|
3
3
|
import { useServer } from "../utils/use-server.js";
|
|
4
|
-
import {
|
|
4
|
+
import { useOpenAPI } from "../utils/create-page.js";
|
|
5
5
|
import { getPreferredType } from "../utils/schema.js";
|
|
6
|
+
import { encodeRequestData } from "../requests/media/encode.js";
|
|
6
7
|
import { useExampleRequests, useOperation } from "../operation.js";
|
|
7
8
|
import { createBrowserFetcher } from "./fetcher.js";
|
|
8
9
|
import { requestOAuthToken, useAuthFields, usePlaygroundAuth } from "./auth.js";
|
|
9
|
-
import { useOpenAPI } from "../utils/create-page.js";
|
|
10
10
|
import { useEffect, useEffectEvent, useMemo, useState } from "react";
|
|
11
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 {
|
|
15
15
|
constructor(defaultValues, auth) {
|
|
@@ -163,5 +163,4 @@ function usePlayground({ authProviders, transformAuthInputs, fetchOptions } = {}
|
|
|
163
163
|
}
|
|
164
164
|
};
|
|
165
165
|
}
|
|
166
|
-
//#endregion
|
|
167
166
|
export { usePlayground };
|
|
@@ -1,4 +1,2 @@
|
|
|
1
1
|
import { CodeUsageGeneratorRegistry } from "./index.js";
|
|
2
|
-
|
|
3
|
-
export declare function registerDefault(registry: CodeUsageGeneratorRegistry): CodeUsageGeneratorRegistry;
|
|
4
|
-
//#endregion
|
|
2
|
+
export declare function registerDefault(registry: CodeUsageGeneratorRegistry): CodeUsageGeneratorRegistry;
|
|
@@ -5,7 +5,7 @@ import { java } from "./java.js";
|
|
|
5
5
|
import { javascript } from "./javascript.js";
|
|
6
6
|
import { python } from "./python.js";
|
|
7
7
|
import { rust } from "./rust.js";
|
|
8
|
-
|
|
8
|
+
// src/requests/generators/all.ts
|
|
9
9
|
function registerDefault(registry) {
|
|
10
10
|
registry.add("curl", curl);
|
|
11
11
|
registry.add("js", javascript);
|
|
@@ -16,5 +16,4 @@ function registerDefault(registry) {
|
|
|
16
16
|
registry.add("rust", rust);
|
|
17
17
|
return registry;
|
|
18
18
|
}
|
|
19
|
-
//#endregion
|
|
20
19
|
export { registerDefault };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cookieString, doubleQuote } from "../string-utils.js";
|
|
2
2
|
import { generateBodyExample } from "../media/adapter.js";
|
|
3
|
-
|
|
3
|
+
// src/requests/generators/csharp.ts
|
|
4
4
|
const csharp = {
|
|
5
5
|
label: "C#",
|
|
6
6
|
lang: "csharp",
|
|
@@ -27,5 +27,4 @@ const csharp = {
|
|
|
27
27
|
return s.join("\n");
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
-
//#endregion
|
|
31
30
|
export { csharp };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { shellQuote } from "../../packages/shared-api/dist/codegen.js";
|
|
2
2
|
import { inputToString } from "../string-utils.js";
|
|
3
3
|
import { resolveMediaType } from "../media/resolve-adapter.js";
|
|
4
|
-
|
|
4
|
+
// src/requests/generators/curl.ts
|
|
5
5
|
const curl = {
|
|
6
6
|
label: "cURL",
|
|
7
7
|
lang: "bash",
|
|
@@ -21,5 +21,4 @@ const curl = {
|
|
|
21
21
|
return s.join(" \\\n ");
|
|
22
22
|
}
|
|
23
23
|
};
|
|
24
|
-
//#endregion
|
|
25
24
|
export { curl };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cookieString, doubleQuote, indent } from "../string-utils.js";
|
|
2
2
|
import { generateBodyExample } from "../media/adapter.js";
|
|
3
|
-
|
|
3
|
+
// src/requests/generators/go.ts
|
|
4
4
|
const go = {
|
|
5
5
|
label: "Go",
|
|
6
6
|
lang: "go",
|
|
@@ -36,5 +36,4 @@ ${body ? `${multipart ? indent(body) : ` ${body}`}\n` : ""}${indent(s.join("\n"
|
|
|
36
36
|
}`;
|
|
37
37
|
}
|
|
38
38
|
};
|
|
39
|
-
//#endregion
|
|
40
39
|
export { go };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { RequestData } from "../types.js";
|
|
2
2
|
import { MediaAdapter } from "../media/adapter.js";
|
|
3
3
|
import { CodeUsageGenerator as CodeUsageGenerator$1, CodeUsageGeneratorRegistry as CodeUsageGeneratorRegistry$1, InlineCodeUsageGenerator as InlineCodeUsageGenerator$1 } from "../../packages/shared-api/dist/codegen.js";
|
|
4
|
-
//#region src/requests/generators/index.d.ts
|
|
5
4
|
export declare function pathnameFromRequest(pathname: string, { path, query }: RequestData): string;
|
|
6
5
|
export type CodeUsageGeneratorRegistry = CodeUsageGeneratorRegistry$1<RequestData & {
|
|
7
6
|
url: string;
|
|
@@ -33,5 +32,4 @@ export type CodeUsageGeneratorFn<T = unknown> = (data: RequestData & {
|
|
|
33
32
|
}, context: {
|
|
34
33
|
mediaAdapters: Record<string, MediaAdapter>;
|
|
35
34
|
custom: T;
|
|
36
|
-
}) => string;
|
|
37
|
-
//#endregion
|
|
35
|
+
}) => string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createCodeUsageGeneratorRegistry as createCodeUsageGeneratorRegistry$1 } from "../../packages/shared-api/dist/codegen.js";
|
|
2
|
-
|
|
2
|
+
// src/requests/generators/index.ts
|
|
3
3
|
function pathnameFromRequest(pathname, { path, query }) {
|
|
4
4
|
for (const key in path) {
|
|
5
5
|
const param = path[key];
|
|
@@ -18,5 +18,4 @@ function pathnameFromRequest(pathname, { path, query }) {
|
|
|
18
18
|
function createCodeUsageGeneratorRegistry(inherit) {
|
|
19
19
|
return createCodeUsageGeneratorRegistry$1(inherit);
|
|
20
20
|
}
|
|
21
|
-
//#endregion
|
|
22
21
|
export { createCodeUsageGeneratorRegistry, pathnameFromRequest };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cookieString, doubleQuote, indent, inputToString } from "../string-utils.js";
|
|
2
2
|
import { generateBodyExample } from "../media/adapter.js";
|
|
3
|
-
|
|
3
|
+
// src/requests/generators/java.ts
|
|
4
4
|
const boundary = "form-data-boundary";
|
|
5
5
|
const java = {
|
|
6
6
|
label: "Java",
|
|
@@ -48,5 +48,4 @@ function multipartBody(body) {
|
|
|
48
48
|
}
|
|
49
49
|
return `var body = HttpRequest.BodyPublishers.ofString(${JSON.stringify(`${text}--${boundary}--\r\n`)});`;
|
|
50
50
|
}
|
|
51
|
-
//#endregion
|
|
52
51
|
export { java };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cookieString, doubleQuote, indent } from "../string-utils.js";
|
|
2
2
|
import { generateBodyExample } from "../media/adapter.js";
|
|
3
|
-
|
|
3
|
+
// src/requests/generators/javascript.ts
|
|
4
4
|
const javascript = {
|
|
5
5
|
label: "JavaScript",
|
|
6
6
|
lang: "js",
|
|
@@ -27,5 +27,4 @@ const javascript = {
|
|
|
27
27
|
return s.join("\n\n");
|
|
28
28
|
}
|
|
29
29
|
};
|
|
30
|
-
//#endregion
|
|
31
30
|
export { javascript };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { doubleQuote } from "../string-utils.js";
|
|
2
2
|
import { generateBodyExample } from "../media/adapter.js";
|
|
3
|
-
|
|
3
|
+
// src/requests/generators/python.ts
|
|
4
4
|
const python = {
|
|
5
5
|
label: "Python",
|
|
6
6
|
lang: "python",
|
|
@@ -40,5 +40,4 @@ function generatePythonObject(v, imports) {
|
|
|
40
40
|
} else if (typeof v === "object") return `{\n${Object.entries(v).map(([key, value]) => ` ${doubleQuote(key)}: ${generatePythonObject(value, imports)}`).join(", \n")}\n}`;
|
|
41
41
|
else throw new Error(`Unsupported type: ${typeof v}`);
|
|
42
42
|
}
|
|
43
|
-
//#endregion
|
|
44
43
|
export { python };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { cookieString, doubleQuote, indent } from "../string-utils.js";
|
|
2
2
|
import { generateBodyExample } from "../media/adapter.js";
|
|
3
|
-
|
|
3
|
+
// src/requests/generators/rust.ts
|
|
4
4
|
const rust = {
|
|
5
5
|
label: "Rust",
|
|
6
6
|
lang: "rust",
|
|
@@ -30,5 +30,4 @@ ${indent(request.join("\n"), 2)}
|
|
|
30
30
|
}`;
|
|
31
31
|
}
|
|
32
32
|
};
|
|
33
|
-
//#endregion
|
|
34
33
|
export { rust };
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
//#region src/requests/media/adapter.d.ts
|
|
2
1
|
interface BaseContext {
|
|
3
2
|
/**
|
|
4
3
|
* Passed by your custom example generator, for your custom media adapter to receive.
|
|
@@ -46,5 +45,4 @@ export interface MediaAdapter {
|
|
|
46
45
|
body: unknown;
|
|
47
46
|
}, ctx: MediaContext) => string | undefined;
|
|
48
47
|
}
|
|
49
|
-
//#endregion
|
|
50
48
|
export {};
|
|
@@ -3,7 +3,7 @@ import { csharpRawString, goString, javaTextBlock, jsTemplateLiteral, pythonStri
|
|
|
3
3
|
import { require_js2xml } from "../../node_modules/.pnpm/xml-js@1.6.11/node_modules/xml-js/lib/js2xml.js";
|
|
4
4
|
import { inputToString } from "../string-utils.js";
|
|
5
5
|
import { resolveMediaAdapter } from "./resolve-adapter.js";
|
|
6
|
-
|
|
6
|
+
// src/requests/media/adapter.ts
|
|
7
7
|
var import_js2xml = /* @__PURE__ */ __toESM(require_js2xml(), 1);
|
|
8
8
|
const defaultAdapters = {
|
|
9
9
|
"application/json": {
|
|
@@ -141,5 +141,4 @@ function str(init, mediaType, ctx) {
|
|
|
141
141
|
case "rust": return `let body = ${rustString(text)};`;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
//#endregion
|
|
145
144
|
export { defaultAdapters, generateBodyExample };
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { RawRequestData, RequestData } from "../types.js";
|
|
2
2
|
import { MediaAdapter } from "./adapter.js";
|
|
3
3
|
import { ParameterObject } from "../../types.js";
|
|
4
|
-
//#region src/requests/media/encode.d.ts
|
|
5
4
|
export interface EncodedParameter {
|
|
6
5
|
readonly value: string;
|
|
7
6
|
}
|
|
@@ -11,5 +10,4 @@ export interface EncodedParameterMultiple {
|
|
|
11
10
|
/**
|
|
12
11
|
* serialize parameters, see https://swagger.io/docs/specification/v3_0/serialization.
|
|
13
12
|
*/
|
|
14
|
-
export declare function encodeRequestData(from: RawRequestData, adapters: Record<string, MediaAdapter>, parameters?: ParameterObject[]): RequestData;
|
|
15
|
-
//#endregion
|
|
13
|
+
export declare function encodeRequestData(from: RawRequestData, adapters: Record<string, MediaAdapter>, parameters?: ParameterObject[]): RequestData;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { resolveMediaAdapter } from "./resolve-adapter.js";
|
|
2
|
-
|
|
2
|
+
// src/requests/media/encode.ts
|
|
3
3
|
/**
|
|
4
4
|
* serialize parameters, see https://swagger.io/docs/specification/v3_0/serialization.
|
|
5
5
|
*/
|
|
@@ -123,5 +123,4 @@ function serializeCookieParameter(field, value, output) {
|
|
|
123
123
|
else if (typeof value === "object") output[field.name] = { value: Object.entries(value).flat().join(",") };
|
|
124
124
|
else output[field.name] = { value: String(value) };
|
|
125
125
|
}
|
|
126
|
-
//#endregion
|
|
127
126
|
export { encodeRequestData };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { MediaAdapter } from "./adapter.js";
|
|
2
|
-
//#region src/requests/media/resolve-adapter.d.ts
|
|
3
2
|
/**
|
|
4
3
|
* Resolve a media adapter for a given media type.
|
|
5
4
|
* Supports exact matches and pattern matching (e.g., +json suffix).
|
|
@@ -8,5 +7,4 @@ import { MediaAdapter } from "./adapter.js";
|
|
|
8
7
|
* @param adapters - Record of media adapters
|
|
9
8
|
* @returns The resolved adapter or undefined if not found
|
|
10
9
|
*/
|
|
11
|
-
export declare function resolveMediaAdapter(mediaType: string, adapters: Record<string, MediaAdapter>): MediaAdapter | undefined;
|
|
12
|
-
//#endregion
|
|
10
|
+
export declare function resolveMediaAdapter(mediaType: string, adapters: Record<string, MediaAdapter>): MediaAdapter | undefined;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
// src/requests/media/resolve-adapter.ts
|
|
2
2
|
const VariantMediaTypeRegex = /^(?<dir>[a-zA-Z0-9._-]+)\/(?<content>[a-zA-Z0-9._-]+)\+(?<variant>[a-zA-Z0-9._-]+)$/;
|
|
3
3
|
/**
|
|
4
4
|
* Resolve the media type of the adapter for a given media type, like `application/json` for `+json` variants.
|
|
@@ -24,5 +24,4 @@ function resolveMediaAdapter(mediaType, adapters) {
|
|
|
24
24
|
const type = resolveMediaType(mediaType, adapters);
|
|
25
25
|
if (type) return adapters[type];
|
|
26
26
|
}
|
|
27
|
-
//#endregion
|
|
28
27
|
export { resolveMediaAdapter, resolveMediaType };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __toESM } from "../_virtual/_rolldown/runtime.js";
|
|
2
2
|
import { require_js2xml } from "../node_modules/.pnpm/xml-js@1.6.11/node_modules/xml-js/lib/js2xml.js";
|
|
3
|
-
|
|
3
|
+
// src/requests/string-utils.ts
|
|
4
4
|
var import_js2xml = /* @__PURE__ */ __toESM(require_js2xml(), 1);
|
|
5
5
|
/**
|
|
6
6
|
* The text of a body value in the format of a media type, strings are already serialized.
|
|
@@ -44,5 +44,4 @@ function indent(code, tab = 1) {
|
|
|
44
44
|
const p = " ".repeat(tab);
|
|
45
45
|
return code.split("\n").map((v) => v.length === 0 ? v : p + v).join("\n");
|
|
46
46
|
}
|
|
47
|
-
//#endregion
|
|
48
47
|
export { cookieString, doubleQuote, indent, inputToString, jsxString };
|
package/dist/requests/types.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { EncodedParameter, EncodedParameterMultiple } from "./media/encode.js";
|
|
2
2
|
import { HttpMethods } from "../types.js";
|
|
3
|
-
//#region src/requests/types.d.ts
|
|
4
3
|
export interface RawRequestData {
|
|
5
4
|
method: HttpMethods;
|
|
6
5
|
path: Record<string, unknown>;
|
|
@@ -18,5 +17,4 @@ export interface RequestData {
|
|
|
18
17
|
cookie: Record<string, EncodedParameter>;
|
|
19
18
|
body?: unknown;
|
|
20
19
|
bodyMediaType?: string;
|
|
21
|
-
}
|
|
22
|
-
//#endregion
|
|
20
|
+
}
|
package/dist/server/index.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ import "../ui/index.js";
|
|
|
9
9
|
import { DynamicSource, LoaderPlugin, MetaData, Page, PageData, Source } from "fumadocs-core/source";
|
|
10
10
|
import { TOCItemType } from "fumadocs-core/toc";
|
|
11
11
|
import { StructuredData } from "fumadocs-core/mdx-plugins/remark-structure";
|
|
12
|
-
//#region src/server/index.d.ts
|
|
13
12
|
/**
|
|
14
13
|
* schema ID -> file path, URL, downloaded schema object, or a function returning them
|
|
15
14
|
*/
|
|
@@ -84,5 +83,4 @@ export declare function openapiSource(server: OpenAPIServer, options?: OpenAPISo
|
|
|
84
83
|
metaData: MetaData;
|
|
85
84
|
pageData: OpenAPIPageData;
|
|
86
85
|
}>>;
|
|
87
|
-
//#endregion
|
|
88
86
|
export type { CreateProxyOptions, OpenAPIPageProps_Preloaded, OpenAPIPageProps_Spec, Proxy };
|
package/dist/server/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import { createOAuthHandler } from "./oauth.js";
|
|
|
7
7
|
import { loadDocument } from "../utils/document/load.js";
|
|
8
8
|
import { MethodLabel } from "../ui/components/method-label.js";
|
|
9
9
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
-
|
|
10
|
+
// src/server/index.tsx
|
|
11
11
|
function createOpenAPI(options = {}) {
|
|
12
12
|
const { disableCache = false, includeDocument = true } = options;
|
|
13
13
|
const docCache = /* @__PURE__ */ new Map();
|
|
@@ -145,5 +145,4 @@ function openapiPlugin() {
|
|
|
145
145
|
async function openapiSource(server, options = {}) {
|
|
146
146
|
return server.staticSource(options);
|
|
147
147
|
}
|
|
148
|
-
//#endregion
|
|
149
148
|
export { createOpenAPI, openapiPlugin, openapiSource };
|
package/dist/server/oauth.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
//#region src/server/oauth.d.ts
|
|
2
1
|
/**
|
|
3
2
|
* A route handler for the redirect URI of OAuth flows, it sends users back to the page that started the flow.
|
|
4
3
|
*/
|
|
5
|
-
export declare function createOAuthHandler(): (req: Request) => Response;
|
|
6
|
-
//#endregion
|
|
4
|
+
export declare function createOAuthHandler(): (req: Request) => Response;
|
package/dist/server/oauth.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
// src/server/oauth.ts
|
|
2
|
+
const script = `const page = sessionStorage.getItem('fumadocs-openapi-oauth');
|
|
3
|
+
if (page) location.replace(location.origin + page + location.search + location.hash);`;
|
|
2
4
|
/**
|
|
3
5
|
* A route handler for the redirect URI of OAuth flows, it sends users back to the page that started the flow.
|
|
4
6
|
*/
|
|
5
7
|
function createOAuthHandler() {
|
|
6
|
-
return (req) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return new Response(null, {
|
|
11
|
-
status: 302,
|
|
12
|
-
headers: { Location: target.pathname + new URL(req.url).search }
|
|
13
|
-
});
|
|
14
|
-
};
|
|
8
|
+
return (req) => new URL(req.url).searchParams.has("script") ? new Response(script, { headers: { "Content-Type": "text/javascript" } }) : new Response("<script src=\"?script\"><\/script>", { headers: {
|
|
9
|
+
"Content-Type": "text/html",
|
|
10
|
+
"Referrer-Policy": "no-referrer"
|
|
11
|
+
} });
|
|
15
12
|
}
|
|
16
|
-
//#endregion
|
|
17
13
|
export { createOAuthHandler };
|