fumadocs-openapi 9.7.3 → 10.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 (148) hide show
  1. package/dist/generate-file.d.ts +3 -4
  2. package/dist/generate-file.d.ts.map +1 -1
  3. package/dist/generate-file.js +4 -34
  4. package/dist/playground/client.d.ts +43 -22
  5. package/dist/playground/client.d.ts.map +1 -1
  6. package/dist/playground/client.js +68 -63
  7. package/dist/playground/{inputs.d.ts → components/inputs.d.ts} +1 -1
  8. package/dist/playground/components/inputs.d.ts.map +1 -0
  9. package/dist/playground/{inputs.js → components/inputs.js} +7 -7
  10. package/dist/playground/components/oauth-dialog.d.ts.map +1 -0
  11. package/dist/playground/components/server-select.d.ts.map +1 -0
  12. package/dist/{ui → playground/components}/server-select.js +6 -7
  13. package/dist/playground/index.d.ts +1 -4
  14. package/dist/playground/index.d.ts.map +1 -1
  15. package/dist/playground/index.js +5 -3
  16. package/dist/playground/lazy.d.ts +2 -0
  17. package/dist/playground/lazy.d.ts.map +1 -0
  18. package/dist/playground/lazy.js +3 -0
  19. package/dist/requests/generators/index.d.ts +2 -2
  20. package/dist/requests/generators/index.d.ts.map +1 -1
  21. package/dist/requests/generators/index.js +6 -0
  22. package/dist/requests/media/adapter.d.ts +0 -6
  23. package/dist/requests/media/adapter.d.ts.map +1 -1
  24. package/dist/scalar/index.d.ts +5 -0
  25. package/dist/scalar/index.d.ts.map +1 -1
  26. package/dist/scalar/index.js +14 -0
  27. package/dist/server/create.d.ts +11 -59
  28. package/dist/server/create.d.ts.map +1 -1
  29. package/dist/server/create.js +5 -14
  30. package/dist/server/source-api.d.ts +1 -1
  31. package/dist/server/source-api.d.ts.map +1 -1
  32. package/dist/server/source-api.js +1 -1
  33. package/dist/types.d.ts +12 -4
  34. package/dist/types.d.ts.map +1 -1
  35. package/dist/ui/api-page.d.ts +145 -0
  36. package/dist/ui/api-page.d.ts.map +1 -0
  37. package/dist/ui/api-page.js +120 -0
  38. package/dist/ui/client/index.d.ts +29 -0
  39. package/dist/ui/client/index.d.ts.map +1 -0
  40. package/dist/ui/client/index.js +4 -0
  41. package/dist/ui/client/storage-key.d.ts +9 -0
  42. package/dist/ui/client/storage-key.d.ts.map +1 -0
  43. package/dist/ui/client/storage-key.js +12 -0
  44. package/dist/ui/components/method-label.d.ts +1 -1
  45. package/dist/ui/contexts/api.d.ts +12 -10
  46. package/dist/ui/contexts/api.d.ts.map +1 -1
  47. package/dist/ui/contexts/api.js +53 -37
  48. package/dist/ui/contexts/api.lazy.d.ts +2 -0
  49. package/dist/ui/contexts/api.lazy.d.ts.map +1 -0
  50. package/dist/ui/contexts/api.lazy.js +3 -0
  51. package/dist/ui/contexts/operation.d.ts +20 -0
  52. package/dist/ui/contexts/operation.d.ts.map +1 -0
  53. package/dist/ui/contexts/operation.js +48 -0
  54. package/dist/ui/contexts/operation.lazy.d.ts +2 -0
  55. package/dist/ui/contexts/operation.lazy.d.ts.map +1 -0
  56. package/dist/ui/contexts/operation.lazy.js +3 -0
  57. package/dist/ui/index.d.ts +1 -8
  58. package/dist/ui/index.d.ts.map +1 -1
  59. package/dist/ui/index.js +1 -26
  60. package/dist/ui/{select-tabs.d.ts → operation/client.d.ts} +5 -2
  61. package/dist/ui/operation/client.d.ts.map +1 -0
  62. package/dist/ui/{client.js → operation/client.js} +18 -1
  63. package/dist/ui/operation/example-panel/client.d.ts +4 -0
  64. package/dist/ui/operation/example-panel/client.d.ts.map +1 -0
  65. package/dist/ui/operation/example-panel/client.js +50 -0
  66. package/dist/ui/operation/example-panel/index.d.ts +58 -0
  67. package/dist/ui/operation/example-panel/index.d.ts.map +1 -0
  68. package/dist/ui/operation/example-panel/index.js +140 -0
  69. package/dist/ui/operation/example-panel/lazy.d.ts +3 -0
  70. package/dist/ui/operation/example-panel/lazy.d.ts.map +1 -0
  71. package/dist/ui/operation/example-panel/lazy.js +4 -0
  72. package/dist/ui/operation/get-request-data.d.ts.map +1 -0
  73. package/dist/ui/operation/index.d.ts +11 -0
  74. package/dist/ui/operation/index.d.ts.map +1 -0
  75. package/dist/{render → ui}/operation/index.js +50 -24
  76. package/dist/ui/schema/client.d.ts +11 -0
  77. package/dist/ui/schema/client.d.ts.map +1 -0
  78. package/dist/{render → ui}/schema/client.js +22 -12
  79. package/dist/{render/schema/server.d.ts → ui/schema/index.d.ts} +5 -4
  80. package/dist/ui/schema/index.d.ts.map +1 -0
  81. package/dist/{render/schema/server.js → ui/schema/index.js} +11 -5
  82. package/dist/ui/schema/lazy.d.ts +2 -0
  83. package/dist/ui/schema/lazy.d.ts.map +1 -0
  84. package/dist/ui/schema/lazy.js +3 -0
  85. package/dist/utils/get-typescript-schema.d.ts +3 -2
  86. package/dist/utils/get-typescript-schema.d.ts.map +1 -1
  87. package/dist/utils/get-typescript-schema.js +12 -7
  88. package/dist/utils/lazy.d.ts +5 -0
  89. package/dist/utils/lazy.d.ts.map +1 -0
  90. package/dist/utils/lazy.js +12 -0
  91. package/dist/utils/pages/builder.d.ts +1 -1
  92. package/dist/utils/pages/builder.d.ts.map +1 -1
  93. package/dist/utils/pages/to-body.d.ts +2 -3
  94. package/dist/utils/pages/to-body.d.ts.map +1 -1
  95. package/dist/utils/pages/to-body.js +7 -7
  96. package/dist/utils/pages/to-text.d.ts.map +1 -1
  97. package/dist/utils/process-document.d.ts +1 -0
  98. package/dist/utils/process-document.d.ts.map +1 -1
  99. package/dist/utils/process-document.js +7 -2
  100. package/package.json +18 -14
  101. package/dist/playground/auth/oauth-dialog.d.ts.map +0 -1
  102. package/dist/playground/inputs.d.ts.map +0 -1
  103. package/dist/render/api-page.d.ts +0 -33
  104. package/dist/render/api-page.d.ts.map +0 -1
  105. package/dist/render/api-page.js +0 -59
  106. package/dist/render/codeblock.d.ts +0 -9
  107. package/dist/render/codeblock.d.ts.map +0 -1
  108. package/dist/render/codeblock.js +0 -14
  109. package/dist/render/heading.d.ts +0 -4
  110. package/dist/render/heading.d.ts.map +0 -1
  111. package/dist/render/heading.js +0 -6
  112. package/dist/render/markdown.d.ts +0 -5
  113. package/dist/render/markdown.d.ts.map +0 -1
  114. package/dist/render/markdown.js +0 -31
  115. package/dist/render/operation/api-example.d.ts +0 -30
  116. package/dist/render/operation/api-example.d.ts.map +0 -1
  117. package/dist/render/operation/api-example.js +0 -103
  118. package/dist/render/operation/get-request-data.d.ts.map +0 -1
  119. package/dist/render/operation/index.d.ts +0 -27
  120. package/dist/render/operation/index.d.ts.map +0 -1
  121. package/dist/render/renderer.d.ts +0 -79
  122. package/dist/render/renderer.d.ts.map +0 -1
  123. package/dist/render/renderer.js +0 -25
  124. package/dist/render/schema/client.d.ts +0 -18
  125. package/dist/render/schema/client.d.ts.map +0 -1
  126. package/dist/render/schema/index.d.ts +0 -7
  127. package/dist/render/schema/index.d.ts.map +0 -1
  128. package/dist/render/schema/index.js +0 -11
  129. package/dist/render/schema/server.d.ts.map +0 -1
  130. package/dist/render/schema/ui.d.ts +0 -16
  131. package/dist/render/schema/ui.d.ts.map +0 -1
  132. package/dist/render/schema/ui.js +0 -14
  133. package/dist/ui/client.d.ts +0 -4
  134. package/dist/ui/client.d.ts.map +0 -1
  135. package/dist/ui/contexts/code-example.d.ts +0 -24
  136. package/dist/ui/contexts/code-example.d.ts.map +0 -1
  137. package/dist/ui/contexts/code-example.js +0 -97
  138. package/dist/ui/lazy.d.ts +0 -16
  139. package/dist/ui/lazy.d.ts.map +0 -1
  140. package/dist/ui/lazy.js +0 -22
  141. package/dist/ui/select-tabs.d.ts.map +0 -1
  142. package/dist/ui/select-tabs.js +0 -20
  143. package/dist/ui/server-select.d.ts.map +0 -1
  144. /package/dist/playground/{auth → components}/oauth-dialog.d.ts +0 -0
  145. /package/dist/playground/{auth → components}/oauth-dialog.js +0 -0
  146. /package/dist/{ui → playground/components}/server-select.d.ts +0 -0
  147. /package/dist/{render → ui}/operation/get-request-data.d.ts +0 -0
  148. /package/dist/{render → ui}/operation/get-request-data.js +0 -0
