fumadocs-openapi 11.4.2 → 12.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/css/generated/shared.css +1 -1
  2. package/css/preset.css +0 -1
  3. package/dist/_virtual/_rolldown/runtime.js +10 -1
  4. package/dist/generate-file.d.ts +2 -2
  5. package/dist/generate-file.js +1 -1
  6. package/dist/i18n.d.ts +6 -8
  7. package/dist/i18n.js +2 -17
  8. package/dist/index.browser.d.ts +13 -0
  9. package/dist/index.browser.js +11 -0
  10. package/dist/index.d.ts +5 -2
  11. package/dist/index.js +3 -1
  12. package/dist/operation.d.ts +133 -0
  13. package/dist/operation.js +296 -0
  14. package/dist/packages/shared-api/dist/.translations/index.d.ts +29 -0
  15. package/dist/packages/shared-api/dist/.translations/keys.js +28 -0
  16. package/dist/packages/shared-api/dist/auto-anchor/client.js +20 -0
  17. package/dist/packages/shared-api/dist/auto-anchor/index.js +17 -0
  18. package/dist/packages/shared-api/dist/codegen.d.ts +42 -0
  19. package/dist/packages/shared-api/dist/codegen.js +35 -0
  20. package/dist/packages/shared-api/dist/components/accordion.js +71 -0
  21. package/dist/packages/shared-api/dist/components/badge.js +21 -0
  22. package/dist/packages/shared-api/dist/components/collapsible.d.ts +7 -0
  23. package/dist/packages/shared-api/dist/components/collapsible.js +16 -0
  24. package/dist/packages/shared-api/dist/components/defaults.d.ts +20 -0
  25. package/dist/packages/shared-api/dist/components/defaults.js +70 -0
  26. package/dist/packages/shared-api/dist/components/dialog.js +55 -0
  27. package/dist/packages/shared-api/dist/components/input.js +14 -0
  28. package/dist/packages/shared-api/dist/components/label.js +11 -0
  29. package/dist/packages/shared-api/dist/components/playground/inputs.js +439 -0
  30. package/dist/packages/shared-api/dist/components/playground/schema.js +112 -0
  31. package/dist/packages/shared-api/dist/components/popover.js +23 -0
  32. package/dist/packages/shared-api/dist/components/schema/client.d.ts +12 -0
  33. package/dist/packages/shared-api/dist/components/schema/client.js +508 -0
  34. package/dist/packages/shared-api/dist/components/schema/index.d.ts +9 -0
  35. package/dist/packages/shared-api/dist/components/schema/index.js +28 -0
  36. package/dist/packages/shared-api/dist/components/select-tab.js +54 -0
  37. package/dist/packages/shared-api/dist/components/select.js +70 -0
  38. package/dist/packages/shared-api/dist/components/spinner.js +14 -0
  39. package/dist/packages/shared-api/dist/i18n.d.ts +3 -0
  40. package/dist/packages/shared-api/dist/i18n.js +7 -0
  41. package/dist/packages/shared-api/dist/utils/cn.js +2 -0
  42. package/dist/packages/shared-api/dist/utils/id-to-title.js +12 -0
  43. package/dist/packages/shared-api/dist/utils/is-plain-object.js +8 -0
  44. package/dist/packages/shared-api/dist/utils/merge-refs.js +11 -0
  45. package/dist/packages/shared-api/dist/utils/url.js +13 -0
  46. package/dist/{utils → packages/shared-api/dist/utils}/use-query.js +2 -1
  47. package/dist/packages/shared-api/dist/utils/use-server-store.js +56 -0
  48. package/dist/playground/auth.d.ts +37 -0
  49. package/dist/playground/auth.js +216 -21
  50. package/dist/playground/fetcher.d.ts +11 -1
  51. package/dist/playground/index.d.ts +3 -0
  52. package/dist/playground/index.js +3 -0
  53. package/dist/requests/generators/csharp.js +0 -1
  54. package/dist/requests/generators/go.js +0 -1
  55. package/dist/requests/generators/index.d.ts +4 -4
  56. package/dist/requests/generators/index.js +2 -2
  57. package/dist/requests/generators/java.js +0 -1
  58. package/dist/requests/generators/javascript.js +0 -1
  59. package/dist/requests/generators/python.js +0 -1
  60. package/dist/requests/generators/rust.js +0 -1
  61. package/dist/requests/index.d.ts +4 -0
  62. package/dist/requests/index.js +3 -0
  63. package/dist/requests/media/adapter.d.ts +1 -0
  64. package/dist/requests/media/encode.d.ts +7 -2
  65. package/dist/requests/media/resolve-adapter.d.ts +20 -0
  66. package/dist/server/index.d.ts +4 -7
  67. package/dist/server/index.js +1 -7
  68. package/dist/types.d.ts +0 -14
  69. package/dist/ui/base.d.ts +3 -2
  70. package/dist/ui/base.js +15 -166
  71. package/dist/ui/components/codeblock.js +3 -10
  72. package/dist/ui/components/heading.js +10 -19
  73. package/dist/ui/components/markdown.js +4 -6
  74. package/dist/ui/components/method-label.js +2 -17
  75. package/dist/ui/components/schema.js +28 -0
  76. package/dist/ui/index.d.ts +7 -198
  77. package/dist/ui/index.js +1 -3
  78. package/dist/ui/operation/index.js +143 -231
  79. package/dist/ui/operation/request-tabs.js +15 -23
  80. package/dist/ui/operation/response-tabs.js +9 -53
  81. package/dist/ui/operation/usage-tabs.js +35 -93
  82. package/dist/{playground → ui/playground}/client.d.ts +10 -21
  83. package/dist/ui/playground/client.js +432 -0
  84. package/dist/{playground → ui/playground}/components/oauth-dialog.js +27 -92
  85. package/dist/{playground → ui/playground}/components/result-display.d.ts +2 -2
  86. package/dist/{playground → ui/playground}/components/result-display.js +7 -7
  87. package/dist/{playground → ui/playground}/components/server-select.js +12 -13
  88. package/dist/{playground → ui/playground}/status-info.js +2 -2
  89. package/dist/{scalar → ui/scalar}/client.js +8 -6
  90. package/dist/{scalar → ui/scalar}/index.d.ts +2 -2
  91. package/dist/{scalar → ui/scalar}/index.js +3 -7
  92. package/dist/utils/create-page.d.ts +216 -0
  93. package/dist/utils/create-page.js +221 -0
  94. package/dist/utils/document/dereference.d.ts +2 -2
  95. package/dist/utils/document/dereference.js +8 -3
  96. package/dist/utils/document/load.js +2 -2
  97. package/dist/utils/get-example-requests.js +11 -13
  98. package/dist/utils/pages/builder.d.ts +15 -2
  99. package/dist/utils/pages/builder.js +6 -6
  100. package/dist/utils/pages/preset-auto.d.ts +1 -1
  101. package/dist/utils/pages/preset-auto.js +3 -3
  102. package/dist/utils/pages/to-static-data.js +4 -4
  103. package/dist/utils/pages/to-text.d.ts +1 -1
  104. package/dist/utils/pages/to-text.js +3 -5
  105. package/dist/utils/schema.js +5 -5
  106. package/dist/utils/use-server.d.ts +24 -0
  107. package/dist/utils/use-server.js +57 -0
  108. package/package.json +31 -20
  109. package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.15/node_modules/@scalar/openapi-upgrader/dist/2.0-to-3.0/upgrade-from-two-to-three.js +0 -508
  110. package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.15/node_modules/@scalar/openapi-upgrader/dist/3.0-to-3.1/upgrade-from-three-to-three-one.js +0 -152
  111. package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.15/node_modules/@scalar/openapi-upgrader/dist/3.1-to-3.2/upgrade-from-three-one-to-three-two.js +0 -61
  112. package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.15/node_modules/@scalar/openapi-upgrader/dist/helpers/traverse.js +0 -25
  113. package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.15/node_modules/@scalar/openapi-upgrader/dist/upgrade.js +0 -15
  114. package/dist/playground/client.js +0 -574
  115. package/dist/ui/contexts/api.d.ts +0 -17
  116. package/dist/ui/contexts/api.js +0 -84
  117. package/dist/ui/create-client.d.ts +0 -9
  118. package/dist/ui/create-client.js +0 -7
  119. package/dist/ui/operation/context.d.ts +0 -15
  120. package/dist/ui/operation/context.js +0 -48
  121. package/dist/ui/operation/request-tabs.d.ts +0 -12
  122. package/dist/ui/operation/response-tabs.d.ts +0 -30
  123. package/dist/utils/get-example-requests.d.ts +0 -11
  124. package/dist/utils/schema.d.ts +0 -3
  125. package/dist/utils/storage-key.js +0 -15
