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
@@ -185,7 +185,6 @@ function toSchema(schema, required, ctx) {
185
185
  }
186
186
  return {
187
187
  type: schema.type === 'integer' ? 'number' : schema.type,
188
- defaultValue: (schema.example ?? ''),
189
188
  isRequired: required,
190
189
  description: schema.description ?? schema.title,
191
190
  };
@@ -1 +1 @@
1
- {"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../src/playground/inputs.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EAEnB,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAWf,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAMxD,KAAK,WAAW,CAAC,IAAI,IAAI,OAAO,CAAC,aAAa,EAAE;IAAE,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC;AA6BhE,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,SAAS,EACT,GAAG,KAAK,EACT,EAAE;IACD,KAAK,EAAE,WAAW,CAAC,QAAQ,CAAC,CAAC;IAC7B,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,cAAc,CAAC,cAAc,CAAC,2CAqBjC;AAoJD,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,SAAS,EACT,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG;IAC/B,KAAK,EAAE,OAAO,CAAC,aAAa,EAAE;QAAE,IAAI,EAAE,UAAU,CAAA;KAAE,CAAC,CAAC;IACpD,SAAS,EAAE,MAAM,CAAC;CACnB,kDAuFA;AAED,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EACL,SAAS,EACT,OAAO,EACP,IAAI,EACJ,GAAG,KAAK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
@@ -17,19 +17,18 @@ export function ObjectInput({ field, fieldName, ...props }) {
17
17
  return (_jsxs("div", { ...props, className: cn('flex flex-col gap-6', props.className), children: [Object.entries(field.properties).map(([key, child]) => (_jsx(FieldSet, { name: key, field: resolve(child, references), fieldName: `${fieldName}.${key}` }, key))), field.additionalProperties ? (_jsx(AdditionalProperties, { fieldName: fieldName, type: field.additionalProperties })) : null] }));
18
18
  }
19
19
  function AdditionalProperties({ fieldName, type, }) {
20
- const { control, setValue } = useFormContext();
21
- const { references, dynamic } = useSchemaContext();
20
+ const { control, setValue, getValues } = useFormContext();
21
+ const { references } = useSchemaContext();
22
22
  const [nextName, setNextName] = useState('');
23
23
  const [properties, setProperties] = useState(() => {
24
- const d = dynamic.current.get(`additional_${fieldName}`);
25
- if (d?.type === 'object')
26
- return d.properties;
24
+ const value = getValues(fieldName);
25
+ if (value)
26
+ return Object.keys(value);
27
27
  return [];
28
28
  });
29
- dynamic.current.set(`additional_${fieldName}`, {
30
- type: 'object',
31
- properties,
32
- });
29
+ const types = typeof type === 'string'
30
+ ? resolveDynamicTypes(references[type], references)
31
+ : anyFields;
33
32
  const onAppend = () => {
34
33
  const name = nextName.trim();
35
34
  if (name.length === 0)
@@ -37,17 +36,14 @@ function AdditionalProperties({ fieldName, type, }) {
37
36
  setProperties((p) => {
38
37
  if (p.includes(name))
39
38
  return p;
40
- setValue(`${fieldName}.${name}`, '');
39
+ setValue(`${fieldName}.${name}`, getDefaultValue(Object.values(types)[0], references));
41
40
  setNextName('');
42
41
  return [...p, name];
43
42
  });
44
43
  };
45
- const types = typeof type === 'string'
46
- ? resolveDynamicTypes(references[type], references)
47
- : undefined;
48
44
  return (_jsxs(_Fragment, { children: [properties.map((item) => (_jsx(FieldSet, { name: item, field: {
49
45
  type: 'switcher',
50
- items: types ?? anyFields,
46
+ items: types,
51
47
  isRequired: false,
52
48
  }, fieldName: `${fieldName}.${item}`, toolbar: _jsx("button", { type: "button", "aria-label": "Remove Item", className: cn(buttonVariants({
53
49
  color: 'secondary',
@@ -76,17 +72,14 @@ const anyFields = {
76
72
  string: {
77
73
  type: 'string',
78
74
  isRequired: false,
79
- defaultValue: '',
80
75
  },
81
76
  boolean: {
82
77
  type: 'boolean',
83
78
  isRequired: false,
84
- defaultValue: '',
85
79
  },
86
80
  number: {
87
81
  type: 'number',
88
82
  isRequired: false,
89
- defaultValue: '',
90
83
  },
91
84
  object: {
92
85
  type: 'object',
@@ -114,41 +107,62 @@ export function FieldInput({ field, fieldName, ...props }) {
114
107
  if (field.type === 'array') {
115
108
  return (_jsx(ArrayInput, { fieldName: fieldName, field: field, ...props, className: cn('rounded-lg border border-fd-primary/20 bg-fd-background p-3 shadow-sm', props.className) }));
116
109
  }
117
- if (field.type === 'file' || field.type === 'boolean') {
118
- return (_jsx(Controller, { control: control, name: fieldName, render: ({ field: { value, onChange, ...restField } }) => field.type === 'file' ? (_jsx("input", { id: fieldName, type: "file", multiple: false, onChange: (e) => {
110
+ if (field.type === 'file') {
111
+ return (_jsx(Controller, { control: control, name: fieldName, render: ({ field: { value: _, onChange, ...restField } }) => (_jsx("input", { id: fieldName, type: "file", multiple: false, onChange: (e) => {
119
112
  if (!e.target.files)
120
113
  return;
121
114
  onChange(e.target.files.item(0));
122
- }, ...props, ...restField })) : (_jsxs(Select, { value: value, onValueChange: onChange, disabled: restField.disabled, children: [_jsx(SelectTrigger, { id: fieldName, className: props.className, ...restField, children: _jsx(SelectValue, {}) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: "true", children: "True" }), _jsx(SelectItem, { value: "false", children: "False" }), field.isRequired ? null : (_jsx(SelectItem, { value: "null", children: "Null" }))] })] })) }));
115
+ }, ...props, ...restField })) }));
116
+ }
117
+ if (field.type === 'boolean') {
118
+ return (_jsx(Controller, { control: control, name: fieldName, render: ({ field: { value, onChange, ...restField } }) => (_jsxs(Select, { value: String(value), onValueChange: (value) => onChange(value === 'null' ? null : value === 'true'), disabled: restField.disabled, children: [_jsx(SelectTrigger, { id: fieldName, className: props.className, ...restField, children: _jsx(SelectValue, {}) }), _jsxs(SelectContent, { children: [_jsx(SelectItem, { value: "true", children: "True" }), _jsx(SelectItem, { value: "false", children: "False" }), field.isRequired ? null : (_jsx(SelectItem, { value: "null", children: "Null" }))] })] })) }));
123
119
  }
124
- return (_jsx(Input, { id: fieldName, placeholder: "Enter value", type: field.type === 'string' ? 'text' : 'number', ...register(fieldName), ...props }));
120
+ return (_jsx(Input, { id: fieldName, placeholder: "Enter value", type: field.type === 'string' ? 'text' : 'number', ...register(fieldName, {
121
+ valueAsNumber: field.type === 'number',
122
+ }), ...props }));
125
123
  }
126
124
  export function FieldSet({ field, fieldName, toolbar, name, ...props }) {
125
+ const form = useFormContext();
127
126
  const { references, dynamic } = useSchemaContext();
128
- const [value, setValue] = useState(() => {
127
+ const [type, setType] = useState(() => {
129
128
  if (field.type !== 'switcher')
130
129
  return '';
131
130
  const d = dynamic.current.get(fieldName);
132
131
  const items = Object.keys(field.items);
133
132
  if (d?.type === 'field') {
134
- // schemas are passed from server components, they shouldn't be re-constructed
133
+ // schemas are passed from server components, object references are maintained
135
134
  const cached = items.find((item) => d.schema === field.items[item]);
136
135
  if (cached)
137
136
  return cached;
138
137
  }
139
- return items[0];
138
+ const value = form.getValues(fieldName);
139
+ let type = typeof value;
140
+ if (Array.isArray(value)) {
141
+ type = 'array';
142
+ }
143
+ else if (value instanceof File) {
144
+ type = 'file';
145
+ }
146
+ else if (value === null) {
147
+ type = 'null';
148
+ }
149
+ return items.find((item) => field.items[item].type === type) ?? items[0];
140
150
  });
141
151
  if (field.type === 'null')
142
152
  return null;
143
- if (value && field.type === 'switcher') {
144
- dynamic.current.set(fieldName, {
145
- type: 'field',
146
- schema: field.items[value],
147
- });
148
- }
149
153
  if (field.type === 'switcher') {
150
- const child = resolve(field.items[value], references);
151
- return (_jsxs("fieldset", { ...props, className: cn('flex flex-col gap-1.5', props.className), children: [_jsxs(FieldHeader, { name: name, htmlFor: fieldName, required: field.isRequired, children: [_jsx("select", { value: value, onChange: (e) => setValue(e.target.value), className: "text-xs", children: Object.keys(field.items).map((item) => (_jsx("option", { value: item, children: item }, item))) }), toolbar] }), _jsx("p", { className: "text-xs text-fd-muted-foreground", children: field.description }), child.type === 'switcher' ? (_jsx(FieldSet, { field: child, fieldName: fieldName })) : (_jsx(FieldInput, { field: child, fieldName: fieldName }))] }));
154
+ const child = resolve(field.items[type], references);
155
+ return (_jsxs("fieldset", { ...props, className: cn('flex flex-col gap-1.5', props.className), children: [_jsxs(FieldHeader, { name: name, htmlFor: fieldName, required: field.isRequired, children: [_jsx("select", { value: type, onChange: (e) => {
156
+ const value = e.target.value;
157
+ if (value === type)
158
+ return;
159
+ setType(value);
160
+ dynamic.current.set(fieldName, {
161
+ type: 'field',
162
+ schema: field.items[value],
163
+ });
164
+ form.setValue(fieldName, getDefaultValue(field.items[value], references));
165
+ }, className: "text-xs", children: Object.keys(field.items).map((item) => (_jsx("option", { value: item, children: item }, item))) }), toolbar] }), _jsx("p", { className: "text-xs text-fd-muted-foreground", children: field.description }), child.type === 'switcher' ? (_jsx(FieldSet, { field: child, fieldName: fieldName })) : (_jsx(FieldInput, { field: child, fieldName: fieldName }))] }));
152
166
  }
153
167
  return (_jsxs("fieldset", { ...props, className: cn('flex flex-col gap-1.5', props.className), children: [_jsx(FieldHeader, { htmlFor: fieldName, name: name, required: field.isRequired, type: field.type, children: toolbar }), _jsx(FieldInput, { field: field, fieldName: fieldName })] }));
154
168
  }
@@ -1,14 +1,28 @@
1
1
  import type { MethodInformation, RenderContext } from '../../types.js';
2
- import type { EndpointSample } from '../../utils/generate-sample.js';
3
- import { type CodeSample } from '../../render/operation.js';
2
+ import { type ReactNode } from 'react';
3
+ import { type CodeSample } from '../../render/operation/index.js';
4
+ import type { RequestData } from '../../requests/_shared.js';
4
5
  interface CustomProperty {
5
6
  'x-codeSamples'?: CodeSample[];
6
7
  'x-selectedCodeSample'?: string;
7
8
  'x-exclusiveCodeSample'?: string;
8
9
  }
9
- export declare function APIExample({ method, endpoint, ctx, }: {
10
+ interface CodeExampleItem {
11
+ key: string;
12
+ name: string;
13
+ description?: string;
14
+ data: RequestData;
15
+ }
16
+ export declare function APIExampleProvider({ examples, method, children, route, }: {
17
+ examples: CodeExampleItem[];
18
+ method: MethodInformation & CustomProperty;
19
+ route: string;
20
+ children: ReactNode;
21
+ }): import("react/jsx-runtime").JSX.Element;
22
+ export declare function getAPIExamples(path: string, method: MethodInformation, ctx: RenderContext): CodeExampleItem[];
23
+ export declare function APIExample({ method, examples, ctx, }: {
24
+ examples: CodeExampleItem[];
10
25
  method: MethodInformation & CustomProperty;
11
- endpoint: EndpointSample;
12
26
  ctx: RenderContext;
13
27
  }): Promise<import("react/jsx-runtime").JSX.Element>;
14
28
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"api-example.d.ts","sourceRoot":"","sources":["../../../src/render/operation/api-example.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAG9D,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AA2BrD,UAAU,cAAc;IACtB,eAAe,CAAC,EAAE,UAAU,EAAE,CAAC;IAC/B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC;AAcD,wBAAsB,UAAU,CAAC,EAC/B,MAAM,EACN,QAAQ,EACR,GAAG,GACJ,EAAE;IACD,MAAM,EAAE,iBAAiB,GAAG,cAAc,CAAC;IAC3C,QAAQ,EAAE,cAAc,CAAC;IACzB,GAAG,EAAE,aAAa,CAAC;CACpB,oDAyFA"}
1
+ {"version":3,"file":"api-example.d.ts","sourceRoot":"","sources":["../../../src/render/operation/api-example.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAU3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAqBtD,UAAU,cAAc;IACtB,eAAe,CAAC,EAAE,UAAU,EAAE,CAAC;IAC/B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC;AAED,UAAU,eAAe;IACvB,GAAG,EAAE,MAAM,CAAC;IAEZ,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,wBAAgB,kBAAkB,CAAC,EACjC,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,KAAK,GACN,EAAE;IACD,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,MAAM,EAAE,iBAAiB,GAAG,cAAc,CAAC;IAC3C,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,SAAS,CAAC;CACrB,2CAeA;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,iBAAiB,EACzB,GAAG,EAAE,aAAa,GACjB,eAAe,EAAE,CA8BnB;AAED,wBAAsB,UAAU,CAAC,EAC/B,MAAM,EACN,QAAQ,EACR,GAAG,GACJ,EAAE;IACD,QAAQ,EAAE,eAAe,EAAE,CAAC;IAC5B,MAAM,EAAE,iBAAiB,GAAG,cAAc,CAAC;IAC3C,GAAG,EAAE,aAAa,CAAC;CACpB,oDAmCA"}
@@ -1,84 +1,75 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import * as CURL from '../../requests/curl.js';
3
- import * as JS from '../../requests/javascript.js';
4
- import * as Go from '../../requests/go.js';
5
- import * as Python from '../../requests/python.js';
6
2
  import { Markdown } from '../../render/markdown.js';
7
3
  import { getTypescriptSchema } from '../../utils/get-typescript-schema.js';
8
4
  import { CodeBlock } from '../../render/codeblock.js';
5
+ import { CodeExample, CodeExampleProvider, } from '../../ui/contexts/code-example.lazy.js';
6
+ import { getPreferredType } from '../../utils/schema.js';
7
+ import { getRequestData } from '../../render/operation/get-request-data.js';
8
+ import { sample } from 'openapi-sampler';
9
9
  const defaultSamples = [
10
10
  {
11
11
  label: 'cURL',
12
- source: CURL.getSampleRequest,
13
12
  lang: 'bash',
14
13
  },
15
14
  {
16
15
  label: 'JavaScript',
17
- source: JS.getSampleRequest,
18
16
  lang: 'js',
19
17
  },
20
18
  {
21
19
  label: 'Go',
22
- source: Go.getSampleRequest,
23
20
  lang: 'go',
24
21
  },
25
22
  {
26
23
  label: 'Python',
27
- source: Python.getSampleRequest,
28
24
  lang: 'python',
29
25
  },
30
26
  ];
31
- export async function APIExample({ method, endpoint, ctx, }) {
32
- const renderer = ctx.renderer;
33
- const samples = new Map();
34
- let children;
35
- for (const [key, sample] of Object.entries(endpoint.body?.samples ?? {
36
- // fallback for methods that have no request body, we also want to show examples for
37
- _default: {},
38
- })) {
39
- samples.set(key, {
40
- title: sample?.summary ?? key,
41
- description: sample?.description,
42
- samples: dedupe([
43
- ...defaultSamples,
44
- ...(ctx.generateCodeSamples
45
- ? await ctx.generateCodeSamples(endpoint)
46
- : []),
47
- ...(method['x-codeSamples'] ?? []),
48
- ]).flatMap((sample) => {
49
- if (sample.source === false)
50
- return [];
51
- const result = typeof sample.source === 'function'
52
- ? sample.source(endpoint, key)
53
- : sample.source;
54
- if (result === undefined)
55
- return [];
56
- return {
57
- ...sample,
58
- source: result,
59
- };
60
- }),
61
- });
62
- }
63
- function renderRequest(sample) {
64
- return (_jsx(renderer.Requests, { items: sample.samples.map((s) => s.label), children: sample.samples.map((s) => (_jsx(renderer.Request, { name: s.label, code: s.source, language: s.lang }, s.label))) }));
65
- }
66
- const exclusiveCodeSamples = method['x-exclusiveCodeSample'];
67
- if ((samples.size === 1 && samples.has('_default')) ||
68
- (exclusiveCodeSamples && samples.has(exclusiveCodeSamples))) {
69
- // if exclusiveSampleKey is present, we don't use tabs
70
- // if only the fallback or non described openapi legacy example is present, we don't use tabs
71
- children = renderRequest(samples.get(exclusiveCodeSamples ?? '_default'));
72
- }
73
- else if (samples.size > 0) {
74
- const entries = Array.from(samples.entries());
75
- children = (_jsx(renderer.Samples, { items: entries.map(([key, sample]) => ({
76
- title: sample.title,
77
- description: sample.description ? (_jsx(Markdown, { text: sample.description })) : null,
78
- value: key,
79
- })), defaultValue: exclusiveCodeSamples, children: entries.map(([key, sample]) => (_jsx(renderer.Sample, { value: key, children: renderRequest(sample) }, key))) }));
27
+ export function APIExampleProvider({ examples, method, children, route, }) {
28
+ const exclusiveSampleKey = method['x-exclusiveCodeSample'];
29
+ return (_jsx(CodeExampleProvider, { initialKey: exclusiveSampleKey, route: route, examples: examples.map((example) => ({
30
+ key: example.key,
31
+ data: example.data,
32
+ })), children: children }));
33
+ }
34
+ export function getAPIExamples(path, method, ctx) {
35
+ const media = method.requestBody
36
+ ? getPreferredType(method.requestBody.content)
37
+ : null;
38
+ const bodyOfType = media ? method.requestBody?.content[media] : null;
39
+ if (bodyOfType?.examples) {
40
+ const result = [];
41
+ for (const [key, value] of Object.entries(bodyOfType.examples)) {
42
+ result.push({
43
+ key,
44
+ name: value.summary ?? key,
45
+ description: value.description,
46
+ data: getRequestData(path, method, key, ctx),
47
+ });
48
+ }
49
+ return result;
80
50
  }
81
- return (_jsxs(renderer.APIExample, { children: [children, _jsx(ResponseTabs, { operation: method, ctx: ctx, endpoint: endpoint })] }));
51
+ return [
52
+ {
53
+ key: '_default',
54
+ name: 'Default',
55
+ description: bodyOfType?.schema?.description,
56
+ data: getRequestData(path, method, null, ctx),
57
+ },
58
+ ];
59
+ }
60
+ export async function APIExample({ method, examples, ctx, }) {
61
+ const renderer = ctx.renderer;
62
+ const generators = dedupe([
63
+ ...defaultSamples,
64
+ ...(ctx.generateCodeSamples ? await ctx.generateCodeSamples(method) : []),
65
+ ...(method['x-codeSamples'] ?? []),
66
+ ]).filter((generator) => generator.source !== false);
67
+ const exclusiveSampleKey = method['x-exclusiveCodeSample'];
68
+ return (_jsxs(renderer.APIExample, { children: [examples.length > 1 && !exclusiveSampleKey && (_jsx(renderer.CodeExampleSelector, { items: examples.map((sample) => ({
69
+ title: sample.name,
70
+ description: sample.description ? (_jsx(Markdown, { text: sample.description })) : null,
71
+ value: sample.key,
72
+ })) })), generators.length > 0 && (_jsx(renderer.Requests, { items: generators.map((s) => s.label), children: generators.map((generator) => (_jsx(renderer.Request, { name: generator.label, children: _jsx(CodeExample, { ...generator }) }, generator.label))) })), _jsx(ResponseTabs, { operation: method, ctx: ctx })] }));
82
73
  }
83
74
  /**
84
75
  * Remove duplicated labels
@@ -94,35 +85,40 @@ function dedupe(samples) {
94
85
  }
95
86
  return out;
96
87
  }
97
- function ResponseTabs({ endpoint, operation, ctx: { renderer, generateTypeScriptSchema, schema }, }) {
88
+ function ResponseTabs({ operation, ctx: { renderer, generateTypeScriptSchema, schema }, }) {
98
89
  if (!operation.responses)
99
90
  return null;
100
91
  async function renderResponse(code) {
101
- const response = code in endpoint.responses ? endpoint.responses[code] : null;
92
+ const response = operation.responses && code in operation.responses
93
+ ? operation.responses[code]
94
+ : null;
95
+ const media = getPreferredType(response?.content ?? {});
96
+ const responseOfType = media ? response?.content?.[media] : null;
102
97
  const description = operation.responses?.[code].description ??
103
- response?.schema.description ??
98
+ responseOfType?.schema?.description ??
104
99
  '';
105
100
  let ts;
106
101
  if (generateTypeScriptSchema) {
107
- ts = await generateTypeScriptSchema(endpoint, code);
102
+ ts = await generateTypeScriptSchema(operation, code);
108
103
  }
109
- else if (generateTypeScriptSchema === undefined) {
110
- ts = await getTypescriptSchema(endpoint, code, schema.dereferenceMap);
104
+ else if (generateTypeScriptSchema === undefined &&
105
+ responseOfType?.schema) {
106
+ ts = await getTypescriptSchema(responseOfType?.schema, schema.dereferenceMap);
111
107
  }
112
108
  const values = [];
113
109
  let exampleSlot;
114
- if (response?.samples._default) {
115
- values.push('Response');
116
- exampleSlot = (_jsx(renderer.ResponseType, { label: "Response", children: _jsx(CodeBlock, { lang: "json", code: JSON.stringify(endpoint.responses[code].samples._default, null, 2) }) }));
117
- }
118
- else if (response) {
119
- exampleSlot = Object.entries(response.samples).map(([key, sample], i) => {
110
+ if (responseOfType?.examples) {
111
+ exampleSlot = Object.entries(responseOfType.examples).map(([key, sample], i) => {
120
112
  const title = sample?.summary ?? `Example ${i + 1}`;
121
113
  values.push(title);
122
- return (_jsxs(renderer.ResponseType, { label: title, children: [sample?.description ? (_jsx(Markdown, { text: sample.description })) : null, _jsx(CodeBlock, { lang: "json", code: JSON.stringify(sample, null, 2) })] }, key));
114
+ return (_jsxs(renderer.ResponseType, { label: title, children: [sample?.description ? (_jsx(Markdown, { text: sample.description })) : null, _jsx(CodeBlock, { lang: "json", code: JSON.stringify(sample.value, null, 2) })] }, key));
123
115
  });
124
116
  }
125
- return (_jsxs(renderer.Response, { value: code, children: [description ? _jsx(Markdown, { text: description }) : null, response && (_jsxs(renderer.ResponseTypes, { defaultValue: values[0], children: [exampleSlot, ts ? (_jsx(renderer.ResponseType, { label: "TypeScript", children: _jsx(CodeBlock, { code: ts, lang: "ts" }) })) : null] }))] }));
117
+ else if (responseOfType?.example || responseOfType?.schema) {
118
+ values.push('Response');
119
+ exampleSlot = (_jsx(renderer.ResponseType, { label: "Response", children: _jsx(CodeBlock, { lang: "json", code: JSON.stringify(responseOfType.example ?? sample(responseOfType.schema), null, 2) }) }));
120
+ }
121
+ return (_jsxs(renderer.Response, { value: code, children: [description ? _jsx(Markdown, { text: description }) : null, exampleSlot ? (_jsxs(renderer.ResponseTypes, { defaultValue: values[0], children: [exampleSlot, ts ? (_jsx(renderer.ResponseType, { label: "TypeScript", children: _jsx(CodeBlock, { code: ts, lang: "ts" }) })) : null] })) : null] }));
126
122
  }
127
123
  const codes = Object.keys(operation.responses);
128
124
  if (codes.length === 0)
@@ -0,0 +1,5 @@
1
+ import type { MethodInformation, RenderContext } from '../../types.js';
2
+ import type { NoReference } from '../../utils/schema.js';
3
+ import type { RequestData } from '../../requests/_shared.js';
4
+ export declare function getRequestData(path: string, method: NoReference<MethodInformation>, sampleKey: string | null, { schema: { document } }: RenderContext): RequestData;
5
+ //# sourceMappingURL=get-request-data.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-request-data.d.ts","sourceRoot":"","sources":["../../../src/render/operation/get-request-data.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAKlD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,wBAAgB,cAAc,CAC5B,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,WAAW,CAAC,iBAAiB,CAAC,EACtC,SAAS,EAAE,MAAM,GAAG,IAAI,EACxB,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,aAAa,GACtC,WAAW,CAqEb"}
@@ -0,0 +1,71 @@
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 getRequestData(path, method, sampleKey, { schema: { document } }) {
5
+ const result = {
6
+ path: {},
7
+ cookie: {},
8
+ header: {},
9
+ query: {},
10
+ method: method.method,
11
+ };
12
+ for (const param of method.parameters ?? []) {
13
+ let schema = param.schema;
14
+ let value;
15
+ if (!schema && param.content) {
16
+ const type = getPreferredType(param.content);
17
+ const content = type ? param.content[type] : undefined;
18
+ if (!content)
19
+ throw new Error(`Cannot find parameter schema for ${param.name} in ${path} ${method.method}`);
20
+ schema = content.schema;
21
+ value = content.example ?? param.example ?? sample(schema);
22
+ }
23
+ else {
24
+ value = param.example ?? sample(schema);
25
+ }
26
+ if (param.in === 'cookie') {
27
+ result.cookie[param.name] = value;
28
+ }
29
+ else if (param.in === 'header') {
30
+ result.header[param.name] = value;
31
+ }
32
+ else if (param.in === 'query') {
33
+ result.query[param.name] = value;
34
+ }
35
+ else if (param.in === 'path') {
36
+ result.path[param.name] = value;
37
+ }
38
+ }
39
+ const requirements = method.security ?? document.security;
40
+ if (requirements && requirements.length > 0) {
41
+ for (const security of getSecurities(requirements[0], document)) {
42
+ const prefix = getSecurityPrefix(security);
43
+ const name = security.type === 'apiKey' ? security.name : 'Authorization';
44
+ result.header[name] = prefix ? `${prefix} <token>` : '<token>';
45
+ }
46
+ }
47
+ if (method.requestBody) {
48
+ const body = method.requestBody.content;
49
+ const type = getPreferredType(body);
50
+ if (!type)
51
+ throw new Error(`Cannot find body schema for ${path} ${method.method}: missing media type`);
52
+ result.bodyMediaType = type;
53
+ const bodyOfType = body[type];
54
+ if (bodyOfType.examples && sampleKey) {
55
+ result.body = bodyOfType.examples[sampleKey].value;
56
+ }
57
+ else if (bodyOfType.example) {
58
+ result.body = bodyOfType.example;
59
+ }
60
+ else {
61
+ result.body = generateBody(method.method, bodyOfType?.schema ?? {});
62
+ }
63
+ }
64
+ return result;
65
+ }
66
+ function generateBody(method, schema) {
67
+ return sample(schema, {
68
+ skipReadOnly: method !== 'GET',
69
+ skipWriteOnly: method === 'GET',
70
+ });
71
+ }
@@ -1,10 +1,10 @@
1
1
  import { type ReactElement } from 'react';
2
- import { type EndpointSample } from '../utils/generate-sample.js';
3
- import type { MethodInformation, RenderContext } from '../types.js';
2
+ import type { MethodInformation, RenderContext } from '../../types.js';
3
+ import type { RequestData } from '../../requests/_shared.js';
4
4
  export interface CodeSample {
5
5
  lang: string;
6
6
  label: string;
7
- source: string | ((endpoint: EndpointSample, exampleKey: string) => string | undefined) | false;
7
+ source?: string | ((url: string, data: RequestData) => string | undefined) | false;
8
8
  }
9
9
  export declare function Operation({ type, path, method, ctx, hasHead, headingLevel, }: {
10
10
  type?: 'webhook' | 'operation';
@@ -14,4 +14,4 @@ export declare function Operation({ type, path, method, ctx, hasHead, headingLev
14
14
  hasHead?: boolean;
15
15
  headingLevel?: number;
16
16
  }): ReactElement;
17
- //# sourceMappingURL=operation.d.ts.map
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +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,EAEjB,aAAa,EAEd,MAAM,SAAS,CAAC;AAgBjB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EACH,MAAM,GACN,CAAC,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,KAAK,MAAM,GAAG,SAAS,CAAC,GACxD,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,16 +1,15 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Fragment } from 'react';
3
- import { generateSample } from '../utils/generate-sample.js';
4
- import { getPreferredType } from '../utils/schema.js';
5
- import { getSecurities, getSecurityPrefix } from '../utils/get-security.js';
6
- import { idToTitle } from '../utils/id-to-title.js';
7
- import { Markdown } from './markdown.js';
8
- import { heading } from './heading.js';
9
- import { Schema } from './schema.js';
10
- import { createMethod } from '../server/create-method.js';
11
- import { methodKeys } from '../build-routes.js';
12
- import { APIExample } from '../render/operation/api-example.js';
13
- import { MethodLabel } from '../ui/components/method-label.js';
3
+ import { getPreferredType } from '../../utils/schema.js';
4
+ import { getSecurities, getSecurityPrefix } from '../../utils/get-security.js';
5
+ import { idToTitle } from '../../utils/id-to-title.js';
6
+ import { Markdown } from '../markdown.js';
7
+ import { heading } from '../heading.js';
8
+ import { Schema } from '../schema.js';
9
+ import { createMethod } from '../../server/create-method.js';
10
+ import { methodKeys } from '../../build-routes.js';
11
+ import { APIExample, APIExampleProvider, getAPIExamples, } from '../../render/operation/api-example.js';
12
+ import { MethodLabel } from '../../ui/components/method-label.js';
14
13
  const ParamTypes = {
15
14
  path: 'Path Parameters',
16
15
  query: 'Query Parameters',
@@ -60,10 +59,9 @@ export function Operation({ type = 'operation', path, method, ctx, hasHead, head
60
59
  } })] }, status));
61
60
  })] }));
62
61
  }
63
- const endpoint = generateSample(path, method, ctx);
64
62
  const parameterNode = Object.entries(ParamTypes).map(([type, title]) => {
65
- const params = endpoint.parameters.filter((param) => param.in === type && !param.isAuthOnly);
66
- if (params.length === 0)
63
+ const params = method.parameters?.filter((param) => param.in === type);
64
+ if (!params || params.length === 0)
67
65
  return;
68
66
  return (_jsxs(Fragment, { children: [heading(headingLevel, title, ctx), _jsx("div", { className: "flex flex-col gap-4", children: params.map((param) => (_jsx(Schema, { name: param.name, schema: {
69
67
  ...param.schema,
@@ -83,7 +81,8 @@ export function Operation({ type = 'operation', path, method, ctx, hasHead, head
83
81
  }
84
82
  const info = (_jsxs(ctx.renderer.APIInfo, { head: headNode, method: method.method, route: path, children: [type === 'operation' ? (ctx.disablePlayground ? (_jsxs("div", { className: "flex flex-row items-center gap-2.5 p-3 rounded-xl border bg-fd-card text-fd-card-foreground not-prose", children: [_jsx(MethodLabel, { className: "text-xs", children: method.method }), _jsx("code", { className: "flex-1 overflow-auto text-nowrap text-[13px] text-fd-muted-foreground", children: path })] })) : (_jsx(ctx.renderer.APIPlayground, { path: path, method: method, ctx: ctx }))) : null, security && Object.keys(security).length > 0 ? (_jsxs(_Fragment, { children: [heading(headingLevel, 'Authorization', ctx), _jsx(AuthSection, { requirements: security, ctx: ctx })] })) : null, bodyNode, parameterNode, responseNode, callbacksNode] }));
85
83
  if (type === 'operation') {
86
- return (_jsxs(ctx.renderer.API, { children: [info, _jsx(APIExample, { method: method, endpoint: endpoint, ctx: ctx })] }));
84
+ const examples = getAPIExamples(path, method, ctx);
85
+ return (_jsx(ctx.renderer.API, { children: _jsxs(APIExampleProvider, { route: path, examples: examples, method: method, children: [info, _jsx(APIExample, { examples: examples, method: method, ctx: ctx })] }) }));
87
86
  }
88
87
  else {
89
88
  return info;
@@ -27,12 +27,7 @@ export interface ObjectCollapsibleProps {
27
27
  children: ReactNode;
28
28
  }
29
29
  export interface RequestProps {
30
- language: string;
31
30
  name: string;
32
- code: string;
33
- }
34
- export interface SampleProps {
35
- value: string;
36
31
  children: ReactNode;
37
32
  }
38
33
  export interface SamplesProps {
@@ -41,8 +36,6 @@ export interface SamplesProps {
41
36
  description?: ReactNode;
42
37
  value: string;
43
38
  }[];
44
- children: ReactNode;
45
- defaultValue?: string;
46
39
  }
47
40
  export interface ResponseTypeProps {
48
41
  label: string;
@@ -65,8 +58,7 @@ export interface Renderer {
65
58
  }>;
66
59
  Responses: ComponentType<ResponsesProps>;
67
60
  Response: ComponentType<ResponseProps>;
68
- Sample: ComponentType<SampleProps>;
69
- Samples: ComponentType<SamplesProps>;
61
+ CodeExampleSelector: ComponentType<SamplesProps>;
70
62
  Requests: ComponentType<{
71
63
  items: string[];
72
64
  children: ReactNode;
@@ -1 +1 @@
1
- {"version":3,"file":"renderer.d.ts","sourceRoot":"","sources":["../../src/render/renderer.tsx"],"names":[],"mappings":"AAAA,OAAO,K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AAkB,CAAC,CAAC;CAClD;AAED,wBAAgB,aAAa,CAC3B,YAAY,EAAE,aAAa,CAAC,cAAc,CAAC,GAC1C,QAAQ,CAuCV"}
@@ -1,10 +1,9 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Tab, Tabs } from 'fumadocs-ui/components/tabs';
3
3
  import { Accordion, Accordions } from 'fumadocs-ui/components/accordion';
4
- import { CodeBlock } from '../render/codeblock.js';
5
4
  import { API, Root, APIInfo, APIExample, Property, ObjectCollapsible, } from '../ui/index.js';
6
5
  import { APIPlayground } from '../playground/index.js';
7
- import { Sample, Samples } from '../ui/client.js';
6
+ import { CodeExampleSelector } from '../ui/contexts/code-example.lazy.js';
8
7
  export function createRenders(shikiOptions) {
9
8
  return {
10
9
  Root: (props) => (_jsx(Root, { shikiOptions: shikiOptions, ...props, children: props.children })),
@@ -18,9 +17,8 @@ export function createRenders(shikiOptions) {
18
17
  Property,
19
18
  ObjectCollapsible,
20
19
  Requests: (props) => (_jsx(Tabs, { groupId: "fumadocs_openapi_requests", ...props })),
21
- Samples,
22
- Sample,
23
- Request: (props) => (_jsx(Tab, { value: props.name, children: _jsx(CodeBlock, { lang: props.language, code: props.code, options: shikiOptions }) })),
20
+ CodeExampleSelector,
21
+ Request: (props) => _jsx(Tab, { value: props.name, children: props.children }),
24
22
  APIPlayground,
25
23
  };
26
24
  }