@@ -25,12 +25,6 @@ export type MediaContext = JavaContext | GoContext | JavaScriptContext | CSharpC
25
25
  lang: string;
26
26
  });
27
27
  export interface MediaAdapter {
28
- /**
29
- * the same adapter that's passed from a client component.
30
- *
31
- * It is needed for client-side serialization of values.
32
- */
33
- client?: MediaAdapter;
34
28
  /**
35
29
  * encode data into specified media type for `fetch()`.
36
30
  *
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../../src/requests/media/adapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAI9E,UAAU,WAAW;IACnB;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED,UAAU,SAAU,SAAQ,WAAW;IACrC,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAED,UAAU,iBAAkB,SAAQ,WAAW;IAC7C,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD;AAED,UAAU,WAAY,SAAQ,WAAW;IACvC,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC;AAED,UAAU,aAAc,SAAQ,WAAW;IACzC,IAAI,EAAE,QAAQ,CAAC;IACf,SAAS,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC;AAED,MAAM,MAAM,YAAY,GACpB,WAAW,GACX,SAAS,GACT,iBAAiB,GACjB,aAAa,GACb,CAAC,WAAW,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAErC,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,MAAM,CAAC,EAAE,YAAY,CAAC;IAEtB;;;;OAIG;I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KAAK,IAAI,CAAC;CACxC;AAED,MAAM,MAAM,YAAY,GACpB,WAAW,GACX,SAAS,GACT,iBAAiB,GACjB,aAAa,GACb,CAAC,WAAW,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAErC,MAAM,WAAW,YAAY;IAC3B;;;;OAIG;IACH,MAAM,EAAE,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,KAAK,QAAQ,CAAC;IAE9C;;;;;;;;OAQG;IACH,eAAe,EAAE,CACf,IAAI,EAAE;QAAE,IAAI,EAAE,OAAO,CAAA;KAAE,EACvB,GAAG,EAAE,YAAY,KACd,MAAM,GAAG,SAAS,CAAC;CACzB;AAED,eAAO,MAAM,eAAe;;;kBAjBH,OAAO;;;kBAYd,OAAO;;;;;kBAZA,OAAO;;;kBAYd,OAAO;;;;;kBAZA,OAAO;;;kBAYd,OAAO;;;;;kBAZA,OAAO;;;kBAYd,OAAO;;;;;kBAZA,OAAO;;;kBAYd,OAAO;;;;;kBAZA,OAAO;YAgLN,QAAQ;;;CAOM,CAAC"}
@@ -1,7 +1,12 @@
1
1
  import type { MethodInformation, RenderContext } from '../types.js';
2
+ import type { CreateAPIPageOptions } from '../ui/index.js';
2
3
  export declare function APIPlayground({ path, method, ctx, }: {
3
4
  path: string;
4
5
  method: MethodInformation;
5
6
  ctx: RenderContext;
6
7
  }): import("react/jsx-runtime").JSX.Element;
8
+ /**
9
+ * Enable Scalar for API playgrounds by wrapping your options inside.
10
+ */
11
+ export declare function withScalar(options?: CreateAPIPageOptions): CreateAPIPageOptions;
7
12
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scalar/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAKhE,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,MAAM,EACN,GAAG,GACJ,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;CACpB,2CAIA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/scalar/index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,MAAM,CAAC;AAKjD,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,MAAM,EACN,GAAG,GACJ,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;CACpB,2CAIA;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,OAAO,GAAE,oBAAyB,GACjC,oBAAoB,CAUtB"}
@@ -4,3 +4,17 @@ const Client = lazy(() => import('./client.js'));
4
4
  export function APIPlayground({ path, method, ctx, }) {
5
5
  return (_jsx(Client, { method: method.method, path: path, spec: ctx.schema.bundled }));
6
6
  }
7
+ /**
8
+ * Enable Scalar for API playgrounds by wrapping your options inside.
9
+ */
10
+ export function withScalar(options = {}) {
11
+ return {
12
+ ...options,
13
+ playground: {
14
+ ...options.playground,
15
+ render(props) {
16
+ return _jsx(APIPlayground, { ...props });
17
+ },
18
+ },
19
+ };
20
+ }
@@ -1,80 +1,32 @@
1
- import type { ApiPageProps } from '../render/api-page.js';
2
1
  import { createProxy } from '../server/proxy.js';
3
- import type { CodeSample } from '../render/operation/index.js';
4
- import type { Renderer } from '../render/renderer.js';
5
- import type { NoReference } from '../utils/schema.js';
6
- import type { HighlightOptionsCommon, HighlightOptionsThemes } from 'fumadocs-core/highlight';
7
- import type { MediaAdapter } from '../requests/media/adapter.js';
8
- import type { MethodInformation } from '../types.js';
9
2
  import type { OpenAPIV3, OpenAPIV3_1 } from 'openapi-types';
10
3
  import { type ProcessedDocument } from '../utils/process-document.js';
11
- type Awaitable<T> = T | Promise<T>;
4
+ import type { CodeUsageGenerator } from '../ui/operation/example-panel/index.js';
12
5
  /**
13
- * schema id -> downloaded schema object
6
+ * schema id -> file path, URL, or downloaded schema object
14
7
  */
15
- type SchemaMap = Record<string, OpenAPIV3_1.Document | OpenAPIV3.Document>;
8
+ type SchemaMap = Record<string, string | OpenAPIV3_1.Document | OpenAPIV3.Document>;
16
9
  type ProcessedSchemaMap = Record<string, ProcessedDocument>;
17
- export interface SharedOpenAPIOptions {
18
- /**
19
- * The url of proxy to avoid CORS issues
20
- */
21
- proxyUrl?: string;
22
- renderer?: Partial<Renderer>;
23
- /**
24
- * Disable API Playground
25
- *
26
- * @defaultValue false
27
- */
28
- disablePlayground?: boolean;
29
- /**
30
- * Generate TypeScript definitions from response schema.
31
- *
32
- * Pass `false` to disable it.
33
- *
34
- * @param method - the operation object
35
- * @param statusCode - status code
36
- */
37
- generateTypeScriptSchema?: ((method: NoReference<MethodInformation>, statusCode: string) => Awaitable<string>) | false;
38
- /**
39
- * Generate code samples for endpoint.
40
- */
41
- generateCodeSamples?: (method: MethodInformation) => Awaitable<CodeSample[]>;
42
- shikiOptions?: Omit<HighlightOptionsCommon, 'lang' | 'components'> & HighlightOptionsThemes;
43
- /**
44
- * Show full response schema instead of only example response & Typescript definitions
45
- *
46
- * @default true
47
- */
48
- showResponseSchema?: boolean;
49
- mediaAdapters?: Record<string, MediaAdapter>;
50
- /**
51
- * Customise page content
52
- */
53
- content?: {
54
- /**
55
- * Show examples under the generated content of JSON schemas.
56
- *
57
- * @defaultValue false
58
- */
59
- showExampleInFields?: boolean;
60
- };
61
- }
62
- export interface OpenAPIOptions extends SharedOpenAPIOptions {
10
+ export interface OpenAPIOptions {
63
11
  /**
64
12
  * Schema files, can be:
65
13
  * - URL
66
14
  * - file path
67
15
  * - a function returning records of downloaded schemas.
68
16
  */
69
- input?: string[] | (() => Promise<SchemaMap>);
17
+ input?: string[] | (() => SchemaMap | Promise<SchemaMap>);
70
18
  disableCache?: boolean;
19
+ /**
20
+ * The url of proxy to avoid CORS issues
21
+ */
22
+ proxyUrl?: string;
71
23
  }
72
24
  export interface OpenAPIServer {
73
- getAPIPageProps: (from: ApiPageProps) => ApiPageProps;
74
25
  createProxy: typeof createProxy;
75
26
  getSchemas: () => Promise<ProcessedSchemaMap>;
27
+ readonly options: OpenAPIOptions;
76
28
  }
77
29
  export declare function createOpenAPI(options?: OpenAPIOptions): OpenAPIServer;
78
- export declare function createCodeSample<T>(options: CodeSample<T>): CodeSample;
30
+ export declare function createCodeSample<T>(options: Partial<CodeUsageGenerator<T>>): CodeUsageGenerator;
79
31
  export {};
80
32
  //# sourceMappingURL=create.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/server/create.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EACV,sBAAsB,EACtB,sBAAsB,EACvB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5D,OAAO,EAGL,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAElC,KAAK,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;AACnC;;G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AAG,aAAa,CAiCzE;AAED,wBAAgB,gBAAgB,CAAC,CAAC,EAChC,OAAO,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,GACtC,kBAAkB,CAQpB"}
@@ -1,7 +1,7 @@
1
1
  import { createProxy } from '../server/proxy.js';
2
- import { processDocument, processDocumentCached, } from '../utils/process-document.js';
2
+ import { processDocument, } from '../utils/process-document.js';
3
3
  export function createOpenAPI(options = {}) {
4
- const { input = [], disableCache = false, ...shared } = options;
4
+ const { input = [], disableCache = false } = options;
5
5
  let schemas;
6
6
  async function getSchemas() {
7
7
  const out = {};
@@ -18,25 +18,16 @@ export function createOpenAPI(options = {}) {
18
18
  return out;
19
19
  }
20
20
  return {
21
+ options,
21
22
  createProxy,
22
23
  async getSchemas() {
23
24
  if (disableCache)
24
25
  return getSchemas();
25
26
  return (schemas ?? (schemas = getSchemas()));
26
27
  },
27
- getAPIPageProps({ document, ...props }) {
28
- return {
29
- ...shared,
30
- ...props,
31
- document: typeof document === 'string'
32
- ? this.getSchemas().then((map) => {
33
- return map[document] ?? processDocumentCached(document);
34
- })
35
- : document,
36
- };
37
- },
38
28
  };
39
29
  }
40
30
  export function createCodeSample(options) {
41
- return options;
31
+ const { lang = 'unknown', id = lang, ...rest } = options;
32
+ return { id, lang, ...rest };
42
33
  }
@@ -1,7 +1,7 @@
1
1
  import type { LoaderPlugin, MetaData, PageData, PageTreeTransformer, Source } from 'fumadocs-core/source';
2
2
  import type { OpenAPIServer } from '../server/create.js';
3
3
  import type { SchemaToPagesOptions } from '../utils/pages/preset-auto.js';
4
- import type { ApiPageProps } from '../render/api-page.js';
4
+ import type { ApiPageProps } from '../ui/api-page.js';
5
5
  declare module 'fumadocs-core/source' {
6
6
  interface PageData {
7
7
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"source-api.d.ts","sourceRoot":"","sources":["../../src/server/source-api.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,Q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AAQ,CAAC,EAAE;YACT,MAAM,CAAC,EAAE,MAAM,CAAC;SACjB,CAAC;KACH;CACF;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,YAAY,CAgC5C;AAED,UAAU,eAAgB,SAAQ,QAAQ;IACxC,eAAe,EAAE,MAAM,YAAY,CAAC;CACrC;AAED;;GAEG;AACH,wBAAsB,aAAa,CACjC,IAAI,EAAE,aAAa,EACnB,OAAO,GAAE,oBAAoB,GAAG;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;CACb,GACL,OAAO,CACR,MAAM,CAAC;IACL,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,eAAe,CAAC;CAC3B,CAAC,CACH,CA+BA;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,mBAAmB,CAExD"}
@@ -43,7 +43,7 @@ export async function openapiSource(from, options = {}) {
43
43
  path: `${baseDir}/${entry.path}`,
44
44
  data: {
45
45
  ...entry.info,
46
- getAPIPageProps: () => toBody(from, entry),
46
+ getAPIPageProps: () => toBody(entry),
47
47
  _openapi: {
48
48
  method: entry.type === 'operation' || entry.type === 'webhook'
49
49
  ? entry.item.method
package/dist/types.d.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import type { OpenAPIV3_1 as V3_1 } from 'openapi-types';
2
2
  import type { default as Slugger } from 'github-slugger';
3
- import { type Renderer } from './render/renderer.js';
4
3
  import type { NoReference } from './utils/schema.js';
5
4
  import type { ProcessedDocument } from './utils/process-document.js';
6
5
  import type { MediaAdapter } from './requests/media/adapter.js';
7
- import type { SharedOpenAPIOptions } from './server/index.js';
6
+ import type { OpenAPIOptions } from './server/index.js';
7
+ import type { CreateAPIPageOptions } from './ui/api-page.js';
8
+ import type { CodeUsageGenerator } from './ui/operation/example-panel/index.js';
9
+ import type { ReactNode } from 'react';
8
10
  export type Document = V3_1.Document;
9
11
  export type OperationObject = V3_1.OperationObject;
10
12
  export type ParameterObject = V3_1.ParameterObject;
@@ -15,11 +17,14 @@ export type TagObject = V3_1.TagObject;
15
17
  export type ServerObject = V3_1.ServerObject;
16
18
  export type CallbackObject = V3_1.CallbackObject;
17
19
  export type ServerVariableObject = V3_1.ServerVariableObject;
20
+ export type ResponseObject = V3_1.ResponseObject;
18
21
  export type MethodInformation = NoReference<OperationObject> & {
19
22
  method: string;
23
+ 'x-codeSamples'?: Omit<CodeUsageGenerator, 'id'>[];
24
+ 'x-selectedCodeSample'?: string;
25
+ 'x-exclusiveCodeSample'?: string;
20
26
  };
21
- export interface RenderContext extends SharedOpenAPIOptions {
22
- renderer: Renderer;
27
+ export interface RenderContext extends Pick<OpenAPIOptions, 'proxyUrl'>, CreateAPIPageOptions {
23
28
  servers: NoReference<ServerObject>[];
24
29
  slugger: Slugger;
25
30
  /**
@@ -27,5 +32,8 @@ export interface RenderContext extends SharedOpenAPIOptions {
27
32
  */
28
33
  schema: ProcessedDocument;
29
34
  mediaAdapters: Record<string, MediaAdapter>;
35
+ renderHeading: (depth: number, text: string) => ReactNode;
36
+ renderMarkdown: (text: string) => ReactNode;
37
+ renderCodeBlock: (lang: string, code: string) => ReactNode;
30
38
  }
31
39
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,IAAI,IAAI,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACzD,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AA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AAC,EACtC,oBAAoB;IACtB,OAAO,EAAE,WAAW,CAAC,YAAY,CAAC,EAAE,CAAC;IACrC,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,MAAM,EAAE,iBAAiB,CAAC;IAE1B,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IAE5C,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,SAAS,CAAC;IAC1D,cAAc,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,SAAS,CAAC;IAC5C,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,SAAS,CAAC;CAC5D"}
@@ -0,0 +1,145 @@
1
+ import type { MethodInformation, RenderContext } from '../types.js';
2
+ import { type NoReference, type ResolvedSchema } from '../utils/schema.js';
3
+ import type { OpenAPIV3_1 } from 'openapi-types';
4
+ import type { ProcessedDocument } from '../utils/process-document.js';
5
+ import { MediaAdapter } from '../requests/media/adapter.js';
6
+ import type { FC, ReactNode } from 'react';
7
+ import { type HighlightOptionsCommon, type HighlightOptionsThemes } from 'fumadocs-core/highlight';
8
+ import type { OpenAPIServer } from '../server/index.js';
9
+ import type { APIPageClientOptions } from './client/index.js';
10
+ import type { CodeUsageGenerator, ResponseTab } from './operation/example-panel/index.js';
11
+ import type { SchemaUIProps } from './schema/client.js';
12
+ type Awaitable<T> = T | Promise<T>;
13
+ export interface CreateAPIPageOptions {
14
+ /**
15
+ * Generate TypeScript definitions from response schema.
16
+ *
17
+ * Pass `false` to disable it.
18
+ *
19
+ * @param method - the operation object
20
+ * @param statusCode - status code
21
+ */
22
+ generateTypeScriptSchema?: ((method: NoReference<MethodInformation>, statusCode: string) => Awaitable<string>) | false;
23
+ /**
24
+ * Generate example code usage for endpoints.
25
+ */
26
+ generateCodeSamples?: (method: MethodInformation) => Awaitable<CodeUsageGenerator[]>;
27
+ shikiOptions?: Omit<HighlightOptionsCommon, 'lang' | 'components'> & HighlightOptionsThemes;
28
+ /**
29
+ * Show full response schema instead of only example response & Typescript definitions.
30
+ *
31
+ * @default true
32
+ */
33
+ showResponseSchema?: boolean;
34
+ /**
35
+ * Support other media types (for server-side generation).
36
+ */
37
+ mediaAdapters?: Record<string, MediaAdapter>;
38
+ /**
39
+ * Customise page content
40
+ */
41
+ content?: {
42
+ renderResponseTabs?: (tabs: ResponseTab[], ctx: RenderContext) => Awaitable<ReactNode>;
43
+ renderAPIExampleLayout?: (slots: {
44
+ selector: ReactNode;
45
+ usageTabs: ReactNode;
46
+ responseTabs: ReactNode;
47
+ }, ctx: RenderContext) => Awaitable<ReactNode>;
48
+ /**
49
+ * @param generators - codegens for API example usages
50
+ */
51
+ renderAPIExampleUsageTabs?: (generators: CodeUsageGenerator<unknown>[], ctx: RenderContext) => Awaitable<ReactNode>;
52
+ /**
53
+ * renderer of the entire page's layout (containing all operations & webhooks UI)
54
+ */
55
+ renderPageLayout?: (slots: {
56
+ operations?: {
57
+ item: OperationItem;
58
+ children: ReactNode;
59
+ }[];
60
+ webhooks?: {
61
+ item: WebhookItem;
62
+ children: ReactNode;
63
+ }[];
64
+ }, ctx: RenderContext) => Awaitable<ReactNode>;
65
+ renderOperationLayout?: (slots: {
66
+ header: ReactNode;
67
+ apiExample: ReactNode;
68
+ apiPlayground: ReactNode;
69
+ authSchemes: ReactNode;
70
+ paremeters: ReactNode;
71
+ body: ReactNode;
72
+ responses: ReactNode;
73
+ callbacks: ReactNode;
74
+ }, ctx: RenderContext, method: MethodInformation) => Awaitable<ReactNode>;
75
+ renderWebhookLayout?: (slots: {
76
+ header: ReactNode;
77
+ authSchemes: ReactNode;
78
+ paremeters: ReactNode;
79
+ body: ReactNode;
80
+ responses: ReactNode;
81
+ callbacks: ReactNode;
82
+ }) => Awaitable<ReactNode>;
83
+ };
84
+ /**
85
+ * Info UI for JSON schemas
86
+ */
87
+ schemaUI?: {
88
+ render?: (options: Omit<SchemaUIProps, 'generated'> & {
89
+ root: ResolvedSchema;
90
+ }, ctx: RenderContext) => Awaitable<ReactNode>;
91
+ /**
92
+ * Show examples under the generated content of JSON schemas.
93
+ *
94
+ * @defaultValue false
95
+ */
96
+ showExample?: boolean;
97
+ };
98
+ /**
99
+ * Customise API playground
100
+ */
101
+ playground?: {
102
+ /**
103
+ * @defaultValue true
104
+ */
105
+ enabled?: boolean;
106
+ /**
107
+ * replace the server-side renderer
108
+ */
109
+ render?: (props: {
110
+ path: string;
111
+ method: MethodInformation;
112
+ ctx: RenderContext;
113
+ }) => Awaitable<ReactNode>;
114
+ };
115
+ client?: APIPageClientOptions;
116
+ }
117
+ export interface ApiPageProps {
118
+ document: Promise<ProcessedDocument> | string | ProcessedDocument;
119
+ hasHead?: boolean;
120
+ /**
121
+ * An array of operations
122
+ */
123
+ operations?: OperationItem[];
124
+ webhooks?: WebhookItem[];
125
+ }
126
+ export interface WebhookItem {
127
+ /**
128
+ * webhook name in `webhooks`
129
+ */
130
+ name: string;
131
+ method: OpenAPIV3_1.HttpMethods;
132
+ }
133
+ export interface OperationItem {
134
+ /**
135
+ * the path of operation in `paths`
136
+ */
137
+ path: string;
138
+ /**
139
+ * the HTTP method of operation
140
+ */
141
+ method: OpenAPIV3_1.HttpMethods;
142
+ }
143
+ export declare function createAPIPage(server: OpenAPIServer, options?: CreateAPIPageOptions): FC<ApiPageProps>;
144
+ export {};
145
+ //# sourceMappingURL=api-page.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api-page.d.ts","sourceRoot":"","sources":["../../src/ui/api-page.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B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AAO,GAAE,oBAAyB,GACjC,EAAE,CAAC,YAAY,CAAC,CAoFlB"}
@@ -0,0 +1,120 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any -- rehype-react without types */
3
+ import Slugger from 'github-slugger';
4
+ import { Operation } from '../ui/operation/index.js';
5
+ import { createMethod, } from '../utils/schema.js';
6
+ import { defaultAdapters } from '../requests/media/adapter.js';
7
+ import { highlight, } from 'fumadocs-core/highlight';
8
+ import { ApiProviderLazy } from './contexts/api.lazy.js';
9
+ import { Heading } from 'fumadocs-ui/components/heading';
10
+ import { rehypeCode, } from 'fumadocs-core/mdx-plugins/rehype-code';
11
+ import { remarkGfm } from 'fumadocs-core/mdx-plugins/remark-gfm';
12
+ import defaultMdxComponents from 'fumadocs-ui/mdx';
13
+ import { remark } from 'remark';
14
+ import remarkRehype from 'remark-rehype';
15
+ import { toJsxRuntime } from 'hast-util-to-jsx-runtime';
16
+ import * as JsxRuntime from 'react/jsx-runtime';
17
+ import { CodeBlock, Pre } from 'fumadocs-ui/components/codeblock';
18
+ export function createAPIPage(server, options = {}) {
19
+ let processor;
20
+ function createMarkdownProcessor() {
21
+ function rehypeReact() {
22
+ this.compiler = (tree, file) => {
23
+ return toJsxRuntime(tree, {
24
+ development: false,
25
+ filePath: file.path,
26
+ ...JsxRuntime,
27
+ components: defaultMdxComponents,
28
+ });
29
+ };
30
+ }
31
+ return remark()
32
+ .use(remarkGfm)
33
+ .use(remarkRehype)
34
+ .use(rehypeCode, {
35
+ langs: [],
36
+ lazy: true,
37
+ })
38
+ .use(rehypeReact);
39
+ }
40
+ return async function APIPageWrapper({ document, ...props }) {
41
+ let processed;
42
+ if (typeof document === 'string') {
43
+ processed = (await server.getSchemas())[document];
44
+ }
45
+ else {
46
+ processed = await document;
47
+ }
48
+ const { dereferenced } = processed;
49
+ const servers = dereferenced.servers && dereferenced.servers.length > 0
50
+ ? dereferenced.servers
51
+ : [{ url: '/' }];
52
+ const slugger = new Slugger();
53
+ const ctx = {
54
+ schema: processed,
55
+ proxyUrl: server.options.proxyUrl,
56
+ ...options,
57
+ servers,
58
+ mediaAdapters: {
59
+ ...defaultAdapters,
60
+ ...options.mediaAdapters,
61
+ },
62
+ slugger,
63
+ renderHeading(depth, text) {
64
+ const id = slugger.slug(text);
65
+ return (_jsx(Heading, { id: id, as: `h${depth}`, children: text }, id));
66
+ },
67
+ async renderMarkdown(text) {
68
+ processor ?? (processor = createMarkdownProcessor());
69
+ const out = await processor.process({
70
+ value: text,
71
+ });
72
+ return out.result;
73
+ },
74
+ async renderCodeBlock(lang, code) {
75
+ const rendered = await highlight(code, {
76
+ lang,
77
+ ...options.shikiOptions,
78
+ components: {
79
+ pre: (props) => _jsx(Pre, { ...props }),
80
+ },
81
+ });
82
+ return _jsx(CodeBlock, { className: "my-0", children: rendered });
83
+ },
84
+ };
85
+ return _jsx(APIPage, { ...props, ctx: ctx });
86
+ };
87
+ }
88
+ async function APIPage({ hasHead = false, operations, webhooks, ctx, }) {
89
+ const { dereferenced } = ctx.schema;
90
+ let { renderPageLayout } = ctx.content ?? {};
91
+ renderPageLayout ?? (renderPageLayout = (slots) => (_jsxs("div", { className: "flex flex-col gap-24 text-sm", children: [slots.operations?.map((op) => op.children), slots.webhooks?.map((op) => op.children)] })));
92
+ const content = await renderPageLayout({
93
+ operations: operations?.map((item) => {
94
+ const pathItem = dereferenced.paths?.[item.path];
95
+ if (!pathItem)
96
+ throw new Error(`[Fumadocs OpenAPI] Path not found in OpenAPI schema: ${item.path}`);
97
+ const operation = pathItem[item.method];
98
+ if (!operation)
99
+ throw new Error(`[Fumadocs OpenAPI] Method ${item.method} not found in operation: ${item.path}`);
100
+ const method = createMethod(item.method, pathItem, operation);
101
+ return {
102
+ item,
103
+ children: (_jsx(Operation, { method: method, path: item.path, ctx: ctx, hasHead: hasHead }, `${item.path}:${item.method}`)),
104
+ };
105
+ }),
106
+ webhooks: webhooks?.map((item) => {
107
+ const webhook = dereferenced.webhooks?.[item.name];
108
+ if (!webhook)
109
+ throw new Error(`[Fumadocs OpenAPI] Webhook not found in OpenAPI schema: ${item.name}`);
110
+ const hook = webhook[item.method];
111
+ if (!hook)
112
+ throw new Error(`[Fumadocs OpenAPI] Method ${item.method} not found in webhook: ${item.name}`);
113
+ return {
114
+ item,
115
+ children: (_jsx(Operation, { type: "webhook", method: createMethod(item.method, webhook, hook), ctx: ctx, path: `/${item.name}`, hasHead: hasHead }, `${item.name}:${item.method}`)),
116
+ };
117
+ }),
118
+ }, ctx);
119
+ return (_jsx(ApiProviderLazy, { servers: ctx.servers, shikiOptions: ctx.shikiOptions, client: ctx.client ?? {}, children: content }));
120
+ }
@@ -0,0 +1,29 @@
1
+ import type { PlaygroundClientOptions } from '../../playground/client.js';
2
+ import type { MediaAdapter } from '../../requests/media/adapter.js';
3
+ import type { APIExampleItem } from '../operation/example-panel/index.js';
4
+ import type { FC } from 'react';
5
+ export interface APIPageClientOptions {
6
+ playground?: PlaygroundClientOptions;
7
+ operation?: OperationClientOptions;
8
+ /**
9
+ * Set a prefix for `localStorage` keys.
10
+ *
11
+ * Useful when using multiple OpenAPI instances to prevent state conflicts.
12
+ *
13
+ * @defaultValue `fumadocs-openapi-`
14
+ */
15
+ storageKeyPrefix?: string;
16
+ /**
17
+ * Support other media types (for client-side serialization)
18
+ */
19
+ mediaAdapters?: Record<string, MediaAdapter>;
20
+ }
21
+ export interface OperationClientOptions {
22
+ APIExampleSelector?: FC<{
23
+ items: APIExampleItem[];
24
+ value: string | undefined;
25
+ onValueChange: (id: string) => void;
26
+ }>;
27
+ }
28
+ export declare function defineClientConfig(options?: APIPageClientOptions): APIPageClientOptions;
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/ui/client/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AACjE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAEhC,MAAM,WAAW,oBAAoB;IACnC,UAAU,CAAC,EAAE,uBAAuB,CAAC;IACrC,SAAS,CAAC,EAAE,sBAAsB,CAAC;IAEnC;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CAC9C;AAED,MAAM,WAAW,sBAAsB;IACrC,kBAAkB,CAAC,EAAE,EAAE,CAAC;QACtB,KAAK,EAAE,cAAc,EAAE,CAAC;QAExB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;QAC1B,aAAa,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;KACrC,CAAC,CAAC;CACJ;AAED,wBAAgB,kBAAkB,CAChC,OAAO,GAAE,oBAAyB,GACjC,oBAAoB,CAEtB"}
@@ -0,0 +1,4 @@
1
+ 'use client';
2
+ export function defineClientConfig(options = {}) {
3
+ return options;
4
+ }
@@ -0,0 +1,9 @@
1
+ import type { AuthField } from '../../playground/client.js';
2
+ type KeyName = 'server-url' | `auth-${string}`;
3
+ export declare function useStorageKey(): {
4
+ of: (name: KeyName) => string;
5
+ AuthField: (field: AuthField) => string;
6
+ };
7
+ export declare function getStorageKey(prefix: string | undefined, name: KeyName): string;
8
+ export {};
9
+ //# sourceMappingURL=storage-key.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storage-key.d.ts","sourceRoot":"","sources":["../../../src/ui/client/storage-key.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAIrD,KAAK,OAAO,GAAG,YAAY,GAAG,QAAQ,MAAM,EAAE,CAAC;AAE/C,wBAAgB,aAAa;eAKZ,OAAO;uBACC,SAAS;EAQjC;AAED,wBAAgB,aAAa,CAAC,MAAM,oBAAsB,EAAE,IAAI,EAAE,OAAO,UAExE"}
@@ -0,0 +1,12 @@
1
+ import { useApiContext } from '../contexts/api.js';
2
+ import { useMemo } from 'react';
3
+ export function useStorageKey() {
4
+ const { storageKeyPrefix } = useApiContext().client;
5
+ return useMemo(() => ({
6
+ of: (name) => getStorageKey(storageKeyPrefix, name),
7
+ AuthField: (field) => getStorageKey(storageKeyPrefix, `auth-${field.original?.id ?? field.fieldName}`),
8
+ }), [storageKeyPrefix]);
9
+ }
10
+ export function getStorageKey(prefix = 'fumadocs-openapi-', name) {
11
+ return prefix + name;
12
+ }
@@ -1,7 +1,7 @@
1
1
  import { type VariantProps } from 'class-variance-authority';
2
2
  import type { HTMLAttributes } from 'react';
3
3
  export declare const badgeVariants: (props?: ({
4
- color?: "red" | "green" | "yellow" | "blue" | "orange" | null | undefined;
4
+ color?: "green" | "yellow" | "red" | "blue" | "orange" | null | undefined;
5
5
  } & import("class-variance-authority/types").ClassProp) | undefined) => string;
6
6
  export declare function Badge({ className, color, ...props }: Omit<HTMLAttributes<HTMLSpanElement>, 'color'> & VariantProps<typeof badgeVariants>): import("react/jsx-runtime").JSX.Element;
7
7
  export declare function MethodLabel({ children, ...props }: Omit<HTMLAttributes<HTMLSpanElement>, 'children'> & {