fumadocs-openapi 6.2.1 → 7.0.0-beta.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 (83) hide show
  1. package/dist/generate-file.d.ts.map +1 -1
  2. package/dist/generate-file.js +13 -12
  3. package/dist/generate.d.ts +9 -0
  4. package/dist/generate.d.ts.map +1 -1
  5. package/dist/playground/client.d.ts +4 -3
  6. package/dist/playground/client.d.ts.map +1 -1
  7. package/dist/playground/client.js +109 -102
  8. package/dist/playground/fetcher.d.ts +6 -22
  9. package/dist/playground/fetcher.d.ts.map +1 -1
  10. package/dist/playground/fetcher.js +25 -85
  11. package/dist/playground/get-default-values.d.ts +2 -3
  12. package/dist/playground/get-default-values.d.ts.map +1 -1
  13. package/dist/playground/get-default-values.js +8 -4
  14. package/dist/playground/index.d.ts +0 -1
  15. package/dist/playground/index.d.ts.map +1 -1
  16. package/dist/playground/index.js +0 -1
  17. package/dist/playground/inputs.d.ts.map +1 -1
  18. package/dist/playground/inputs.js +46 -32
  19. package/dist/render/operation/api-example.d.ts +18 -4
  20. package/dist/render/operation/api-example.d.ts.map +1 -1
  21. package/dist/render/operation/api-example.js +68 -72
  22. package/dist/render/operation/get-request-data.d.ts +5 -0
  23. package/dist/render/operation/get-request-data.d.ts.map +1 -0
  24. package/dist/render/operation/get-request-data.js +71 -0
  25. package/dist/render/{operation.d.ts → operation/index.d.ts} +4 -4
  26. package/dist/render/operation/index.d.ts.map +1 -0
  27. package/dist/render/{operation.js → operation/index.js} +14 -15
  28. package/dist/render/renderer.d.ts +1 -9
  29. package/dist/render/renderer.d.ts.map +1 -1
  30. package/dist/render/renderer.js +3 -5
  31. package/dist/requests/_shared.d.ts +11 -0
  32. package/dist/requests/_shared.d.ts.map +1 -0
  33. package/dist/requests/_shared.js +4 -0
  34. package/dist/requests/curl.d.ts +2 -2
  35. package/dist/requests/curl.d.ts.map +1 -1
  36. package/dist/requests/curl.js +17 -18
  37. package/dist/requests/go.d.ts +2 -2
  38. package/dist/requests/go.d.ts.map +1 -1
  39. package/dist/requests/go.js +15 -14
  40. package/dist/requests/index.d.ts +3 -0
  41. package/dist/requests/index.d.ts.map +1 -0
  42. package/dist/requests/index.js +26 -0
  43. package/dist/requests/javascript.d.ts +2 -2
  44. package/dist/requests/javascript.d.ts.map +1 -1
  45. package/dist/requests/javascript.js +20 -27
  46. package/dist/requests/python.d.ts +2 -2
  47. package/dist/requests/python.d.ts.map +1 -1
  48. package/dist/requests/python.js +18 -22
  49. package/dist/server/api-page.js +1 -1
  50. package/dist/types.d.ts +5 -6
  51. package/dist/types.d.ts.map +1 -1
  52. package/dist/ui/client.d.ts +1 -2
  53. package/dist/ui/client.d.ts.map +1 -1
  54. package/dist/ui/client.js +1 -3
  55. package/dist/ui/components/method-label.d.ts +1 -1
  56. package/dist/ui/contexts/api.d.ts +3 -5
  57. package/dist/ui/contexts/api.d.ts.map +1 -1
  58. package/dist/ui/contexts/api.js +2 -7
  59. package/dist/ui/contexts/code-example.d.ts +25 -0
  60. package/dist/ui/contexts/code-example.d.ts.map +1 -0
  61. package/dist/ui/contexts/code-example.js +104 -0
  62. package/dist/ui/contexts/code-example.lazy.d.ts +12 -0
  63. package/dist/ui/contexts/code-example.lazy.d.ts.map +1 -0
  64. package/dist/ui/contexts/code-example.lazy.js +5 -0
  65. package/dist/ui/server-select.d.ts +6 -1
  66. package/dist/ui/server-select.d.ts.map +1 -1
  67. package/dist/ui/server-select.js +6 -7
  68. package/dist/utils/generate-document.d.ts.map +1 -1
  69. package/dist/utils/generate-document.js +9 -1
  70. package/dist/utils/get-pathname-from-input.d.ts +2 -0
  71. package/dist/utils/get-pathname-from-input.d.ts.map +1 -0
  72. package/dist/utils/get-pathname-from-input.js +15 -0
  73. package/dist/utils/get-typescript-schema.d.ts +2 -3
  74. package/dist/utils/get-typescript-schema.d.ts.map +1 -1
  75. package/dist/utils/get-typescript-schema.js +13 -16
  76. package/package.json +6 -6
  77. package/dist/render/operation.d.ts.map +0 -1
  78. package/dist/ui/sample-select.d.ts +0 -4
  79. package/dist/ui/sample-select.d.ts.map +0 -1
  80. package/dist/ui/sample-select.js +0 -19
  81. package/dist/utils/generate-sample.d.ts +0 -40
  82. package/dist/utils/generate-sample.d.ts.map +0 -1
  83. package/dist/utils/generate-sample.js +0 -109
