fumadocs-openapi 10.8.5 → 10.9.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 (56) hide show
  1. package/css/generated/shared.css +26 -6
  2. package/dist/generate-file.d.ts +1 -1
  3. package/dist/generate-file.js +1 -1
  4. package/dist/i18n.d.ts +9 -4
  5. package/dist/i18n.js +14 -5
  6. package/dist/index.d.ts +2 -2
  7. package/dist/node_modules/.pnpm/{@scalar_helpers@0.6.0 → @scalar_helpers@0.8.0}/node_modules/@scalar/helpers/dist/general/create-limiter.js +1 -1
  8. package/dist/node_modules/.pnpm/{@scalar_helpers@0.6.0 → @scalar_helpers@0.8.0}/node_modules/@scalar/helpers/dist/object/is-object.js +1 -1
  9. package/dist/node_modules/.pnpm/{@scalar_helpers@0.6.0 → @scalar_helpers@0.8.0}/node_modules/@scalar/helpers/dist/object/prevent-pollution.js +1 -1
  10. package/dist/node_modules/.pnpm/{@scalar_helpers@0.6.0 → @scalar_helpers@0.8.0}/node_modules/@scalar/helpers/dist/queue/queue.js +1 -1
  11. package/dist/node_modules/.pnpm/{@scalar_helpers@0.6.0 → @scalar_helpers@0.8.0}/node_modules/@scalar/helpers/dist/string/generate-hash.js +1 -1
  12. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/bundle.js +2 -2
  13. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/plugins/fetch-urls/index.js +2 -2
  14. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/plugins/read-files/index.js +1 -1
  15. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/value-generator.js +2 -2
  16. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/convert-to-local-ref.js +1 -1
  17. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/escape-json-pointer.js +1 -1
  18. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/get-schemas.js +1 -1
  19. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/get-segments-from-path.js +1 -1
  20. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/get-value-by-path.js +1 -1
  21. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/is-file-path.js +1 -1
  22. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/is-http-url.js +1 -1
  23. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/is-json-object.js +2 -2
  24. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/is-yaml.js +1 -1
  25. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.14/node_modules/@scalar/json-magic/dist/helpers/normalize.js +33 -0
  26. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/resolve-reference-path.js +1 -1
  27. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/set-value-at-path.js +2 -2
  28. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/to-relative-path.js +1 -1
  29. package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/helpers/unescape-json-pointer.js +1 -1
  30. package/dist/playground/client.js +1 -1
  31. package/dist/playground/components/oauth-dialog.js +1 -1
  32. package/dist/playground/components/result-display.js +3 -2
  33. package/dist/playground/components/spinner.js +2 -1
  34. package/dist/scalar/client.js +2 -1
  35. package/dist/server/index.d.ts +108 -3
  36. package/dist/server/index.js +181 -2
  37. package/dist/server/proxy.d.ts +1 -1
  38. package/dist/types.d.ts +1 -1
  39. package/dist/ui/base.d.ts +1 -1
  40. package/dist/ui/client/i18n.js +7 -10
  41. package/dist/ui/components/method-label.js +1 -4
  42. package/dist/ui/index.d.ts +1 -1
  43. package/dist/utils/document/process.js +4 -4
  44. package/dist/utils/pages/builder.d.ts +4 -3
  45. package/dist/utils/pages/builder.js +20 -1
  46. package/dist/utils/pages/to-text.d.ts +1 -1
  47. package/dist/utils/pages/to-text.js +23 -42
  48. package/dist/utils/schema/sample.js +1 -1
  49. package/package.json +9 -9
  50. package/dist/node_modules/.pnpm/@scalar_json-magic@0.12.12/node_modules/@scalar/json-magic/dist/helpers/normalize.js +0 -26
  51. package/dist/server/create.d.ts +0 -40
  52. package/dist/server/create.js +0 -42
  53. package/dist/server/source-api.d.ts +0 -55
  54. package/dist/server/source-api.js +0 -149
  55. /package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/plugins/node.js +0 -0
  56. /package/dist/node_modules/.pnpm/{@scalar_json-magic@0.12.12 → @scalar_json-magic@0.12.14}/node_modules/@scalar/json-magic/dist/bundle/plugins/parse-yaml/index.js +0 -0
