fumadocs-openapi 10.6.4 → 10.6.6

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 (231) hide show
  1. package/css/generated/shared.css +34 -7
  2. package/dist/_openapi/types.d.ts +1 -2
  3. package/dist/generate-file.d.ts +1 -2
  4. package/dist/generate-file.js +3 -4
  5. package/dist/i18n.d.ts +2 -2
  6. package/dist/i18n.js +1 -2
  7. package/dist/playground/auth.js +92 -0
  8. package/dist/playground/client.d.ts +5 -10
  9. package/dist/playground/client.js +280 -199
  10. package/dist/playground/components/inputs.js +0 -2
  11. package/dist/playground/components/oauth-dialog.js +125 -164
  12. package/dist/playground/components/server-select.js +0 -2
  13. package/dist/playground/components/spinner.js +14 -0
  14. package/dist/playground/fetcher.d.ts +1 -2
  15. package/dist/playground/fetcher.js +0 -2
  16. package/dist/playground/schema.d.ts +1 -2
  17. package/dist/playground/schema.js +24 -15
  18. package/dist/playground/status-info.js +0 -2
  19. package/dist/requests/generators/all.d.ts +1 -2
  20. package/dist/requests/generators/all.js +0 -2
  21. package/dist/requests/generators/csharp.d.ts +1 -2
  22. package/dist/requests/generators/csharp.js +2 -3
  23. package/dist/requests/generators/curl.d.ts +1 -2
  24. package/dist/requests/generators/curl.js +5 -7
  25. package/dist/requests/generators/go.d.ts +1 -2
  26. package/dist/requests/generators/go.js +5 -7
  27. package/dist/requests/generators/index.d.ts +1 -2
  28. package/dist/requests/generators/index.js +0 -2
  29. package/dist/requests/generators/java.d.ts +1 -2
  30. package/dist/requests/generators/java.js +4 -6
  31. package/dist/requests/generators/javascript.d.ts +1 -2
  32. package/dist/requests/generators/javascript.js +3 -5
  33. package/dist/requests/generators/python.d.ts +1 -2
  34. package/dist/requests/generators/python.js +5 -6
  35. package/dist/requests/media/adapter.d.ts +1 -2
  36. package/dist/requests/media/adapter.js +7 -9
  37. package/dist/requests/media/encode.d.ts +1 -2
  38. package/dist/requests/media/encode.js +0 -2
  39. package/dist/requests/media/resolve-adapter.js +0 -2
  40. package/dist/requests/string-utils.js +25 -6
  41. package/dist/requests/types.d.ts +4 -4
  42. package/dist/scalar/client.js +0 -2
  43. package/dist/scalar/index.d.ts +1 -2
  44. package/dist/scalar/index.js +0 -2
  45. package/dist/server/create.d.ts +2 -3
  46. package/dist/server/create.js +0 -2
  47. package/dist/server/proxy.d.ts +1 -2
  48. package/dist/server/proxy.js +0 -2
  49. package/dist/server/source-api.d.ts +1 -2
  50. package/dist/server/source-api.js +0 -2
  51. package/dist/types.d.ts +1 -2
  52. package/dist/ui/api-page.d.ts +1 -2
  53. package/dist/ui/api-page.js +3 -3
  54. package/dist/ui/base.d.ts +9 -6
  55. package/dist/ui/base.js +8 -5
  56. package/dist/ui/client/boundary.d.ts +1 -2
  57. package/dist/ui/client/boundary.js +0 -2
  58. package/dist/ui/client/boundary.lazy.js +2 -3
  59. package/dist/ui/client/full.js +0 -2
  60. package/dist/ui/client/i18n.js +0 -2
  61. package/dist/ui/client/index.d.ts +1 -2
  62. package/dist/ui/client/index.js +0 -2
  63. package/dist/ui/client/storage-key.js +1 -3
  64. package/dist/ui/components/accordion.js +0 -2
  65. package/dist/ui/components/codeblock.d.ts +1 -2
  66. package/dist/ui/components/codeblock.js +0 -2
  67. package/dist/ui/components/dialog.js +0 -2
  68. package/dist/ui/components/input.js +0 -2
  69. package/dist/ui/components/method-label.js +0 -2
  70. package/dist/ui/components/select-tab.js +0 -2
  71. package/dist/ui/components/select.js +0 -2
  72. package/dist/ui/contexts/api.d.ts +7 -5
  73. package/dist/ui/contexts/api.js +7 -4
  74. package/dist/ui/create-client.d.ts +1 -2
  75. package/dist/ui/create-client.js +6 -3
  76. package/dist/ui/index.d.ts +1 -2
  77. package/dist/ui/index.js +0 -2
  78. package/dist/ui/operation/client.js +0 -2
  79. package/dist/ui/operation/get-example-requests.d.ts +1 -2
  80. package/dist/ui/operation/get-example-requests.js +0 -2
  81. package/dist/ui/operation/index.js +0 -2
  82. package/dist/ui/operation/request-tabs.d.ts +10 -0
  83. package/dist/ui/operation/request-tabs.js +43 -39
  84. package/dist/ui/operation/response-tabs.d.ts +1 -2
  85. package/dist/ui/operation/response-tabs.js +0 -2
  86. package/dist/ui/operation/usage-tabs/client.d.ts +1 -2
  87. package/dist/ui/operation/usage-tabs/client.js +0 -2
  88. package/dist/ui/operation/usage-tabs/index.js +0 -2
  89. package/dist/ui/schema/client.d.ts +1 -2
  90. package/dist/ui/schema/client.js +0 -2
  91. package/dist/ui/schema/index.d.ts +3 -4
  92. package/dist/ui/schema/index.js +1 -3
  93. package/dist/utils/deep-equal.js +0 -2
  94. package/dist/utils/document/dereference.d.ts +1 -2
  95. package/dist/utils/document/dereference.js +0 -2
  96. package/dist/utils/document/process.d.ts +1 -2
  97. package/dist/utils/document/process.js +0 -2
  98. package/dist/utils/id-to-title.js +0 -2
  99. package/dist/utils/is-plain-object.js +0 -2
  100. package/dist/utils/pages/builder.d.ts +1 -2
  101. package/dist/utils/pages/builder.js +0 -2
  102. package/dist/utils/pages/preset-auto.d.ts +1 -2
  103. package/dist/utils/pages/preset-auto.js +0 -2
  104. package/dist/utils/pages/to-static-data.js +0 -2
  105. package/dist/utils/pages/to-text.d.ts +1 -2
  106. package/dist/utils/pages/to-text.js +5 -6
  107. package/dist/utils/remove-undefined.js +0 -2
  108. package/dist/utils/schema/dereference.js +22 -14
  109. package/dist/utils/schema/index.d.ts +4 -10
  110. package/dist/utils/schema/index.js +4 -11
  111. package/dist/utils/{merge-schema.js → schema/merge.js} +2 -4
  112. package/dist/utils/schema/pick.js +0 -2
  113. package/dist/utils/schema/ref.js +0 -2
  114. package/dist/utils/schema/resolve-ref.js +0 -2
  115. package/dist/utils/schema/to-string.js +4 -7
  116. package/dist/utils/url.js +0 -2
  117. package/dist/utils/use-query.js +2 -3
  118. package/package.json +2 -2
  119. package/dist/_openapi/types.d.ts.map +0 -1
  120. package/dist/generate-file.d.ts.map +0 -1
  121. package/dist/generate-file.js.map +0 -1
  122. package/dist/i18n.d.ts.map +0 -1
  123. package/dist/i18n.js.map +0 -1
  124. package/dist/playground/client.d.ts.map +0 -1
  125. package/dist/playground/client.js.map +0 -1
  126. package/dist/playground/components/inputs.js.map +0 -1
  127. package/dist/playground/components/oauth-dialog.js.map +0 -1
  128. package/dist/playground/components/server-select.js.map +0 -1
  129. package/dist/playground/fetcher.d.ts.map +0 -1
  130. package/dist/playground/fetcher.js.map +0 -1
  131. package/dist/playground/schema.d.ts.map +0 -1
  132. package/dist/playground/schema.js.map +0 -1
  133. package/dist/playground/status-info.js.map +0 -1
  134. package/dist/requests/generators/all.d.ts.map +0 -1
  135. package/dist/requests/generators/all.js.map +0 -1
  136. package/dist/requests/generators/csharp.d.ts.map +0 -1
  137. package/dist/requests/generators/csharp.js.map +0 -1
  138. package/dist/requests/generators/curl.d.ts.map +0 -1
  139. package/dist/requests/generators/curl.js.map +0 -1
  140. package/dist/requests/generators/go.d.ts.map +0 -1
  141. package/dist/requests/generators/go.js.map +0 -1
  142. package/dist/requests/generators/index.d.ts.map +0 -1
  143. package/dist/requests/generators/index.js.map +0 -1
  144. package/dist/requests/generators/java.d.ts.map +0 -1
  145. package/dist/requests/generators/java.js.map +0 -1
  146. package/dist/requests/generators/javascript.d.ts.map +0 -1
  147. package/dist/requests/generators/javascript.js.map +0 -1
  148. package/dist/requests/generators/python.d.ts.map +0 -1
  149. package/dist/requests/generators/python.js.map +0 -1
  150. package/dist/requests/media/adapter.d.ts.map +0 -1
  151. package/dist/requests/media/adapter.js.map +0 -1
  152. package/dist/requests/media/encode.d.ts.map +0 -1
  153. package/dist/requests/media/encode.js.map +0 -1
  154. package/dist/requests/media/resolve-adapter.js.map +0 -1
  155. package/dist/requests/string-utils.js.map +0 -1
  156. package/dist/requests/types.d.ts.map +0 -1
  157. package/dist/scalar/client.js.map +0 -1
  158. package/dist/scalar/index.d.ts.map +0 -1
  159. package/dist/scalar/index.js.map +0 -1
  160. package/dist/server/create.d.ts.map +0 -1
  161. package/dist/server/create.js.map +0 -1
  162. package/dist/server/proxy.d.ts.map +0 -1
  163. package/dist/server/proxy.js.map +0 -1
  164. package/dist/server/source-api.d.ts.map +0 -1
  165. package/dist/server/source-api.js.map +0 -1
  166. package/dist/types.d.ts.map +0 -1
  167. package/dist/ui/api-page.d.ts.map +0 -1
  168. package/dist/ui/api-page.js.map +0 -1
  169. package/dist/ui/base.d.ts.map +0 -1
  170. package/dist/ui/base.js.map +0 -1
  171. package/dist/ui/client/boundary.d.ts.map +0 -1
  172. package/dist/ui/client/boundary.js.map +0 -1
  173. package/dist/ui/client/boundary.lazy.js.map +0 -1
  174. package/dist/ui/client/full.js.map +0 -1
  175. package/dist/ui/client/i18n.js.map +0 -1
  176. package/dist/ui/client/index.d.ts.map +0 -1
  177. package/dist/ui/client/index.js.map +0 -1
  178. package/dist/ui/client/storage-key.js.map +0 -1
  179. package/dist/ui/components/accordion.js.map +0 -1
  180. package/dist/ui/components/codeblock.d.ts.map +0 -1
  181. package/dist/ui/components/codeblock.js.map +0 -1
  182. package/dist/ui/components/dialog.js.map +0 -1
  183. package/dist/ui/components/input.js.map +0 -1
  184. package/dist/ui/components/method-label.js.map +0 -1
  185. package/dist/ui/components/select-tab.js.map +0 -1
  186. package/dist/ui/components/select.js.map +0 -1
  187. package/dist/ui/contexts/api.d.ts.map +0 -1
  188. package/dist/ui/contexts/api.js.map +0 -1
  189. package/dist/ui/create-client.d.ts.map +0 -1
  190. package/dist/ui/create-client.js.map +0 -1
  191. package/dist/ui/index.d.ts.map +0 -1
  192. package/dist/ui/index.js.map +0 -1
  193. package/dist/ui/operation/client.js.map +0 -1
  194. package/dist/ui/operation/get-example-requests.d.ts.map +0 -1
  195. package/dist/ui/operation/get-example-requests.js.map +0 -1
  196. package/dist/ui/operation/index.js.map +0 -1
  197. package/dist/ui/operation/request-tabs.js.map +0 -1
  198. package/dist/ui/operation/response-tabs.d.ts.map +0 -1
  199. package/dist/ui/operation/response-tabs.js.map +0 -1
  200. package/dist/ui/operation/usage-tabs/client.d.ts.map +0 -1
  201. package/dist/ui/operation/usage-tabs/client.js.map +0 -1
  202. package/dist/ui/operation/usage-tabs/index.js.map +0 -1
  203. package/dist/ui/schema/client.d.ts.map +0 -1
  204. package/dist/ui/schema/client.js.map +0 -1
  205. package/dist/ui/schema/index.d.ts.map +0 -1
  206. package/dist/ui/schema/index.js.map +0 -1
  207. package/dist/utils/deep-equal.js.map +0 -1
  208. package/dist/utils/document/dereference.d.ts.map +0 -1
  209. package/dist/utils/document/dereference.js.map +0 -1
  210. package/dist/utils/document/process.d.ts.map +0 -1
  211. package/dist/utils/document/process.js.map +0 -1
  212. package/dist/utils/id-to-title.js.map +0 -1
  213. package/dist/utils/is-plain-object.js.map +0 -1
  214. package/dist/utils/merge-schema.js.map +0 -1
  215. package/dist/utils/pages/builder.d.ts.map +0 -1
  216. package/dist/utils/pages/builder.js.map +0 -1
  217. package/dist/utils/pages/preset-auto.d.ts.map +0 -1
  218. package/dist/utils/pages/preset-auto.js.map +0 -1
  219. package/dist/utils/pages/to-static-data.js.map +0 -1
  220. package/dist/utils/pages/to-text.d.ts.map +0 -1
  221. package/dist/utils/pages/to-text.js.map +0 -1
  222. package/dist/utils/remove-undefined.js.map +0 -1
  223. package/dist/utils/schema/dereference.js.map +0 -1
  224. package/dist/utils/schema/index.d.ts.map +0 -1
  225. package/dist/utils/schema/index.js.map +0 -1
  226. package/dist/utils/schema/pick.js.map +0 -1
  227. package/dist/utils/schema/ref.js.map +0 -1
  228. package/dist/utils/schema/resolve-ref.js.map +0 -1
  229. package/dist/utils/schema/to-string.js.map +0 -1
  230. package/dist/utils/url.js.map +0 -1
  231. package/dist/utils/use-query.js.map +0 -1
