fumadocs-openapi 9.6.4 → 9.7.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 (42) hide show
  1. package/dist/generate-file.d.ts +1 -1
  2. package/dist/generate-file.d.ts.map +1 -1
  3. package/dist/generate-file.js +5 -2
  4. package/dist/index.d.ts +3 -1
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +0 -1
  7. package/dist/render/api-page.d.ts +9 -0
  8. package/dist/render/api-page.d.ts.map +1 -1
  9. package/dist/render/operation/index.d.ts.map +1 -1
  10. package/dist/render/operation/index.js +1 -2
  11. package/dist/server/source-api.d.ts +3 -10
  12. package/dist/server/source-api.d.ts.map +1 -1
  13. package/dist/server/source-api.js +3 -24
  14. package/dist/types.d.ts +4 -5
  15. package/dist/types.d.ts.map +1 -1
  16. package/dist/ui/contexts/api.d.ts +2 -1
  17. package/dist/ui/contexts/api.d.ts.map +1 -1
  18. package/dist/ui/server-select.d.ts.map +1 -1
  19. package/dist/utils/pages/builder.d.ts +87 -0
  20. package/dist/utils/pages/builder.d.ts.map +1 -0
  21. package/dist/utils/pages/builder.js +122 -0
  22. package/dist/utils/pages/preset-auto.d.ts +68 -0
  23. package/dist/utils/pages/preset-auto.d.ts.map +1 -0
  24. package/dist/utils/pages/preset-auto.js +138 -0
  25. package/dist/utils/pages/to-body.d.ts +1 -1
  26. package/dist/utils/pages/to-body.d.ts.map +1 -1
  27. package/dist/utils/pages/to-text.d.ts +1 -1
  28. package/dist/utils/pages/to-text.d.ts.map +1 -1
  29. package/dist/utils/pages/to-text.js +1 -1
  30. package/dist/utils/schema.d.ts +1 -0
  31. package/dist/utils/schema.d.ts.map +1 -1
  32. package/dist/utils/schema.js +8 -0
  33. package/dist/utils/url.d.ts +1 -0
  34. package/dist/utils/url.d.ts.map +1 -1
  35. package/dist/utils/url.js +3 -0
  36. package/package.json +5 -5
  37. package/dist/build-routes.d.ts +0 -15
  38. package/dist/build-routes.d.ts.map +0 -1
  39. package/dist/build-routes.js +0 -38
  40. package/dist/utils/schema-to-pages.d.ts +0 -97
  41. package/dist/utils/schema-to-pages.d.ts.map +0 -1
  42. package/dist/utils/schema-to-pages.js +0 -167
@@ -1,7 +1,7 @@
1
1
  import { type PagesToTextOptions } from './utils/pages/to-text.js';
2
2
  import { type ProcessedDocument } from './utils/process-document.js';
3
3
  import type { OpenAPIServer } from './server/index.js';
