fumadocs-openapi 9.0.8 → 9.0.10

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 (35) hide show
  1. package/dist/media/adapter.d.ts +18 -8
  2. package/dist/media/adapter.d.ts.map +1 -1
  3. package/dist/media/adapter.js +38 -18
  4. package/dist/playground/auth/oauth-dialog.d.ts +2 -1
  5. package/dist/playground/auth/oauth-dialog.d.ts.map +1 -1
  6. package/dist/playground/client.js +6 -6
  7. package/dist/playground/inputs.d.ts +1 -2
  8. package/dist/playground/inputs.d.ts.map +1 -1
  9. package/dist/playground/inputs.js +8 -5
  10. package/dist/render/operation/api-example.d.ts.map +1 -1
  11. package/dist/render/operation/api-example.js +8 -0
  12. package/dist/render/schema.d.ts.map +1 -1
  13. package/dist/render/schema.js +24 -14
  14. package/dist/requests/csharp.d.ts +3 -0
  15. package/dist/requests/csharp.d.ts.map +1 -0
  16. package/dist/requests/csharp.js +46 -0
  17. package/dist/requests/curl.d.ts.map +1 -1
  18. package/dist/requests/curl.js +7 -11
  19. package/dist/requests/index.d.ts.map +1 -1
  20. package/dist/requests/index.js +12 -0
  21. package/dist/requests/java.d.ts +3 -0
  22. package/dist/requests/java.d.ts.map +1 -0
  23. package/dist/requests/java.js +68 -0
  24. package/dist/server/source-api.d.ts +2 -2
  25. package/dist/server/source-api.d.ts.map +1 -1
  26. package/dist/server/source-api.js +4 -1
  27. package/dist/ui/contexts/code-example.d.ts +2 -1
  28. package/dist/ui/contexts/code-example.d.ts.map +1 -1
  29. package/dist/ui/lazy.d.ts +1 -1
  30. package/dist/utils/input-to-string.d.ts +2 -1
  31. package/dist/utils/input-to-string.d.ts.map +1 -1
  32. package/dist/utils/input-to-string.js +15 -16
  33. package/dist/utils/url.d.ts.map +1 -1
  34. package/dist/utils/url.js +8 -7
  35. package/package.json +17 -13
@@ -1,19 +1,29 @@
1
1
  import type { RequestData } from '../requests/_shared.js';
