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.
Files changed (135) hide show
  1. package/css/generated/shared.css +1 -1
  2. package/dist/.translations/index.d.ts +6 -3
  3. package/dist/.translations/keys.js +6 -2
  4. package/dist/_virtual/_rolldown/runtime.js +1 -2
  5. package/dist/generate-file.d.ts +1 -3
  6. package/dist/generate-file.js +3 -3
  7. package/dist/i18n.d.ts +1 -3
  8. package/dist/i18n.js +1 -2
  9. package/dist/index.browser.d.ts +0 -2
  10. package/dist/index.browser.js +1 -2
  11. package/dist/node_modules/.pnpm/fast-content-type-parse@4.0.1/node_modules/fast-content-type-parse/index.js +1 -2
  12. package/dist/node_modules/.pnpm/xml-js@1.6.11/node_modules/xml-js/lib/array-helper.js +1 -2
  13. package/dist/node_modules/.pnpm/xml-js@1.6.11/node_modules/xml-js/lib/js2xml.js +1 -2
  14. package/dist/node_modules/.pnpm/xml-js@1.6.11/node_modules/xml-js/lib/options-helper.js +1 -2
  15. package/dist/operation.d.ts +1 -3
  16. package/dist/operation.js +3 -4
  17. package/dist/packages/shared-api/dist/.translations/index.d.ts +2 -5
  18. package/dist/packages/shared-api/dist/.translations/keys.js +2 -2
  19. package/dist/packages/shared-api/dist/auto-anchor/index.js +1 -2
  20. package/dist/packages/shared-api/dist/codegen.d.ts +0 -3
  21. package/dist/packages/shared-api/dist/codegen.js +1 -2
  22. package/dist/packages/shared-api/dist/components/badge.js +1 -2
  23. package/dist/packages/shared-api/dist/components/collapsible.js +1 -2
  24. package/dist/packages/shared-api/dist/components/copy-typescript.js +1 -2
  25. package/dist/packages/shared-api/dist/components/defaults.d.ts +1 -4
  26. package/dist/packages/shared-api/dist/components/defaults.js +1 -2
  27. package/dist/packages/shared-api/dist/components/dialog.js +1 -2
  28. package/dist/packages/shared-api/dist/components/example.js +3 -3
  29. package/dist/packages/shared-api/dist/components/playground/fields.js +28 -10
  30. package/dist/packages/shared-api/dist/components/playground/json-editor.js +1 -2
  31. package/dist/packages/shared-api/dist/components/playground/panels.js +2 -3
  32. package/dist/packages/shared-api/dist/components/playground/param-input.js +1 -2
  33. package/dist/packages/shared-api/dist/components/playground/result.js +1 -2
  34. package/dist/packages/shared-api/dist/components/playground/schema.js +1 -2
  35. package/dist/packages/shared-api/dist/components/playground/server-select.js +2 -3
  36. package/dist/packages/shared-api/dist/components/schema/client.d.ts +1 -4
  37. package/dist/packages/shared-api/dist/components/schema/client.js +3 -2
  38. package/dist/packages/shared-api/dist/components/schema/index.d.ts +0 -3
  39. package/dist/packages/shared-api/dist/components/schema/index.js +1 -2
  40. package/dist/packages/shared-api/dist/components/segmented.js +1 -2
  41. package/dist/packages/shared-api/dist/components/select-tab.js +1 -2
  42. package/dist/packages/shared-api/dist/components/select.js +1 -2
  43. package/dist/packages/shared-api/dist/components/spinner.js +1 -2
  44. package/dist/packages/shared-api/dist/i18n.js +1 -2
  45. package/dist/packages/shared-api/dist/source.d.ts +1 -4
  46. package/dist/packages/shared-api/dist/source.js +1 -2
  47. package/dist/packages/shared-api/dist/utils/document-cache.js +1 -2
  48. package/dist/packages/shared-api/dist/utils/id-to-title.js +1 -2
  49. package/dist/packages/shared-api/dist/utils/is-plain-object.js +1 -2
  50. package/dist/packages/shared-api/dist/utils/url.js +1 -2
  51. package/dist/packages/shared-api/dist/utils/use-query.js +1 -2
  52. package/dist/packages/shared-api/dist/utils/use-server-store.js +1 -2
  53. package/dist/playground/auth.d.ts +8 -8
  54. package/dist/playground/auth.js +90 -59
  55. package/dist/playground/fetcher.d.ts +1 -3
  56. package/dist/playground/fetcher.js +1 -2
  57. package/dist/playground/use-playground.d.ts +1 -3
  58. package/dist/playground/use-playground.js +3 -4
  59. package/dist/requests/generators/all.d.ts +1 -3
  60. package/dist/requests/generators/all.js +1 -2
  61. package/dist/requests/generators/csharp.d.ts +1 -3
  62. package/dist/requests/generators/csharp.js +1 -2
  63. package/dist/requests/generators/curl.d.ts +1 -3
  64. package/dist/requests/generators/curl.js +1 -2
  65. package/dist/requests/generators/go.d.ts +1 -3
  66. package/dist/requests/generators/go.js +1 -2
  67. package/dist/requests/generators/index.d.ts +1 -3
  68. package/dist/requests/generators/index.js +1 -2
  69. package/dist/requests/generators/java.d.ts +1 -3
  70. package/dist/requests/generators/java.js +1 -2
  71. package/dist/requests/generators/javascript.d.ts +1 -3
  72. package/dist/requests/generators/javascript.js +1 -2
  73. package/dist/requests/generators/python.d.ts +1 -3
  74. package/dist/requests/generators/python.js +1 -2
  75. package/dist/requests/generators/rust.d.ts +1 -3
  76. package/dist/requests/generators/rust.js +1 -2
  77. package/dist/requests/media/adapter.d.ts +0 -2
  78. package/dist/requests/media/adapter.js +1 -2
  79. package/dist/requests/media/encode.d.ts +1 -3
  80. package/dist/requests/media/encode.js +1 -2
  81. package/dist/requests/media/resolve-adapter.d.ts +1 -3
  82. package/dist/requests/media/resolve-adapter.js +1 -2
  83. package/dist/requests/string-utils.js +1 -2
  84. package/dist/requests/types.d.ts +1 -3
  85. package/dist/server/index.d.ts +0 -2
  86. package/dist/server/index.js +1 -2
  87. package/dist/server/oauth.d.ts +1 -3
  88. package/dist/server/oauth.js +7 -11
  89. package/dist/server/proxy.d.ts +0 -2
  90. package/dist/server/proxy.js +8 -4
  91. package/dist/types/openapi.d.ts +1 -3
  92. package/dist/types.d.ts +1 -3
  93. package/dist/ui/base.d.ts +1 -3
  94. package/dist/ui/base.js +1 -2
  95. package/dist/ui/components/codeblock.js +1 -2
  96. package/dist/ui/components/endpoint.js +1 -2
  97. package/dist/ui/components/heading.js +1 -2
  98. package/dist/ui/components/markdown.js +1 -2
  99. package/dist/ui/components/method-label.js +1 -2
  100. package/dist/ui/components/schema.js +1 -2
  101. package/dist/ui/index.d.ts +0 -2
  102. package/dist/ui/index.js +1 -2
  103. package/dist/ui/operation/index.js +29 -16
  104. package/dist/ui/operation/usage-tabs.js +13 -6
  105. package/dist/ui/playground/client.d.ts +5 -4
  106. package/dist/ui/playground/client.js +5 -6
  107. package/dist/ui/playground/components/auth.js +4 -5
  108. package/dist/ui/playground/components/request-panel.d.ts +8 -0
  109. package/dist/ui/playground/components/request-panel.js +17 -11
  110. package/dist/ui/playground/components/response-panel.js +1 -2
  111. package/dist/ui/playground/components/result-display.d.ts +1 -3
  112. package/dist/ui/playground/components/result-display.js +1 -2
  113. package/dist/ui/playground/components/server-select.js +1 -2
  114. package/dist/ui/playground/components/url-bar.js +1 -2
  115. package/dist/ui/scalar/client.js +1 -2
  116. package/dist/ui/scalar/index.d.ts +1 -3
  117. package/dist/ui/scalar/index.js +1 -2
  118. package/dist/utils/create-page.d.ts +1 -3
  119. package/dist/utils/create-page.js +2 -4
  120. package/dist/utils/document/dereference.d.ts +1 -3
  121. package/dist/utils/document/dereference.js +1 -2
  122. package/dist/utils/document/load.js +1 -2
  123. package/dist/utils/get-example-requests.js +2 -3
  124. package/dist/utils/pages/builder.d.ts +0 -2
  125. package/dist/utils/pages/builder.js +1 -2
  126. package/dist/utils/pages/preset-auto.d.ts +0 -2
  127. package/dist/utils/pages/preset-auto.js +1 -2
  128. package/dist/utils/pages/to-static-data.d.ts +1 -3
  129. package/dist/utils/pages/to-static-data.js +1 -2
  130. package/dist/utils/pages/to-text.d.ts +1 -3
  131. package/dist/utils/pages/to-text.js +1 -2
  132. package/dist/utils/schema.js +1 -2
  133. package/dist/utils/use-server.d.ts +2 -4
  134. package/dist/utils/use-server.js +3 -3
  135. package/package.json +3 -3