4
- import { type SchemaToPagesOptions } from './utils/schema-to-pages.js';
4
+ import { type SchemaToPagesOptions } from './utils/pages/preset-auto.js';
5
5
  export interface OutputFile {
6
6
  path: string;
7
7
  content: string;
@@ -1 +1 @@
1
- {"version":3,"file":"generate-file.d.ts","sourceRoot":"","sources":["../src/generate-file.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,kBAAkB,EAExB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAG9C,OAAO,EAGL,KAAK,oBAAoB,EAC1B,MAAM,yBAAyB,CAAC;AAEjC,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,UAAU,WAAW;IACnB,KAAK,EAAE,SAAS,EAAE,GAAG,CAAC,CAAC,GAAG,EAAE,WAAW,KAAK,SAAS,EAAE,CAAC,CAAC;IAEzD;;OAEG;IACH,GAAG,EACC,CAAC,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC,GAC9B;QACE,OAAO,EAAE,MAAM,CAAC;QAChB;;WAEG;QACH,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACP;AAED,UAAU,SAAS;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;;;OAIG;IACH,IA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B,CAAC,CAAC;CACvD;AAED,wBAAsB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAclE;AAED,wBAAsB,iBAAiB,CACrC,OAAO,EAAE,oBAAoB,GAAG,IAAI,CAAC,mBAAmB,EAAE,QAAQ,CAAC,GAClE,OAAO,CAAC,UAAU,EAAE,CAAC,CA+DvB"}
@@ -5,7 +5,9 @@ import { generateDocument, toText, } from './utils/pages/to-text.js';
5
5
  import { processDocumentCached, } from './utils/process-document.js';
6
6
  import { createGetUrl, getSlugs } from 'fumadocs-core/source';
7
7
  import matter from 'gray-matter';
8
- import { isUrl, schemaToPages, } from './utils/schema-to-pages.js';
8
+ import { createAutoPreset, } from './utils/pages/preset-auto.js';
9
+ import { isUrl } from './utils/url.js';
10
+ import { fromSchema } from './utils/pages/builder.js';
9
11
  export async function generateFiles(options) {
10
12
  const files = await generateFilesOnly(options);
11
13
  const { output, cwd = process.cwd() } = options;
@@ -52,8 +54,9 @@ export async function generateFilesOnly(options) {
52
54
  if (entries.length === 0) {
53
55
  throw new Error('No input files found.');
54
56
  }
57
+ const preset = createAutoPreset(options);
55
58
  for (const [id, schema] of entries) {
56
- const result = schemaToPages(id, schema, options).map((page) => ({
59
+ const result = fromSchema(id, schema, preset).map((page) => ({
57
60
  path: page.path,
58
61
  content: toText(page, schema, options),
59
62
  }));
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from './generate-file.js';
2
- export * from './types.js';
3
2
  export type { MediaAdapter } from './requests/media/adapter.js';
3
+ export type * from './types.js';
4
+ export type * from './utils/pages/builder.js';
5
+ export type * from './utils/pages/preset-auto.js';
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,SAAS,CAAC;AACxB,YAAY,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,YAAY,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D,mBAAmB,SAAS,CAAC;AAC7B,mBAAmB,uBAAuB,CAAC;AAC3C,mBAAmB,2BAA2B,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1 @@
1
1
  export * from './generate-file.js';
2
- export * from './types.js';
@@ -12,11 +12,20 @@ export interface ApiPageProps extends SharedOpenAPIOptions {
12
12
  webhooks?: WebhookItem[];
13
13
  }
14
14
  export interface WebhookItem {
15
+ /**
16
+ * webhook name in `webhooks`
17
+ */
15
18
  name: string;
16
19
  method: OpenAPIV3_1.HttpMethods;
17
20
  }
18
21
  export interface OperationItem {
22
+ /**
23
+ * the path of operation in `paths`
24
+ */
19
25
  path: string;
26
+ /**
27
+ * the HTTP method of operation
28
+ */
20
29
  method: OpenAPIV3_1.HttpMethods;
21
30
  }
22
31
  export declare function APIPage(props: ApiPageProps): Promise<import("react/jsx-runtime").JSX.Element>;
@@ -1 +1 @@
1
- {"version":3,"file":"api-page.d.ts","sourceRoot":"","sources":["../../src/render/api-page.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAG7C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,0BAA0B,CAAC;AAElC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD,MAAM,WAAW,YAAa,SAAQ,oBAAoB;IACxD,QAAQ,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,MAAM,GAAG,iBAAiB,CAAC;IAClE,OAAO,EAAE,OAAO,CAAC;IAEjB;;OAEG;IACH,UAAU,CAAC,EAAE,aAAa,EAAE,CAAC;IAE7B,QAAQ,C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AE,YAAY,oDAgEhD;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,iBAAiB,EACzB,OAAO,GAAE,oBAAyB,GACjC,OAAO,CAAC,aAAa,CAAC,CA0BxB"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/render/operation/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EAEV,iBAAiB,EACjB,aAAa,EAEd,MAAM,SAAS,CAAC;AAajB,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAYxD,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,OAAO;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;IAE7C;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,CAAC;CACnB;AASD,wBAAgB,SAAS,CAAC,EACxB,IAAkB,EAClB,IAAI,EACJ,MAAM,EACN,GAAG,EACH,OAAO,EACP,YAAgB,GACjB,EAAE;IACD,IAAI,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;IAEnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,YAAY,CAiNf"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/render/operation/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAC;AACpE,OAAO,KAAK,EAEV,iBAAiB,EACjB,aAAa,EAEd,MAAM,SAAS,CAAC;AAiBjB,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAYxD,MAAM,WAAW,UAAU,CAAC,CAAC,GAAG,OAAO;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;;OAKG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,eAAe,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;IAE7C;;OAEG;IACH,aAAa,CAAC,EAAE,CAAC,CAAC;CACnB;AASD,wBAAgB,SAAS,CAAC,EACxB,IAAkB,EAClB,IAAI,EACJ,MAAM,EACN,GAAG,EACH,OAAO,EACP,YAAgB,GACjB,EAAE;IACD,IAAI,CAAC,EAAE,SAAS,GAAG,WAAW,CAAC;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,iBAAiB,CAAC;IAC1B,GAAG,EAAE,aAAa,CAAC;IAEnB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GAAG,YAAY,CAiNf"}
@@ -1,11 +1,10 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Fragment } from 'react';
3
- import { createMethod } from '../../utils/schema.js';
3
+ import { createMethod, methodKeys, } from '../../utils/schema.js';
4
4
  import { idToTitle } from '../../utils/id-to-title.js';
5
5
  import { Markdown } from '../markdown.js';
6
6
  import { heading } from '../heading.js';
7
7
  import { Schema } from '../schema/index.js';
8
- import { methodKeys } from '../../build-routes.js';
9
8
  import { APIExample, APIExampleProvider, getAPIExamples, } from '../../render/operation/api-example.js';
10
9
  import { MethodLabel } from '../../ui/components/method-label.js';
11
10
  import { getTypescriptSchema } from '../../utils/get-typescript-schema.js';
@@ -1,8 +1,7 @@
1
- import type * as PageTree from 'fumadocs-core/page-tree';
2
- import { LoaderPlugin, MetaData, PageData, PageFile, PageTreeTransformer, Source } from 'fumadocs-core/source';
1
+ import type { LoaderPlugin, MetaData, PageData, PageTreeTransformer, Source } from 'fumadocs-core/source';
3
2
  import type { OpenAPIServer } from '../server/create.js';
4
- import type { SchemaToPagesOptions } from '../utils/schema-to-pages.js';
5
- import { ApiPageProps } from '../render/api-page.js';
3
+ import type { SchemaToPagesOptions } from '../utils/pages/preset-auto.js';
4
+ import type { ApiPageProps } from '../render/api-page.js';
6
5
  declare module 'fumadocs-core/source' {
7
6
  interface PageData {
8
7
  /**
@@ -29,12 +28,6 @@ export declare function openapiSource(from: OpenAPIServer, options?: SchemaToPag
29
28
  metaData: MetaData;
30
29
  pageData: OpenAPIPageData;
31
30
  }>>;
32
- /**
33
- * Source API Integration, add this to page tree builder options.
34
- *
35
- * @deprecated use `openapiPlugin()`
36
- */
37
- export declare const attachFile: (node: PageTree.Item, file: PageFile | undefined) => PageTree.Item;
38
31
  /**
39
32
  * @deprecated use `openapiPlugin()`
40
33
  */
@@ -1 +1 @@
1
- {"version":3,"file":"source-api.d.ts","sourceRoot":"","sources":["../../src/server/source-api.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACzD,OAAO,EACL,YAAY,EACZ,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,mBAAmB,EACnB,MAAM,EAEP,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAEjD,OAAO,QAAQ,sBAAsB,CAAC;IACpC,UAAiB,QAAQ;QACvB;;WAEG;QACH,QAAQ,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,Y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CAAC;IACL,QAAQ,EAAE,QAAQ,CAAC;IACnB,QAAQ,EAAE,eAAe,CAAC;CAC3B,CAAC,CACH,CA+BA;AAED;;GAEG;AACH,wBAAgB,kBAAkB,IAAI,mBAAmB,CAExD"}
@@ -32,10 +32,11 @@ export function openapiPlugin() {
32
32
  */
33
33
  export async function openapiSource(from, options = {}) {
34
34
  const { baseDir = '' } = options;
35
- const { serverToPages } = await import('../utils/schema-to-pages.js');
35
+ const { createAutoPreset } = await import('../utils/pages/preset-auto.js');
36
+ const { fromServer } = await import('../utils/pages/builder.js');
36
37
  const { toBody } = await import('../utils/pages/to-body.js');
37
38
  const files = [];
38
- const entries = await serverToPages(from, options);
39
+ const entries = await fromServer(from, createAutoPreset(options));
39
40
  for (const entry of Object.values(entries).flat()) {
40
41
  files.push({
41
42
  type: 'page',
@@ -55,28 +56,6 @@ export async function openapiSource(from, options = {}) {
55
56
  files,
56
57
  };
57
58
  }
58
- /**
59
- * Source API Integration, add this to page tree builder options.
60
- *
61
- * @deprecated use `openapiPlugin()`
62
- */
63
- export const attachFile = (node, file) => {
64
- if (!file)
65
- return node;
66
- let data = file.data;
67
- // backward compatible with older versions with `_openapi` is located in `data.data`
68
- if ('data' in data && data.data && typeof data === 'object')
69
- data = data.data;
70
- let method;
71
- if ('_openapi' in data && typeof data._openapi === 'object') {
72
- const meta = data._openapi;
73
- method = meta.method;
74
- }
75
- if (method) {
76
- node.name = (_jsxs(_Fragment, { children: [node.name, ' ', _jsx(MethodLabel, { className: "ms-auto text-xs text-nowrap", children: method })] }));
77
- }
78
- return node;
79
- };
80
59
  /**
81
60
  * @deprecated use `openapiPlugin()`
82
61
  */
package/dist/types.d.ts CHANGED
@@ -8,20 +8,19 @@ import type { SharedOpenAPIOptions } from './server/index.js';
8
8
  export type Document = V3_1.Document;
9
9
  export type OperationObject = V3_1.OperationObject;
10
10
  export type ParameterObject = V3_1.ParameterObject;
11
- export type SecurityRequirementObject = V3_1.SecurityRequirementObject;
12
11
  export type SecuritySchemeObject = V3_1.SecuritySchemeObject;
13
12
  export type ReferenceObject = V3_1.ReferenceObject;
14
13
  export type PathItemObject = V3_1.PathItemObject;
15
14
  export type TagObject = V3_1.TagObject;
16
- export type ServerObject = NoReference<V3_1.ServerObject>;
17
- export type CallbackObject = NoReference<V3_1.CallbackObject>;
18
- export type ServerVariableObject = NoReference<V3_1.ServerVariableObject>;
15
+ export type ServerObject = V3_1.ServerObject;
16
+ export type CallbackObject = V3_1.CallbackObject;
17
+ export type ServerVariableObject = V3_1.ServerVariableObject;
19
18
  export type MethodInformation = NoReference<OperationObject> & {
20
19
  method: string;
21
20
  };
22
21
  export interface RenderContext extends SharedOpenAPIOptions {
23
22
  renderer: Renderer;
24
- servers: ServerObject[];
23
+ servers: NoReference<ServerObject>[];
25
24
  slugger: Slugger;
26
25
  /**
27
26
  * dereferenced schema
@@ -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;AAErD,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;AACrC,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;AACnD,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;AACnD,MAAM,MAAM,yBAAyB,GAAG,IAA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Y,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC;AAErD,MAAM,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC;AACrC,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;AACnD,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;AACnD,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,CAAC;AAC7D,MAAM,MAAM,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;AACnD,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;AACjD,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,SAAS,CAAC;AACvC,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,YAAY,CAAC;AAC7C,MAAM,MAAM,cAAc,GAAG,IAAI,CAAC,cAAc,CAAC;AACjD,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,oBAAoB,CAAC;AAE7D,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,eAAe,CAAC,GAAG;IAC7D,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,WAAW,aAAc,SAAQ,oBAAoB;IACzD,QAAQ,EAAE,QAAQ,CAAC;IACnB,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;CAC7C"}
@@ -1,6 +1,7 @@
1
1
  import { type ReactNode } from 'react';
2
2
  import type { RenderContext, ServerObject } from '../../types.js';
3
3
  import { type MediaAdapter } from '../../requests/media/adapter.js';
4
+ import type { NoReference } from '../../utils/schema.js';
4
5
  export interface ApiProviderProps extends Omit<ApiContextType, 'mediaAdapters'> {
5
6
  /**
6
7
  * Base URL for API requests
@@ -14,7 +15,7 @@ export interface SelectedServer {
14
15
  variables: Record<string, string>;
15
16
  }
16
17
  interface ApiContextType {
17
- servers: ServerObject[];
18
+ servers: NoReference<ServerObject>[];
18
19
  shikiOptions: RenderContext['shikiOptions'];
19
20
  mediaAdapters: Record<string, MediaAdapter>;
20
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/api.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,SAAS,EAKf,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAC3D,OAAO,EAAmB,KAAK,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE9E,MAAM,WAAW,gBACf,SAAQ,IAAI,CAAC,cAAc,EAAE,eAAe,CAAC;IAC7C;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CAC9C;AAED,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnC;AAED,UAAU,cAAc;IACtB,OAAO,EAAE,YAAY,EAAE,CAAC;IACxB,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,CAAC;IAC5C,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;CAC7C;AAED,UAAU,gBAAgB;IACxB,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IAC9B,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CAC7D;AAKD,wBAAg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AK,IAAI,CAAC;CAC7D;AAKD,wBAAgB,aAAa,IAAI,cAAc,CAK9C;AAED,wBAAgB,sBAAsB,IAAI,gBAAgB,CAKzD;AAED,wBAAgB,WAAW,CAAC,EAC1B,cAAc,EACd,QAAQ,EACR,OAAO,EACP,aAAa,EACb,YAAY,GACb,EAAE,gBAAgB,2CA2ElB"}
@@ -1 +1 @@
1
- {"version":3,"file":"server-select.d.ts","sourceRoot":"","sources":["../../src/ui/server-select.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,cAAc,EAAuB,MAAM,OAAO,CAAC;AAejE,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,KAAK,EAAE,cAAc,CAAC,cAAc,CAAC,uDAwDzE"}
1
+ {"version":3,"file":"server-select.d.ts","sourceRoot":"","sources":["../../src/ui/server-select.tsx"],"names":[],"mappings":"AAUA,OAAO,EAAE,KAAK,cAAc,EAAuB,MAAM,OAAO,CAAC;AAgBjE,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,KAAK,EAAE,cAAc,CAAC,cAAc,CAAC,uDAwDzE"}
@@ -0,0 +1,87 @@
1
+ import type { ProcessedDocument } from '../../utils/process-document.js';
2
+ import type { OpenAPIServer } from '../../server/index.js';
3
+ import type { OperationItem, WebhookItem } from '../../render/api-page.js';
4
+ import type { OperationObject, PathItemObject, TagObject } from '../../types.js';
5
+ import { type NoReference } from '../../utils/schema.js';
6
+ interface BaseEntry {
7
+ path: string;
8
+ schemaId: string;
9
+ info: {
10
+ title: string;
11
+ description?: string;
12
+ };
13
+ }
14
+ export interface OperationOutput extends BaseEntry {
15
+ type: 'operation';
16
+ item: OperationItem;
17
+ }
18
+ export interface WebhookOutput extends BaseEntry {
19
+ type: 'webhook';
20
+ item: WebhookItem;
21
+ }
22
+ export interface TagOutput extends BaseEntry {
23
+ type: 'tag';
24
+ tag: string;
25
+ rawTag: TagObject;
26
+ operations: OperationItem[];
27
+ webhooks: WebhookItem[];
28
+ }
29
+ export interface OutputGroup extends BaseEntry {
30
+ type: 'group';
31
+ operations: OperationItem[];
32
+ webhooks: WebhookItem[];
33
+ }
34
+ export type OutputEntry = TagOutput | OperationOutput | WebhookOutput | OutputGroup;
35
+ export interface PagesBuilderConfig {
36
+ toPages: (builder: PagesBuilder) => void;
37
+ }
38
+ export interface PagesBuilder {
39
+ /**
40
+ * the input ID in OpenAPI server
41
+ */
42
+ id: string;
43
+ document: ProcessedDocument;
44
+ /**
45
+ * add output entry.
46
+ *
47
+ * When the `path` property is unspecified, it will generate one.
48
+ */
49
+ create: (entry: OutputEntry) => void;
50
+ /**
51
+ * get file path from operation path, useful for generating output paths.
52
+ */
53
+ routePathToFilePath: (path: string) => string;
54
+ /**
55
+ * Extract useful info for rendering
56
+ */
57
+ extract: () => ExtractedInfo;
58
+ fromExtractedWebhook: (item: WebhookItem) => {
59
+ get displayName(): string;
60
+ pathItem: NoReference<PathItemObject>;
61
+ operation: NoReference<OperationObject>;
62
+ } | undefined;
63
+ fromExtractedOperation: (item: OperationItem) => {
64
+ get displayName(): string;
65
+ pathItem: NoReference<PathItemObject>;
66
+ operation: NoReference<OperationObject>;
67
+ } | undefined;
68
+ fromTag: (tag: TagObject) => {
69
+ get displayName(): string;
70
+ };
71
+ fromTagName: (tag: string) => {
72
+ info: TagObject;
73
+ get displayName(): string;
74
+ } | undefined;
75
+ }
76
+ interface ExtractedInfo {
77
+ webhooks: (WebhookItem & {
78
+ tags?: string[];
79
+ })[];
80
+ operations: (OperationItem & {
81
+ tags?: string[];
82
+ })[];
83
+ }
84
+ export declare function fromServer(server: OpenAPIServer, config: PagesBuilderConfig): Promise<Record<string, OutputEntry[]>>;
85
+ export declare function fromSchema(schemaId: string, processed: ProcessedDocument, config: PagesBuilderConfig): OutputEntry[];
86
+ export {};
87
+ //# sourceMappingURL=builder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"builder.d.ts","sourceRoot":"","sources":["../../../src/utils/pages/builder.ts"],"names":[],"mappings":"AAAA,OAAO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ACzB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,EAAE,CAAC,CAAC,CAcxC;AAED,wBAAgB,UAAU,CACxB,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,iBAAiB,EAC5B,MAAM,EAAE,kBAAkB,GACzB,WAAW,EAAE,CA2Ef"}
@@ -0,0 +1,122 @@
1
+ import { getTagDisplayName, methodKeys, } from '../../utils/schema.js';
2
+ import { idToTitle } from '../../utils/id-to-title.js';
3
+ export async function fromServer(server, config) {
4
+ const schemas = await server.getSchemas();
5
+ const generated = {};
6
+ const entries = Object.entries(schemas);
7
+ if (entries.length === 0) {
8
+ throw new Error('No input files found.');
9
+ }
10
+ for (const [id, schema] of entries) {
11
+ generated[id] = fromSchema(id, schema, config);
12
+ }
13
+ return generated;
14
+ }
15
+ export function fromSchema(schemaId, processed, config) {
16
+ const files = [];
17
+ const { toPages } = config;
18
+ const { dereferenced } = processed;
19
+ toPages({
20
+ id: schemaId,
21
+ document: processed,
22
+ create(entry) {
23
+ files.push(entry);
24
+ },
25
+ extract: () => extractInfo(dereferenced),
26
+ routePathToFilePath(path) {
27
+ return path
28
+ .toLowerCase()
29
+ .replaceAll('.', '-')
30
+ .split('/')
31
+ .flatMap((v) => {
32
+ if (v.startsWith('{') && v.endsWith('}'))
33
+ return v.slice(1, -1);
34
+ if (v.length === 0)
35
+ return [];
36
+ return v;
37
+ })
38
+ .join('/');
39
+ },
40
+ fromExtractedWebhook(item) {
41
+ const pathItem = dereferenced.webhooks?.[item.name];
42
+ if (!pathItem)
43
+ return;
44
+ const operation = pathItem?.[item.method];
45
+ if (!operation)
46
+ return;
47
+ return {
48
+ pathItem,
49
+ operation,
50
+ get displayName() {
51
+ return operation.summary ?? pathItem.summary ?? idToTitle(item.name);
52
+ },
53
+ };
54
+ },
55
+ fromExtractedOperation(item) {
56
+ const pathItem = dereferenced.paths?.[item.path];
57
+ if (!pathItem)
58
+ return;
59
+ const operation = pathItem?.[item.method];
60
+ if (!operation)
61
+ return;
62
+ return {
63
+ pathItem,
64
+ operation,
65
+ get displayName() {
66
+ return (operation.summary ??
67
+ pathItem.summary ??
68
+ (operation.operationId
69
+ ? idToTitle(operation.operationId)
70
+ : item.path));
71
+ },
72
+ };
73
+ },
74
+ fromTag(tag) {
75
+ return {
76
+ get displayName() {
77
+ return getTagDisplayName(tag);
78
+ },
79
+ };
80
+ },
81
+ fromTagName(name) {
82
+ const tag = dereferenced.tags?.find((item) => item.name === name);
83
+ if (!tag)
84
+ return;
85
+ return {
86
+ info: tag,
87
+ ...this.fromTag(tag),
88
+ };
89
+ },
90
+ });
91
+ return files;
92
+ }
93
+ function extractInfo(document) {
94
+ const result = { webhooks: [], operations: [] };
95
+ for (const [path, pathItem] of Object.entries(document.paths ?? {})) {
96
+ if (!pathItem)
97
+ continue;
98
+ for (const methodKey of methodKeys) {
99
+ if (!pathItem[methodKey])
100
+ continue;
101
+ result.operations.push({
102
+ method: methodKey,
103
+ path,
104
+ tags: pathItem[methodKey]?.tags,
105
+ });
106
+ }
107
+ }
108
+ for (const [name, pathItem] of Object.entries(document.webhooks ?? {})) {
109
+ if (!pathItem)
110
+ continue;
111
+ for (const methodKey of methodKeys) {
112
+ if (!pathItem[methodKey])
113
+ continue;
114
+ result.webhooks.push({
115
+ method: methodKey,
116
+ name,
117
+ tags: pathItem[methodKey]?.tags,
118
+ });
119
+ }
120
+ }
121
+ return result;
122
+ }
@@ -0,0 +1,68 @@
1
+ import type { ProcessedDocument } from '../../utils/process-document.js';
2
+ import type { OperationOutput, OutputGroup, PagesBuilder, PagesBuilderConfig, TagOutput, WebhookOutput } from '../../utils/pages/builder.js';
3
+ interface OperationConfig extends BaseConfig {
4
+ /**
5
+ * Generate a page for each API endpoint/operation (default).
6
+ */
7
+ per?: 'operation';
8
+ /**
9
+ * Group output using folders (Only works on `operation` mode)
10
+ * - tag: `{tag}/{file}`
11
+ * - route: `{endpoint}/{method}` (it will ignore the `name` option)
12
+ * - none: `{file}` (default)
13
+ * - a function that aligns group name (folder path) to each entry
14
+ *
15
+ * @defaultValue 'none'
16
+ */
17
+ groupBy?: 'tag' | 'route' | 'none' | ((entry: OperationOutput | WebhookOutput) => string);
18
+ /**
19
+ * Specify name for output file
20
+ */
21
+ name?: NameFn<OperationOutput | WebhookOutput> | NameFnOptions;
22
+ }
23
+ interface TagConfig extends BaseConfig {
24
+ /**
25
+ * Generate a page for each tag.
26
+ */
27
+ per: 'tag';
28
+ /**
29
+ * Specify name for output file
30
+ */
31
+ name?: NameFn<TagOutput> | NameFnOptions;
32
+ }
33
+ interface SchemaConfig extends BaseConfig {
34
+ /**
35
+ * Generate a page for each schema file.
36
+ */
37
+ per: 'file';
38
+ /**
39
+ * Specify name for output file
40
+ */
41
+ name?: NameFn<OutputGroup> | NameFnOptions;
42
+ }
43
+ export type SchemaToPagesOptions = SchemaConfig | TagConfig | OperationConfig | ({
44
+ per: 'custom';
45
+ } & PagesBuilderConfig);
46
+ type NameFn<Entry> = (this: PagesBuilder, output: Entry, document: ProcessedDocument['dereferenced']) => string;
47
+ interface NameFnOptions {
48
+ /**
49
+ * The version of algorithm used to generate file paths.
50
+ *
51
+ * v1: Fumadocs OpenAPI v8
52
+ * v2: Fumadocs OpenAPI v9
53
+ *
54
+ * @defaultValue v2
55
+ */
56
+ algorithm?: 'v2' | 'v1';
57
+ }
58
+ interface BaseConfig {
59
+ /**
60
+ * Custom function to convert names into file names.
61
+ *
62
+ * By default, it only escapes whitespaces and upper case (English) characters
63
+ */
64
+ slugify?: (name: string) => string;
65
+ }
66
+ export declare function createAutoPreset(options: SchemaToPagesOptions): PagesBuilderConfig;
67
+ export {};
68
+ //# sourceMappingURL=preset-auto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preset-auto.d.ts","sourceRoot":"","sources":["../../../src/utils/pages/preset-auto.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,KAAK,EACV,eAAe,E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O,EAAE,oBAAoB,GAC5B,kBAAkB,CAyLpB"}
@@ -0,0 +1,138 @@
1
+ import * as path from 'node:path';
2
+ import { isUrl } from '../../utils/url.js';
3
+ export function createAutoPreset(options) {
4
+ if (options.per === 'custom')
5
+ return options;
6
+ const { slugify = (s) => {
7
+ return s.replace(/\s+/g, '-').toLowerCase();
8
+ }, } = options;
9
+ let nameFn;
10
+ if (typeof options.name === 'function') {
11
+ nameFn = options.name;
12
+ }
13
+ else {
14
+ const { algorithm = 'v2' } = options.name ?? {};
15
+ nameFn = function (result, document) {
16
+ if (result.type === 'tag') {
17
+ return slugify(result.tag);
18
+ }
19
+ if (result.type === 'group') {
20
+ const schemaId = result.schemaId;
21
+ return isUrl(schemaId)
22
+ ? 'index'
23
+ : path.basename(schemaId, path.extname(schemaId));
24
+ }
25
+ if (result.type === 'operation') {
26
+ const operation = document.paths[result.item.path][result.item.method];
27
+ if (algorithm === 'v2' && operation.operationId) {
28
+ return operation.operationId;
29
+ }
30
+ return path.join(this.routePathToFilePath(result.item.path), result.item.method.toLowerCase());
31
+ }
32
+ const hook = document.webhooks[result.item.name][result.item.method];
33
+ if (algorithm === 'v2' && hook.operationId) {
34
+ return hook.operationId;
35
+ }
36
+ return slugify(result.item.name);
37
+ };
38
+ }
39
+ function groupOutput(builder, entry) {
40
+ const { dereferenced } = builder.document;
41
+ const { groupBy = 'none' } = options;
42
+ if (groupBy === 'route') {
43
+ return [
44
+ path.join(builder.routePathToFilePath(entry.type === 'operation' ? entry.item.path : entry.item.name), `${entry.item.method.toLowerCase()}.mdx`),
45
+ ];
46
+ }
47
+ const file = nameFn.call(builder, entry, dereferenced);
48
+ if (groupBy === 'tag') {
49
+ let tags = entry.type === 'operation'
50
+ ? dereferenced.paths[entry.item.path][entry.item.method].tags
51
+ : dereferenced.webhooks[entry.item.name][entry.item.method].tags;
52
+ if (!tags || tags.length === 0) {
53
+ console.warn('When `groupBy` is set to `tag`, make sure a `tags` is defined for every operation schema.');
54
+ tags = ['unknown'];
55
+ }
56
+ return tags.map((tag) => path.join(slugify(tag), `${file}.mdx`));
57
+ }
58
+ if (typeof groupBy === 'function') {
59
+ return [path.join(slugify(groupBy(entry)), `${file}.mdx`)];
60
+ }
61
+ return [`${file}.mdx`];
62
+ }
63
+ return {
64
+ toPages(builder) {
65
+ const { dereferenced } = builder.document;
66
+ const items = builder.extract();
67
+ if (options.per === 'file') {
68
+ const entry = {
69
+ type: 'group',
70
+ schemaId: builder.id,
71
+ path: '',
72
+ info: {
73
+ title: dereferenced.info.title,
74
+ description: dereferenced.info.description,
75
+ },
76
+ ...items,
77
+ };
78
+ entry.path = nameFn.call(builder, entry, dereferenced) + '.mdx';
79
+ builder.create(entry);
80
+ return;
81
+ }
82
+ if (options.per === 'tag') {
83
+ const tags = dereferenced.tags ?? [];
84
+ for (const tag of tags) {
85
+ const { displayName } = builder.fromTag(tag);
86
+ const entry = {
87
+ type: 'tag',
88
+ path: '',
89
+ schemaId: builder.id,
90
+ info: {
91
+ title: displayName,
92
+ description: tag.description,
93
+ },
94
+ webhooks: items.webhooks.filter((webhook) => webhook.tags?.includes(tag.name)),
95
+ operations: items.operations.filter((op) => op.tags?.includes(tag.name)),
96
+ tag: tag.name,
97
+ rawTag: tag,
98
+ };
99
+ entry.path = nameFn.call(builder, entry, dereferenced) + '.mdx';
100
+ builder.create(entry);
101
+ }
102
+ return;
103
+ }
104
+ for (const op of items.operations) {
105
+ const { pathItem, operation, displayName } = builder.fromExtractedOperation(op);
106
+ const entry = {
107
+ type: 'operation',
108
+ schemaId: builder.id,
109
+ item: op,
110
+ path: '',
111
+ info: {
112
+ title: displayName,
113
+ description: operation.description ?? pathItem.description,
114
+ },
115
+ };
116
+ for (const outputPath of groupOutput(builder, entry)) {
117
+ builder.create({ ...entry, path: outputPath });
118
+ }
119
+ }
120
+ for (const webhook of items.webhooks) {
121
+ const { pathItem, operation, displayName } = builder.fromExtractedWebhook(webhook);
122
+ const entry = {
123
+ type: 'webhook',
124
+ schemaId: builder.id,
125
+ info: {
126
+ title: displayName,
127
+ description: operation.description ?? pathItem.description,
128
+ },
129
+ item: webhook,
130
+ path: '',
131
+ };
132
+ for (const outputPath of groupOutput(builder, entry)) {
133
+ builder.create({ ...entry, path: outputPath });
134
+ }
135
+ }
136
+ },
137
+ };
138
+ }
@@ -1,5 +1,5 @@
1
- import type { OutputEntry } from '../../utils/schema-to-pages.js';
2
1
  import type { ApiPageProps } from '../../render/api-page.js';
3
2
  import type { OpenAPIServer } from '../../server/index.js';
3
+ import type { OutputEntry } from '../../utils/pages/builder.js';
4
4
  export declare function toBody(server: OpenAPIServer, entry: OutputEntry): ApiPageProps;
5
5
  //# sourceMappingURL=to-body.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"to-body.d.ts","sourceRoot":"","sources":["../../../src/utils/pages/to-body.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAC3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAE9C,wBAAgB,MAAM,CACpB,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,WAAW,GACjB,YAAY,CAoBd"}
1
+ {"version":3,"file":"to-body.d.ts","sourceRoot":"","sources":["../../../src/utils/pages/to-body.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,wBAAgB,MAAM,CACpB,MAAM,EAAE,aAAa,EACrB,KAAK,EAAE,WAAW,GACjB,YAAY,CAoBd"}
@@ -1,6 +1,6 @@
1
1
  import type { ProcessedDocument } from '../../utils/process-document.js';
2
2
  import type { TagObject } from '../../types.js';
3
- import type { OutputEntry } from '../../utils/schema-to-pages.js';
3
+ import type { OutputEntry } from '../../utils/pages/builder.js';
4
4
  export interface PagesToTextOptions {
5
5
  /**
6
6
  * Additional imports of your MDX components.
@@ -1 +1 @@
1
- {"version":3,"file":"to-text.d.ts","sourceRoot":"","sources":["../../../src/utils/pages/to-text.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,KAAK,EAAY,SAAS,EAAE,MAAM,SAAS,CAAC;AAKnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE3D,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,CAAC,EAAE;QACR,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd,EAAE,CAAC;IAEJ;;;;OAIG;IACH,WAAW,CAAC,EAAE,CACZ,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,OAAO,EAAE,eAAe,KACrB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE7B;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;;;;;OAOG;IACH,mBAAmB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CACxC;AAED,wBAAgB,MAAM,CACpB,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,iBAAiB,EAC5B,OAAO,GAAE,kBAAuB,UAuEjC;AAED,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,OAAO,EACpB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,kBAAkB,GAC1B,MAAM,CA+BR;AAOD,MAAM,MAAM,eAAe,GACvB;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,SAAS,GAAG,SAAS,CAAC;CAC5B,GACD;IACE,IAAI,EAAE,WAAW,CAAC;CACnB,GACD;IACE,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
1
+ {"version":3,"file":"to-text.d.ts","sourceRoot":"","sources":["../../../src/utils/pages/to-text.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,KAAK,EAAY,SAAS,EAAE,MAAM,SAAS,CAAC;AAKnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,OAAO,CAAC,EAAE;QACR,KAAK,EAAE,MAAM,EAAE,CAAC;QAChB,IAAI,EAAE,MAAM,CAAC;KACd,EAAE,CAAC;IAEJ;;;;OAIG;IACH,WAAW,CAAC,EAAE,CACZ,KAAK,EAAE,MAAM,EACb,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,OAAO,EAAE,eAAe,KACrB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE7B;;;;;;OAMG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAE7B;;;;;;;OAOG;IACH,mBAAmB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CACxC;AAED,wBAAgB,MAAM,CACpB,KAAK,EAAE,WAAW,EAClB,SAAS,EAAE,iBAAiB,EAC5B,OAAO,GAAE,kBAAuB,UAuEjC;AAED,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,OAAO,EACpB,OAAO,EAAE,MAAM,EACf,OAAO,EAAE,kBAAkB,GAC1B,MAAM,CA+BR;AAOD,MAAM,MAAM,eAAe,GACvB;IACE,IAAI,EAAE,KAAK,CAAC;IACZ,GAAG,EAAE,SAAS,GAAG,SAAS,CAAC;CAC5B,GACD;IACE,IAAI,EAAE,WAAW,CAAC;CACnB,GACD;IACE,IAAI,EAAE,MAAM,CAAC;CACd,CAAC"}
@@ -14,7 +14,7 @@ export function toText(entry, processed, options = {}) {
14
14
  }, {
15
15
  type: 'operation',
16
16
  });
17
- case 'schema':
17
+ case 'group':
18
18
  return generatePage(entry.schemaId, processed, {
19
19
  operations: entry.operations,
20
20
  webhooks: entry.webhooks,
@@ -1,5 +1,6 @@
1
1
  import type { JSONSchema } from 'json-schema-typed/draft-2020-12';
2
2
  import type { MethodInformation, OperationObject, PathItemObject, ReferenceObject, TagObject } from '../types.js';
3
+ export declare const methodKeys: readonly ["get", "post", "patch", "delete", "head", "put"];
3
4
  export type NoReference<T> = T extends (infer I)[] ? NoReference<I>[] : T extends ReferenceObject ? Exclude<T, ReferenceObject> : T extends object ? {
4
5
  [K in keyof T]: NoReference<T[K]>;
5
6
  } : T;
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/utils/schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAClE,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,eAAe,EACf,SAAS,EACV,MAAM,SAAS,CAAC;AAGjB,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GAC9C,WAAW,CAAC,CAAC,CAAC,EAAE,GAChB,CAAC,SAAS,eAAe,GACvB,OAAO,CAAC,CAAC,EAAE,eAAe,CAAC,GAC3B,CAAC,SAAS,MAAM,GACd;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAClC,GACD,CAAC,CAAC;AAEV,KAAK,qBAAqB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,GACjD,WAAW,CAAC,CAAC,CAAC,EAAE,GAChB,CAAC,SAAS;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,GACzB,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,GACf,CAAC,CAAC;AAER,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC;AACtC,MAAM,MAAM,cAAc,GAAG,qB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,YAAY,GAAG,UAAU,CAAC;AACtC,MAAM,MAAM,cAAc,GAAG,qBAAqB,CAAC,YAAY,CAAC,CAAC;AAEjE,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAChE,IAAI,EAAE,CAAC,GACN,MAAM,CAAC,GAAG,SAAS,CAIrB;AAED,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,SAAS,GAAG,MAAM,CAIxD;AAED;;GAEG;AACH,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,WAAW,CAAC,cAAc,CAAC,EACjC,SAAS,EAAE,WAAW,CAAC,eAAe,CAAC,GACtC,iBAAiB,CAQnB"}
@@ -1,4 +1,12 @@
1
1
  import { idToTitle } from '../utils/id-to-title.js';
2
+ export const methodKeys = [
3
+ 'get',
4
+ 'post',
5
+ 'patch',
6
+ 'delete',
7
+ 'head',
8
+ 'put',
9
+ ];
2
10
  export function getPreferredType(body) {
3
11
  if ('application/json' in body)
4
12
  return 'application/json';
@@ -1,4 +1,5 @@
1
1
  import type { RequestData } from '../requests/types.js';
2
+ export declare function isUrl(schemaId: string): boolean;
2
3
  export declare function joinURL(base: string, pathname: string): string;
3
4
  /**
4
5
  * @param url - URL (can be relative)
@@ -1 +1 @@
1
- {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAM9D;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAM1D;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,MAAM,CAMR;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,WAAW,GAC3B,MAAM,CAoCR"}
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD,wBAAgB,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAE/C;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAM9D;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAM1D;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAChC,MAAM,CAMR;AAED,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,WAAW,GAC3B,MAAM,CAoCR"}
package/dist/utils/url.js CHANGED
@@ -1,3 +1,6 @@
1
+ export function isUrl(schemaId) {
2
+ return schemaId.startsWith('https://') || schemaId.startsWith('http://');
3
+ }
1
4
  export function joinURL(base, pathname) {
2
5
  if (pathname.startsWith('/'))
3
6
  pathname = pathname.slice(1);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "9.6.4",
3
+ "version": "9.7.0",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -65,8 +65,8 @@
65
65
  "remark-rehype": "^11.1.2",
66
66
  "tinyglobby": "^0.2.15",
67
67
  "xml-js": "^1.6.11",
68
- "fumadocs-core": "16.0.3",
69
- "fumadocs-ui": "16.0.3"
68
+ "fumadocs-core": "16.0.4",
69
+ "fumadocs-ui": "16.0.4"
70
70
  },
71
71
  "devDependencies": {
72
72
  "@scalar/api-client-react": "^1.3.46",
@@ -78,8 +78,8 @@
78
78
  "openapi-types": "^12.1.3",
79
79
  "tailwindcss": "^4.1.15",
80
80
  "tsc-alias": "^1.8.16",
81
- "eslint-config-custom": "0.0.0",
82
- "tsconfig": "0.0.0"
81
+ "tsconfig": "0.0.0",
82
+ "eslint-config-custom": "0.0.0"
83
83
  },
84
84
  "peerDependencies": {
85
85
  "@scalar/api-client-react": "*",
@@ -1,15 +0,0 @@
1
- import { type Document } from './types.js';
2
- import type { NoReference } from './utils/schema.js';
3
- import type { OperationItem, WebhookItem } from './render/api-page.js';
4
- export declare const methodKeys: readonly ["get", "post", "patch", "delete", "head", "put"];
5
- type Result = {
6
- webhooks: (WebhookItem & {
7
- tags?: string[];
8
- })[];
9
- operations: (OperationItem & {
10
- tags?: string[];
11
- })[];
12
- };
13
- export declare function getAPIPageItems(document: NoReference<Document>): Result;
14
- export {};
15
- //# sourceMappingURL=build-routes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"build-routes.d.ts","sourceRoot":"","sources":["../src/build-routes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,SAAS,CAAC;AACxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGpE,eAAO,MAAM,UAAU,4DAOb,CAAC;AAEX,KAAK,MAAM,GAAG;IACZ,QAAQ,EAAE,CAAC,WAAW,GAAG;QAAE,IAAI,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC,EAAE,CAAC;IAChD,UAAU,EAAE,CAAC,aAAa,GAAG;QAC3B,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;KACjB,CAAC,EAAE,CAAC;CACN,CAAC;AAEF,wBAAgB,eAAe,CAAC,QAAQ,EAAE,WAAW,CAAC,QAAQ,CAAC,GAAG,MAAM,CAgCvE"}
@@ -1,38 +0,0 @@
1
- export const methodKeys = [
2
- 'get',
3
- 'post',
4
- 'patch',
5
- 'delete',
6
- 'head',
7
- 'put',
8
- ];
9
- export function getAPIPageItems(document) {
10
- const result = { webhooks: [], operations: [] };
11
- for (const [path, pathItem] of Object.entries(document.paths ?? {})) {
12
- if (!pathItem)
13
- continue;
14
- for (const methodKey of methodKeys) {
15
- if (!pathItem[methodKey])
16
- continue;
17
- result.operations.push({
18
- method: methodKey,
19
- path,
20
- tags: pathItem[methodKey]?.tags,
21
- });
22
- }
23
- }
24
- for (const [name, pathItem] of Object.entries(document.webhooks ?? {})) {
25
- if (!pathItem)
26
- continue;
27
- for (const methodKey of methodKeys) {
28
- if (!pathItem[methodKey])
29
- continue;
30
- result.webhooks.push({
31
- method: methodKey,
32
- name,
33
- tags: pathItem[methodKey]?.tags,
34
- });
35
- }
36
- }
37
- return result;
38
- }
@@ -1,97 +0,0 @@
1
- import { type ProcessedDocument } from '../utils/process-document.js';
2
- import type { OpenAPIServer } from '../server/index.js';
3
- import type { OperationItem, WebhookItem } from '../render/api-page.js';
4
- import type { TagObject } from '../types.js';
5
- interface BaseEntry {
6
- path: string;
7
- schemaId: string;
8
- info: {
9
- title: string;
10
- description?: string;
11
- };
12
- }
13
- export interface OutputOperationEntry extends BaseEntry {
14
- type: 'operation';
15
- item: OperationItem;
16
- }
17
- export interface OutputWebhookEntry extends BaseEntry {
18
- type: 'webhook';
19
- item: WebhookItem;
20
- }
21
- export interface OutputTagEntry extends BaseEntry {
22
- type: 'tag';
23
- tag: string;
24
- rawTag: TagObject;
25
- operations: OperationItem[];
26
- webhooks: WebhookItem[];
27
- }
28
- export interface OutputSchemaEntry extends BaseEntry {
29
- type: 'schema';
30
- operations: OperationItem[];
31
- webhooks: WebhookItem[];
32
- }
33
- export type OutputEntry = OutputTagEntry | OutputOperationEntry | OutputWebhookEntry | OutputSchemaEntry;
34
- interface OperationConfig extends BaseConfig {
35
- /**
36
- * Generate a page for each API endpoint/operation (default).
37
- */
38
- per?: 'operation';
39
- /**
40
- * Group output using folders (Only works on `operation` mode)
41
- * - tag: `{tag}/{file}`
42
- * - route: `{endpoint}/{method}` (it will ignore the `name` option)
43
- * - none: `{file}` (default)
44
- *
45
- * @defaultValue 'none'
46
- */
47
- groupBy?: 'tag' | 'route' | 'none';
48
- /**
49
- * Specify name for output file
50
- */
51
- name?: NameFn<OutputOperationEntry | OutputWebhookEntry>;
52
- }
53
- interface TagConfig extends BaseConfig {
54
- /**
55
- * Generate a page for each tag.
56
- */
57
- per: 'tag';
58
- /**
59
- * Specify name for output file
60
- */
61
- name?: NameFn<OutputTagEntry>;
62
- }
63
- interface SchemaConfig extends BaseConfig {
64
- /**
65
- * Generate a page for each schema file.
66
- */
67
- per: 'file';
68
- /**
69
- * Specify name for output file
70
- */
71
- name?: NameFn<OutputSchemaEntry>;
72
- }
73
- export type SchemaToPagesOptions = SchemaConfig | TagConfig | OperationConfig;
74
- type NameFn<Entry> = ((output: Entry, document: ProcessedDocument['dereferenced']) => string) | {
75
- /**
76
- * The version of algorithm used to generate file paths.
77
- *
78
- * v1: Fumadocs OpenAPI v8
79
- * v2: Fumadocs OpenAPI v9
80
- *
81
- * @defaultValue v2
82
- */
83
- algorithm?: 'v2' | 'v1';
84
- };
85
- interface BaseConfig {
86
- /**
87
- * Custom function to convert names into file names.
88
- *
89
- * By default, it only escapes whitespaces and upper case (English) characters
90
- */
91
- slugify?: (name: string) => string;
92
- }
93
- export declare function serverToPages(server: OpenAPIServer, options: SchemaToPagesOptions): Promise<Record<string, OutputEntry[]>>;
94
- export declare function schemaToPages(schemaId: string, processed: ProcessedDocument, options: SchemaToPagesOptions): OutputEntry[];
95
- export declare function isUrl(schemaId: string): boolean;
96
- export {};
97
- //# sourceMappingURL=schema-to-pages.d.ts.map
@@ -1 +0,0 @@
1
- {"version":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../utils/id-to-title.js';
3
- import { getAPIPageItems } from '../build-routes.js';
4
- import { getTagDisplayName } from '../utils/schema.js';
5
- export async function serverToPages(server, options) {
6
- const schemas = await server.getSchemas();
7
- const generated = {};
8
- const entries = Object.entries(schemas);
9
- if (entries.length === 0) {
10
- throw new Error('No input files found.');
11
- }
12
- for (const [id, schema] of entries) {
13
- generated[id] = schemaToPages(id, schema, options);
14
- }
15
- return generated;
16
- }
17
- export function schemaToPages(schemaId, processed, options) {
18
- const files = [];
19
- const { dereferenced } = processed;
20
- const { slugify = defaultSlugify } = options;
21
- let nameFn;
22
- if (!options.name || typeof options.name !== 'function') {
23
- const algorithm = options.name?.algorithm;
24
- nameFn = (out, doc) => defaultNameFn(schemaId, out, doc, options, algorithm);
25
- }
26
- else {
27
- nameFn = options.name;
28
- }
29
- function getOutputPaths(groupBy = 'none', entry) {
30
- if (groupBy === 'route') {
31
- return [
32
- path.join(getOutputPathFromRoute(entry.type === 'operation' ? entry.item.path : entry.item.name), `${entry.item.method.toLowerCase()}.mdx`),
33
- ];
34
- }
35
- const file = nameFn(entry, dereferenced);
36
- if (groupBy === 'tag') {
37
- let tags = entry.type === 'operation'
38
- ? dereferenced.paths[entry.item.path][entry.item.method].tags
39
- : dereferenced.webhooks[entry.item.name][entry.item.method].tags;
40
- if (!tags || tags.length === 0) {
41
- console.warn('When `groupBy` is set to `tag`, make sure a `tags` is defined for every operation schema.');
42
- tags = ['unknown'];
43
- }
44
- return tags.map((tag) => path.join(slugify(tag), `${file}.mdx`));
45
- }
46
- return [`${file}.mdx`];
47
- }
48
- if (options.per === 'file') {
49
- const items = getAPIPageItems(dereferenced);
50
- const entry = {
51
- type: 'schema',
52
- schemaId,
53
- path: '',
54
- info: {
55
- title: dereferenced.info.title,
56
- description: dereferenced.info.description,
57
- },
58
- ...items,
59
- };
60
- entry.path = nameFn(entry, dereferenced) + '.mdx';
61
- files.push(entry);
62
- return files;
63
- }
64
- if (options.per === 'tag') {
65
- const items = getAPIPageItems(dereferenced);
66
- const tags = dereferenced.tags ?? [];
67
- for (const tag of tags) {
68
- const entry = {
69
- type: 'tag',
70
- path: '',
71
- schemaId,
72
- info: {
73
- title: getTagDisplayName(tag),
74
- description: tag.description,
75
- },
76
- webhooks: items.webhooks.filter((webhook) => webhook.tags?.includes(tag.name)),
77
- operations: items.operations.filter((op) => op.tags?.includes(tag.name)),
78
- tag: tag.name,
79
- rawTag: tag,
80
- };
81
- entry.path = nameFn(entry, dereferenced) + '.mdx';
82
- files.push(entry);
83
- }
84
- return files;
85
- }
86
- const results = getAPIPageItems(dereferenced);
87
- for (const op of results.operations) {
88
- const pathItem = dereferenced.paths[op.path];
89
- const operation = pathItem[op.method];
90
- const entry = {
91
- type: 'operation',
92
- schemaId,
93
- item: op,
94
- path: '',
95
- info: {
96
- title: operation.summary ??
97
- pathItem.summary ??
98
- idToTitle(operation.operationId ?? 'unknown'),
99
- description: operation.description ?? pathItem.description,
100
- },
101
- };
102
- for (const outputPath of getOutputPaths(options.groupBy, entry)) {
103
- files.push({ ...entry, path: outputPath });
104
- }
105
- }
106
- for (const webhook of results.webhooks) {
107
- const pathItem = dereferenced.webhooks[webhook.name];
108
- const operation = pathItem[webhook.method];
109
- const entry = {
110
- type: 'webhook',
111
- schemaId,
112
- info: {
113
- title: operation.summary ?? pathItem.summary ?? idToTitle(webhook.name),
114
- description: operation.description ?? pathItem.description,
115
- },
116
- item: webhook,
117
- path: '',
118
- };
119
- for (const outputPath of getOutputPaths(options.groupBy, entry)) {
120
- files.push({ ...entry, path: outputPath });
121
- }
122
- }
123
- return files;
124
- }
125
- function defaultNameFn(schemaId, result, document, options, algorithm = 'v2') {
126
- const { slugify = defaultSlugify } = options;
127
- if (result.type === 'tag') {
128
- return slugify(result.tag);
129
- }
130
- if (result.type === 'schema') {
131
- return isUrl(schemaId)
132
- ? 'index'
133
- : path.basename(schemaId, path.extname(schemaId));
134
- }
135
- if (result.type === 'operation') {
136
- const operation = document.paths[result.item.path][result.item.method];
137
- if (algorithm === 'v2' && operation.operationId) {
138
- return operation.operationId;
139
- }
140
- return path.join(getOutputPathFromRoute(result.item.path), result.item.method.toLowerCase());
141
- }
142
- const hook = document.webhooks[result.item.name][result.item.method];
143
- if (algorithm === 'v2' && hook.operationId) {
144
- return hook.operationId;
145
- }
146
- return slugify(result.item.name);
147
- }
148
- export function isUrl(schemaId) {
149
- return schemaId.startsWith('https://') || schemaId.startsWith('http://');
150
- }
151
- function getOutputPathFromRoute(path) {
152
- return path
153
- .toLowerCase()
154
- .replaceAll('.', '-')
155
- .split('/')
156
- .flatMap((v) => {
157
- if (v.startsWith('{') && v.endsWith('}'))
158
- return v.slice(1, -1);
159
- if (v.length === 0)
160
- return [];
161
- return v;
162
- })
163
- .join('/');
164
- }
165
- function defaultSlugify(s) {
166
- return s.replace(/\s+/g, '-').toLowerCase();
167
- }