doccupine 0.0.133 → 0.0.135

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 (174) hide show
  1. package/README.md +50 -10
  2. package/dist/index.d.ts +1 -1
  3. package/dist/index.js +478 -45
  4. package/dist/lib/config-manager.d.ts +8 -1
  5. package/dist/lib/config-manager.js +98 -4
  6. package/dist/lib/metadata.d.ts +5 -0
  7. package/dist/lib/metadata.js +15 -4
  8. package/dist/lib/openapi-types.d.ts +120 -0
  9. package/dist/lib/openapi-types.js +14 -0
  10. package/dist/lib/openapi.d.ts +52 -0
  11. package/dist/lib/openapi.js +603 -0
  12. package/dist/lib/rss.d.ts +24 -0
  13. package/dist/lib/rss.js +137 -0
  14. package/dist/lib/structures.js +50 -4
  15. package/dist/lib/types.d.ts +22 -0
  16. package/dist/lib/utils.d.ts +8 -0
  17. package/dist/lib/utils.js +14 -0
  18. package/dist/templates/app/api/playground/route.d.ts +1 -0
  19. package/dist/templates/app/api/playground/route.js +199 -0
  20. package/dist/templates/app/rssRoute.d.ts +11 -0
  21. package/dist/templates/app/rssRoute.js +30 -0
  22. package/dist/templates/components/Docs.d.ts +1 -1
  23. package/dist/templates/components/Docs.js +15 -3
  24. package/dist/templates/components/MDXComponents.d.ts +1 -1
  25. package/dist/templates/components/MDXComponents.js +29 -0
  26. package/dist/templates/components/SideBar.d.ts +1 -1
  27. package/dist/templates/components/SideBar.js +13 -0
  28. package/dist/templates/components/layout/Accordion.d.ts +1 -1
  29. package/dist/templates/components/layout/Accordion.js +3 -2
  30. package/dist/templates/components/layout/ActionBar.d.ts +1 -1
  31. package/dist/templates/components/layout/ActionBar.js +65 -27
  32. package/dist/templates/components/layout/ApiPlayground.d.ts +1 -0
  33. package/dist/templates/components/layout/ApiPlayground.js +1075 -0
  34. package/dist/templates/components/layout/ApiPlaygroundDemo.d.ts +1 -0
  35. package/dist/templates/components/layout/ApiPlaygroundDemo.js +81 -0
  36. package/dist/templates/components/layout/Badge.d.ts +1 -0
  37. package/dist/templates/components/layout/Badge.js +455 -0
  38. package/dist/templates/components/layout/Code.d.ts +1 -1
  39. package/dist/templates/components/layout/Code.js +10 -22
  40. package/dist/templates/components/layout/CopyButton.d.ts +1 -0
  41. package/dist/templates/components/layout/CopyButton.js +68 -0
  42. package/dist/templates/components/layout/DocsComponents.d.ts +1 -1
  43. package/dist/templates/components/layout/DocsComponents.js +14 -0
  44. package/dist/templates/components/layout/Mermaid.d.ts +1 -1
  45. package/dist/templates/components/layout/Mermaid.js +21 -3
  46. package/dist/templates/components/layout/Prompt.d.ts +1 -0
  47. package/dist/templates/components/layout/Prompt.js +149 -0
  48. package/dist/templates/components/layout/SharedStyles.d.ts +1 -1
  49. package/dist/templates/components/layout/SharedStyles.js +0 -4
  50. package/dist/templates/components/layout/Steps.d.ts +1 -1
  51. package/dist/templates/components/layout/Steps.js +0 -1
  52. package/dist/templates/components/layout/Tooltip.d.ts +1 -0
  53. package/dist/templates/components/layout/Tooltip.js +222 -0
  54. package/dist/templates/components/layout/Tree.d.ts +1 -0
  55. package/dist/templates/components/layout/Tree.js +322 -0
  56. package/dist/templates/components/layout/TreeData.d.ts +1 -0
  57. package/dist/templates/components/layout/TreeData.js +131 -0
  58. package/dist/templates/components/layout/Update.d.ts +1 -1
  59. package/dist/templates/components/layout/Update.js +5 -1
  60. package/dist/templates/lib/rss.d.ts +1 -0
  61. package/dist/templates/lib/rss.js +78 -0
  62. package/dist/templates/mdx/accordion.mdx.d.ts +1 -1
  63. package/dist/templates/mdx/accordion.mdx.js +19 -1
  64. package/dist/templates/mdx/ai-assistant.mdx.d.ts +1 -1
  65. package/dist/templates/mdx/ai-assistant.mdx.js +3 -2
  66. package/dist/templates/mdx/analytics.mdx.d.ts +1 -1
  67. package/dist/templates/mdx/analytics.mdx.js +2 -2
  68. package/dist/templates/mdx/api-playground.mdx.d.ts +1 -0
  69. package/dist/templates/mdx/api-playground.mdx.js +158 -0
  70. package/dist/templates/mdx/authentication.mdx.d.ts +1 -1
  71. package/dist/templates/mdx/authentication.mdx.js +3 -3
  72. package/dist/templates/mdx/badges.mdx.d.ts +1 -0
  73. package/dist/templates/mdx/badges.mdx.js +237 -0
  74. package/dist/templates/mdx/buttons.mdx.d.ts +1 -1
  75. package/dist/templates/mdx/buttons.mdx.js +1 -1
  76. package/dist/templates/mdx/callouts.mdx.d.ts +1 -1
  77. package/dist/templates/mdx/callouts.mdx.js +1 -1
  78. package/dist/templates/mdx/cards.mdx.d.ts +1 -1
  79. package/dist/templates/mdx/cards.mdx.js +1 -1
  80. package/dist/templates/mdx/color-swatches.mdx.d.ts +1 -1
  81. package/dist/templates/mdx/color-swatches.mdx.js +1 -1
  82. package/dist/templates/mdx/columns.mdx.d.ts +1 -1
  83. package/dist/templates/mdx/columns.mdx.js +1 -1
  84. package/dist/templates/mdx/commands.mdx.d.ts +1 -1
  85. package/dist/templates/mdx/commands.mdx.js +3 -2
  86. package/dist/templates/mdx/components.mdx.d.ts +1 -1
  87. package/dist/templates/mdx/components.mdx.js +25 -10
  88. package/dist/templates/mdx/deployment-and-hosting.mdx.d.ts +1 -1
  89. package/dist/templates/mdx/deployment-and-hosting.mdx.js +4 -3
  90. package/dist/templates/mdx/fields.mdx.d.ts +1 -1
  91. package/dist/templates/mdx/fields.mdx.js +1 -1
  92. package/dist/templates/mdx/fonts.mdx.d.ts +1 -1
  93. package/dist/templates/mdx/fonts.mdx.js +2 -2
  94. package/dist/templates/mdx/footer-links.mdx.d.ts +1 -1
  95. package/dist/templates/mdx/footer-links.mdx.js +1 -1
  96. package/dist/templates/mdx/frames.mdx.d.ts +1 -1
  97. package/dist/templates/mdx/frames.mdx.js +1 -1
  98. package/dist/templates/mdx/globals.mdx.d.ts +1 -1
  99. package/dist/templates/mdx/globals.mdx.js +1 -1
  100. package/dist/templates/mdx/icons.mdx.d.ts +1 -1
  101. package/dist/templates/mdx/icons.mdx.js +1 -1
  102. package/dist/templates/mdx/image-and-embeds.mdx.d.ts +1 -1
  103. package/dist/templates/mdx/image-and-embeds.mdx.js +1 -1
  104. package/dist/templates/mdx/images-and-embeds.mdx.d.ts +1 -0
  105. package/dist/templates/mdx/images-and-embeds.mdx.js +118 -0
  106. package/dist/templates/mdx/media-and-assets.mdx.d.ts +1 -1
  107. package/dist/templates/mdx/media-and-assets.mdx.js +2 -2
  108. package/dist/templates/mdx/mermaid.mdx.d.ts +1 -1
  109. package/dist/templates/mdx/mermaid.mdx.js +1 -1
  110. package/dist/templates/mdx/model-context-protocol.mdx.d.ts +1 -1
  111. package/dist/templates/mdx/model-context-protocol.mdx.js +2 -2
  112. package/dist/templates/mdx/navigation.mdx.d.ts +1 -1
  113. package/dist/templates/mdx/navigation.mdx.js +27 -12
  114. package/dist/templates/mdx/platform/ai-assistant.mdx.d.ts +1 -1
  115. package/dist/templates/mdx/platform/ai-assistant.mdx.js +4 -3
  116. package/dist/templates/mdx/platform/analytics.mdx.d.ts +1 -1
  117. package/dist/templates/mdx/platform/analytics.mdx.js +2 -2
  118. package/dist/templates/mdx/platform/api-playground.mdx.d.ts +1 -0
  119. package/dist/templates/mdx/platform/api-playground.mdx.js +62 -0
  120. package/dist/templates/mdx/platform/billing.mdx.d.ts +1 -1
  121. package/dist/templates/mdx/platform/billing.mdx.js +1 -1
  122. package/dist/templates/mdx/platform/build-and-deploy.mdx.d.ts +1 -1
  123. package/dist/templates/mdx/platform/build-and-deploy.mdx.js +1 -1
  124. package/dist/templates/mdx/platform/creating-a-project.mdx.d.ts +1 -1
  125. package/dist/templates/mdx/platform/creating-a-project.mdx.js +12 -2
  126. package/dist/templates/mdx/platform/custom-domains.mdx.d.ts +1 -1
  127. package/dist/templates/mdx/platform/custom-domains.mdx.js +1 -1
  128. package/dist/templates/mdx/platform/fonts-settings.mdx.d.ts +1 -1
  129. package/dist/templates/mdx/platform/fonts-settings.mdx.js +1 -1
  130. package/dist/templates/mdx/platform/footer-links.mdx.d.ts +1 -0
  131. package/dist/templates/mdx/platform/{external-links.mdx.js → footer-links.mdx.js} +5 -5
  132. package/dist/templates/mdx/platform/import-from-github.mdx.d.ts +1 -0
  133. package/dist/templates/mdx/platform/import-from-github.mdx.js +91 -0
  134. package/dist/templates/mdx/platform/mcp.mdx.d.ts +1 -1
  135. package/dist/templates/mdx/platform/mcp.mdx.js +3 -3
  136. package/dist/templates/mdx/platform/project-settings.mdx.d.ts +1 -1
  137. package/dist/templates/mdx/platform/project-settings.mdx.js +1 -1
  138. package/dist/templates/mdx/platform/self-updating-docs.mdx.d.ts +1 -0
  139. package/dist/templates/mdx/platform/self-updating-docs.mdx.js +113 -0
  140. package/dist/templates/mdx/platform/team-members.mdx.d.ts +1 -1
  141. package/dist/templates/mdx/platform/team-members.mdx.js +1 -1
  142. package/dist/templates/mdx/prompt.mdx.d.ts +1 -0
  143. package/dist/templates/mdx/prompt.mdx.js +69 -0
  144. package/dist/templates/mdx/sections.mdx.d.ts +1 -1
  145. package/dist/templates/mdx/sections.mdx.js +1 -1
  146. package/dist/templates/mdx/steps.mdx.d.ts +1 -1
  147. package/dist/templates/mdx/steps.mdx.js +1 -1
  148. package/dist/templates/mdx/tabs.mdx.d.ts +1 -1
  149. package/dist/templates/mdx/tabs.mdx.js +1 -1
  150. package/dist/templates/mdx/theme.mdx.d.ts +1 -1
  151. package/dist/templates/mdx/theme.mdx.js +1 -1
  152. package/dist/templates/mdx/tooltips.mdx.d.ts +1 -0
  153. package/dist/templates/mdx/tooltips.mdx.js +57 -0
  154. package/dist/templates/mdx/tree.mdx.d.ts +1 -0
  155. package/dist/templates/mdx/tree.mdx.js +158 -0
  156. package/dist/templates/mdx/update.mdx.d.ts +1 -1
  157. package/dist/templates/mdx/update.mdx.js +42 -2
  158. package/dist/templates/mdx/what-is-doccupine.mdx.d.ts +1 -1
  159. package/dist/templates/mdx/what-is-doccupine.mdx.js +1 -1
  160. package/dist/templates/package.js +7 -7
  161. package/dist/templates/services/openapi/playgroundAllowlistStub.d.ts +1 -0
  162. package/dist/templates/services/openapi/playgroundAllowlistStub.js +4 -0
  163. package/dist/templates/types/openapi.d.ts +1 -0
  164. package/dist/templates/types/openapi.js +93 -0
  165. package/dist/templates/utils/apiSnippets.d.ts +1 -0
  166. package/dist/templates/utils/apiSnippets.js +94 -0
  167. package/dist/templates/utils/orderNavItems.d.ts +1 -1
  168. package/dist/templates/utils/orderNavItems.js +3 -0
  169. package/dist/templates/utils/playgroundAllowlist.d.ts +1 -0
  170. package/dist/templates/utils/playgroundAllowlist.js +70 -0
  171. package/dist/templates/utils/ssrfGuard.d.ts +1 -0
  172. package/dist/templates/utils/ssrfGuard.js +217 -0
  173. package/package.json +4 -3
  174. package/dist/templates/mdx/platform/external-links.mdx.d.ts +0 -1