@@ -1,15 +1,26 @@
1
+ import { useApiContext } from "../../ui/contexts/api.js";
1
2
  import { cn } from "../../utils/cn.js";
2
3
  import { useQuery } from "../../utils/use-query.js";
3
4
  import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../../ui/components/select.js";
4
5
  import { Input, labelVariants } from "../../ui/components/input.js";
5
6
  import { useTranslations } from "../../ui/client/i18n.js";
6
7
  import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from "../../ui/components/dialog.js";
7
- import { useEffect, useMemo, useState } from "react";
8
+ import { useAuth } from "../auth.js";
9
+ import { useMemo, useState } from "react";
8
10
  import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
9
11
  import { buttonVariants } from "fumadocs-ui/components/ui/button";
10
12
  import { useForm } from "react-hook-form";
11
13
  //#region src/playground/components/oauth-dialog.tsx
12
- function OauthDialog({ scheme, scopes, setToken, children, open, setOpen }) {
14
+ const OAuthDialog = Dialog;
15
+ function OAuthDialogContent(props) {
16
+ const t = useTranslations();
17
+ return /* @__PURE__ */ jsxs(DialogContent, { children: [/* @__PURE__ */ jsxs(DialogHeader, { children: [/* @__PURE__ */ jsx(DialogTitle, { children: t.authorization }), /* @__PURE__ */ jsx(DialogDescription, { children: t.obtainAccessToken })] }), /* @__PURE__ */ jsx(Content, { ...props })] });
18
+ }
19
+ function Content({ schemeId, scopes, setToken, setOpen }) {
20
+ const { schemes } = useApiContext();
21
+ const tokenInfo = useAuth().store[schemeId];
22
+ const scheme = schemes[schemeId];
23
+ if (!scheme || scheme.type !== "oauth2") throw new Error("unexpected schemaId: must be type oauth2");
13
24
  const [type, setType] = useState(() => {
14
25
  return Object.keys(scheme.flows)[0];
15
26
  });
@@ -41,58 +52,14 @@ function OauthDialog({ scheme, scopes, setToken, children, open, setOpen }) {
41
52
  supported: false
42
53
  }
43
54
  }), [t]);