@@ -0,0 +1,12 @@
1
+ export declare const CodeExampleProvider: import("react").ComponentType<{
2
+ route: string;
3
+ examples: {
4
+ key: string;
5
+ data: import("../../requests/_shared.js").RequestData;
6
+ }[];
7
+ initialKey?: string;
8
+ children: React.ReactNode;
9
+ }>;
10
+ export declare const CodeExample: import("react").ComponentType<import("../../render/operation/index.js").CodeSample>;
11
+ export declare const CodeExampleSelector: import("react").ComponentType<import("../../render/renderer.js").SamplesProps>;
12
+ //# sourceMappingURL=code-example.lazy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"code-example.lazy.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/code-example.lazy.tsx"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB;;;;;;;cASi4B,MAAO,SAAS;EAPh7B,CAAC;AACF,eAAO,MAAM,WAAW,4EAEvB,CAAC;AACF,eAAO,MAAM,mBAAmB,6EAE/B,CAAC"}
@@ -0,0 +1,5 @@
1
+ 'use client';
2
+ import dynamic from 'next/dynamic';
3
+ export const CodeExampleProvider = dynamic(() => import('./code-example.js').then((mod) => mod.CodeExampleProvider));
4
+ export const CodeExample = dynamic(() => import('./code-example.js').then((mod) => mod.CodeExample));
5
+ export const CodeExampleSelector = dynamic(() => import('./code-example.js').then((mod) => mod.CodeExampleSelector));
@@ -1,3 +1,8 @@
1
+ import { type SelectedServer } from '../ui/contexts/api.js';
1
2
  import type { HTMLAttributes } from 'react';
2
- export default function ServerSelect(props: HTMLAttributes<HTMLDivElement>): import("react/jsx-runtime").JSX.Element | null;
3
+ export default function ServerSelect({ server, onServerChanged, onVariablesChanged, ...props }: HTMLAttributes<HTMLDivElement> & {
4
+ server: SelectedServer | null;
5
+ onServerChanged: (value: string) => void;
6
+ onVariablesChanged: (value: Record<string, string>) => void;
7
+ }): import("react/jsx-runtime").JSX.Element | null;
3
8
  //# sourceMappingURL=server-select.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"server-select.d.ts","sourceRoot":"","sources":["../../src/ui/server-select.tsx"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAG5C,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,KAAK,EAAE,cAAc,CAAC,cAAc,CAAC,kDA6EzE"}