@@ -0,0 +1,1075 @@
1
+ export const apiPlaygroundTemplate = `"use client";
2
+ import React, { useCallback, useMemo, useRef, useState } from "react";
3
+ import styled, { css } from "styled-components";
4
+ import {
5
+ styledSmall,
6
+ interactiveStyles,
7
+ Input,
8
+ Textarea,
9
+ Modal,
10
+ } from "cherry-styled-components";
11
+ import { mq, Theme } from "@/app/theme";
12
+ import { Code, CodeTabs } from "@/components/layout/Code";
13
+ import { Icon } from "@/components/layout/Icon";
14
+ import { Accordion } from "@/components/layout/Accordion";
15
+ import { Badge, httpMethodBadgeColor } from "@/components/layout/Badge";
16
+ import { CopyButton } from "@/components/layout/CopyButton";
17
+ import { Spinner } from "@/components/Spinner";
18
+ import { matchAllowlist, matchAllowlistIn } from "@/utils/playgroundAllowlist";
19
+ import type { AllowlistEntry } from "@/utils/playgroundAllowlist";
20
+ import { buildSnippets } from "@/utils/apiSnippets";
21
+ import type { SnippetLanguage } from "@/utils/apiSnippets";
22
+ import type {
23
+ OperationDescriptor,
24
+ ParameterDescriptor,
25
+ ServerDescriptor,
26
+ } from "@/types/openapi";
27
+
28
+ interface PlaygroundResponse {
29
+ status: number;
30
+ statusText: string;
31
+ headers: Record<string, string>;
32
+ contentType: string | null;
33
+ bodyEncoding: "utf8" | "base64";
34
+ body: string;
35
+ truncated: boolean;
36
+ byteLength: number;
37
+ durationMs: number;
38
+ }
39
+
40
+ interface BuiltRequest {
41
+ url: string;
42
+ headers: Record<string, string>;
43
+ body: string | null;
44
+ secretHeaderNames: string[];
45
+ }
46
+
47
+ export interface ApiPlaygroundProps {
48
+ operation: OperationDescriptor;
49
+ defaultMode?: "proxy" | "direct";
50
+ allowDirect?: boolean;
51
+ // Extra client-side allowlist entries. The server proxy always enforces the
52
+ // build-time allowlist regardless; this only relaxes the client pre-flight
53
+ // (used by the docs demo to run in direct mode without a configured spec).
54
+ allowlist?: AllowlistEntry[];
55
+ snippetLanguages?: SnippetLanguage[];
56
+ }
57
+
58
+ function schemaTypeLabel(schema: unknown): string {
59
+ if (schema && typeof schema === "object") {
60
+ const record = schema as { type?: unknown; format?: unknown };
61
+ if (typeof record.type === "string") {
62
+ return typeof record.format === "string"
63
+ ? record.type + " (" + record.format + ")"
64
+ : record.type;
65
+ }
66
+ }
67
+ return "string";
68
+ }
69
+
70
+ function serverBase(server: ServerDescriptor | undefined): string {
71
+ if (!server) return "";
72
+ let url = server.url;
73
+ const variables = server.variables;
74
+ if (variables) {
75
+ for (const key of Object.keys(variables)) {
76
+ url = url.split("{" + key + "}").join(variables[key].default);
77
+ }
78
+ }
79
+ while (url.endsWith("/")) url = url.slice(0, -1);
80
+ return url;
81
+ }
82
+
83
+ function applyPathParams(
84
+ template: string,
85
+ values: Record<string, string>,
86
+ ): string {
87
+ let result = template;
88
+ for (const key of Object.keys(values)) {
89
+ result = result
90
+ .split("{" + key + "}")
91
+ .join(encodeURIComponent(values[key]));
92
+ }
93
+ return result;
94
+ }
95
+
96
+ function firstJsonExample(op: OperationDescriptor): {
97
+ contentType: string;
98
+ text: string;
99
+ } | null {
100
+ if (!op.requestBody || op.requestBody.content.length === 0) return null;
101
+ const media =
102
+ op.requestBody.content.find((m) => m.contentType.includes("json")) ??
103
+ op.requestBody.content[0];
104
+ let text = "";
105
+ if (media.example !== undefined) {
106
+ try {
107
+ text = JSON.stringify(media.example, null, 2);
108
+ } catch {
109
+ text = "";
110
+ }
111
+ }
112
+ return { contentType: media.contentType, text };
113
+ }
114
+
115
+ function classifyResponse(
116
+ contentType: string | null,
117
+ ): "image" | "video" | "audio" | "text" | "binary" {
118
+ if (!contentType) return "text";
119
+ const t = contentType.toLowerCase();
120
+ if (t.startsWith("image/") && !t.includes("svg")) return "image";
121
+ if (t.startsWith("video/")) return "video";
122
+ if (t.startsWith("audio/")) return "audio";
123
+ if (
124
+ t.includes("json") ||
125
+ t.startsWith("text/") ||
126
+ t.includes("xml") ||
127
+ t.includes("svg") ||
128
+ t.includes("html") ||
129
+ t.includes("javascript") ||
130
+ t.includes("csv")
131
+ ) {
132
+ return "text";
133
+ }
134
+ return "binary";
135
+ }
136
+
137
+ function codeLanguage(contentType: string | null): string {
138
+ if (!contentType) return "text";
139
+ const t = contentType.toLowerCase();
140
+ if (t.includes("json")) return "json";
141
+ if (t.includes("html")) return "html";
142
+ if (t.includes("xml") || t.includes("svg")) return "xml";
143
+ if (t.includes("javascript")) return "javascript";
144
+ return "text";
145
+ }
146
+
147
+ function prettyBody(contentType: string | null, body: string): string {
148
+ if (contentType && contentType.toLowerCase().includes("json")) {
149
+ try {
150
+ return JSON.stringify(JSON.parse(body), null, 2);
151
+ } catch {
152
+ return body;
153
+ }
154
+ }
155
+ return body;
156
+ }
157
+
158
+ function bufferToBase64(buffer: ArrayBuffer): string {
159
+ let binary = "";
160
+ const bytes = new Uint8Array(buffer);
161
+ const chunk = 0x8000;
162
+ for (let i = 0; i < bytes.length; i += chunk) {
163
+ binary += String.fromCharCode(...bytes.subarray(i, i + chunk));
164
+ }
165
+ return btoa(binary);
166
+ }
167
+
168
+ function renderPath(path: string): React.ReactNode {
169
+ return path
170
+ .split(/(\\{[^}]+\\})/g)
171
+ .map((part, index) =>
172
+ part.startsWith("{") ? (
173
+ <PathParam key={index}>{part}</PathParam>
174
+ ) : (
175
+ <span key={index}>{part}</span>
176
+ ),
177
+ );
178
+ }
179
+
180
+ const LOCATIONS: ParameterDescriptor["in"][] = [
181
+ "path",
182
+ "query",
183
+ "header",
184
+ "cookie",
185
+ ];
186
+
187
+ const LOCATION_TITLES: Record<string, string> = {
188
+ path: "Path",
189
+ query: "Query",
190
+ header: "Headers",
191
+ cookie: "Cookies",
192
+ };
193
+
194
+ /* ---------- compact bar ---------- */
195
+
196
+ const CompactBar = styled.div\`
197
+ display: flex;
198
+ align-items: center;
199
+ gap: 10px;
200
+ margin: 0;
201
+ padding: 8px 8px 8px 12px;
202
+ border: solid 1px \${({ theme }: { theme: Theme }) => theme.colors.grayLight};
203
+ border-radius: \${({ theme }: { theme: Theme }) => theme.spacing.radius.lg};
204
+ background: \${({ theme }: { theme: Theme }) => theme.colors.light};
205
+ \`;
206
+
207
+ // The method chip is Badge's mono+solid variation; only bar-layout metrics
208
+ // are adjusted here.
209
+ const MethodBadge = styled(Badge)\`
210
+ flex-shrink: 0;
211
+ padding: 0 4px;
212
+ border: none;
213
+ \`;
214
+
215
+ const PathText = styled.span\`
216
+ flex: 1;
217
+ min-width: 0;
218
+ font-family: \${({ theme }: { theme: Theme }) => theme.fonts.mono};
219
+ font-weight: 600;
220
+ font-size: 14px;
221
+ color: \${({ theme }: { theme: Theme }) => theme.colors.dark};
222
+ overflow-x: auto;
223
+ white-space: nowrap;
224
+ &::-webkit-scrollbar {
225
+ display: none;
226
+ }
227
+ \`;
228
+
229
+ const PathParam = styled.span\`
230
+ font-family: \${({ theme }: { theme: Theme }) => theme.fonts.mono};
231
+ background: \${({ theme }: { theme: Theme }) =>
232
+ \`color-mix(in srgb, \${theme.colors.primaryLight} 20%, transparent)\`};
233
+ color: \${({ theme }: { theme: Theme }) => theme.colors.dark};
234
+ padding: 2px 4px;
235
+ border-radius: \${({ theme }: { theme: Theme }) => theme.spacing.radius.xs};
236
+ overflow-wrap: anywhere;
237
+ \`;
238
+
239
+ const AccentButton = styled.button<{ theme: Theme }>\`
240
+ cursor: pointer;
241
+ display: inline-flex;
242
+ align-items: center;
243
+ gap: 6px;
244
+ flex-shrink: 0;
245
+ font-family: \${({ theme }: { theme: Theme }) => theme.fonts.text};
246
+ font-weight: 600;
247
+ font-size: 14px;
248
+ color: \${({ theme }: { theme: Theme }) => theme.colors.surface};
249
+ background: \${({ theme }: { theme: Theme }) => theme.colors.primary};
250
+ border: none;
251
+ padding: 8px 14px;
252
+ border-radius: \${({ theme }: { theme: Theme }) => theme.spacing.radius.xs};
253
+ \${interactiveStyles};
254
+
255
+ & svg {
256
+ color: \${({ theme }: { theme: Theme }) => theme.colors.surface};
257
+ stroke: \${({ theme }: { theme: Theme }) => theme.colors.surface};
258
+ }
259
+
260
+ &:hover {
261
+ background: \${({ theme }: { theme: Theme }) => theme.colors.primaryDark};
262
+ }
263
+ &:disabled {
264
+ opacity: 0.6;
265
+ cursor: default;
266
+ }
267
+ \`;
268
+
269
+ /* ---------- modal ---------- */
270
+
271
+ const DialogHeader = styled.div\`
272
+ display: flex;
273
+ align-items: center;
274
+ gap: 10px;
275
+ flex-wrap: wrap;
276
+ margin: 5px 0 0 0;
277
+ \`;
278
+
279
+ const PathBar = styled.div\`
280
+ flex: 1;
281
+ min-width: 200px;
282
+ display: flex;
283
+ align-items: center;
284
+ gap: 8px;
285
+ padding: 8px 8px 8px 12px;
286
+ border: solid 1px \${({ theme }: { theme: Theme }) => theme.colors.grayLight};
287
+ border-radius: \${({ theme }: { theme: Theme }) => theme.spacing.radius.xs};
288
+ background: \${({ theme }: { theme: Theme }) => theme.colors.light};
289
+ \`;
290
+
291
+ const DialogBody = styled.div\`
292
+ display: grid;
293
+ grid-template-columns: 1fr;
294
+ gap: 20px;
295
+ padding: 0;
296
+ margin: 20px 0 0 0;
297
+
298
+ \${mq("lg")} {
299
+ grid-template-columns: 1fr 1fr;
300
+ }
301
+ \`;
302
+
303
+ const Column = styled.div\`
304
+ display: flex;
305
+ flex-direction: column;
306
+ gap: 20px;
307
+ min-width: 0;
308
+ \`;
309
+
310
+ const Description = styled.p\`
311
+ margin: 0;
312
+ \${({ theme }: { theme: Theme }) => styledSmall(theme)};
313
+ color: \${({ theme }: { theme: Theme }) => theme.colors.grayDark};
314
+ \`;
315
+
316
+ const Toolbar = styled.div\`
317
+ display: flex;
318
+ align-items: center;
319
+ gap: 8px;
320
+ flex-wrap: wrap;
321
+ \`;
322
+
323
+ const Toggle = styled.button<{ theme: Theme; $active?: boolean }>\`
324
+ position: relative;
325
+ cursor: pointer;
326
+ text-decoration: none;
327
+ font-size: \${({ theme }) => theme.fontSizes.small.lg};
328
+ line-height: 1;
329
+ color: \${({ theme }) => theme.colors.accent};
330
+ display: flex;
331
+ gap: 6px;
332
+ transition: all 0.3s ease;
333
+ font-weight: 600;
334
+ white-space: nowrap;
335
+ min-width: fit-content;
336
+ background: \${({ theme }) =>
337
+ \`color-mix(in srgb, \${theme.colors.primaryLight} 10%, transparent)\`};
338
+ padding: 6px 8px;
339
+ border: none;
340
+ border-radius: \${({ theme }) => theme.spacing.radius.xs};
341
+ \${interactiveStyles};
342
+
343
+ \${({ $active, theme }) =>
344
+ $active &&
345
+ css\`
346
+ background: \${theme.colors.primary};
347
+ color: \${theme.colors.surface};
348
+ \`}
349
+ \`;
350
+
351
+ /* ---------- collapsible card ---------- */
352
+
353
+ const Card = styled.div\`
354
+ border: solid 1px \${({ theme }: { theme: Theme }) => theme.colors.grayLight};
355
+ border-radius: \${({ theme }: { theme: Theme }) => theme.spacing.radius.lg};
356
+ overflow: hidden;
357
+ \`;
358
+
359
+ const CardHead = styled.button\`
360
+ cursor: pointer;
361
+ width: 100%;
362
+ display: flex;
363
+ align-items: center;
364
+ justify-content: space-between;
365
+ gap: 8px;
366
+ padding: 12px 20px;
367
+ border: none;
368
+ background: transparent;
369
+ color: \${({ theme }: { theme: Theme }) => theme.colors.dark};
370
+ \${({ theme }: { theme: Theme }) => styledSmall(theme)};
371
+ \`;
372
+
373
+ const Inline = styled.span\`
374
+ display: inline-flex;
375
+ align-items: center;
376
+ gap: 8px;
377
+ \`;
378
+
379
+ const CardBody = styled.div\`
380
+ padding: 0 20px 20px;
381
+ display: flex;
382
+ flex-direction: column;
383
+ gap: 16px;
384
+ \`;
385
+
386
+ /* ---------- fields ---------- */
387
+
388
+ // Wraps an accordion section's content and insets it, so full-width inputs'
389
+ // focus rings (a 4px box-shadow) are not clipped by the accordion's own
390
+ // overflow. Keeps the accordion component untouched.
391
+ const SectionInner = styled.div\`
392
+ display: flex;
393
+ flex-direction: column;
394
+ gap: 16px;
395
+ padding: 4px;
396
+ \`;
397
+
398
+ const Field = styled.div\`
399
+ display: flex;
400
+ flex-direction: column;
401
+ gap: 6px;
402
+ \`;
403
+
404
+ const FieldHead = styled.div\`
405
+ display: flex;
406
+ align-items: center;
407
+ gap: 8px;
408
+ flex-wrap: wrap;
409
+ \${({ theme }: { theme: Theme }) => styledSmall(theme)};
410
+ \`;
411
+
412
+ const FieldName = styled.span\`
413
+ font-family: \${({ theme }: { theme: Theme }) => theme.fonts.mono};
414
+ font-weight: 600;
415
+ color: \${({ theme }: { theme: Theme }) => theme.colors.dark};
416
+ \`;
417
+
418
+ const TypeChip = styled.span\`
419
+ font-family: \${({ theme }: { theme: Theme }) => theme.fonts.mono};
420
+ color: \${({ theme }: { theme: Theme }) => theme.colors.grayDark};
421
+ background: \${({ theme }: { theme: Theme }) =>
422
+ \`color-mix(in srgb, \${theme.colors.gray} 15%, transparent)\`};
423
+ padding: 0 4px;
424
+ border-radius: \${({ theme }: { theme: Theme }) => theme.spacing.radius.xs};
425
+ \`;
426
+
427
+ const RequiredChip = styled.span\`
428
+ font-family: \${({ theme }: { theme: Theme }) => theme.fonts.mono};
429
+ color: \${({ theme }: { theme: Theme }) => theme.colors.error};
430
+ \`;
431
+
432
+ const FieldDesc = styled.p\`
433
+ margin: 0;
434
+ width: 100%;
435
+ \${({ theme }: { theme: Theme }) => styledSmall(theme)};
436
+ color: \${({ theme }: { theme: Theme }) => theme.colors.gray};
437
+ \`;
438
+
439
+ /* ---------- response ---------- */
440
+
441
+ const StatusPill = styled.span<{ theme: Theme; $ok: boolean }>\`
442
+ font-family: \${({ theme }) => theme.fonts.mono};
443
+ font-weight: 700;
444
+ color: \${({ theme }) => theme.colors.surface};
445
+ background: \${({ theme, $ok }) =>
446
+ $ok ? theme.colors.success : theme.colors.error};
447
+ padding: 0 4px;
448
+ border-radius: \${({ theme }) => theme.spacing.radius.xs};
449
+ \`;
450
+
451
+ const Meta = styled.span\`
452
+ \${({ theme }: { theme: Theme }) => styledSmall(theme)};
453
+ color: \${({ theme }: { theme: Theme }) => theme.colors.gray};
454
+ \`;
455
+
456
+ const ErrorText = styled.p\`
457
+ margin: 0;
458
+ \${({ theme }: { theme: Theme }) => styledSmall(theme)};
459
+ color: \${({ theme }: { theme: Theme }) => theme.colors.error};
460
+ \`;
461
+
462
+ const Placeholder = styled.div\`
463
+ border: dashed 1px \${({ theme }: { theme: Theme }) => theme.colors.grayLight};
464
+ border-radius: \${({ theme }: { theme: Theme }) => theme.spacing.radius.lg};
465
+ padding: 24px;
466
+ min-height: 120px;
467
+ display: flex;
468
+ align-items: center;
469
+ justify-content: center;
470
+ gap: 10px;
471
+ text-align: center;
472
+ \${({ theme }: { theme: Theme }) => styledSmall(theme)};
473
+ color: \${({ theme }: { theme: Theme }) => theme.colors.gray};
474
+ \`;
475
+
476
+ // Holds the response (or empty placeholder) and lets the loading spinner sit on
477
+ // top of it, so a re-send keeps the previous content in place instead of
478
+ // collapsing and jumping the layout.
479
+ const ResponseArea = styled.div\`
480
+ position: relative;
481
+ \`;
482
+
483
+ const LoadingOverlay = styled.div\`
484
+ position: absolute;
485
+ inset: 0;
486
+ z-index: 1;
487
+ display: flex;
488
+ align-items: center;
489
+ justify-content: center;
490
+ border: solid 1px \${({ theme }: { theme: Theme }) => theme.colors.grayLight};
491
+ border-radius: \${({ theme }: { theme: Theme }) => theme.spacing.radius.lg};
492
+ color: \${({ theme }: { theme: Theme }) => theme.colors.grayDark};
493
+ background: \${({ theme }: { theme: Theme }) =>
494
+ \`color-mix(in srgb, \${theme.colors.light} 60%, transparent)\`};
495
+ backdrop-filter: blur(1px);
496
+ \`;
497
+
498
+ const ResponseMedia = styled.img\`
499
+ max-width: 100%;
500
+ border-radius: \${({ theme }: { theme: Theme }) => theme.spacing.radius.xs};
501
+ \`;
502
+
503
+ export function ApiPlayground({
504
+ operation,
505
+ defaultMode = "proxy",
506
+ allowDirect = true,
507
+ allowlist,
508
+ snippetLanguages = ["curl", "javascript", "python"],
509
+ }: ApiPlaygroundProps) {
510
+ const [open, setOpen] = useState(false);
511
+ const [paramValues, setParamValues] = useState<Record<string, string>>({});
512
+ const [authValues, setAuthValues] = useState<Record<string, string>>({});
513
+ const initialBody = useMemo(() => firstJsonExample(operation), [operation]);
514
+ const [bodyText, setBodyText] = useState(initialBody?.text ?? "");
515
+ const [mode, setMode] = useState<"proxy" | "direct">(defaultMode);
516
+ const [showSecrets, setShowSecrets] = useState(false);
517
+ const [loading, setLoading] = useState(false);
518
+ const [response, setResponse] = useState<PlaygroundResponse | null>(null);
519
+ const [error, setError] = useState<string | null>(null);
520
+ const [corsRetry, setCorsRetry] = useState(false);
521
+ const abortRef = useRef<AbortController | null>(null);
522
+
523
+ const paramKey = (p: ParameterDescriptor) => p.in + ":" + p.name;
524
+
525
+ const isAllowed = useCallback(
526
+ (url: string) =>
527
+ Boolean(
528
+ matchAllowlist(url) ??
529
+ (allowlist ? matchAllowlistIn(allowlist, url) : null),
530
+ ),
531
+ [allowlist],
532
+ );
533
+
534
+ const buildRequest = useCallback((): BuiltRequest => {
535
+ const base = serverBase(operation.servers[0]);
536
+ const pathValues: Record<string, string> = {};
537
+ const queryParts: string[] = [];
538
+ const headers: Record<string, string> = {};
539
+ const secretHeaderNames: string[] = [];
540
+ let cookie = "";
541
+
542
+ for (const param of operation.parameters) {
543
+ const value = paramValues[paramKey(param)];
544
+ if (value === undefined || value === "") continue;
545
+ if (param.in === "path") pathValues[param.name] = value;
546
+ else if (param.in === "query")
547
+ queryParts.push(
548
+ encodeURIComponent(param.name) + "=" + encodeURIComponent(value),
549
+ );
550
+ else if (param.in === "header") headers[param.name] = value;
551
+ else if (param.in === "cookie")
552
+ cookie += (cookie ? "; " : "") + param.name + "=" + value;
553
+ }
554
+
555
+ for (const requirement of operation.security) {
556
+ const scheme = requirement.scheme;
557
+ if (!scheme) continue;
558
+ if (scheme.type === "apiKey" && scheme.name) {
559
+ const value = authValues[requirement.schemeName];
560
+ if (!value) continue;
561
+ if (scheme.in === "header") {
562
+ headers[scheme.name] = value;
563
+ secretHeaderNames.push(scheme.name);
564
+ } else if (scheme.in === "query") {
565
+ queryParts.push(
566
+ encodeURIComponent(scheme.name) + "=" + encodeURIComponent(value),
567
+ );
568
+ } else if (scheme.in === "cookie") {
569
+ cookie += (cookie ? "; " : "") + scheme.name + "=" + value;
570
+ }
571
+ } else if (scheme.type === "http" && scheme.scheme === "basic") {
572
+ const user = authValues[requirement.schemeName + ":user"] ?? "";
573
+ const pass = authValues[requirement.schemeName + ":pass"] ?? "";
574
+ if (user || pass) {
575
+ headers["Authorization"] = "Basic " + btoa(user + ":" + pass);
576
+ secretHeaderNames.push("Authorization");
577
+ }
578
+ } else {
579
+ const token = authValues[requirement.schemeName];
580
+ if (token) {
581
+ headers["Authorization"] = "Bearer " + token;
582
+ secretHeaderNames.push("Authorization");
583
+ }
584
+ }
585
+ }
586
+
587
+ if (cookie) headers["Cookie"] = cookie;
588
+
589
+ const hasBody =
590
+ operation.requestBody !== undefined &&
591
+ operation.method !== "get" &&
592
+ operation.method !== "head" &&
593
+ bodyText.trim() !== "";
594
+ if (hasBody && !headers["Content-Type"] && initialBody) {
595
+ headers["Content-Type"] = initialBody.contentType;
596
+ }
597
+
598
+ const query = queryParts.join("&");
599
+ const url =
600
+ base +
601
+ applyPathParams(operation.path, pathValues) +
602
+ (query ? "?" + query : "");
603
+
604
+ return { url, headers, body: hasBody ? bodyText : null, secretHeaderNames };
605
+ }, [operation, paramValues, authValues, bodyText, initialBody]);
606
+
607
+ const snippets = useMemo(() => {
608
+ const built = buildRequest();
609
+ const headers: Record<string, string> = { ...built.headers };
610
+ if (!showSecrets) {
611
+ for (const name of built.secretHeaderNames) {
612
+ headers[name] = "<YOUR_CREDENTIALS>";
613
+ }
614
+ }
615
+ return buildSnippets(
616
+ {
617
+ method: operation.method.toUpperCase(),
618
+ url: built.url || operation.path,
619
+ headers,
620
+ body: built.body,
621
+ },
622
+ snippetLanguages,
623
+ );
624
+ }, [buildRequest, showSecrets, operation, snippetLanguages]);
625
+
626
+ const sendProxy = useCallback(
627
+ async (
628
+ built: BuiltRequest,
629
+ signal: AbortSignal,
630
+ ): Promise<PlaygroundResponse> => {
631
+ const res = await fetch("/api/playground", {
632
+ method: "POST",
633
+ headers: { "Content-Type": "application/json" },
634
+ signal,
635
+ body: JSON.stringify({
636
+ targetUrl: built.url,
637
+ method: operation.method.toUpperCase(),
638
+ headers: built.headers,
639
+ body: built.body ?? undefined,
640
+ bodyEncoding: "utf8",
641
+ }),
642
+ });
643
+ const data = await res.json();
644
+ if (!res.ok) {
645
+ throw new Error(
646
+ typeof data?.error === "string" ? data.error : "Request failed",
647
+ );
648
+ }
649
+ return data as PlaygroundResponse;
650
+ },
651
+ [operation],
652
+ );
653
+
654
+ const sendDirect = useCallback(
655
+ async (
656
+ built: BuiltRequest,
657
+ signal: AbortSignal,
658
+ ): Promise<PlaygroundResponse> => {
659
+ const start = Date.now();
660
+ const res = await fetch(built.url, {
661
+ method: operation.method.toUpperCase(),
662
+ headers: built.headers,
663
+ body: built.body ?? undefined,
664
+ signal,
665
+ });
666
+ const buffer = await res.arrayBuffer();
667
+ const contentType = res.headers.get("content-type");
668
+ const isText = classifyResponse(contentType) === "text";
669
+ const headers: Record<string, string> = {};
670
+ res.headers.forEach((value, key) => {
671
+ headers[key] = value;
672
+ });
673
+ return {
674
+ status: res.status,
675
+ statusText: res.statusText,
676
+ headers,
677
+ contentType,
678
+ bodyEncoding: isText ? "utf8" : "base64",
679
+ body: isText
680
+ ? new TextDecoder().decode(buffer)
681
+ : bufferToBase64(buffer),
682
+ truncated: false,
683
+ byteLength: buffer.byteLength,
684
+ durationMs: Date.now() - start,
685
+ };
686
+ },
687
+ [operation],
688
+ );
689
+
690
+ const send = useCallback(async () => {
691
+ setError(null);
692
+ setCorsRetry(false);
693
+ // Keep any previous response on screen; the loading overlay covers it so
694
+ // the layout does not collapse and jump while the new request is in flight.
695
+
696
+ const built = buildRequest();
697
+ if (!built.url) {
698
+ setError("No server URL is configured for this endpoint.");
699
+ return;
700
+ }
701
+ if (!isAllowed(built.url)) {
702
+ setError("This endpoint's server is not in the allowed list.");
703
+ return;
704
+ }
705
+ if (
706
+ mode === "direct" &&
707
+ typeof window !== "undefined" &&
708
+ window.location.protocol === "https:" &&
709
+ built.url.startsWith("http:")
710
+ ) {
711
+ setError(
712
+ "Browsers block HTTP requests from an HTTPS page. Use proxy mode.",
713
+ );
714
+ return;
715
+ }
716
+
717
+ const controller = new AbortController();
718
+ abortRef.current = controller;
719
+ setLoading(true);
720
+ try {
721
+ const result =
722
+ mode === "direct"
723
+ ? await sendDirect(built, controller.signal)
724
+ : await sendProxy(built, controller.signal);
725
+ setResponse(result);
726
+ } catch (err) {
727
+ if (controller.signal.aborted) return;
728
+ if (mode === "direct" && err instanceof TypeError) {
729
+ setCorsRetry(true);
730
+ setError(
731
+ "The browser blocked this cross-origin request (CORS). Run it server-side instead.",
732
+ );
733
+ } else {
734
+ setError(err instanceof Error ? err.message : "Request failed");
735
+ }
736
+ } finally {
737
+ setLoading(false);
738
+ abortRef.current = null;
739
+ }
740
+ }, [buildRequest, isAllowed, mode, sendDirect, sendProxy]);
741
+
742
+ const retryViaProxy = useCallback(() => {
743
+ setMode("proxy");
744
+ setCorsRetry(false);
745
+ void send();
746
+ }, [send]);
747
+
748
+ const groupedParams = LOCATIONS.map((location) => ({
749
+ location,
750
+ params: operation.parameters.filter((p) => p.in === location),
751
+ })).filter((group) => group.params.length > 0);
752
+ // Only the first visible section starts expanded.
753
+ const hasAuth = operation.security.length > 0;
754
+
755
+ const responseKind = response ? classifyResponse(response.contentType) : null;
756
+ const mediaSrc =
757
+ response && responseKind && responseKind !== "text"
758
+ ? "data:" +
759
+ (response.contentType ?? "application/octet-stream") +
760
+ ";base64," +
761
+ response.body
762
+ : "";
763
+
764
+ const renderParamField = (param: ParameterDescriptor) => (
765
+ <Field key={param.anchorId}>
766
+ <FieldHead>
767
+ <FieldName>{param.name}</FieldName>
768
+ <TypeChip>{schemaTypeLabel(param.schema)}</TypeChip>
769
+ {param.required ? <RequiredChip>required</RequiredChip> : null}
770
+ </FieldHead>
771
+ {param.description ? <FieldDesc>{param.description}</FieldDesc> : null}
772
+ <Input
773
+ $fullWidth
774
+ type="text"
775
+ aria-label={param.name}
776
+ placeholder={
777
+ param.example !== undefined
778
+ ? String(param.example)
779
+ : "enter " + param.name
780
+ }
781
+ value={paramValues[paramKey(param)] ?? ""}
782
+ onChange={(e) =>
783
+ setParamValues((prev) => ({
784
+ ...prev,
785
+ [paramKey(param)]: e.target.value,
786
+ }))
787
+ }
788
+ />
789
+ </Field>
790
+ );
791
+
792
+ return (
793
+ <>
794
+ <CompactBar>
795
+ <MethodBadge
796
+ mono
797
+ solid
798
+ size="sm"
799
+ color={httpMethodBadgeColor(operation.method)}
800
+ >
801
+ {operation.method}
802
+ </MethodBadge>
803
+ <PathText>{renderPath(operation.path)}</PathText>
804
+ <CopyButton
805
+ text={operation.method.toUpperCase() + " " + operation.path}
806
+ label="Copy endpoint"
807
+ size={16}
808
+ />
809
+ <AccentButton type="button" onClick={() => setOpen(true)}>
810
+ Try it
811
+ <Icon name="play" size={14} />
812
+ </AccentButton>
813
+ </CompactBar>
814
+
815
+ <Modal
816
+ $isOpen={open}
817
+ $onClose={() => setOpen(false)}
818
+ $width={1120}
819
+ $title={
820
+ operation.summary ??
821
+ operation.method.toUpperCase() + " " + operation.path
822
+ }
823
+ >
824
+ <DialogHeader>
825
+ <PathBar>
826
+ <MethodBadge
827
+ mono
828
+ solid
829
+ size="sm"
830
+ color={httpMethodBadgeColor(operation.method)}
831
+ >
832
+ {operation.method}
833
+ </MethodBadge>
834
+ <PathText>{renderPath(operation.path)}</PathText>
835
+ <AccentButton
836
+ type="button"
837
+ onClick={() => void send()}
838
+ disabled={loading}
839
+ >
840
+ Send
841
+ {loading ? <Spinner size={14} /> : <Icon name="play" size={14} />}
842
+ </AccentButton>
843
+ </PathBar>
844
+ </DialogHeader>
845
+
846
+ <DialogBody>
847
+ <Column>
848
+ {operation.description || operation.summary ? (
849
+ <Description>
850
+ {operation.description ?? operation.summary}
851
+ </Description>
852
+ ) : null}
853
+
854
+ <Toolbar>
855
+ {operation.servers.length > 0 ? (
856
+ <Meta>{serverBase(operation.servers[0])}</Meta>
857
+ ) : null}
858
+ {allowDirect ? (
859
+ <>
860
+ <Toggle
861
+ type="button"
862
+ $active={mode === "proxy"}
863
+ onClick={() => setMode("proxy")}
864
+ >
865
+ Proxy
866
+ </Toggle>
867
+ <Toggle
868
+ type="button"
869
+ $active={mode === "direct"}
870
+ onClick={() => setMode("direct")}
871
+ >
872
+ Direct
873
+ </Toggle>
874
+ </>
875
+ ) : null}
876
+ <Toggle
877
+ type="button"
878
+ $active={showSecrets}
879
+ onClick={() => setShowSecrets((v) => !v)}
880
+ >
881
+ {showSecrets ? "Hide secrets" : "Show secrets"}
882
+ </Toggle>
883
+ </Toolbar>
884
+
885
+ {operation.security.length > 0 ? (
886
+ <Accordion title="Authorization" defaultOpen>
887
+ <SectionInner>
888
+ {operation.security.map((requirement) => {
889
+ const scheme = requirement.scheme;
890
+ if (
891
+ scheme &&
892
+ scheme.type === "http" &&
893
+ scheme.scheme === "basic"
894
+ ) {
895
+ return (
896
+ <Field key={requirement.schemeName}>
897
+ <FieldHead>
898
+ <FieldName>{requirement.schemeName}</FieldName>
899
+ <TypeChip>basic</TypeChip>
900
+ </FieldHead>
901
+ <Input
902
+ $fullWidth
903
+ type="text"
904
+ aria-label={requirement.schemeName + " username"}
905
+ placeholder="username"
906
+ value={
907
+ authValues[requirement.schemeName + ":user"] ?? ""
908
+ }
909
+ onChange={(e) =>
910
+ setAuthValues((prev) => ({
911
+ ...prev,
912
+ [requirement.schemeName + ":user"]:
913
+ e.target.value,
914
+ }))
915
+ }
916
+ />
917
+ <Input
918
+ $fullWidth
919
+ type={showSecrets ? "text" : "password"}
920
+ aria-label={requirement.schemeName + " password"}
921
+ placeholder="password"
922
+ value={
923
+ authValues[requirement.schemeName + ":pass"] ?? ""
924
+ }
925
+ onChange={(e) =>
926
+ setAuthValues((prev) => ({
927
+ ...prev,
928
+ [requirement.schemeName + ":pass"]:
929
+ e.target.value,
930
+ }))
931
+ }
932
+ />
933
+ </Field>
934
+ );
935
+ }
936
+ const chip =
937
+ scheme?.type === "apiKey"
938
+ ? "apiKey"
939
+ : scheme?.scheme === "bearer"
940
+ ? "bearer"
941
+ : (scheme?.type ?? "token");
942
+ return (
943
+ <Field key={requirement.schemeName}>
944
+ <FieldHead>
945
+ <FieldName>{requirement.schemeName}</FieldName>
946
+ <TypeChip>{chip}</TypeChip>
947
+ <RequiredChip>required</RequiredChip>
948
+ </FieldHead>
949
+ <Input
950
+ $fullWidth
951
+ type={showSecrets ? "text" : "password"}
952
+ aria-label={requirement.schemeName}
953
+ placeholder={
954
+ chip === "bearer"
955
+ ? "enter bearer token"
956
+ : "enter value"
957
+ }
958
+ value={authValues[requirement.schemeName] ?? ""}
959
+ onChange={(e) =>
960
+ setAuthValues((prev) => ({
961
+ ...prev,
962
+ [requirement.schemeName]: e.target.value,
963
+ }))
964
+ }
965
+ />
966
+ </Field>
967
+ );
968
+ })}
969
+ </SectionInner>
970
+ </Accordion>
971
+ ) : null}
972
+
973
+ {groupedParams.map((group, index) => (
974
+ <Accordion
975
+ key={group.location}
976
+ title={LOCATION_TITLES[group.location]}
977
+ defaultOpen={!hasAuth && index === 0}
978
+ >
979
+ <SectionInner>
980
+ {group.params.map(renderParamField)}
981
+ </SectionInner>
982
+ </Accordion>
983
+ ))}
984
+
985
+ {operation.requestBody &&
986
+ operation.method !== "get" &&
987
+ operation.method !== "head" ? (
988
+ <Accordion
989
+ title="Body"
990
+ defaultOpen={!hasAuth && groupedParams.length === 0}
991
+ >
992
+ <SectionInner>
993
+ <Textarea
994
+ $fullWidth
995
+ rows={8}
996
+ aria-label="Request body"
997
+ spellCheck={false}
998
+ value={bodyText}
999
+ onChange={(e) => setBodyText(e.target.value)}
1000
+ />
1001
+ </SectionInner>
1002
+ </Accordion>
1003
+ ) : null}
1004
+
1005
+ {error ? (
1006
+ <Field>
1007
+ <ErrorText>{error}</ErrorText>
1008
+ {corsRetry ? (
1009
+ <Toggle type="button" onClick={retryViaProxy}>
1010
+ Retry via proxy
1011
+ </Toggle>
1012
+ ) : null}
1013
+ </Field>
1014
+ ) : null}
1015
+ </Column>
1016
+
1017
+ <Column>
1018
+ <ResponseArea>
1019
+ {response ? (
1020
+ <Card>
1021
+ <CardHead as="div">
1022
+ <Inline>
1023
+ <StatusPill
1024
+ $ok={response.status >= 200 && response.status < 400}
1025
+ >
1026
+ {response.status} {response.statusText}
1027
+ </StatusPill>
1028
+ <Meta>{response.durationMs}ms</Meta>
1029
+ <Meta>{response.byteLength} bytes</Meta>
1030
+ {response.truncated ? <Meta>(truncated)</Meta> : null}
1031
+ </Inline>
1032
+ </CardHead>
1033
+ <CardBody>
1034
+ {responseKind === "image" ? (
1035
+ <ResponseMedia src={mediaSrc} alt="Response" />
1036
+ ) : responseKind === "video" ? (
1037
+ <video
1038
+ controls
1039
+ src={mediaSrc}
1040
+ style={{ maxWidth: "100%" }}
1041
+ />
1042
+ ) : responseKind === "audio" ? (
1043
+ <audio controls src={mediaSrc} />
1044
+ ) : responseKind === "binary" ? (
1045
+ <a href={mediaSrc} download>
1046
+ Download response ({response.byteLength} bytes)
1047
+ </a>
1048
+ ) : (
1049
+ <Code
1050
+ language={codeLanguage(response.contentType)}
1051
+ code={prettyBody(response.contentType, response.body)}
1052
+ />
1053
+ )}
1054
+ </CardBody>
1055
+ </Card>
1056
+ ) : (
1057
+ <Placeholder>
1058
+ Send the request to see the live response here.
1059
+ </Placeholder>
1060
+ )}
1061
+ {loading ? (
1062
+ <LoadingOverlay>
1063
+ <Spinner size={22} />
1064
+ </LoadingOverlay>
1065
+ ) : null}
1066
+ </ResponseArea>
1067
+
1068
+ {snippets.length > 0 ? <CodeTabs tabs={snippets} /> : null}
1069
+ </Column>
1070
+ </DialogBody>
1071
+ </Modal>
1072
+ </>
1073
+ );
1074
+ }
1075
+ `;