44
- const form = useForm({ defaultValues: {
45
- clientId: "",
46
- clientSecret: "",
47
- username: "",
48
- password: ""
49
- } });
50
- const authCodeCallback = useQuery(async (code, state) => {
51
- const value = scheme.flows.authorizationCode;
52
- const res = await fetch(value.tokenUrl, {
53
- method: "POST",
54
- headers: { "Content-Type": "application/x-www-form-urlencoded" },
55
- body: new URLSearchParams({
56
- grant_type: "authorization_code",
57
- code,
58
- redirect_uri: state.redirect_uri,
59
- client_id: state.client_id,
60
- client_secret: state.client_secret
61
- })
62
- });
63
- if (!res.ok) throw new Error(await res.text());
64
- const { access_token, token_type = "Bearer" } = await res.json();
65
- setToken(`${token_type} ${access_token}`);
66
- setOpen(false);
67
- });
68
- useEffect(() => {
69
- if (scheme.flows.authorizationCode) {
70
- const params = new URLSearchParams(window.location.search);
71
- const state = params.get("state");
72
- const code = params.get("code");
73
- if (state && code) {
74
- const parsedState = JSON.parse(state);
75
- setOpen(true);
76
- form.setValue("clientId", parsedState.client_id);
77
- form.setValue("clientSecret", parsedState.client_secret);
78
- authCodeCallback.start(code, parsedState);
79
- window.history.replaceState(null, "", window.location.pathname);
80
- return;
81
- }
82
- }
83
- if (scheme.flows.implicit && window.location.hash.length > 1) {
84
- const params = new URLSearchParams(window.location.hash.slice(1));
85
- const state = params.get("state");
86
- const token = params.get("access_token");
87
- const type = params.get("token_type") ?? "Bearer";
88
- if (state && token) {
89
- const parsedState = JSON.parse(state);
90
- form.setValue("clientId", parsedState.client_id);
91
- setToken(`${type} ${token}`);
92
- window.history.replaceState(null, "", window.location.pathname);
93
- }
94
- }
95
- }, []);
55
+ const form = useForm({ defaultValues: useMemo(() => {
56
+ return {
57
+ clientId: tokenInfo?.client_id ?? "",
58
+ clientSecret: tokenInfo?.type === "authorization_code" ? tokenInfo.client_secret : "",
59
+ username: "",
60
+ password: ""
61
+ };
62
+ }, [tokenInfo]) });
96
63
  const authorize = useQuery(async (values) => {
97
64
  if (type === "implicit") {
98
65
  const value = scheme.flows[type];
@@ -102,6 +69,7 @@ function OauthDialog({ scheme, scopes, setToken, children, open, setOpen }) {
102
69
  params.set("redirect_uri", window.location.href);
103
70
  params.set("scope", scopes.join("+"));
104
71
  params.set("state", JSON.stringify({
72
+ scheme: schemeId,
105
73
  client_id: values.clientId,
106
74
  redirect_uri: window.location.href
107
75
  }));
@@ -118,7 +86,8 @@ function OauthDialog({ scheme, scopes, setToken, children, open, setOpen }) {
118
86
  params.set("state", JSON.stringify({
119
87
  client_id: values.clientId,
120
88
  client_secret: values.clientSecret,
121
- redirect_uri: window.location.href
89
+ redirect_uri: window.location.href,
90
+ scheme: schemeId
122
91
  }));
123
92
  window.location.replace(`${value.authorizationUrl}?${params.toString()}`);
124
93
  return;
@@ -157,129 +126,121 @@ function OauthDialog({ scheme, scopes, setToken, children, open, setOpen }) {
157
126
  setOpen(false);
158
127
  }
159
128
  });
129
+ const isLoading = authorize.isLoading;
160
130
  const onSubmit = form.handleSubmit((values) => {
161
131
  return authorize.start(values);
162
132
  });
163
- const isLoading = authorize.isLoading || authCodeCallback.isLoading;
164
- const error = authCodeCallback.error ?? authorize.error;
165
- return /* @__PURE__ */ jsxs(Dialog, {
166
- open,
167
- onOpenChange: setOpen,
168
- children: [children, /* @__PURE__ */ jsxs(DialogContent, { children: [/* @__PURE__ */ jsxs(DialogHeader, { children: [/* @__PURE__ */ jsx(DialogTitle, { children: t.authorization }), /* @__PURE__ */ jsx(DialogDescription, { children: t.obtainAccessToken })] }), /* @__PURE__ */ jsxs("form", {
169
- className: "flex flex-col gap-6",
170
- onSubmit: (e) => {
171
- onSubmit(e);
172
- e.stopPropagation();
173
- },
174
- children: [
175
- /* @__PURE__ */ jsxs(Select, {
176
- value: type,
177
- onValueChange: setType,
178
- children: [/* @__PURE__ */ jsx(SelectTrigger, { children: /* @__PURE__ */ jsx(SelectValue, {}) }), /* @__PURE__ */ jsx(SelectContent, { children: Object.keys(scheme.flows).map((key) => {
179
- const { name, description } = allFlows[key];
180
- return /* @__PURE__ */ jsxs(SelectItem, {
181
- value: key,
182
- children: [/* @__PURE__ */ jsx("p", {
183
- className: "font-medium",
184
- children: name
185
- }), /* @__PURE__ */ jsx("p", {
186
- className: "text-fd-muted-foreground",
187
- children: description
188
- })]
189
- }, key);
190
- }) })]
191
- }),
192
- (type === "authorizationCode" || type === "clientCredentials" || type === "implicit") && /* @__PURE__ */ jsxs("fieldset", {
193
- className: "flex flex-col gap-1.5",
194
- children: [
195
- /* @__PURE__ */ jsx("label", {
196
- htmlFor: "client_id",
197
- className: cn(labelVariants()),
198
- children: t.clientId
199
- }),
200
- /* @__PURE__ */ jsx("p", {
201
- className: "text-fd-muted-foreground text-sm",
202
- children: t.clientIdHint
203
- }),
204
- /* @__PURE__ */ jsx(Input, {
205
- id: "client_id",
206
- placeholder: t.inputPlaceholder,
207
- type: "text",
208
- autoComplete: "off",
209
- disabled: isLoading,
210
- ...form.register("clientId", { required: true })
211
- })
212
- ]
213
- }),
214
- (type === "authorizationCode" || type === "clientCredentials") && /* @__PURE__ */ jsxs("fieldset", {
215
- className: "flex flex-col gap-1.5",
216
- children: [
217
- /* @__PURE__ */ jsx("label", {
218
- htmlFor: "client_secret",
219
- className: cn(labelVariants()),
220
- children: t.clientSecret
221
- }),
222
- /* @__PURE__ */ jsx("p", {
223
- className: "text-fd-muted-foreground text-sm",
224
- children: t.clientSecretHint
225
- }),
226
- /* @__PURE__ */ jsx(Input, {
227
- id: "client_secret",
228
- placeholder: t.inputPlaceholder,
229
- type: "password",
230
- autoComplete: "off",
231
- disabled: isLoading,
232
- ...form.register("clientSecret", { required: true })
233
- })
234
- ]
235
- }),
236
- type === "password" && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("fieldset", {
237
- className: "flex flex-col gap-1.5",
238
- children: [/* @__PURE__ */ jsx("label", {
239
- htmlFor: "username",
133
+ return /* @__PURE__ */ jsxs("form", {
134
+ className: "flex flex-col gap-6",
135
+ onSubmit: (e) => {
136
+ onSubmit(e);
137
+ e.stopPropagation();
138
+ },
139
+ children: [
140
+ /* @__PURE__ */ jsxs(Select, {
141
+ value: type ?? "",
142
+ onValueChange: setType,
143
+ children: [/* @__PURE__ */ jsx(SelectTrigger, { children: /* @__PURE__ */ jsx(SelectValue, { placeholder: "Select a flow" }) }), /* @__PURE__ */ jsx(SelectContent, { children: Object.keys(scheme.flows).map((key) => {
144
+ const { name, description } = allFlows[key];
145
+ return /* @__PURE__ */ jsxs(SelectItem, {
146
+ value: key,
147
+ children: [/* @__PURE__ */ jsx("p", {
148
+ className: "font-medium",
149
+ children: name
150
+ }), /* @__PURE__ */ jsx("p", {
151
+ className: "text-fd-muted-foreground",
152
+ children: description
153
+ })]
154
+ }, key);
155
+ }) })]
156
+ }),
157
+ (type === "authorizationCode" || type === "clientCredentials" || type === "implicit") && /* @__PURE__ */ jsxs("fieldset", {
158
+ className: "flex flex-col gap-1.5",
159
+ children: [
160
+ /* @__PURE__ */ jsx("label", {
161
+ htmlFor: "client_id",
240
162
  className: cn(labelVariants()),
241
- children: t.usernameField
242
- }), /* @__PURE__ */ jsx(Input, {
243
- id: "username",
163
+ children: t.clientId
164
+ }),
165
+ /* @__PURE__ */ jsx("p", {
166
+ className: "text-fd-muted-foreground text-sm",
167
+ children: t.clientIdHint
168
+ }),
169
+ /* @__PURE__ */ jsx(Input, {
170
+ id: "client_id",
244
171
  placeholder: t.inputPlaceholder,
245
172
  type: "text",
246
- disabled: isLoading,
247
173
  autoComplete: "off",
248
- ...form.register("username", { required: true })
249
- })]
250
- }), /* @__PURE__ */ jsxs("fieldset", {
251
- className: "flex flex-col gap-1.5",
252
- children: [/* @__PURE__ */ jsx("label", {
253
- htmlFor: "password",
174
+ disabled: isLoading,
175
+ ...form.register("clientId", { required: true })
176
+ })
177
+ ]
178
+ }),
179
+ (type === "authorizationCode" || type === "clientCredentials") && /* @__PURE__ */ jsxs("fieldset", {
180
+ className: "flex flex-col gap-1.5",
181
+ children: [
182
+ /* @__PURE__ */ jsx("label", {
183
+ htmlFor: "client_secret",
254
184
  className: cn(labelVariants()),
255
185
  children: t.clientSecret
256
- }), /* @__PURE__ */ jsx(Input, {
257
- id: "password",
186
+ }),
187
+ /* @__PURE__ */ jsx("p", {
188
+ className: "text-fd-muted-foreground text-sm",
189
+ children: t.clientSecretHint
190
+ }),
191
+ /* @__PURE__ */ jsx(Input, {
192
+ id: "client_secret",
258
193
  placeholder: t.inputPlaceholder,
259
194
  type: "password",
260
195
  autoComplete: "off",
261
196
  disabled: isLoading,
262
- ...form.register("password", { required: true })
263
- })]
264
- })] }),
265
- allFlows[type].supported ? /* @__PURE__ */ jsxs(Fragment$1, { children: [error ? /* @__PURE__ */ jsx("p", {
266
- className: "text-red-400 font-medium text-sm",
267
- children: String(error)
268
- }) : null, /* @__PURE__ */ jsx("button", {
269
- type: "submit",
197
+ ...form.register("clientSecret", { required: true })
198
+ })
199
+ ]
200
+ }),
201
+ type === "password" && /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("fieldset", {
202
+ className: "flex flex-col gap-1.5",
203
+ children: [/* @__PURE__ */ jsx("label", {
204
+ htmlFor: "username",
205
+ className: cn(labelVariants()),
206
+ children: t.usernameField
207
+ }), /* @__PURE__ */ jsx(Input, {
208
+ id: "username",
209
+ placeholder: t.inputPlaceholder,
210
+ type: "text",
211
+ autoComplete: "off",
270
212
  disabled: isLoading,
271
- className: cn(buttonVariants({ color: "primary" })),
272
- children: authCodeCallback.isLoading ? t.fetchingToken : t.submit
273
- })] }) : /* @__PURE__ */ jsx("p", {
274
- className: "text-fd-muted-foreground bg-fd-muted p-2 rounded-lg border",
275
- children: t.unsupported
276
- })
277
- ]
278
- })] })]
213
+ ...form.register("username", { required: true })
214
+ })]
215
+ }), /* @__PURE__ */ jsxs("fieldset", {
216
+ className: "flex flex-col gap-1.5",
217
+ children: [/* @__PURE__ */ jsx("label", {
218
+ htmlFor: "password",
219
+ className: cn(labelVariants()),
220
+ children: t.clientSecret
221
+ }), /* @__PURE__ */ jsx(Input, {
222
+ id: "password",
223
+ placeholder: t.inputPlaceholder,
224
+ type: "password",
225
+ autoComplete: "off",
226
+ disabled: isLoading,
227
+ ...form.register("password", { required: true })
228
+ })]
229
+ })] }),
230
+ type && allFlows[type].supported ? /* @__PURE__ */ jsxs(Fragment$1, { children: [authorize.error ? /* @__PURE__ */ jsx("p", {
231
+ className: "text-red-400 font-medium text-sm",
232
+ children: String(authorize.error)
233
+ }) : null, /* @__PURE__ */ jsx("button", {
234
+ type: "submit",
235
+ className: cn(buttonVariants({ color: "primary" })),
236
+ children: t.submit
237
+ })] }) : /* @__PURE__ */ jsx("p", {
238
+ className: "text-fd-muted-foreground bg-fd-muted p-2 rounded-lg border",
239
+ children: t.unsupported
240
+ })
241
+ ]
279
242
  });