2
- interface GoContext {
2
+ interface BaseContext {
3
+ /**
4
+ * Passed by your custom example generator, for your custom media adapter to receive.
5
+ */
6
+ customData?: Record<string, unknown>;
7
+ }
8
+ interface GoContext extends BaseContext {
3
9
  lang: 'go';
4
10
  addImport: (name: string) => void;
5
11
  }
6
- interface JavaScriptContext {
12
+ interface JavaScriptContext extends BaseContext {
7
13
  lang: 'js';
8
14
  addImport: (pkg: string, name: string) => void;
9
15
  }
10
- export type MediaContext = GoContext | JavaScriptContext | {
16
+ interface JavaContext extends BaseContext {
17
+ lang: 'java';
18
+ addImport: (specifier: string) => void;
19
+ }
20
+ interface CSharpContext extends BaseContext {
21
+ lang: 'csharp';
22
+ addImport: (specifier: string) => void;
23
+ }
24
+ export type MediaContext = JavaContext | GoContext | JavaScriptContext | CSharpContext | (BaseContext & {
11
25
  lang: string;
12
- /**
13
- * Passed by your custom example generator, for your custom media adapter to receive.
14
- */
15
- customData?: Record<string, unknown>;
16
- };
26
+ });
17
27
  export interface MediaAdapter {
18
28
  /**
19
29
  * encode request data into body for `fetch()`.
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/media/adapter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,UAAU,SAAS;IACjB,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAED,UAAU,iBAAiB;IACzB,IAAI,EAAE,IAAI,CAAC;IACX,SAAS,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAChD;AAED,MAAM,MAAM,YAAY,GACpB,SAAS,GACT,iBAAiB,GACjB;IACE,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC,CAAC;AAEN,MAAM,WAAW,YAAY;IAC3B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AY;IAC3B;;;;OAIG;IACH,MAAM,EAAE,CAAC,IAAI,EAAE,WAAW,KAAK,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE5D;;;;;;;;OAQG;IACH,eAAe,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,EAAE,YAAY,KAAK,MAAM,GAAG,SAAS,CAAC;CAC/E;AAED,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;mCAuIF,QAAQ;;;CAOM,CAAC"}
@@ -1,12 +1,12 @@
1
1
  'use client';
2
- import { inputToString } from '../utils/input-to-string.js';
2
+ import { escapeString, inputToString } from '../utils/input-to-string.js';
3
3
  export const defaultAdapters = {
4
4
  'application/json': {
5
5
  encode(data) {
6
6
  return JSON.stringify(data.body);
7
7
  },
8
8
  generateExample(data, ctx) {
9
- return str(data.body, 'json', ctx);
9
+ return str(data.body, 'application/json', ctx);
10
10
  },
11
11
  },
12
12
  'application/xml': {
@@ -19,7 +19,7 @@ export const defaultAdapters = {
19
19
  });
20
20
  },
21
21
  generateExample(data, ctx) {
22
- return str(data.body, 'xml', ctx);
22
+ return str(data.body, 'application/xml', ctx);
23
23
  },
24
24
  },
25
25
  'application/x-ndjson': {
@@ -30,7 +30,7 @@ export const defaultAdapters = {
30
30
  return JSON.stringify(data.body);
31
31
  },
32
32
  generateExample(data, ctx) {
33
- return str(data.body, 'ndjson', ctx);
33
+ return str(data.body, 'application/x-ndjson', ctx);
34
34
  },
35
35
  },
36
36
  'application/x-www-form-urlencoded': {
@@ -47,7 +47,7 @@ export const defaultAdapters = {
47
47
  if (ctx.lang === 'js') {
48
48
  return `const body = new URLSearchParams(${JSON.stringify(data.body, null, 2)})`;
49
49
  }
50
- return str(data.body, 'url', ctx);
50
+ return str(data.body, 'application/x-www-form-urlencoded', ctx);
51
51
  },
52
52
  },
53
53
  'multipart/form-data': {
@@ -81,18 +81,28 @@ export const defaultAdapters = {
81
81
  if (ctx.lang === 'js') {
82
82
  s.push(`const body = new FormData();`);
83
83
  for (const [key, value] of Object.entries(data.body)) {
84
- s.push(`body.set(${key}, ${inputToString(value)})`);
84
+ s.push(`body.set(${key}, ${JSON.stringify(inputToString(value))})`);
85
85
  }
86
86
  }
87
- if (ctx.lang === 'go' && 'addImport' in ctx) {
88
- ctx.addImport('mime/multipart');
89
- ctx.addImport('bytes');
87
+ if (ctx.lang === 'go') {
88
+ const { addImport } = ctx;
89
+ addImport('mime/multipart');
90
+ addImport('bytes');
90
91
  s.push('body := new(bytes.Buffer)');
91
92
  s.push('mp := multipart.NewWriter(payload)');
92
93
  for (const [key, value] of Object.entries(data.body)) {
93
- s.push(`mp.WriteField("${key}", ${inputToString(value, 'json', 'backtick')})`);
94
+ const escaped = escapeString(inputToString(value, 'application/json'), '`');
95
+ s.push(`mp.WriteField("${key}", ${escaped})`);
94
96
  }
95
97
  }
98
+ if (ctx.lang === 'java') {
99
+ const { addImport } = ctx;
100
+ addImport('java.net.http.HttpRequest.BodyPublishers');
101
+ s.push(`var body = BodyPublishers.ofByteArray(new byte[] { ... });`);
102
+ }
103
+ if (ctx.lang === 'csharp') {
104
+ s.push(`var body = new MultipartFormDataContent();`);
105
+ }
96
106
  if (s.length > 0)
97
107
  return s.join('\n');
98
108
  },
@@ -107,20 +117,30 @@ export const defaultAdapters = {
107
117
  },
108
118
  },
109
119
  };
110
- function str(init, format, ctx) {
120
+ function str(init, mediaType, ctx) {
111
121
  if (ctx.lang === 'js') {
112
- if (format === 'json') {
122
+ if (mediaType === 'application/json') {
113
123
  return `const body = JSON.stringify(${JSON.stringify(init, null, 2)})`;
114
124
  }
115
- return `const body = ${inputToString(init, format, 'backtick')}`;
125
+ return `const body = ${escapeString(inputToString(init, mediaType), '`')}`;
116
126
  }
117
127
  if (ctx.lang === 'python') {
118
- if (format === 'json')
128
+ if (mediaType === 'application/json')
119
129
  return `body = ${JSON.stringify(init, null, 2)}`;
120
- return `body = ${inputToString(init, format, 'python')}`;
130
+ return `body = ${escapeString(inputToString(init, mediaType), '"""')}`;
131
+ }
132
+ if (ctx.lang === 'go') {
133
+ const { addImport } = ctx;
134
+ addImport('strings');
135
+ return `body := strings.NewReader(${escapeString(inputToString(init, mediaType), '`')})`;
136
+ }
137
+ if (ctx.lang === 'java') {
138
+ const { addImport } = ctx;
139
+ addImport('java.net.http.HttpRequest.BodyPublishers');
140
+ return `var body = BodyPublishers.ofString(${escapeString(inputToString(init, mediaType), '"""')});`;
121
141
  }
122
- if (ctx.lang === 'go' && 'addImport' in ctx) {
123
- ctx.addImport('strings');
124
- return `body := strings.NewReader(${inputToString(init, format, 'backtick')})`;
142
+ if (ctx.lang === 'csharp') {
143
+ const input = `\n${inputToString(init, mediaType)}\n`;
144
+ return `var body = new StringContent(${escapeString(input, '"""')}, Encoding.UTF8, "${mediaType}");`;
125
145
  }
126
146
  }
@@ -1,11 +1,12 @@
1
1
  import type { OpenAPIV3_1 } from 'openapi-types';
2
+ import { type ReactNode } from 'react';
2
3
  export interface AuthDialogProps {
3
4
  scheme: OpenAPIV3_1.OAuth2SecurityScheme;
4
5
  scopes: string[];
5
6
  open: boolean;
6
7
  setOpen: (v: boolean) => void;
7
8
  setToken: (token: string) => void;
8
- children: React.ReactNode;
9
+ children: ReactNode;
9
10
  }
10
11
  export declare function OauthDialog({ scheme, scopes, setToken, children, open, setOpen, }: AuthDialogProps): import("react/jsx-runtime").JSX.Element;
11
12
  export declare const OauthDialogTrigger: import("react").ForwardRefExoticComponent<import("@radix-ui/react-dialog").DialogTriggerProps & import("react").RefAttributes<HTMLButtonElement>>;
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-dialog.d.ts","sourceRoot":"","sources":["../../../src/playground/auth/oauth-dialog.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAiBjD,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,WAAW,CAAC,oBAAoB,CAAC;IACzC,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B;AAuCD,wBAAgB,WAAW,CAAC,EAC1B,MAAM,EACN,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,OAAO,GACR,EAAE,eAAe,2CAwSjB;AAED,eAAO,MAAM,kBAAkB,mJAAgB,CAAC"}
1
+ {"version":3,"file":"oauth-dialog.d.ts","sourceRoot":"","sources":["../../../src/playground/auth/oauth-dialog.tsx"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAIjD,OAAO,EAAE,KAAK,SAAS,EAAuB,MAAM,OAAO,CAAC;AAa5D,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,WAAW,CAAC,oBAAoB,CAAC;IACzC,MAAM,EAAE,MAAM,EAAE,CAAC;IAEjB,IAAI,EAAE,OAAO,CAAC;IACd,OAAO,EAAE,CAAC,CAAC,EAAE,OAAO,KAAK,IAAI,CAAC;IAC9B,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,EAAE,SAAS,CAAC;CACrB;AAuCD,wBAAgB,WAAW,CAAC,EAC1B,MAAM,EACN,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,OAAO,GACR,EAAE,eAAe,2CAwSjB;AAED,eAAO,MAAM,kBAAkB,mJAAgB,CAAC"}
@@ -169,14 +169,14 @@ function BodyInput({ field: _field }) {
169
169
  const [isJson, setIsJson] = useState(false);
170
170
  if (field.format === 'binary')
171
171
  return _jsx(FieldSet, { field: field, fieldName: "body" });
172
- return (_jsx(_Fragment, { children: isJson ? (_jsx(JsonInput, { fieldName: "body", children: _jsx("button", { className: cn(buttonVariants({
173
- color: 'ghost',
174
- size: 'sm',
175
- className: 'p-2',
176
- })), onClick: () => setIsJson(false), type: "button", children: "Close JSON Editor" }) })) : (_jsx(FieldSet, { field: field, fieldName: "body", collapsible: false, name: _jsx("button", { className: cn(buttonVariants({
172
+ return (_jsx(_Fragment, { children: isJson ? (_jsxs(_Fragment, { children: [_jsx("button", { className: cn(buttonVariants({
173
+ color: 'secondary',
174
+ size: 'sm',
175
+ className: 'w-fit font-mono p-2',
176
+ })), onClick: () => setIsJson(false), type: "button", children: "Close JSON Editor" }), _jsx(JsonInput, { fieldName: "body" })] })) : (_jsx(FieldSet, { field: field, fieldName: "body", collapsible: false, name: _jsx("button", { className: cn(buttonVariants({
177
177
  color: 'secondary',
178
178
  size: 'sm',
179
- className: 'font-mono p-2',
179
+ className: 'p-2',
180
180
  })), onClick: () => setIsJson(true), type: "button", children: "Open JSON Editor" }) })) }));
181
181
  }
182
182
  /**
@@ -4,9 +4,8 @@ export declare function ObjectInput({ field: _field, fieldName, ...props }: {
4
4
  field: Exclude<RequestSchema, boolean>;
5
5
  fieldName: string;
6
6
  } & ComponentProps<'div'>): import("react/jsx-runtime").JSX.Element | undefined;
7
- export declare function JsonInput({ fieldName, children, }: {
7
+ export declare function JsonInput({ fieldName }: {
8
8
  fieldName: string;
9
- children: ReactNode;
10
9
  }): import("react/jsx-runtime").JSX.Element;
11
10
  export declare function FieldInput({ field, fieldName, isRequired, ...props }: HTMLAttributes<HTMLElement> & {
12
11
  field: Exclude<RequestSchema, boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"inputs.d.ts","sourceRoot":"","sources":["../../src/playground/inputs.tsx"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,SAAS,EAGf,MAAM,OAAO,CAAC;AAef,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAkDxD,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EAAE,MAAM,EACb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AAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAkDxD,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EAAE,MAAM,EACb,SAAS,EACT,GAAG,KAAK,EACT,EAAE;IACD,KAAK,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACvC,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,cAAc,CAAC,KAAK,CAAC,uDAwCxB;AAED,wBAAgB,SAAS,CAAC,EAAE,SAAS,EAAE,EAAE;IAAE,SAAS,EAAE,MAAM,CAAA;CAAE,2CA8B7D;AA6FD,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,SAAS,EACT,UAAU,EACV,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG;IAC/B,KAAK,EAAE,OAAO,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;IACvC,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;CACnB,uDAmFA;AAED,wBAAgB,QAAQ,CAAC,EACvB,KAAK,EAAE,MAAM,EACb,SAAS,EACT,OAAO,EACP,IAAI,EACJ,UAAU,EACV,KAAS,EACT,QAAQ,EACR,WAAkB,EAClB,GAAG,KAAK,EACT,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG;IAC/B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,EAAE,aAAa,CAAC;IACrB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,kDA2KA"}
@@ -36,20 +36,23 @@ export function ObjectInput({ field: _field, fieldName, ...props }) {
36
36
  return anyFields;
37
37
  } }))] }));
38
38
  }
39
- export function JsonInput({ fieldName, children, }) {
39
+ export function JsonInput({ fieldName }) {
40
40
  const controller = useController({
41
41
  name: fieldName,
42
42
  });
43
+ const [error, setError] = useState(null);
43
44
  const [value, setValue] = useState(() => JSON.stringify(controller.field.value, null, 2));
44
- return (_jsxs("div", { className: "rounded-lg border bg-fd-secondary text-fd-secondary-foreground", children: [children, _jsx("textarea", { ...controller.field, value: value, className: "p-2 w-full h-[240px] text-[13px] font-mono resize-none focus-visible:outline-none", onChange: (v) => {
45
+ return (_jsxs("div", { className: "flex flex-col bg-fd-secondary text-fd-secondary-foreground overflow-hidden border rounded-lg", children: [_jsx("textarea", { ...controller.field, value: value, className: "p-2 h-[240px] text-sm font-mono resize-none focus-visible:outline-none", onChange: (v) => {
45
46
  setValue(v.target.value);
46
47
  try {
47
48
  controller.field.onChange(JSON.parse(v.target.value));
49
+ setError(null);
48
50
  }
49
- catch {
50
- // ignore
51
+ catch (e) {
52
+ if (e instanceof Error)
53
+ setError(e.message);
51
54
  }
52
- } })] }));
55
+ } }), _jsx("p", { className: "p-2 text-xs font-mono border-t text-red-400 empty:hidden", children: error })] }));
53
56
  }
54
57
  function DynamicProperties({ fieldName, filterKey = () => true, getType = () => anyFields, }) {
55
58
  const { control, setValue, getValues } = useFormContext();
@@ -1 +1 @@
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;AAM3D,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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AAI,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"}
@@ -22,6 +22,14 @@ const defaultSamples = [
22
22
  label: 'Python',
23
23
  lang: 'python',
24
24
  },
25
+ {
26
+ label: 'Java',
27
+ lang: 'java',
28
+ },
29
+ {
30
+ label: 'C#',
31
+ lang: 'csharp',
32
+ },
25
33
  ];
26
34
  export function APIExampleProvider({ examples, method, children, route, }) {
27
35
  const exclusiveSampleKey = method['x-exclusiveCodeSample'];
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/render/schema.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAwB7C,wBAAgB,MAAM,CAAC,EACrB,IAAI,EACJ,MAAM,EACN,QAAgB,EAChB,QAAgB,EAChB,SAAiB,EACjB,EAAe,EACf,GAAG,EAAE,EAAE,QAAQ,EAAE,GAClB,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,cAAc,CAAC;IACvB,EAAE,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IAEzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,GAAG,EAAE,aAAa,CAAC;CACpB,GAAG,SAAS,CAiSZ"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../src/render/schema.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACjD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAe7C,wBAAgB,MAAM,CAAC,EACrB,IAAI,EACJ,MAAM,EACN,QAAgB,EAChB,QAAgB,EAChB,SAAiB,EACjB,EAAe,EACf,GAAG,EAAE,EAAE,QAAQ,EAAE,GAClB,EAAE;IACD,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,MAAM,EAAE,cAAc,CAAC;IACvB,EAAE,CAAC,EAAE,UAAU,GAAG,MAAM,CAAC;IAEzB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,GAAG,EAAE,aAAa,CAAC;CACpB,GAAG,SAAS,CAoTZ"}
@@ -4,12 +4,6 @@ import { combineSchema } from '../utils/combine-schema.js';
4
4
  import { Markdown } from './markdown.js';
5
5
  import { schemaToString } from '../utils/schema-to-string.js';
6
6
  import { Tabs, TabsContent, TabsList, TabsTrigger, } from 'fumadocs-ui/components/tabs';
7
- const keys = {
8
- default: 'Default',
9
- pattern: 'Pattern',
10
- format: 'Format',
11
- multipleOf: 'Multiple of',
12
- };
13
7
  export function Schema({ name, schema, required = false, readOnly = false, writeOnly = false, as = 'property', ctx: { renderer }, }) {
14
8
  function propertyBody(schema, renderPrimitive, ctx) {
15
9
  if (Array.isArray(schema.type)) {
@@ -51,13 +45,29 @@ export function Schema({ name, schema, required = false, readOnly = false, write
51
45
  }
52
46
  function propertyInfo(schema) {
53
47
  const fields = [];
54
- for (const key in keys) {
55
- if (key in schema) {
56
- fields.push({
57
- key: keys[key],
58
- value: JSON.stringify(schema[key]),
59
- });
60
- }
48
+ if (schema.default) {
49
+ fields.push({
50
+ key: 'Default',
51
+ value: JSON.stringify(schema.default),
52
+ });
53
+ }
54
+ if (schema.pattern) {
55
+ fields.push({
56
+ key: 'Match',
57
+ value: schema.pattern,
58
+ });
59
+ }
60
+ if (schema.format) {
61
+ fields.push({
62
+ key: 'Format',
63
+ value: schema.format,
64
+ });
65
+ }
66
+ if (schema.multipleOf) {
67
+ fields.push({
68
+ key: 'Multiple Of',
69
+ value: String(schema.multipleOf),
70
+ });
61
71
  }
62
72
  let range = getRange('value', schema.minimum, schema.exclusiveMinimum, schema.maximum, schema.exclusiveMaximum);
63
73
  if (range)
@@ -85,7 +95,7 @@ export function Schema({ name, schema, required = false, readOnly = false, write
85
95
  }
86
96
  if (fields.length === 0)
87
97
  return;
88
- return (_jsx("div", { className: "flex flex-wrap gap-2 not-prose", children: fields.map((field) => (_jsxs("div", { className: "bg-fd-secondary text-fd-secondary-foreground border rounded-lg text-xs p-1.5 shadow-md", children: [_jsx("span", { className: "font-medium me-2", children: field.key }), _jsx("code", { className: "text-fd-muted-foreground", children: field.value })] }, field.key))) }));
98
+ return (_jsx("div", { className: "flex flex-wrap gap-2 not-prose", children: fields.map((field) => (_jsxs("div", { className: "bg-fd-secondary border rounded-lg text-xs p-1.5 shadow-md", children: [_jsx("span", { className: "font-medium me-2", children: field.key }), _jsx("code", { className: "text-fd-muted-foreground", children: field.value })] }, field.key))) }));
89
99
  }
90
100
  function primitiveBody(schema, ctx, collapsible, nested) {
91
101
  if (schema.type === 'object') {
@@ -0,0 +1,3 @@
1
+ import type { SampleGenerator } from '../requests/_shared.js';
2
+ export declare const generator: SampleGenerator;
3
+ //# sourceMappingURL=csharp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"csharp.d.ts","sourceRoot":"","sources":["../../src/requests/csharp.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAG1D,eAAO,MAAM,SAAS,EAAE,eA0DvB,CAAC"}
@@ -0,0 +1,46 @@
1
+ 'use client';
2
+ import { resolveRequestData } from '../utils/url.js';
3
+ export const generator = (url, data, { mediaAdapters }) => {
4
+ const s = [];
5
+ const imports = new Set(['System', 'System.Net.Http', 'System.Text']);
6
+ const headers = { ...data.header };
7
+ // Handle request body
8
+ let body;
9
+ if (data.body && data.bodyMediaType && data.bodyMediaType in mediaAdapters) {
10
+ body = mediaAdapters[data.bodyMediaType].generateExample(data, {
11
+ lang: 'csharp',
12
+ addImport(from) {
13
+ imports.add(from);
14
+ },
15
+ });
16
+ }
17
+ for (const specifier of imports) {
18
+ s.push(`using ${specifier};`);
19
+ }
20
+ s.push('');
21
+ if (body) {
22
+ s.push(body, '');
23
+ }
24
+ s.push('var client = new HttpClient();');
25
+ // Add cookie header if cookies are present
26
+ if (Object.keys(data.cookie).length > 0) {
27
+ headers['cookie'] = Object.entries(data.cookie)
28
+ .map(([key, value]) => `${key}=${value}`)
29
+ .join('; ');
30
+ }
31
+ // Add headers
32
+ const headerLines = Object.entries(headers).map(([key, value]) => `client.DefaultRequestHeaders.Add("${key}", ${JSON.stringify(value)});`);
33
+ s.push(...headerLines);
34
+ // Build the request
35
+ const resolvedUrl = resolveRequestData(url, data);
36
+ const method = data.method[0].toUpperCase() + data.method.slice(1).toLowerCase() + 'Async';
37
+ if (body) {
38
+ s.push(`var response = await client.${method}("${resolvedUrl}", body);`);
39
+ }
40
+ else {
41
+ s.push(`var response = await client.${method}("${resolvedUrl}");`);
42
+ }
43
+ // Add response handling
44
+ s.push('var responseBody = await response.Content.ReadAsStringAsync();');
45
+ return s.join('\n');
46
+ };
@@ -1 +1 @@
1
- {"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../src/requests/curl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AASjE,eAAO,MAAM,SAAS,EAAE,eA0CvB,CAAC"}
1
+ {"version":3,"file":"curl.d.ts","sourceRoot":"","sources":["../../src/requests/curl.ts"],"names":[],"mappings":"AAEA,OAAO,EAAS,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGjE,eAAO,MAAM,SAAS,EAAE,eAsCvB,CAAC"}
@@ -1,12 +1,7 @@
1
1
  'use client';
2
- import { inputToString } from '../utils/input-to-string.js';
2
+ import { escapeString, inputToString } from '../utils/input-to-string.js';
3
3
  import { ident } from '../requests/_shared.js';
4
4
  import { resolveRequestData } from '../utils/url.js';
5
- const MediaTypeFormatMap = {
6
- 'application/json': 'json',
7
- 'application/xml': 'xml',
8
- 'application/x-www-form-urlencoded': 'url',
9
- };
10
5
  export const generator = (url, data) => {
11
6
  const s = [];
12
7
  s.push(`curl -X ${data.method} "${resolveRequestData(url, data)}"`);
@@ -22,14 +17,15 @@ export const generator = (url, data) => {
22
17
  if (typeof data.body !== 'object')
23
18
  throw new Error('[CURL] request body must be an object.');
24
19
  for (const [key, value] of Object.entries(data.body)) {
25
- s.push(`-F ${key}=${inputToString(value)}`);
20
+ s.push(`-F ${key}=${JSON.stringify(inputToString(value))}`);
26
21
  }
27
22
  }
28
- else if (data.body &&
29
- data.bodyMediaType &&
30
- data.bodyMediaType in MediaTypeFormatMap) {
23
+ else if (data.body && data.bodyMediaType) {
24
+ const escaped = escapeString(inputToString(data.body,
25
+ // @ts-expect-error -- assume the body media type is supported
26
+ data.bodyMediaType), "'");
31
27
  s.push(`-H "Content-Type: ${data.bodyMediaType}"`);
32
- s.push(`-d ${inputToString(data.body, MediaTypeFormatMap[data.bodyMediaType], 'single-quote')}`);
28
+ s.push(`-d ${escaped}`);
33
29
  }
34
30
  return s.flatMap((v, i) => ident(v, i > 0 ? 1 : 0)).join(' \\\n');
35
31
  };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/requests/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAMrD,eAAO,MAAM,cAAc,EAAE,UAAU,EAqBtC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/requests/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAQrD,eAAO,MAAM,cAAc,EAAE,UAAU,EA+BtC,CAAC"}
@@ -2,6 +2,8 @@ import * as CURL from '../requests/curl.js';
2
2
  import * as JS from '../requests/javascript.js';
3
3
  import * as Go from '../requests/go.js';
4
4
  import * as Python from '../requests/python.js';
5
+ import * as Java from '../requests/java.js';
6
+ import * as CSharp from '../requests/csharp.js';
5
7
  export const defaultSamples = [
6
8
  {
7
9
  label: 'cURL',
@@ -23,4 +25,14 @@ export const defaultSamples = [
23
25
  source: Python.generator,
24
26
  lang: 'python',
25
27
  },
28
+ {
29
+ label: 'Java',
30
+ source: Java.generator,
31
+ lang: 'java',
32
+ },
33
+ {
34
+ label: 'C#',
35
+ source: CSharp.generator,
36
+ lang: 'csharp',
37
+ },
26
38
  ];
@@ -0,0 +1,3 @@
1
+ import { type SampleGenerator } from '../requests/_shared.js';
2
+ export declare const generator: SampleGenerator;
3
+ //# sourceMappingURL=java.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"java.d.ts","sourceRoot":"","sources":["../../src/requests/java.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,KAAK,eAAe,EAAE,MAAM,oBAAoB,CAAC;AAGjE,eAAO,MAAM,SAAS,EAAE,eAmFvB,CAAC"}
@@ -0,0 +1,68 @@
1
+ 'use client';
2
+ import { ident } from '../requests/_shared.js';
3
+ import { resolveRequestData } from '../utils/url.js';
4
+ export const generator = (url, data, { mediaAdapters }) => {
5
+ const s = [];
6
+ const headers = { ...data.header };
7
+ const imports = new Set([
8
+ 'java.net.URI',
9
+ 'java.net.http.HttpClient',
10
+ 'java.net.http.HttpRequest',
11
+ 'java.net.http.HttpResponse',
12
+ 'java.net.http.HttpResponse.BodyHandlers',
13
+ 'java.time.Duration',
14
+ ]);
15
+ // Handle body if present
16
+ let body;
17
+ if (data.body && data.bodyMediaType && data.bodyMediaType in mediaAdapters) {
18
+ const adapter = mediaAdapters[data.bodyMediaType];
19
+ body = adapter.generateExample(data, {
20
+ lang: 'java',
21
+ addImport(specifier) {
22
+ imports.add(specifier);
23
+ },
24
+ });
25
+ }
26
+ for (const value of imports.values()) {
27
+ s.push(`import ${value};`);
28
+ }
29
+ s.push('');
30
+ if (body) {
31
+ s.push(body);
32
+ }
33
+ // Create HttpClient
34
+ s.push('HttpClient client = HttpClient.newBuilder()');
35
+ s.push(ident('.connectTimeout(Duration.ofSeconds(10))'));
36
+ s.push(ident('.build();'));
37
+ s.push('');
38
+ // Build request
39
+ s.push('HttpRequest.Builder requestBuilder = HttpRequest.newBuilder()');
40
+ s.push(ident(`.uri(URI.create(${JSON.stringify(resolveRequestData(url, data))}))`));
41
+ // Add headers
42
+ for (const [key, value] of Object.entries(headers)) {
43
+ s.push(ident(`.header(${JSON.stringify(key)}, ${JSON.stringify(value)})`));
44
+ }
45
+ if (data.bodyMediaType) {
46
+ s.push(ident(`.header("Content-Type", "${data.bodyMediaType}")`));
47
+ }
48
+ // Add cookies if present
49
+ const cookieString = Object.entries(data.cookie)
50
+ .map(([key, value]) => `${key}=${value}`)
51
+ .join('; ');
52
+ if (cookieString.length > 0) {
53
+ s.push(ident(`.header("Cookie", ${JSON.stringify(cookieString)})`));
54
+ }
55
+ const arg = body ? 'body' : '';
56
+ s.push(ident(`.${data.method.toUpperCase()}(${arg})`));
57
+ s.push(ident('.build();'));
58
+ s.push('');
59
+ // Add response handling
60
+ s.push('try {');
61
+ s.push(ident('HttpResponse<String> response = client.send(requestBuilder.build(), BodyHandlers.ofString());'));
62
+ s.push(ident('System.out.println("Status code: " + response.statusCode());'));
63
+ s.push(ident('System.out.println("Response body: " + response.body());'));
64
+ s.push('} catch (Exception e) {');
65
+ s.push(ident('e.printStackTrace();'));
66
+ s.push('}');
67
+ return s.join('\n');
68
+ };
@@ -1,9 +1,9 @@
1
- import type { FileSystem } from 'fumadocs-core/source';
2
1
  import type { PageTree } from 'fumadocs-core/server';
2
+ import type { PageFile } from 'fumadocs-core/source';
3
3
  /**
4
4
  * Source API Integration
5
5
  *
6
6
  * Add this to page tree builder options
7
7
  */
8
- export declare const attachFile: (node: PageTree.Item, file: FileSystem.PageFile | undefined) => PageTree.Item;
8
+ export declare const attachFile: (node: PageTree.Item, file: PageFile | undefined) => PageTree.Item;
9
9
  //# sourceMappingURL=source-api.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"source-api.d.ts","sourceRoot":"","sources":["../../src/server/source-api.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,UAAU,GACrB,MAAM,QAAQ,CAAC,IAAI,EACnB,MAAM,UAAU,CAAC,QAAQ,GAAG,SAAS,KACpC,QAAQ,CAAC,IAyBX,CAAC"}
1
+ {"version":3,"file":"source-api.d.ts","sourceRoot":"","sources":["../../src/server/source-api.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAErD;;;;GAIG;AACH,eAAO,MAAM,UAAU,GACrB,MAAM,QAAQ,CAAC,IAAI,EACnB,MAAM,QAAQ,GAAG,SAAS,KACzB,QAAQ,CAAC,IA4BX,CAAC"}
@@ -8,7 +8,10 @@ import { MethodLabel } from '../ui/components/method-label.js';
8
8
  export const attachFile = (node, file) => {
9
9
  if (!file)
10
10
  return node;
11
- const data = file.data.data;
11
+ let data = file.data;
12
+ // backward compatible with older versions with `_openapi` is located in `data.data`
13
+ if ('data' in data && data.data && typeof data === 'object')
14
+ data = data.data;
12
15
  let method;
13
16
  if ('_openapi' in data && typeof data._openapi === 'object') {
14
17
  const meta = data._openapi;
@@ -1,3 +1,4 @@
1
+ import { type ReactNode } from 'react';
1
2
  import type { CodeSample } from '../../render/operation/index.js';
2
3
  import type { SamplesProps } from '../../render/renderer.js';
3
4
  import type { RequestData } from '../../requests/_shared.js';
@@ -8,7 +9,7 @@ export declare function CodeExampleProvider({ route, examples, initialKey, child
8
9
  data: RequestData;
9
10
  }[];
10
11
  initialKey?: string;
11
- children: React.ReactNode;
12
+ children: ReactNode;
12
13
  }): import("react/jsx-runtime").JSX.Element;
13
14
  export declare function CodeExample(props: CodeSample): import("react/jsx-runtime").JSX.Element | null;
14
15
  export declare function CodeExampleSelector({ items }: SamplesProps): import("react/jsx-runtime").JSX.Element;
@@ -1 +1 @@
1
- {"version":3,"file":"code-example.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/code-example.tsx"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAUtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAqBtD,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,WAAW,CAAC;KACnB,EAAE,CAAC;IACJ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;CAC3B,2CAwDA;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,kDAgD5C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,EAAE,YAAY,2CAoB1D;AAgBD,wBAAgB,qBAAqB,gBAOpC;AAED,wBAAgB,qBAAqB;oBA5KnB,WAAW,KAAK,IAAI;EA+KrC"}
1
+ {"version":3,"file":"code-example.d.ts","sourceRoot":"","sources":["../../../src/ui/contexts/code-example.tsx"],"names":[],"mappings":"AACA,OAAO,EAGL,KAAK,SAAS,EAMf,MAAM,OAAO,CAAC;AAGf,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAUtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAqBtD,wBAAgB,mBAAmB,CAAC,EAClC,KAAK,EACL,QAAQ,EACR,UAAU,EACV,QAAQ,GACT,EAAE;IACD,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;QACZ,IAAI,EAAE,WAAW,CAAC;KACnB,EAAE,CAAC;IACJ,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,SAAS,CAAC;CACrB,2CAwDA;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,kDAgD5C;AAED,wBAAgB,mBAAmB,CAAC,EAAE,KAAK,EAAE,EAAE,YAAY,2CAoB1D;AAgBD,wBAAgB,qBAAqB,gBAOpC;AAED,wBAAgB,qBAAqB;oBA5KnB,WAAW,KAAK,IAAI;EA+KrC"}
package/dist/ui/lazy.d.ts CHANGED
@@ -5,7 +5,7 @@ export declare const CodeExampleProvider: import("react").ComponentType<{
5
5
  data: import("../requests/_shared.js").RequestData;
6
6
  }[];
7
7
  initialKey?: string;
8
- children: React.ReactNode;
8
+ children: import("react").ReactNode;
9
9
  }>;
10
10
  export declare const CodeExample: import("react").ComponentType<import("../render/operation/index.js").CodeSample>;
11
11
  export declare const CodeExampleSelector: import("react").ComponentType<import("../render/renderer.js").SamplesProps>;
@@ -1,5 +1,6 @@
1
1
  /**
2
2
  * Convert input value to hardcoded string (with quotes)
3
3
  */
4
- export declare function inputToString(value: unknown, format?: 'xml' | 'json' | 'url' | 'ndjson', multiLine?: 'single-quote' | 'backtick' | 'python' | 'none'): string;
4
+ export declare function inputToString(value: unknown, format?: 'application/x-www-form-urlencoded' | 'application/x-ndjson' | 'application/json' | 'application/xml'): string;
5
+ export declare function escapeString(str: string, delimit?: string): string;
5
6
  //# sourceMappingURL=input-to-string.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"input-to-string.d.ts","sourceRoot":"","sources":["../../src/utils/input-to-string.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,EACd,MAAM,GAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAiB,EAClD,SAAS,GAAE,cAAc,GAAG,UAAU,GAAG,QAAQ,GAAG,MAAe,GAClE,MAAM,CAyCR"}
1
+ {"version":3,"file":"input-to-string.d.ts","sourceRoot":"","sources":["../../src/utils/input-to-string.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,OAAO,EACd,MAAM,GACF,mCAAmC,GACnC,sBAAsB,GACtB,kBAAkB,GAClB,iBAAsC,GACzC,MAAM,CA6BR;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAIlE"}
@@ -3,24 +3,18 @@ import js2xml from 'xml-js/lib/js2xml';
3
3
  /**
4
4
  * Convert input value to hardcoded string (with quotes)
5
5
  */
6
- export function inputToString(value, format = 'json', multiLine = 'none') {
7
- const getStr = (v) => {
8
- if (multiLine === 'none')
9
- return JSON.stringify(v);
10
- const delimit = { backtick: `\``, 'single-quote': `'`, python: `"""` }[multiLine];
11
- return `${delimit}${v.replaceAll(delimit, `\\${delimit}`)}${delimit}`;
12
- };
6
+ export function inputToString(value, format = 'application/json') {
13
7
  if (typeof value === 'string')
14
- return getStr(value);
15
- if (format === 'json') {
16
- return getStr(JSON.stringify(value, null, 2));
8
+ return value;
9
+ if (format === 'application/json') {
10
+ return JSON.stringify(value, null, 2);
17
11
  }
18
- if (format === 'ndjson') {
19
- return getStr(Array.isArray(value)
12
+ if (format === 'application/x-ndjson') {
13
+ return Array.isArray(value)
20
14
  ? value.map((v) => JSON.stringify(v)).join('\n')
21
- : JSON.stringify(value, null, 2));
15
+ : JSON.stringify(value, null, 2);
22
16
  }
23
- if (format === 'url') {
17
+ if (format === 'application/x-www-form-urlencoded') {
24
18
  const params = new URLSearchParams();
25
19
  if (typeof value !== 'object')
26
20
  throw new Error(`For url encoded data, \`value\` must be an object, but received: ${typeof value}`);
@@ -28,7 +22,12 @@ export function inputToString(value, format = 'json', multiLine = 'none') {
28
22
  if (value[key])
29
23
  params.set(key, String(value[key]));
30
24
  }
31
- return getStr(params.toString());
25
+ return params.toString();
32
26
  }
33
- return getStr(js2xml(value, { compact: true, spaces: 2 }));
27
+ return js2xml(value, { compact: true, spaces: 2 });
28
+ }
29
+ export function escapeString(str, delimit) {
30
+ if (!delimit)
31
+ return JSON.stringify(str);
32
+ return `${delimit}${str.replaceAll(delimit, `\\${delimit}`)}${delimit}`;
34
33
  }
@@ -1 +1 @@
1
- {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM,CAQ9D;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,CAyBR"}
1
+ {"version":3,"file":"url.d.ts","sourceRoot":"","sources":["../../src/utils/url.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,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,CAyBR"}
package/dist/utils/url.js CHANGED
@@ -1,11 +1,12 @@
1
1
  export function joinURL(base, pathname) {
2
- pathname = pathname
3
- .split('/')
4
- .filter((v) => v.length > 0)
5
- .join('/');
6
- if (!base.endsWith('/') && pathname.length > 0)
7
- base += '/';
8
- return base + pathname;
2
+ if (pathname.startsWith('/'))
3
+ pathname = pathname.slice(1);
4
+ if (base.endsWith('/'))
5
+ base = base.slice(0, -1);
6
+ if (pathname.length > 0)
7
+ return base + '/' + pathname;
8
+ else
9
+ return base;
9
10
  }
10
11
  /**
11
12
  * @param url - URL (can be relative)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fumadocs-openapi",
3
- "version": "9.0.8",
3
+ "version": "9.0.10",
4
4
  "description": "Generate MDX docs for your OpenAPI spec",
5
5
  "keywords": [
6
6
  "NextJs",
@@ -50,7 +50,7 @@
50
50
  "@radix-ui/react-dialog": "^1.1.14",
51
51
  "@radix-ui/react-select": "^2.2.5",
52
52
  "@radix-ui/react-slot": "^1.2.3",
53
- "@scalar/openapi-parser": "0.13.0",
53
+ "@scalar/openapi-parser": "0.16.0",
54
54
  "ajv": "^8.17.1",
55
55
  "class-variance-authority": "^0.7.1",
56
56
  "github-slugger": "^2.0.0",
@@ -58,36 +58,40 @@
58
58
  "js-yaml": "^4.1.0",
59
59
  "next-themes": "^0.4.6",
60
60
  "openapi-sampler": "^1.6.1",
61
- "react-hook-form": "^7.56.3",
61
+ "react-hook-form": "^7.57.0",
62
62
  "remark": "^15.0.1",
63
63
  "remark-rehype": "^11.1.2",
64
- "shiki": "^3.4.2",
64
+ "shiki": "^3.6.0",
65
65
  "tinyglobby": "^0.2.14",
66
66
  "xml-js": "^1.6.11",
67
- "fumadocs-core": "15.5.1",
68
- "fumadocs-ui": "15.5.1"
67
+ "fumadocs-core": "15.5.2",
68
+ "fumadocs-ui": "15.5.2"
69
69
  },
70
70
  "devDependencies": {
71
- "@scalar/api-client-react": "^1.3.5",
71
+ "@scalar/api-client-react": "^1.3.10",
72
72
  "@types/js-yaml": "^4.0.9",
73
- "@types/node": "22.15.28",
73
+ "@types/node": "24.0.1",
74
74
  "@types/openapi-sampler": "^1.0.3",
75
- "@types/react": "^19.1.6",
75
+ "@types/react": "^19.1.8",
76
76
  "json-schema-typed": "^8.0.1",
77
77
  "next": "15.3.3",
78
78
  "openapi-types": "^12.1.3",
79
- "tailwindcss": "^4.1.8",
79
+ "tailwindcss": "^4.1.10",
80
80
  "tsc-alias": "^1.8.16",
81
- "tsconfig": "0.0.0",
82
- "eslint-config-custom": "0.0.0"
81
+ "eslint-config-custom": "0.0.0",
82
+ "tsconfig": "0.0.0"
83
83
  },
84
84
  "peerDependencies": {
85
85
  "@scalar/api-client-react": "*",
86
86
  "next": "14.x.x || 15.x.x",
87
87
  "react": "18.x.x || 19.x.x",
88
- "react-dom": "18.x.x || 19.x.x"
88
+ "react-dom": "18.x.x || 19.x.x",
89
+ "@types/react": "*"
89
90
  },
90
91
  "peerDependenciesMeta": {
92
+ "@types/react": {
93
+ "optional": true
94
+ },
91
95
  "@scalar/api-client-react": {
92
96
  "optional": true
93
97
  }