@@ -1,18 +1,16 @@
1
1
  import { getPreferredType, pickExample } from "./schema.js";
2
2
  import { encodeRequestData } from "../requests/media/encode.js";
3
- import { dereferenceShallow } from "@fumadocs/api-docs/schema/dereference";
4
3
  import { getRaw } from "@scalar/json-magic/magic-proxy";
5
- import { sample } from "@fumadocs/api-docs/schema/sample";
4
+ import { dereference, sample } from "@fumadocs/json-schema";
6
5
  //#region src/utils/get-example-requests.ts
7
- function getExampleRequests({ path, method, ctx, operation, pathItem }) {
8
- const requestBody = dereferenceShallow(operation.requestBody);
6
+ function getExampleRequests({ path, method, mediaAdapters, operation, parameters }) {
7
+ const requestBody = dereference(operation.requestBody);
9
8
  const media = requestBody?.content ? getPreferredType(requestBody.content) : null;
10
- const bodyOfType = media ? dereferenceShallow(requestBody.content[media]) : null;
11
- const parameters = [...operation.parameters ?? [], ...pathItem.parameters ?? []].map(dereferenceShallow);
9
+ const bodyOfType = media ? dereference(requestBody.content[media]) : null;
12
10
  if (bodyOfType?.examples) {
13
11
  const result = [];
14
12
  for (const [key, item] of Object.entries(bodyOfType.examples)) {
15
- const { summary, description } = dereferenceShallow(item);
13
+ const { summary, description } = dereference(item);
16
14
  const data = getRequestData({
17
15
  path,
18
16
  body: requestBody,
@@ -25,7 +23,7 @@ function getExampleRequests({ path, method, ctx, operation, pathItem }) {
25
23
  name: summary || key,
26
24
  description,
27
25
  data,
28
- encoded: encodeRequestData(data, ctx.mediaAdapters, parameters)
26
+ encoded: encodeRequestData(data, mediaAdapters, parameters)
29
27
  });
30
28
  }
31
29
  if (result.length > 0) return result;
@@ -36,13 +34,13 @@ function getExampleRequests({ path, method, ctx, operation, pathItem }) {
36
34
  method,
37
35
  parameters
38
36
  });
39
- const schema = dereferenceShallow(bodyOfType?.schema);
37
+ const schema = dereference(bodyOfType?.schema);
40
38
  return [{
41
39
  id: "_default",
42
40
  name: "Default",
43
41
  description: typeof schema === "object" ? schema.description : void 0,
44
42
  data,
45
- encoded: encodeRequestData(data, ctx.mediaAdapters, parameters)
43
+ encoded: encodeRequestData(data, mediaAdapters, parameters)
46
44
  }];
47
45
  }
48
46
  function getRequestData({ method, path, parameters, sampleKey, body }) {
@@ -59,7 +57,7 @@ function getRequestData({ method, path, parameters, sampleKey, body }) {
59
57
  if (param.schema) value = sample(param.schema);
60
58
  else if (param.content) {
61
59
  const type = getPreferredType(param.content);
62
- const content = type ? dereferenceShallow(param.content[type]) : void 0;
60
+ const content = type ? dereference(param.content[type]) : void 0;
63
61
  if (!content || !content.schema) throw new Error(`Cannot find "${param.name}" parameter info for media type "${type}" in ${path} ${method}`);
64
62
  value = sample(content.schema);
65
63
  }
@@ -81,8 +79,8 @@ function getRequestData({ method, path, parameters, sampleKey, body }) {
81
79
  const type = getPreferredType(body.content);
82
80
  if (!type) throw new Error(`Cannot find body schema for ${path} ${method}: missing media type`);
83
81
  result.bodyMediaType = type;
84
- const bodyOfType = dereferenceShallow(body.content[type]);
85
- if (bodyOfType.examples && sampleKey) result.body = getRaw(dereferenceShallow(bodyOfType.examples[sampleKey]).value);
82
+ const bodyOfType = dereference(body.content[type]);
83
+ if (bodyOfType.examples && sampleKey) result.body = getRaw(dereference(bodyOfType.examples[sampleKey]).value);
86
84
  else if (bodyOfType.example) result.body = getRaw(bodyOfType.example);
87
85
  else result.body = sample(bodyOfType?.schema ?? {}, {
88
86
  skipReadOnly: method !== "get",
@@ -1,5 +1,5 @@
1
1
  import { Document, HttpMethods, OperationObject, PathItemObject, TagObject } from "../../types.js";
2
- import { NoReferenceSwallow } from "@fumadocs/api-docs/schema";
2
+ import { DereferencedShallow } from "@fumadocs/json-schema";
3
3
  //#region src/utils/pages/builder.d.ts
4
4
  interface BaseEntry {
5
5
  path: string;
@@ -59,7 +59,7 @@ export interface PagesBuilder {
59
59
  id: string;
60
60
  /** bundled OpenAPI document (not dereferenced) */
61
61
  document: Document;
62
- dereferenceShallow: <T>(schema: T) => NoReferenceSwallow<T>;
62
+ dereferenceShallow: <T>(schema: T) => DereferencedShallow<T>;
63
63
  /**
64
64
  * add output entry.
65
65
  */
@@ -109,4 +109,17 @@ export interface GeneratedPageProps {
109
109
  operations?: OperationItem[];
110
110
  webhooks?: WebhookItem[];
111
111
  }
112
+ export type OpenAPIPageProps = OpenAPIPageProps_Spec | OpenAPIPageProps_Preloaded;
113
+ export type OpenAPIPageProps_Spec = Omit<GeneratedPageProps, 'document'> & {
114
+ payload: {
115
+ bundled: Document;
116
+ proxyUrl?: string;
117
+ };
118
+ };
119
+ export type OpenAPIPageProps_Preloaded = GeneratedPageProps & {
120
+ preloaded: {
121
+ docs: Record<string, Document>;
122
+ proxyUrl?: string;
123
+ };
124
+ };
112
125
  //#endregion
@@ -1,7 +1,7 @@
1
+ import { idToTitle } from "../../packages/shared-api/dist/utils/id-to-title.js";
1
2
  import { getTagDisplayName, methodKeys } from "../schema.js";
2
- import { idToTitle } from "@fumadocs/api-docs/utils/id-to-title";
3
- import { dereferenceShallow } from "@fumadocs/api-docs/schema/dereference";
4
3
  import { createMagicProxy } from "@scalar/json-magic/magic-proxy";
4
+ import { dereference } from "@fumadocs/json-schema";
5
5
  //#region src/utils/pages/builder.ts
6
6
  function fromSchema(schemaId, bundled, config) {
7
7
  const files = [];
@@ -10,7 +10,7 @@ function fromSchema(schemaId, bundled, config) {
10
10
  toPages({
11
11
  id: schemaId,
12
12
  document,
13
- dereferenceShallow: (s) => dereferenceShallow(s),
13
+ dereferenceShallow: (s) => dereference(s),
14
14
  create(entry) {
15
15
  files.push(entry);
16
16
  },
@@ -31,7 +31,7 @@ function fromSchema(schemaId, bundled, config) {
31
31
  }
32
32
  }
33
33
  for (const [name, _pathItem] of Object.entries(document.webhooks ?? {})) {
34
- const pathItem = dereferenceShallow(_pathItem);
34
+ const pathItem = dereference(_pathItem);
35
35
  if (!pathItem) continue;
36
36
  for (const methodKey of methodKeys) {
37
37
  if (!pathItem[methodKey]) continue;
@@ -52,7 +52,7 @@ function fromSchema(schemaId, bundled, config) {
52
52
  }).join("/");
53
53
  },
54
54
  fromExtractedWebhook(item) {
55
- const pathItem = dereferenceShallow(document.webhooks?.[item.name]);
55
+ const pathItem = dereference(document.webhooks?.[item.name]);
56
56
  if (!pathItem) return;
57
57
  const operation = pathItem?.[item.method];
58
58
  if (!operation) return;
@@ -65,7 +65,7 @@ function fromSchema(schemaId, bundled, config) {
65
65
  };
66
66
  },
67
67
  fromExtractedOperation(item) {
68
- const pathItem = dereferenceShallow(document.paths?.[item.path]);
68
+ const pathItem = dereference(document.paths?.[item.path]);
69
69
  if (!pathItem) return;
70
70
  const operation = pathItem?.[item.method];
71
71
  if (!operation) return;
@@ -1,5 +1,5 @@
1
- import { OperationOutput, PageOutput, PagesBuilder, PagesBuilderConfig, WebhookOutput } from "./builder.js";
2
1
  import { DistributiveOmit } from "../../types.js";
2
+ import { OperationOutput, PageOutput, PagesBuilder, PagesBuilderConfig, WebhookOutput } from "./builder.js";
3
3
  //#region src/utils/pages/preset-auto.d.ts
4
4
  interface OperationConfig extends BaseConfig {
5
5
  /**
@@ -1,6 +1,6 @@
1
1
  import { getTagDisplayName } from "../schema.js";
2
+ import { dereference } from "@fumadocs/json-schema";
2
3
  import * as path$1 from "node:path";
3
- import { dereferenceShallow } from "@fumadocs/api-docs/schema/dereference";
4
4
  //#region src/utils/pages/preset-auto.ts
5
5
  function createAutoPreset(options) {
6
6
  if (options.per === "custom") return options;
@@ -22,7 +22,7 @@ function createAutoPreset(options) {
22
22
  if (algorithm === "v2" && operation.operationId) return operation.operationId;
23
23
  return path$1.join(this.routePathToFilePath(result.item.path), result.item.method.toLowerCase());
24
24
  }
25
- const hook = dereferenceShallow(this.document.webhooks[result.item.name])[result.item.method];
25
+ const hook = dereference(this.document.webhooks[result.item.name])[result.item.method];
26
26
  if (algorithm === "v2" && hook.operationId) return hook.operationId;
27
27
  return slugify(result.item.name);
28
28
  };
@@ -83,7 +83,7 @@ function createAutoPreset(options) {
83
83
  break;
84
84
  }
85
85
  case "tag": {
86
- const operation = entry.type === "operation" ? dereferenceShallow(doc.paths?.[entry.item.path])?.[entry.item.method] : dereferenceShallow(doc.webhooks?.[entry.item.name])?.[entry.item.method];
86
+ const operation = entry.type === "operation" ? dereference(doc.paths?.[entry.item.path])?.[entry.item.method] : dereference(doc.webhooks?.[entry.item.name])?.[entry.item.method];
87
87
  const tags = [];
88
88
  for (const name of operation?.tags ?? []) {
89
89
  const kind = docTags.get(name)?.kind;
@@ -1,6 +1,6 @@
1
- import { idToTitle } from "@fumadocs/api-docs/utils/id-to-title";
2
- import { dereferenceShallow } from "@fumadocs/api-docs/schema/dereference";
1
+ import { idToTitle } from "../../packages/shared-api/dist/utils/id-to-title.js";
3
2
  import { createMagicProxy } from "@scalar/json-magic/magic-proxy";
3
+ import { dereference } from "@fumadocs/json-schema";
4
4
  import Slugger from "github-slugger";
5
5
  //#region src/utils/pages/to-static-data.ts
6
6
  const proxyCache = /* @__PURE__ */ new WeakMap();
@@ -36,12 +36,12 @@ function toStaticData(page, doc) {
36
36
  });
37
37
  }
38
38
  for (const item of page.operations ?? []) {
39
- const operation = dereferenceShallow(proxied.paths?.[item.path])?.[item.method];
39
+ const operation = dereference(proxied.paths?.[item.path])?.[item.method];
40
40
  if (!operation) continue;
41
41
  pathItem(operation, item.path);
42
42
  }
43
43
  for (const item of page.webhooks ?? []) {
44
- const webhook = dereferenceShallow(proxied.webhooks?.[item.name])?.[item.method];
44
+ const webhook = dereference(proxied.webhooks?.[item.name])?.[item.method];
45
45
  if (!webhook) continue;
46
46
  pathItem(webhook, item.name);
47
47
  }
@@ -1,5 +1,5 @@
1
- import "./builder.js";
2
1
  import { TagObject } from "../../types.js";
2
+ import "./builder.js";
3
3
  //#region src/utils/pages/to-text.d.ts
4
4
  export interface PagesToTextOptions {
5
5
  /**
@@ -1,6 +1,6 @@
1
+ import { doubleQuote } from "../../requests/string-utils.js";
1
2
  import { getPageProps } from "./builder.js";
2
3
  import { toStaticData } from "./to-static-data.js";
3
- import { doubleQuote } from "../../requests/string-utils.js";
4
4
  import { stringify } from "yaml";
5
5
  //#region src/utils/pages/to-text.ts
6
6
  function toText(entry, doc, options = {}) {
@@ -61,13 +61,11 @@ function pageContent({ showTitle, showDescription, document, webhooks, operation
61
61
  if (showTitle) propStrs.push(`showTitle`);
62
62
  if (showDescription) propStrs.push(`showDescription`);
63
63
  return `export default function Layout(props) {
64
- const { APIPage, OpenAPIPage } = props.components ?? {};
65
- // "APIPage" is the old name from v10, this allows both for backward compatibility
66
- const Comp = OpenAPIPage ?? APIPage;
64
+ const { OpenAPIPage } = props.components ?? {};
67
65
  return (
68
66
  <>
69
67
  {props.children}
70
- <Comp ${propStrs.join(" ")} />
68
+ <OpenAPIPage ${propStrs.join(" ")} />
71
69
  </>
72
70
  );
73
71
  }`;
@@ -1,6 +1,6 @@
1
- import { idToTitle } from "@fumadocs/api-docs/utils/id-to-title";
2
- import { dereferenceShallow } from "@fumadocs/api-docs/schema/dereference";
1
+ import { idToTitle } from "../packages/shared-api/dist/utils/id-to-title.js";
3
2
  import { getRaw } from "@scalar/json-magic/magic-proxy";
3
+ import { dereference } from "@fumadocs/json-schema";
4
4
  //#region src/utils/schema.ts
5
5
  const methodKeys = [
6
6
  "get",
@@ -23,16 +23,16 @@ function pickExample(value) {
23
23
  if (value.example !== void 0) return getRaw(value.example);
24
24
  if (value.content) {
25
25
  const type = getPreferredType(value.content);
26
- const content = type ? dereferenceShallow(value.content[type]) : void 0;
26
+ const content = type ? dereference(value.content[type]) : void 0;
27
27
  if (type && content) {
28
28
  const example = value.examples?.[type];
29
- const out = (example !== void 0 ? getRaw(dereferenceShallow(example).value) : void 0) ?? pickExample(content);
29
+ const out = (example !== void 0 ? getRaw(dereference(example).value) : void 0) ?? pickExample(content);
30
30
  if (out !== void 0) return out;
31
31
  }
32
32
  }
33
33
  if (value.examples) {
34
34
  const examples = Object.values(value.examples);
35
- if (examples.length > 0) return getRaw(dereferenceShallow(examples[0]).value);
35
+ if (examples.length > 0) return getRaw(dereference(examples[0]).value);
36
36
  }
37
37
  }
38
38
  //#endregion
@@ -0,0 +1,24 @@
1
+ import { ServerObject } from "../types.js";
2
+ import { ReactNode } from "react";
3
+ //#region src/utils/use-server.d.ts
4
+ export interface SelectedServer {
5
+ url: string;
6
+ name?: string;
7
+ variables: Record<string, string>;
8
+ }
9
+ interface ServerContextType {
10
+ servers?: ServerObject[];
11
+ server: SelectedServer | null;
12
+ /**
13
+ * The URL of `pathname` on the selected server, with the server variables resolved.
14
+ *
15
+ * It is resolved against the page origin, which also serves the request when no server is
16
+ * selected. On the server and during hydration the origin is unknown, so it is
17
+ * `https://example.com`.
18
+ */
19
+ resolveUrl: (pathname?: string) => string;
20
+ setServer: (value: string) => void;
21
+ setServerVariables: (value: Record<string, string>) => void;
22
+ }
23
+ export declare function useServer(): ServerContextType;
24
+ //#endregion
@@ -0,0 +1,57 @@
1
+ "use client";
2
+ import { useServerStore } from "../packages/shared-api/dist/utils/use-server-store.js";
3
+ import { joinURL, resolveServerUrl } from "../packages/shared-api/dist/utils/url.js";
4
+ import { createContext, use, useCallback, useMemo, useSyncExternalStore } from "react";
5
+ import { jsx } from "react/jsx-runtime";
6
+ //#region src/utils/use-server.tsx
7
+ const ServerContext = createContext(null);
8
+ const keyOfServer = (server) => server.url;
9
+ const noop = () => () => {};
10
+ function useServer() {
11
+ const ctx = use(ServerContext);
12
+ if (!ctx) throw new Error("Component must be used under <OpenAPIProvider />");
13
+ return ctx;
14
+ }
15
+ function ServerProvider({ servers, storageKeyPrefix, children }) {
16
+ const resolve = useCallback((url) => {
17
+ const server = servers?.find((item) => item.url === url);
18
+ if (!server) return null;
19
+ return {
20
+ name: server.name,
21
+ url,
22
+ variables: getDefaultValues(server)
23
+ };
24
+ }, [servers]);
25
+ const store = useServerStore({
26
+ storageKey: `${storageKeyPrefix}server-url`,
27
+ keyOf: keyOfServer,
28
+ resolve,
29
+ defaultKey: servers?.[0]?.url
30
+ });
31
+ const { server } = store;
32
+ const isClient = useSyncExternalStore(noop, () => true, () => false);
33
+ const resolveUrl = useCallback((pathname = "") => {
34
+ const base = isClient ? new URL(server ? resolveServerUrl(server.url, server.variables) : "/", window.location.origin).href : "https://example.com";
35
+ return pathname ? joinURL(base, pathname) : base;
36
+ }, [server, isClient]);
37
+ return /* @__PURE__ */ jsx(ServerContext, {
38
+ value: useMemo(() => ({
39
+ servers,
40
+ resolveUrl,
41
+ ...store
42
+ }), [
43
+ servers,
44
+ resolveUrl,
45
+ store
46
+ ]),
47
+ children
48
+ });
49
+ }
50
+ function getDefaultValues(server) {
51
+ const out = {};
52
+ if (!server.variables) return out;
53
+ for (const [k, v] of Object.entries(server.variables)) if (v.default !== void 0) out[k] = String(v.default);
54
+ return out;
55
+ }
56
+ //#endregion
57
+ export { ServerProvider, useServer };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "11.4.2",
3
+ "version": "12.0.0",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "Docs",
@@ -18,10 +18,19 @@
18
18
  "dist"
19
19
  ],
20
20
  "type": "module",
21
+ "sideEffects": [
22
+ "./css/**/*.css"
23
+ ],
21
24
  "exports": {
22
- ".": "./dist/index.js",
25
+ ".": {
26
+ "types": "./dist/index.d.ts",
27
+ "browser": "./dist/index.browser.js",
28
+ "import": "./dist/index.js"
29
+ },
23
30
  "./i18n": "./dist/i18n.js",
24
- "./playground/client": "./dist/playground/client.js",
31
+ "./operation": "./dist/operation.js",
32
+ "./playground": "./dist/playground/index.js",
33
+ "./requests": "./dist/requests/index.js",
25
34
  "./requests/generators": "./dist/requests/generators/index.js",
26
35
  "./requests/generators/all": "./dist/requests/generators/all.js",
27
36
  "./requests/generators/csharp": "./dist/requests/generators/csharp.js",
@@ -31,11 +40,11 @@
31
40
  "./requests/generators/javascript": "./dist/requests/generators/javascript.js",
32
41
  "./requests/generators/python": "./dist/requests/generators/python.js",
33
42
  "./requests/generators/rust": "./dist/requests/generators/rust.js",
34
- "./scalar": "./dist/scalar/index.js",
35
43
  "./server": "./dist/server/index.js",
36
44
  "./ui": "./dist/ui/index.js",
37
45
  "./ui/base": "./dist/ui/base.js",
38
- "./ui/create-client": "./dist/ui/create-client.js",
46
+ "./ui/playground/client": "./dist/ui/playground/client.js",
47
+ "./ui/scalar": "./dist/ui/scalar/index.js",
39
48
  "./package.json": "./package.json",
40
49
  "./css/*": "./css/*"
41
50
  },
@@ -43,36 +52,39 @@
43
52
  "access": "public"
44
53
  },
45
54
  "dependencies": {
55
+ "@base-ui/react": "^1.8.0",
46
56
  "@fuma-translate/react": "^1.0.2",
57
+ "@fumadocs/json-schema": "0.2.0",
47
58
  "@fumari/json-schema-ts": "^1.0.2",
48
- "@scalar/json-magic": "^0.13.4",
59
+ "@fumari/stf": "1.1.1",
60
+ "@scalar/json-magic": "^0.13.5",
61
+ "@scalar/openapi-upgrader": "^0.2.16",
49
62
  "chokidar": "^5.0.0",
50
63
  "class-variance-authority": "^0.7.1",
51
- "cn": "^0.2.6",
64
+ "cn": "^0.3.0",
52
65
  "github-slugger": "^2.0.0",
53
66
  "hast-util-to-jsx-runtime": "^2.3.6",
54
- "lucide-react": "^1.43.0",
67
+ "lucide-react": "^1.47.0",
55
68
  "remark": "^15.0.1",
56
69
  "remark-rehype": "^11.1.2",
57
70
  "shiki": "^4.4.3",
58
- "yaml": "^2.9.0",
59
- "@fumadocs/api-docs": "0.2.8",
60
- "@fumari/stf": "1.1.0"
71
+ "yaml": "^2.9.1"
61
72
  },
62
73
  "devDependencies": {
63
- "@scalar/api-client-react": "^2.0.44",
64
- "@scalar/openapi-upgrader": "^0.2.15",
74
+ "@scalar/api-client-react": "^2.0.45",
65
75
  "@tailwindcss/oxide": "^4.3.3",
66
- "@types/node": "26.5.0",
67
- "@types/react": "^19.2.18",
76
+ "@types/node": "26.6.1",
77
+ "@types/react": "^19.3.0",
78
+ "@types/react-dom": "^19.3.0",
68
79
  "fast-content-type-parse": "^4.0.0",
69
80
  "fuma-cli": "^0.1.1",
81
+ "fumadocs-core": "16.15.12",
82
+ "fumadocs-ui": "npm:@fumadocs/base-ui@16.15.12",
70
83
  "json-schema-typed": "^8.0.2",
84
+ "shared-api": "0.2.10",
85
+ "tsconfig": "0.0.0",
71
86
  "tsdown": "0.23.0",
72
- "xml-js": "^1.6.11",
73
- "fumadocs-core": "16.15.9",
74
- "fumadocs-ui": "npm:@fumadocs/base-ui@16.15.9",
75
- "tsconfig": "0.0.0"
87
+ "xml-js": "^1.6.11"
76
88
  },
77
89
  "peerDependencies": {
78
90
  "@scalar/api-client-react": "^2.0.20",
@@ -95,7 +107,6 @@
95
107
  }
96
108
  },
97
109
  "inlinedDependencies": {
98
- "@scalar/openapi-upgrader": "0.2.15",
99
110
  "fast-content-type-parse": "4.0.0",
100
111
  "xml-js": "1.6.11"
101
112
  },