280
243
  }
281
- const OauthDialogTrigger = DialogTrigger;
244
+ const OAuthDialogTrigger = DialogTrigger;
282
245
  //#endregion
283
- export { OauthDialog, OauthDialogTrigger };
284
-
285
- //# sourceMappingURL=oauth-dialog.js.map
246
+ export { OAuthDialog, OAuthDialogContent, OAuthDialogTrigger };
@@ -124,5 +124,3 @@ function Field({ fieldName, variable }) {
124
124
  }
125
125
  //#endregion
126
126
  export { ServerSelect as default };
127
-
128
- //# sourceMappingURL=server-select.js.map
@@ -0,0 +1,14 @@
1
+ import { cn } from "../../utils/cn.js";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { Loader2Icon } from "lucide-react";
4
+ //#region src/playground/components/spinner.tsx
5
+ function Spinner({ className, ...props }) {
6
+ return /* @__PURE__ */ jsx(Loader2Icon, {
7
+ role: "status",
8
+ "aria-label": "Loading",
9
+ className: cn("size-4 animate-spin", className),
10
+ ...props
11
+ });
12
+ }
13
+ //#endregion
14
+ export { Spinner };
@@ -24,5 +24,4 @@ interface BrowserFetcherOptions {
24
24
  onRequestInit?: (requestInit: RequestInit) => Awaitable<RequestInit>;
25
25
  }