1
+ {"version":3,"file":"server-select.d.ts","sourceRoot":"","sources":["../../src/ui/server-select.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,cAAc,EAAiB,MAAM,mBAAmB,CAAC;AASvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAG5C,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,MAAM,EACN,eAAe,EACf,kBAAkB,EAClB,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,cAAc,CAAC,GAAG;IAClC,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC;IAC9B,eAAe,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,kBAAkB,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;CAC7D,kDA4EA"}
@@ -1,25 +1,24 @@
1
1
  'use client';
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useApiContext, useServerSelectContext } from '../ui/contexts/api.js';
3
+ import { useApiContext } from '../ui/contexts/api.js';
4
4
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../ui/components/select.js';
5
5
  import { Input, labelVariants } from '../ui/components/input.js';
6
6
  import { cn } from 'fumadocs-ui/components/api';
7
- export default function ServerSelect(props) {
7
+ export default function ServerSelect({ server, onServerChanged, onVariablesChanged, ...props }) {
8
8
  const { servers } = useApiContext();
9
- const { server, setServer, setServerVariables } = useServerSelectContext();
10
9
  if (servers.length <= 1)
11
10
  return null;
12
11
  const schema = server
13
12
  ? servers.find((item) => item.url === server.url)
14
- : undefined;
15
- return (_jsxs("div", { ...props, className: cn('flex flex-col gap-4', props.className), children: [_jsxs(Select, { value: server?.url, onValueChange: setServer, children: [_jsx(SelectTrigger, { className: "h-auto break-all", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: servers.map((item) => (_jsxs(SelectItem, { value: item.url, children: [item.url, _jsx("p", { className: "text-start text-fd-muted-foreground", children: item.description })] }, item.url))) })] }), Object.entries(schema?.variables ?? {}).map(([key, variable]) => {
13
+ : null;
14
+ return (_jsxs("div", { ...props, className: cn('flex flex-col gap-4', props.className), children: [_jsxs(Select, { value: server?.url, onValueChange: onServerChanged, children: [_jsx(SelectTrigger, { className: "h-auto break-all", children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: servers.map((item) => (_jsxs(SelectItem, { value: item.url, children: [item.url, _jsx("p", { className: "text-start text-fd-muted-foreground", children: item.description })] }, item.url))) })] }), Object.entries(schema?.variables ?? {}).map(([key, variable]) => {
16
15
  if (!server)
17
16
  return;
18
17
  const id = `fd_server_select_${key}`;
19
- return (_jsxs("fieldset", { className: "flex flex-col gap-1", children: [_jsx("label", { className: cn(labelVariants()), htmlFor: id, children: key }), _jsx("p", { className: "text-xs text-fd-muted-foreground empty:hidden", children: variable.description }), variable.enum ? (_jsxs(Select, { value: server.variables[key], onValueChange: (v) => setServerVariables({
18
+ return (_jsxs("fieldset", { className: "flex flex-col gap-1", children: [_jsx("label", { className: cn(labelVariants()), htmlFor: id, children: key }), _jsx("p", { className: "text-xs text-fd-muted-foreground empty:hidden", children: variable.description }), variable.enum ? (_jsxs(Select, { value: server.variables[key], onValueChange: (v) => onVariablesChanged({
20
19
  ...server?.variables,
21
20
  [key]: v,
22
- }), children: [_jsx(SelectTrigger, { id: id, children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: variable.enum.map((value) => (_jsx(SelectItem, { value: value, children: value }, value))) })] })) : (_jsx(Input, { id: id, value: server.variables[key], onChange: (e) => setServerVariables({
21
+ }), children: [_jsx(SelectTrigger, { id: id, children: _jsx(SelectValue, {}) }), _jsx(SelectContent, { children: variable.enum.map((value) => (_jsx(SelectItem, { value: value, children: value }, value))) })] })) : (_jsx(Input, { id: id, value: server.variables[key], onChange: (e) => onVariablesChanged({
23
22
  ...server?.variables,
24
23
  [key]: e.target.value,
25
24
  }) }))] }, key));
@@ -1 +1 @@
1
- {"version":3,"file":"generate-document.d.ts","sourceRoot":"","sources":["../../src/utils/generate-document.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,YAAY,EAGb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAOlD,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;AAEN,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,eAAe,GAAG;IACzB,YAAY,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IACpC,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,eAAe,CAAC;CAC1B,GACA,MAAM,CAkDR"}
1
+ {"version":3,"file":"generate-document.d.ts","sourceRoot":"","sources":["../../src/utils/generate-document.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,YAAY,EAGb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD,OAAO,KAAK,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAOlD,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;AAEN,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,eAAe,GAAG;IACzB,YAAY,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IACpC,IAAI,EAAE,YAAY,CAAC;IACnB,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,eAAe,CAAC;CAC1B,GACA,MAAM,CAkER"}
@@ -2,7 +2,7 @@ import { dump } from 'js-yaml';
2
2
  import Slugger from 'github-slugger';
3
3
  import { idToTitle } from '../utils/id-to-title.js';
4
4
  export function generateDocument(options) {
5
- const { frontmatter, includeDescription = false } = options;
5
+ const { frontmatter, includeDescription = false, addGeneratedComment = true, } = options;
6
6
  const out = [];
7
7
  const extend = frontmatter?.(options.title, options.description, options.context);
8
8
  let meta;
@@ -27,6 +27,14 @@ export function generateDocument(options) {
27
27
  }).trim();
28
28
  if (banner.length > 0)
29
29
  out.push(`---\n${banner}\n---`);
30
+ if (addGeneratedComment !== false) {
31
+ let commentContent = 'This file was generated by Fumadocs.\nDo not edit this file directly. Any changes should be made by running the generation command again.';
32
+ if (typeof addGeneratedComment === 'string') {
33
+ commentContent = addGeneratedComment;
34
+ }
35
+ commentContent = commentContent.replaceAll('/', '\\/');
36
+ out.push(`{/* ${commentContent} */}`);
37
+ }
30
38
  const imports = options.imports
31
39
  ?.map((item) => `import { ${item.names.join(', ')} } from ${JSON.stringify(item.from)};`)
32
40
  .join('\n');
@@ -0,0 +1,2 @@
1
+ export declare function getPathnameFromInput(url: string, path: Record<string, unknown>, query: Record<string, unknown>): string;
2
+ //# sourceMappingURL=get-pathname-from-input.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-pathname-from-input.d.ts","sourceRoot":"","sources":["../../src/utils/get-pathname-from-input.ts"],"names":[],"mappings":"AAAA,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,MAAM,CAkBR"}
@@ -0,0 +1,15 @@
1
+ export function getPathnameFromInput(url, path, query) {
2
+ let pathname = url;
3
+ for (const key in path) {
4
+ const paramValue = path[key];
5
+ if (typeof paramValue === 'string' && paramValue.length > 0)
6
+ pathname = pathname.replace(`{${key}}`, paramValue);
7
+ }
8
+ const searchParams = new URLSearchParams();
9
+ for (const key in query) {
10
+ const paramValue = query[key];
11
+ if (typeof paramValue === 'string' && paramValue.length > 0)
12
+ searchParams.append(key, paramValue);
13
+ }
14
+ return searchParams.size > 0 ? `${pathname}?${searchParams}` : pathname;
15
+ }
@@ -1,4 +1,3 @@
1
- import type { EndpointSample } from '../utils/generate-sample.js';
2
- import { DereferenceMap } from '../types.js';
3
- export declare function getTypescriptSchema(endpoint: EndpointSample, code: string, dereferenceMap: DereferenceMap): Promise<string | undefined>;
1
+ import type { DereferenceMap } from '../types.js';
2
+ export declare function getTypescriptSchema(schema: object, dereferenceMap: DereferenceMap): Promise<string | undefined>;
4
3
  //# sourceMappingURL=get-typescript-schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-typescript-schema.d.ts","sourceRoot":"","sources":["../../src/utils/get-typescript-schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAEzC,wBAAsB,mBAAmB,CACvC,QAAQ,EAAE,cAAc,EACxB,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAmB7B"}
1
+ {"version":3,"file":"get-typescript-schema.d.ts","sourceRoot":"","sources":["../../src/utils/get-typescript-schema.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAE9C,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,EACd,cAAc,EAAE,cAAc,GAC7B,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAgB7B"}
@@ -1,18 +1,15 @@
1
1
  import { compile } from '@fumari/json-schema-to-typescript';
2
- export async function getTypescriptSchema(endpoint, code, dereferenceMap) {
3
- if (code in endpoint.responses) {
4
- return compile(
5
- // re-running on the same schema results in error
6
- // because it uses `defineProperty` to define internal references
7
- // we clone the schema to fix this problem
8
- // @ts-expect-error any types
9
- endpoint.responses[code].schema, 'Response', {
10
- $refOptions: false,
11
- schemaToId: dereferenceMap,
12
- bannerComment: '',
13
- additionalProperties: false,
14
- format: true,
15
- enableConstEnums: false,
16
- });
17
- }
2
+ export async function getTypescriptSchema(schema, dereferenceMap) {
3
+ return compile(
4
+ // re-running on the same schema results in error
5
+ // because it uses `defineProperty` to define internal references
6
+ // we clone the schema to fix this problem
7
+ schema, 'Response', {
8
+ $refOptions: false,
9
+ schemaToId: dereferenceMap,
10
+ bannerComment: '',
11
+ additionalProperties: false,
12
+ format: true,
13
+ enableConstEnums: false,
14
+ });
18
15
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "6.2.1",
3
+ "version": "7.0.0-beta.0",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -62,16 +62,16 @@
62
62
  "remark-rehype": "^11.1.1",
63
63
  "shiki": "^3.1.0",
64
64
  "xml-js": "^1.6.11",
65
- "fumadocs-core": "15.0.14",
66
- "fumadocs-ui": "15.0.14"
65
+ "fumadocs-ui": "15.0.15",
66
+ "fumadocs-core": "15.0.15"
67
67
  },
68
68
  "devDependencies": {
69
- "@scalar/api-client-react": "^1.1.33",
69
+ "@scalar/api-client-react": "^1.1.35",
70
70
  "@types/js-yaml": "^4.0.9",
71
- "@types/node": "22.13.8",
71
+ "@types/node": "22.13.9",
72
72
  "@types/openapi-sampler": "^1.0.3",
73
73
  "@types/react": "^19.0.10",
74
- "next": "15.2.0",
74
+ "next": "15.2.1",
75
75
  "openapi-types": "^12.1.3",
76
76
  "tailwindcss": "^4.0.9",
77
77
  "tsc-alias": "^1.8.11",
@@ -1 +0,0 @@
1
- {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../src/render/operation.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,YAAY,EAAkB,MAAM,OAAO,CAAC;AACpE,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9E,OAAO,KAAK,EAEV,iBAAiB,EAEjB,aAAa,EAEd,MAAM,SAAS,CAAC;AAYjB,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EACF,MAAM,GACN,CAAC,CAAC,QAAQ,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC,GACtE,KAAK,CAAC;CACX;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,CAkLf"}
@@ -1,4 +0,0 @@
1
- import type { SampleProps, SamplesProps } from '../render/renderer.js';
2
- export declare function Samples({ items, defaultValue, children, }: SamplesProps): import("react/jsx-runtime").JSX.Element;
3
- export declare function Sample({ value, children }: SampleProps): import("react").ReactNode;
4
- //# sourceMappingURL=sample-select.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"sample-select.d.ts","sourceRoot":"","sources":["../../src/ui/sample-select.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAWnE,wBAAgB,OAAO,CAAC,EACtB,KAAK,EACL,YAA6B,EAC7B,QAAQ,GACT,EAAE,YAAY,2CA0Bd;AAWD,wBAAgB,MAAM,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,EAAE,WAAW,6BAKtD"}
@@ -1,19 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { createContext, use, useState } from 'react';
3
- import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from '../ui/components/select.js';
4
- const ActiveSampleContext = createContext('');
5
- export function Samples({ items, defaultValue = items[0].value, children, }) {
6
- const [value, setValue] = useState('');
7
- const active = value === '' ? defaultValue : value;
8
- const defaultItem = items.find((item) => item.value === defaultValue);
9
- return (_jsxs(_Fragment, { children: [_jsxs(Select, { value: value, onValueChange: setValue, children: [_jsx(SelectTrigger, { className: "not-prose mb-2", children: _jsx(SelectValue, { placeholder: defaultItem ? _jsx(SelectDisplay, { ...defaultItem }) : null }) }), _jsx(SelectContent, { children: items.map((item) => (_jsx(SelectItem, { value: item.value, children: _jsx(SelectDisplay, { ...item }) }, item.value))) })] }), _jsx(ActiveSampleContext, { value: active, children: children })] }));
10
- }
11
- function SelectDisplay(item) {
12
- return (_jsxs(_Fragment, { children: [_jsx("span", { className: "font-medium text-sm", children: item.title }), _jsx("span", { className: "text-fd-muted-foreground", children: item.description })] }));
13
- }
14
- export function Sample({ value, children }) {
15
- const active = use(ActiveSampleContext);
16
- if (value !== active)
17
- return;
18
- return children;
19
- }
@@ -1,40 +0,0 @@
1
- import type { MethodInformation, RenderContext } from '../types.js';
2
- import { type ParsedSchema, type NoReference } from '../utils/schema.js';
3
- import type { OpenAPIV3_1 } from 'openapi-types';
4
- export type Samples = {
5
- [key in '_default' | (string & {})]?: {
6
- value?: unknown;
7
- description?: string;
8
- summary?: string;
9
- externalValue?: string;
10
- };
11
- };
12
- /**
13
- * Sample info of endpoint
14
- */
15
- export interface EndpointSample {
16
- /**
17
- * Request URL, including path and query parameters
18
- */
19
- url: string;
20
- method: string;
21
- body?: {
22
- schema: ParsedSchema;
23
- mediaType: string;
24
- samples: Samples;
25
- };
26
- responses: Record<string, ResponseSample>;
27
- parameters: ParameterSample[];
28
- }
29
- interface ResponseSample {
30
- mediaType: string;
31
- samples: Samples;
32
- schema: ParsedSchema;
33
- }
34
- interface ParameterSample extends NoReference<OpenAPIV3_1.ParameterObject> {
35
- sample: unknown;
36
- isAuthOnly: boolean;
37
- }
38
- export declare function generateSample(path: string, method: MethodInformation, { baseUrl, schema: { document } }: RenderContext): EndpointSample;
39
- export {};
40
- //# sourceMappingURL=generate-sample.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-sample.d.ts","sourceRoot":"","sources":["../../src/utils/generate-sample.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,WAAW,EACjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,MAAM,MAAM,OAAO,GAAG;KACnB,GAAG,IAAI,UAAU,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,EAAE;QACpC,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,aAAa,CAAC,EAAE,MAAM,CAAC;KACxB;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE;QACL,MAAM,EAAE,YAAY,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC;IACF,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC1C,UAAU,EAAE,eAAe,EAAE,CAAC;CAC/B;AAED,UAAU,cAAc;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,YAAY,CAAC;CACtB;AAED,UAAU,eAAgB,SAAQ,WAAW,CAAC,WAAW,CAAC,eAAe,CAAC;IACxE,MAAM,EAAE,OAAO,CAAC;IAChB,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,aAAa,GAC/C,cAAc,CA0HhB"}
@@ -1,109 +0,0 @@
1
- import { sample } from 'openapi-sampler';
2
- import { getPreferredType, } from '../utils/schema.js';
3
- import { getSecurities, getSecurityPrefix } from '../utils/get-security.js';
4
- export function generateSample(path, method, { baseUrl, schema: { document } }) {
5
- const params = [];
6
- const responses = {};
7
- for (const param of method.parameters ?? []) {
8
- let schema = param.schema, value;
9
- if (!schema && param.content) {
10
- const key = getPreferredType(param.content);
11
- const content = key ? param.content[key] : undefined;
12
- if (!content)
13
- throw new Error(`Cannot find parameter schema for ${param.name} in ${path} ${method.method}`);
14
- schema = content.schema;
15
- value = content.example ?? param.example ?? sample(schema);
16
- }
17
- else {
18
- value = param.example ?? sample(schema);
19
- }
20
- if (schema?.type && param.schema?.type === value) {
21
- // if no example is defined make sure its visible that there is still a placeholder, equal to auth <token>
22
- value = `<${value}>`;
23
- }
24
- params.push({
25
- ...param,
26
- sample: value,
27
- isAuthOnly: false,
28
- });
29
- }
30
- const requirements = method.security ?? document.security;
31
- if (requirements && requirements.length > 0) {
32
- for (const security of getSecurities(requirements[0], document)) {
33
- const prefix = getSecurityPrefix(security);
34
- params.push({
35
- name: security.type === 'apiKey' ? security.name : 'Authorization',
36
- schema: {
37
- type: 'string',
38
- },
39
- sample: prefix ? `${prefix} <token>` : '<token>',
40
- in: 'header',
41
- isAuthOnly: true,
42
- });
43
- }
44
- }
45
- let bodyOutput;
46
- if (method.requestBody) {
47
- const body = method.requestBody.content;
48
- const type = getPreferredType(body);
49
- if (!type)
50
- throw new Error(`Cannot find body schema for ${path} ${method.method}: missing media type`);
51
- const schema = (type ? body[type].schema : undefined) ?? {};
52
- bodyOutput = {
53
- schema,
54
- mediaType: type,
55
- samples: body[type].examples
56
- ? body[type].examples
57
- : {
58
- _default: {
59
- value: body[type].example ?? generateBody(method.method, schema),
60
- },
61
- },
62
- };
63
- }
64
- for (const [code, response] of Object.entries(method.responses ?? {})) {
65
- const content = response.content;
66
- if (!content)
67
- continue;
68
- const mediaType = getPreferredType(content);
69
- if (!mediaType)
70
- continue;
71
- const responseSchema = content[mediaType].schema;
72
- if (!responseSchema)
73
- continue;
74
- const examples = content[mediaType].examples ?? content.examples;
75
- const example = content[mediaType].example ?? content.example;
76
- responses[code] = {
77
- mediaType,
78
- samples: examples
79
- ? examples
80
- : {
81
- _default: example ?? generateBody(method.method, responseSchema),
82
- },
83
- schema: responseSchema,
84
- };
85
- }
86
- let pathWithParameters = path;
87
- const queryParams = new URLSearchParams();
88
- for (const param of params) {
89
- if (param.in === 'query')
90
- queryParams.append(param.name, String(param.sample));
91
- if (param.in === 'path')
92
- pathWithParameters = pathWithParameters.replace(`{${param.name}}`, String(param.sample));
93
- }
94
- if (queryParams.size > 0)
95
- pathWithParameters = `${pathWithParameters}?${queryParams.toString()}`;
96
- return {
97
- url: `${baseUrl}${pathWithParameters}`,
98
- body: bodyOutput,
99
- responses,
100
- method: method.method,
101
- parameters: params,
102
- };
103
- }
104
- function generateBody(method, schema) {
105
- return sample(schema, {
106
- skipReadOnly: method !== 'GET',
107
- skipWriteOnly: method === 'GET',
108
- });
109
- }