@@ -1,40 +0,0 @@
1
- import { InlineCodeUsageGenerator } from "../requests/generators/index.js";
2
- import { createProxy } from "./proxy.js";
3
- import { ProcessedDocument } from "../utils/document/process.js";
4
- import { Document } from "../types.js";
5
-
6
- //#region src/server/create.d.ts
7
- /**
8
- * schema id -> file path, URL, or downloaded schema object
9
- */
10
- type SchemaMap = Record<string, string | Document>;
11
- type ProcessedSchemaMap = Record<string, ProcessedDocument>;
12
- interface OpenAPIOptions {
13
- /**
14
- * Schema files, can be:
15
- * - URL
16
- * - file path
17
- * - a function returning records of downloaded schemas.
18
- */
19
- input?: string[] | (() => SchemaMap | Promise<SchemaMap>);
20
- disableCache?: boolean;
21
- /**
22
- * The url of proxy to avoid CORS issues
23
- */
24
- proxyUrl?: string;
25
- }
26
- interface OpenAPIServer {
27
- createProxy: typeof createProxy;
28
- getSchemas: () => Promise<ProcessedSchemaMap>;
29
- getSchema: (document: string) => Promise<ProcessedDocument>;
30
- /** @private internal API */
31
- _getWatchPaths: () => string[];
32
- readonly options: OpenAPIOptions;
33
- }
34
- declare function createOpenAPI(options?: OpenAPIOptions): OpenAPIServer;
35
- /**
36
- * @deprecated
37
- */
38
- declare function createCodeSample<T>(options: InlineCodeUsageGenerator<T>): InlineCodeUsageGenerator<T>;
39
- //#endregion
40
- export { OpenAPIOptions, OpenAPIServer, createCodeSample, createOpenAPI };
@@ -1,42 +0,0 @@
1
- import { createProxy } from "./proxy.js";
2
- import { processDocument } from "../utils/document/process.js";
3
- import fs from "node:fs";
4
- //#region src/server/create.ts
5
- function createOpenAPI(options = {}) {
6
- const { input = [], disableCache = false } = options;
7
- let schemas;
8
- async function getSchemas() {
9
- if (Array.isArray(input)) {
10
- const entries = await Promise.all(input.map(async (item) => [item, await processDocument(item)]));
11
- return Object.fromEntries(entries);
12
- } else {
13
- const entries = await Promise.all(Object.entries(await input()).map(async ([k, v]) => [k, await processDocument(v)]));
14
- return Object.fromEntries(entries);
15
- }
16
- }
17
- return {
18
- options,
19
- createProxy,
20
- _getWatchPaths() {
21
- return (Array.isArray(input) ? input : Object.keys(input)).filter((key) => !URL.canParse(key) && fs.existsSync(key));
22
- },
23
- async getSchema(document) {
24
- const schemas = await this.getSchemas();
25
- if (document in schemas) return schemas[document];
26
- console.warn(`[Fumadocs OpenAPI] the document "${document}" is not listed in the input array, this may not be expected.`);
27
- return processDocument(document);
28
- },
29
- async getSchemas() {
30
- if (disableCache) return getSchemas();
31
- return schemas ??= getSchemas();
32
- }
33
- };
34
- }
35
- /**
36
- * @deprecated
37
- */
38
- function createCodeSample(options) {
39
- return options;
40
- }
41
- //#endregion
42
- export { createCodeSample, createOpenAPI };
@@ -1,55 +0,0 @@
1
- import { OpenAPIServer } from "./create.js";
2
- import { ApiPageProps } from "../ui/api-page.js";
3
- import { SchemaToPagesOptions } from "../utils/pages/preset-auto.js";
4
- import { ClientApiPageProps } from "../ui/create-client.js";
5
- import { DereferencedDocument } from "../utils/document/dereference.js";
6
- import { LoaderPlugin, MetaData, PageData, PageTreeTransformer, Source } from "fumadocs-core/source";
7
- import { StructuredData } from "fumadocs-core/mdx-plugins";
8
- import { TOCItemType } from "fumadocs-core/toc";
9
-
10
- //#region src/server/source-api.d.ts
11
- declare module 'fumadocs-core/source' {
12
- interface PageData {
13
- /**
14
- * Added by Fumadocs OpenAPI
15
- */
16
- _openapi?: InternalOpenAPIMeta;
17
- }
18
- }
19
- interface InternalOpenAPIMeta {
20
- method?: string;
21
- webhook?: boolean;
22
- deprecated?: boolean;
23
- }
24
- /**
25
- * Fumadocs Source API integration, pass this to `plugins` array in `loader()`.
26
- */
27
- declare function openapiPlugin(): LoaderPlugin;
28
- interface OpenAPIPageData extends PageData {
29
- getAPIPageProps: () => ApiPageProps;
30
- getSchema: () => {
31
- id: string;
32
- } & DereferencedDocument;
33
- getClientAPIPageProps: () => Promise<ClientApiPageProps>;
34
- structuredData: StructuredData;
35
- toc: TOCItemType[];
36
- }
37
- type OpenAPISourceOptions = SchemaToPagesOptions & {
38
- baseDir?: string; /** Generate `meta.json` files */
39
- meta?: boolean | {
40
- folderStyle?: 'folder' | 'separator';
41
- };
42
- };
43
- /**
44
- * Generate virtual pages for Fumadocs Source API
45
- */
46
- declare function openapiSource(server: OpenAPIServer, options?: OpenAPISourceOptions): Promise<Source<{
47
- metaData: MetaData;
48
- pageData: OpenAPIPageData;
49
- }>>;
50
- /**
51
- * @deprecated use `openapiPlugin()`
52
- */
53
- declare function transformerOpenAPI(): PageTreeTransformer;
54
- //#endregion
55
- export { InternalOpenAPIMeta, OpenAPIPageData, OpenAPISourceOptions, openapiPlugin, openapiSource, transformerOpenAPI };
@@ -1,149 +0,0 @@
1
- import { toStaticData } from "../utils/pages/to-static-data.js";
2
- import { MethodLabel } from "../ui/components/method-label.js";
3
- import path from "node:path";
4
- import { PathUtils } from "fumadocs-core/source";
5
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
- //#region src/server/source-api.tsx
7
- /**
8
- * Fumadocs Source API integration, pass this to `plugins` array in `loader()`.
9
- */
10
- function openapiPlugin() {
11
- return {
12
- name: "fumadocs:openapi",
13
- enforce: "pre",
14
- transformPageTree: { file(node, filePath) {
15
- if (!filePath) return node;
16
- const file = this.storage.read(filePath);
17
- if (!file || file.format !== "page") return node;
18
- const openApiData = file.data._openapi;
19
- if (!openApiData || typeof openApiData !== "object") return node;
20
- if (openApiData.deprecated) node.name = /* @__PURE__ */ jsx("span", {
21
- className: "fd-page-tree-item-name line-through",
22
- children: node.name
23
- });
24
- if (openApiData.webhook) node.name = /* @__PURE__ */ jsxs(Fragment, { children: [
25
- node.name,
26
- " ",
27
- /* @__PURE__ */ jsx("span", {
28
- className: "ms-auto border border-current px-1 rounded-lg text-xs text-nowrap font-mono",
29
- children: "Webhook"
30
- })
31
- ] });
32
- else if (openApiData.method) node.name = /* @__PURE__ */ jsxs(Fragment, { children: [
33
- node.name,
34
- " ",
35
- /* @__PURE__ */ jsx(MethodLabel, {
36
- className: "ms-auto text-xs text-nowrap",
37
- children: openApiData.method
38
- })
39
- ] });
40
- return node;
41
- } }
42
- };
43
- }
44
- /**
45
- * Generate virtual pages for Fumadocs Source API
46
- */
47
- async function openapiSource(server, options = {}) {
48
- const { baseDir = "", meta = false } = options;
49
- const { createAutoPreset } = await import("../utils/pages/preset-auto.js");
50
- const { fromServer } = await import("../utils/pages/builder.js");
51
- const files = [];
52
- const entries = await fromServer(server, createAutoPreset(options));
53
- for (const [schemaId, list] of Object.entries(entries)) {
54
- const processed = await server.getSchema(schemaId);
55
- function onEntry(entry) {
56
- const props = getProps(entry);
57
- files.push({
58
- type: "page",
59
- path: `${baseDir}/${entry.path}`,
60
- data: {
61
- ...entry.info,
62
- getAPIPageProps() {
63
- return props;
64
- },
65
- async getClientAPIPageProps() {
66
- return {
67
- payload: {
68
- bundled: processed.bundled,
69
- proxyUrl: server.options.proxyUrl
70
- },
71
- ...props
72
- };
73
- },
74
- getSchema() {
75
- return {
76
- id: schemaId,
77
- ...processed
78
- };
79
- },
80
- ...toStaticData(props, processed.dereferenced),
81
- _openapi: {
82
- method: entry.type === "operation" || entry.type === "webhook" ? entry.item.method : void 0,
83
- webhook: entry.type === "webhook",
84
- deprecated: entry.info.deprecated
85
- }
86
- }
87
- });
88
- }
89
- function onEntries(entries, parent) {
90
- if (!meta) {
91
- for (const entry of entries) if (entry.type === "group") onEntries(entry.entries, entry);
92
- else onEntry(entry);
93
- return;
94
- }
95
- const { folderStyle = "folder" } = meta === true ? {} : meta;
96
- const pages = [];
97
- for (const entry of entries) {
98
- const relativePath = PathUtils.slash(parent ? path.relative(parent.path, entry.path) : entry.path);
99
- if (entry.type === "group") {
100
- onEntries(entry.entries, entry);
101
- if (folderStyle === "folder") pages.push(relativePath);
102
- else pages.push(`---${entry.info.title}---`, `...${relativePath}`);
103
- } else {
104
- onEntry(entry);
105
- pages.push(relativePath.slice(0, -PathUtils.extname(entry.path).length));
106
- }
107
- }
108
- if (pages.length === 0) return;
109
- files.push({
110
- type: "meta",
111
- path: path.join(baseDir, parent?.path ?? "", "meta.json"),
112
- data: {
113
- title: parent?.info.title,
114
- description: parent?.info.description,
115
- pages
116
- }
117
- });
118
- }
119
- onEntries(list);
120
- }
121
- return { files };
122
- }
123
- function getProps(entry) {
124
- if (entry.type === "operation") return {
125
- document: entry.schemaId,
126
- operations: [entry.item],
127
- showDescription: true
128
- };
129
- if (entry.type === "webhook") return {
130
- document: entry.schemaId,
131
- webhooks: [entry.item],
132
- showDescription: true
133
- };
134
- return {
135
- showTitle: true,
136
- showDescription: true,
137
- document: entry.schemaId,
138
- operations: entry.operations,
139
- webhooks: entry.webhooks
140
- };
141
- }
142
- /**
143
- * @deprecated use `openapiPlugin()`
144
- */
145
- function transformerOpenAPI() {
146
- return openapiPlugin().transformPageTree;
147
- }
148
- //#endregion
149
- export { openapiPlugin, openapiSource, transformerOpenAPI };