26
26
  //#endregion
27
- export { BrowserFetcherOptions, FetchResult };
28
- //# sourceMappingURL=fetcher.d.ts.map
27
+ export { BrowserFetcherOptions, FetchResult };
@@ -67,5 +67,3 @@ function createBrowserFetcher(adapters, { proxyUrl, proxyForwardCookie = true, r
67
67
  }
68
68
  //#endregion
69
69
  export { createBrowserFetcher };
70
-
71
- //# sourceMappingURL=fetcher.js.map
@@ -14,5 +14,4 @@ interface SchemaScope {
14
14
  readOnly: boolean;
15
15
  }
16
16
  //#endregion
17
- export { SchemaScope };
18
- //# sourceMappingURL=schema.d.ts.map
17
+ export { SchemaScope };
@@ -1,5 +1,6 @@
1
- import { mergeAllOf } from "../utils/merge-schema.js";
1
+ import { mergeAllOf } from "../utils/schema/merge.js";
2
2
  import { schemaToString } from "../utils/schema/to-string.js";
3
+ import { dereferenceSwallow } from "../utils/schema/dereference.js";
3
4
  import { createContext, use, useMemo } from "react";
4
5
  import { jsx } from "react/jsx-runtime";
5
6
  import { Ajv2020 } from "ajv/dist/2020.js";
@@ -19,7 +20,7 @@ const anyFields = {
19
20
  items: true,
20
21
  additionalProperties: true
21
22
  };
22
- function SchemaProvider({ schema, readOnly, writeOnly, children }) {
23
+ function SchemaProvider({ doc, readOnly, writeOnly, children }) {
23
24
  const ajv = useMemo(() => new Ajv2020({
24
25
  strict: false,
25
26
  validateSchema: false,
@@ -27,12 +28,12 @@ function SchemaProvider({ schema, readOnly, writeOnly, children }) {
27
28
  }), []);
28
29
  return /* @__PURE__ */ jsx(SchemaContext.Provider, {
29
30
  value: useMemo(() => ({
30
- schema,
31
+ doc,
31
32
  ajv,
32
33
  readOnly,
33
34
  writeOnly
34
35
  }), [
35
- schema,
36
+ doc,
36
37
  ajv,
37
38
  readOnly,
38
39
  writeOnly
@@ -51,7 +52,7 @@ function useSchemaScope() {
51
52
  * @param depth - The depth to avoid duplicated field name with same schema (e.g. nested `oneOf`).
52
53
  */
53
54
  function useFieldInfo(fieldName, schema, depth = 0) {
54
- const { ajv } = use(SchemaContext);
55
+ const { ajv, doc } = use(SchemaContext);
55
56
  const engine = useDataEngine();
56
57
  const { generateDefault } = useSchemaUtils();
57
58
  const [info, setInfo] = useFieldValue([], { stf: useNamespace({
@@ -62,7 +63,10 @@ function useFieldInfo(fieldName, schema, depth = 0) {
62
63
  const union = getUnion(schema);
63
64
  if (union) {
64
65
  const [members, field] = union;
65
- out.oneOf = members.findIndex((item) => ajv.validate(item, value));
66
+ out.oneOf = members.findIndex((item) => typeof item === "object" && ajv.validate({
67
+ ...doc,
68
+ ...item
69
+ }, value));
66
70
  if (out.oneOf === -1) out.oneOf = 0;
67
71
  out.unionField = field;
68
72
  }
@@ -70,6 +74,7 @@ function useFieldInfo(fieldName, schema, depth = 0) {
70
74
  const types = schema.type;
71
75
  out.selectedType = types.find((type) => {
72
76
  return ajv.validate({
77
+ ...doc,
73
78
  ...schema,
74
79
  type
75
80
  }, value);
@@ -100,29 +105,35 @@ function useFieldInfo(fieldName, schema, depth = 0) {
100
105
  };
101
106
  }
102
107
  function useSchemaUtils() {
103
- const { schema, readOnly } = use(SchemaContext);
108
+ const { doc, readOnly } = use(SchemaContext);
104
109
  return {
105
110
  generateDefault(schema) {
106
111
  return sample(schema, {
107
112
  skipNonRequired: true,
108
113
  skipReadOnly: !readOnly,
109
114
  quiet: true
110
- });
115
+ }, doc);
111
116
  },
112
117
  schemaToString(value, flags) {
113
- return schemaToString(value, schema, flags);
118
+ return schemaToString(value, (raw) => ({
119
+ raw,
120
+ dereferenced: dereferenceSwallow(raw, doc)
121
+ }), flags);
114
122
  }
115
123
  };
116
124
  }
117
125
  /**
118
- * merge `allOf`.
126
+ * dereference & merge `allOf`.
119
127
  */
120
128
  function useResolvedSchema(raw) {
129
+ const { doc } = use(SchemaContext);
121
130
  return useMemo(() => {
122
- let out = raw;
123
- if (typeof out === "object" && out.allOf) out = mergeAllOf(out);
131
+ let out = dereferenceSwallow(raw, doc);
132
+ if (typeof out === "object" && out.allOf) out = mergeAllOf(out, { dereference(schema) {
133
+ return dereferenceSwallow(schema, doc);
134
+ } });
124
135
  return typeof out === "boolean" ? anyFields : out;
125
- }, [raw]);
136
+ }, [doc, raw]);
126
137
  }
127
138
  function getUnion(schema) {
128
139
  if (schema.anyOf) return [schema.anyOf, "anyOf"];
@@ -130,5 +141,3 @@ function getUnion(schema) {
130
141
  }
131
142
  //#endregion
132
143
  export { SchemaProvider, anyFields, useFieldInfo, useResolvedSchema, useSchemaScope, useSchemaUtils };
133
-
134
- //# sourceMappingURL=schema.js.map
@@ -54,5 +54,3 @@ function getStatusInfo(status, t) {
54
54
  }
55
55
  //#endregion
56
56
  export { getStatusInfo };
57
-
58
- //# sourceMappingURL=status-info.js.map
@@ -3,5 +3,4 @@ import { CodeUsageGeneratorRegistry } from "./index.js";
3
3
  //#region src/requests/generators/all.d.ts
4
4
  declare function registerDefault(registry: CodeUsageGeneratorRegistry): void;
5
5
  //#endregion
6
- export { registerDefault };
7
- //# sourceMappingURL=all.d.ts.map
6
+ export { registerDefault };
@@ -15,5 +15,3 @@ function registerDefault(registry) {
15
15
  }
16
16
  //#endregion
17
17
  export { registerDefault };
18
-
19
- //# sourceMappingURL=all.js.map
@@ -3,5 +3,4 @@ import { CodeUsageGenerator } from "./index.js";
3
3
  //#region src/requests/generators/csharp.d.ts
4
4
  declare const csharp: CodeUsageGenerator;
5
5
  //#endregion
6
- export { csharp };
7
- //# sourceMappingURL=csharp.d.ts.map
6
+ export { csharp };
@@ -1,3 +1,4 @@
1
+ import { doubleQuote } from "../string-utils.js";
1
2
  import { resolveMediaAdapter } from "../media/resolve-adapter.js";
2
3
  import "../media/adapter.js";
3
4
  //#region src/requests/generators/csharp.ts
@@ -25,7 +26,7 @@ const csharp = {
25
26
  s.push("var client = new HttpClient();");
26
27
  const headerLines = [];
27
28
  function addHeader(key, value) {
28
- headerLines.push(`client.DefaultRequestHeaders.Add("${key}", ${JSON.stringify(value)});`);
29
+ headerLines.push(`client.DefaultRequestHeaders.Add("${key}", ${doubleQuote(value)});`);
29
30
  }
30
31
  for (const k in headers) addHeader(k, headers[k].value);
31
32
  if (Object.keys(data.cookie).length > 0) addHeader("cookie", Object.entries(data.cookie).map(([key, param]) => `${key}=${param.value}`).join("; "));
@@ -39,5 +40,3 @@ const csharp = {
39
40
  };
40
41
  //#endregion
41
42
  export { csharp };
42
-
43
- //# sourceMappingURL=csharp.js.map
@@ -3,5 +3,4 @@ import { CodeUsageGenerator } from "./index.js";
3
3
  //#region src/requests/generators/curl.d.ts
4
4
  declare const curl: CodeUsageGenerator;
5
5
  //#endregion
6
- export { curl };
7
- //# sourceMappingURL=curl.d.ts.map
6
+ export { curl };
@@ -1,24 +1,24 @@
1
- import { escapeString, indent, inputToString } from "../string-utils.js";
1
+ import { doubleQuote, indent, inputToString, singleQuote } from "../string-utils.js";
2
2
  //#region src/requests/generators/curl.ts
3
3
  const curl = {
4
4
  label: "cURL",
5
5
  lang: "bash",
6
6
  generate(url, data) {
7
7
  const s = [];
8
- s.push(`curl -X ${data.method} "${url}"`);
8
+ s.push(`curl -X ${data.method.toUpperCase()} "${url}"`);
9
9
  for (const header in data.header) {
10
10
  const value = `${header}: ${data.header[header].value}`;
11
11
  s.push(`-H "${value}"`);
12
12
  }
13
13
  for (const k in data.cookie) {
14
14
  const param = data.cookie[k];
15
- s.push(`--cookie ${JSON.stringify(`${k}=${param.value}`)}`);
15
+ s.push(`--cookie ${doubleQuote(`${k}=${param.value}`)}`);
16
16
  }
17
17
  if (data.body && data.bodyMediaType === "multipart/form-data") {
18
18
  if (typeof data.body !== "object") throw new Error("[CURL] request body must be an object.");
19
- for (const [key, value] of Object.entries(data.body)) s.push(`-F ${key}=${JSON.stringify(inputToString(value))}`);
19
+ for (const [key, value] of Object.entries(data.body)) s.push(`-F ${key}=${doubleQuote(inputToString(value))}`);
20
20
  } else if (data.body && data.bodyMediaType) {
21
- const escaped = escapeString(inputToString(data.body, data.bodyMediaType), "'");
21
+ const escaped = singleQuote(inputToString(data.body, data.bodyMediaType));
22
22
  s.push(`-H "Content-Type: ${data.bodyMediaType}"`);
23
23
  s.push(`-d ${escaped}`);
24
24
  }
@@ -27,5 +27,3 @@ const curl = {
27
27
  };
28
28
  //#endregion
29
29
  export { curl };
30
-
31
- //# sourceMappingURL=curl.js.map
@@ -3,5 +3,4 @@ import { CodeUsageGenerator } from "./index.js";
3
3
  //#region src/requests/generators/go.d.ts
4
4
  declare const go: CodeUsageGenerator;
5
5
  //#endregion
6
- export { go };
7
- //# sourceMappingURL=go.d.ts.map
6
+ export { go };
@@ -1,4 +1,4 @@
1
- import { indent } from "../string-utils.js";
1
+ import { doubleQuote, indent } from "../string-utils.js";
2
2
  import { resolveMediaAdapter } from "../media/resolve-adapter.js";
3
3
  import "../media/adapter.js";
4
4
  //#region src/requests/generators/go.ts
@@ -13,10 +13,10 @@ const go = {
13
13
  ];
14
14
  const headers = /* @__PURE__ */ new Map();
15
15
  const variables = /* @__PURE__ */ new Map();
16
- variables.set("url", JSON.stringify(url));
17
- for (const header in data.header) headers.set(header, JSON.stringify(data.header[header].value));
16
+ variables.set("url", doubleQuote(url));
17
+ for (const header in data.header) headers.set(header, doubleQuote(data.header[header].value));
18
18
  const cookies = Object.entries(data.cookie);
19
- if (cookies.length > 0) headers.set("Cookie", JSON.stringify(cookies.map(([k, param]) => `${k}=${param.value}`).join("; ")));
19
+ if (cookies.length > 0) headers.set("Cookie", doubleQuote(cookies.map(([k, param]) => `${k}=${param.value}`).join("; ")));
20
20
  let body;
21
21
  if (data.body && data.bodyMediaType) {
22
22
  const adapter = resolveMediaAdapter(data.bodyMediaType, mediaAdapters);
@@ -37,7 +37,7 @@ ${indent(imports.map((v) => `"${v}"`).join("\n"))}
37
37
  func main() {
38
38
  ${Array.from(variables.entries()).map(([k, v]) => indent(`${k} := ${v}`)).join("\n")}
39
39
  ${body ? indent(body) : ""}
40
- req, _ := http.NewRequest("${data.method}", url, ${body ? "body" : "nil"})
40
+ req, _ := http.NewRequest("${data.method.toUpperCase()}", url, ${body ? "body" : "nil"})
41
41
  ${indent(Array.from(headers.entries()).map(([key, value]) => `req.Header.Add("${key}", ${value})`).join("\n"))}
42
42
  res, _ := http.DefaultClient.Do(req)
43
43
  defer res.Body.Close()
@@ -50,5 +50,3 @@ ${indent(Array.from(headers.entries()).map(([key, value]) => `req.Header.Add("${
50
50
  };
51
51
  //#endregion
52
52
  export { go };
53
-
54
- //# sourceMappingURL=go.js.map
@@ -52,5 +52,4 @@ type CodeUsageGeneratorFn<ServerContext = unknown> = (url: string, data: Request
52
52
  server: ServerContext;
53
53
  }) => string;
54
54
  //#endregion
55
- export { CodeUsageGenerator, CodeUsageGeneratorFn, CodeUsageGeneratorRegistry, InlineCodeUsageGenerator, createCodeUsageGeneratorRegistry };
56
- //# sourceMappingURL=index.d.ts.map
55
+ export { CodeUsageGenerator, CodeUsageGeneratorFn, CodeUsageGeneratorRegistry, InlineCodeUsageGenerator, createCodeUsageGeneratorRegistry };
@@ -37,5 +37,3 @@ function createCodeUsageGeneratorRegistry(inherit) {
37
37
  }
38
38
  //#endregion
39
39
  export { createCodeUsageGeneratorRegistry };
40
-
41
- //# sourceMappingURL=index.js.map
@@ -3,5 +3,4 @@ import { CodeUsageGenerator } from "./index.js";
3
3
  //#region src/requests/generators/java.d.ts
4
4
  declare const java: CodeUsageGenerator;
5
5
  //#endregion
6
- export { java };
7
- //# sourceMappingURL=java.d.ts.map
6
+ export { java };