@@ -1,18 +1,17 @@
1
1
  "use client";
2
2
  import { useServer } from "../utils/use-server.js";
3
- import { useQuery } from "../packages/shared-api/dist/utils/use-query.js";
3
+ import { useOpenAPI } from "../utils/create-page.js";
4
4
  import { useOperation } from "../operation.js";
5
5
  import { proxied } from "./fetcher.js";
6
- import { useOpenAPI } from "../utils/create-page.js";
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 { useListener, useStf } from "@fumari/stf";
8
+ import { DataEngine, useListener } from "@fumari/stf";
10
9
  import { arrayStartsWith, objectGet } from "@fumari/stf/lib/utils";
11
- //#region src/playground/auth.tsx
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) document.cookie = `fumadocs-openapi-oauth=${encodeURIComponent(window.location.pathname)}; path=/`;
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
- const AuthContext = createContext(null);
260
- /**
261
- * The auth of page: the values of security schemes, and the flow that returned to it.
262
- */
263
- function usePlaygroundAuth() {
264
- const ctx = use(AuthContext);
265
- if (!ctx) throw new Error("Component must be used under <OpenAPIProvider />");
266
- return ctx;
267
- }
268
- function PlaygroundAuthProvider({ children }) {
269
- const stf = useStf({ defaultValues: { auth: {} } });
270
- const returned = useSyncExternalStore(subscribeNever, getReturnedFlow, () => void 0);
271
- const query = useQuery(async (flow) => {
272
- const result = finishOAuthFlow(flow.url, flow.data);
273
- if (result !== void 0) window.history.replaceState(null, "", window.location.pathname);
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
- if (token === void 0) return;
277
- stf.dataEngine.update(["auth", flow.scheme], token);
278
- const { client_id, client_secret, client_auth } = flow.data;
279
- const info = typeof result === "string" ? {
280
- type: "implicit",
281
- client_id,
282
- token
283
- } : {
284
- type: "authorization_code",
285
- client_id,
286
- client_secret,
287
- client_auth,
288
- token
289
- };
290
- return { [flow.scheme]: info };
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
- return /* @__PURE__ */ jsx(AuthContext, {
300
- value: useMemo(() => ({
301
- stf,
302
- returned,
303
- origin: returned?.origin,
304
- isLoading: query.isLoading,
305
- error: query.error,
306
- store: query.data ?? {}
307
- }), [
308
- stf,
309
- returned,
310
- query.isLoading,
311
- query.error,
312
- query.data
313
- ]),
314
- children
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
- //#endregion
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
- //#region src/playground/fetcher.ts
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 { encodeRequestData } from "../requests/media/encode.js";
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
- //#region src/playground/use-playground.tsx
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
- //#region src/requests/generators/all.d.ts
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
- //#region src/requests/generators/all.ts
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,4 +1,2 @@
1
1
  import { CodeUsageGenerator } from "./index.js";
2
- //#region src/requests/generators/csharp.d.ts
3
- export declare const csharp: CodeUsageGenerator;
4
- //#endregion
2
+ export declare const csharp: CodeUsageGenerator;
@@ -1,6 +1,6 @@
1
1
  import { cookieString, doubleQuote } from "../string-utils.js";
2
2
  import { generateBodyExample } from "../media/adapter.js";
3
- //#region src/requests/generators/csharp.ts
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,4 +1,2 @@
1
1
  import { CodeUsageGenerator } from "./index.js";
2
- //#region src/requests/generators/curl.d.ts
3
- export declare const curl: CodeUsageGenerator;
4
- //#endregion
2
+ export declare const curl: CodeUsageGenerator;
@@ -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
- //#region src/requests/generators/curl.ts
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,4 +1,2 @@
1
1
  import { CodeUsageGenerator } from "./index.js";
2
- //#region src/requests/generators/go.d.ts
3
- export declare const go: CodeUsageGenerator;
4
- //#endregion
2
+ export declare const go: CodeUsageGenerator;
@@ -1,6 +1,6 @@
1
1
  import { cookieString, doubleQuote, indent } from "../string-utils.js";
2
2
  import { generateBodyExample } from "../media/adapter.js";
3
- //#region src/requests/generators/go.ts
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
- //#region src/requests/generators/index.ts
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,4 +1,2 @@
1
1
  import { CodeUsageGenerator } from "./index.js";
2
- //#region src/requests/generators/java.d.ts
3
- export declare const java: CodeUsageGenerator;
4
- //#endregion
2
+ export declare const java: CodeUsageGenerator;
@@ -1,6 +1,6 @@
1
1
  import { cookieString, doubleQuote, indent, inputToString } from "../string-utils.js";
2
2
  import { generateBodyExample } from "../media/adapter.js";
3
- //#region src/requests/generators/java.ts
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,4 +1,2 @@
1
1
  import { CodeUsageGenerator } from "./index.js";
2
- //#region src/requests/generators/javascript.d.ts
3
- export declare const javascript: CodeUsageGenerator;
4
- //#endregion
2
+ export declare const javascript: CodeUsageGenerator;
@@ -1,6 +1,6 @@
1
1
  import { cookieString, doubleQuote, indent } from "../string-utils.js";
2
2
  import { generateBodyExample } from "../media/adapter.js";
3
- //#region src/requests/generators/javascript.ts
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,4 +1,2 @@
1
1
  import { CodeUsageGenerator } from "./index.js";
2
- //#region src/requests/generators/python.d.ts
3
- export declare const python: CodeUsageGenerator;
4
- //#endregion
2
+ export declare const python: CodeUsageGenerator;
@@ -1,6 +1,6 @@
1
1
  import { doubleQuote } from "../string-utils.js";
2
2
  import { generateBodyExample } from "../media/adapter.js";
3
- //#region src/requests/generators/python.ts
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,4 +1,2 @@
1
1
  import { CodeUsageGenerator } from "./index.js";
2
- //#region src/requests/generators/rust.d.ts
3
- export declare const rust: CodeUsageGenerator;
4
- //#endregion
2
+ export declare const rust: CodeUsageGenerator;
@@ -1,6 +1,6 @@
1
1
  import { cookieString, doubleQuote, indent } from "../string-utils.js";
2
2
  import { generateBodyExample } from "../media/adapter.js";
3
- //#region src/requests/generators/rust.ts
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
- //#region src/requests/media/adapter.ts
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
- //#region src/requests/media/encode.ts
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
- //#region src/requests/media/resolve-adapter.ts
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
- //#region src/requests/string-utils.ts
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 };
@@ -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
+ }
@@ -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 };
@@ -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
- //#region src/server/index.tsx
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 };
@@ -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;
@@ -1,17 +1,13 @@
1
- //#region src/server/oauth.ts
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
- const page = /(?:^|;\s*)fumadocs-openapi-oauth=([^;]+)/.exec(req.headers.get("cookie") ?? "");
8
- const target = page && URL.parse(decodeURIComponent(page[1]), "http://localhost");
9
- if (!target || target.origin !== "http://localhost") return new Response(null, { status: 400 });
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 };