@clarify-labs/renderer 0.11.0 → 0.11.1

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 (58) hide show
  1. package/output/{ClarifyShell-BAjq876Z.cjs → ClarifyShell-C2XnkFQ6.cjs} +37 -21
  2. package/output/ClarifyShell-C2XnkFQ6.cjs.map +1 -0
  3. package/output/{ClarifyShell-GoSXvgMg.js → ClarifyShell-CwRtof1h.js} +37 -21
  4. package/output/ClarifyShell-CwRtof1h.js.map +1 -0
  5. package/output/{MermaidViewer-BZ8ghcFP.cjs → MermaidViewer-CTvMCE19.cjs} +2 -2
  6. package/output/{MermaidViewer-BZ8ghcFP.cjs.map → MermaidViewer-CTvMCE19.cjs.map} +1 -1
  7. package/output/{MermaidViewer-CkIxyqtf.js → MermaidViewer-CwkiQ2gO.js} +2 -2
  8. package/output/{MermaidViewer-CkIxyqtf.js.map → MermaidViewer-CwkiQ2gO.js.map} +1 -1
  9. package/output/{OpenApiOperation-C2vJztWZ.js → OpenApiOperation-CFo6_otd.js} +470 -123
  10. package/output/OpenApiOperation-CFo6_otd.js.map +1 -0
  11. package/output/{OpenApiOperation-D-5uE5v7.cjs → OpenApiOperation-D1WNrj5X.cjs} +470 -123
  12. package/output/OpenApiOperation-D1WNrj5X.cjs.map +1 -0
  13. package/output/{PageActions-bugd7GZh.js → PageActions-3eo05fb_.js} +47 -6
  14. package/output/PageActions-3eo05fb_.js.map +1 -0
  15. package/output/{PageActions-DJRXlGhz.cjs → PageActions-Lp_NeIKr.cjs} +46 -5
  16. package/output/PageActions-Lp_NeIKr.cjs.map +1 -0
  17. package/output/{SearchDialog-CBJjDs_9.js → SearchDialog-BvCBIFqs.js} +3 -3
  18. package/output/{SearchDialog-CBJjDs_9.js.map → SearchDialog-BvCBIFqs.js.map} +1 -1
  19. package/output/{SearchDialog-8AdCRp6K.cjs → SearchDialog-CM9DrE2Y.cjs} +3 -3
  20. package/output/{SearchDialog-8AdCRp6K.cjs.map → SearchDialog-CM9DrE2Y.cjs.map} +1 -1
  21. package/output/client.cjs +3 -3
  22. package/output/client.js +3 -3
  23. package/output/core/i18n.d.ts +1 -1
  24. package/output/core/types.d.ts +1 -1
  25. package/output/{i18n-BPrC45nD.js → i18n-BxXpRSFX.js} +9 -1
  26. package/output/i18n-BxXpRSFX.js.map +1 -0
  27. package/output/{i18n-wXINKKV0.cjs → i18n-DsjZ51U1.cjs} +9 -1
  28. package/output/i18n-DsjZ51U1.cjs.map +1 -0
  29. package/output/index.cjs +5 -5
  30. package/output/index.js +5 -5
  31. package/output/openapi/components/InlineListbox.d.ts +1 -0
  32. package/output/openapi/components/OpenApiRequestBodyEditor.d.ts +14 -0
  33. package/output/openapi/components/OpenApiResponseViewer.d.ts +6 -0
  34. package/output/openapi/components/useOpenApiRequestState.d.ts +9 -2
  35. package/output/openapi/lib/api-request.d.ts +1 -0
  36. package/output/openapi/lib/helpers.d.ts +8 -0
  37. package/output/openapi/types.d.ts +2 -0
  38. package/output/preview.cjs +14 -18
  39. package/output/preview.cjs.map +1 -1
  40. package/output/preview.js +14 -18
  41. package/output/preview.js.map +1 -1
  42. package/output/{render-FICIzeXz.cjs → render-CKG4X-me.cjs} +2 -2
  43. package/output/{render-FICIzeXz.cjs.map → render-CKG4X-me.cjs.map} +1 -1
  44. package/output/{render-XQiw_48i.js → render-vlp3hwW3.js} +2 -2
  45. package/output/{render-XQiw_48i.js.map → render-vlp3hwW3.js.map} +1 -1
  46. package/output/renderer.css +129 -48
  47. package/output/server.cjs +2 -2
  48. package/output/server.js +2 -2
  49. package/package.json +2 -1
  50. package/output/ClarifyShell-BAjq876Z.cjs.map +0 -1
  51. package/output/ClarifyShell-GoSXvgMg.js.map +0 -1
  52. package/output/OpenApiOperation-C2vJztWZ.js.map +0 -1
  53. package/output/OpenApiOperation-D-5uE5v7.cjs.map +0 -1
  54. package/output/PageActions-DJRXlGhz.cjs.map +0 -1
  55. package/output/PageActions-bugd7GZh.js.map +0 -1
  56. package/output/core/index.d.ts +0 -3
  57. package/output/i18n-BPrC45nD.js.map +0 -1
  58. package/output/i18n-wXINKKV0.cjs.map +0 -1
@@ -1,5 +1,5 @@
1
- import { a as useConfig, s as useLocale, t as useBuiltInText } from "./i18n-BPrC45nD.js";
2
- import { C as isExternalHref, E as copyTextToClipboard, c as lucideIconRegistry, h as useTheme, l as resolveLucideIconName, n as PageTitleActions, o as useSectionStore, s as remToPx, w as localizeHref } from "./PageActions-bugd7GZh.js";
1
+ import { a as useConfig, s as useLocale, t as useBuiltInText } from "./i18n-BxXpRSFX.js";
2
+ import { C as isExternalHref, E as copyTextToClipboard, c as lucideIconRegistry, h as useTheme, l as resolveLucideIconName, n as PageTitleActions, o as useSectionStore, s as remToPx, w as localizeHref } from "./PageActions-3eo05fb_.js";
3
3
  import { t as markdownRemarkPlugins } from "./remark-C9iRQM0R.js";
4
4
  import clsx from "clsx";
5
5
  import { Children, Suspense, cloneElement, createContext, createElement, forwardRef, isValidElement, lazy, useContext, useEffect, useId, useLayoutEffect, useRef, useState } from "react";
@@ -14,6 +14,7 @@ import rehypeRaw from "rehype-raw";
14
14
  import { slug } from "github-slugger";
15
15
  import { codeToTokens, createCssVariablesTheme } from "shiki";
16
16
  import { snippetz } from "@scalar/snippetz";
17
+ import { parse, stringify } from "yaml";
17
18
  //#region \0rolldown/runtime.js
18
19
  var __defProp = Object.defineProperty;
19
20
  var __exportAll = (all, no_symbols) => {
@@ -252,7 +253,7 @@ function Card(arg0) {
252
253
  }
253
254
  //#endregion
254
255
  //#region source/components/Mermaid.tsx
255
- var MermaidViewer = lazy(() => import("./MermaidViewer-CkIxyqtf.js"));
256
+ var MermaidViewer = lazy(() => import("./MermaidViewer-CwkiQ2gO.js"));
256
257
  var mermaidModulePromise;
257
258
  async function loadMermaid() {
258
259
  mermaidModulePromise = mermaidModulePromise ?? import("mermaid").then((module) => module.default);
@@ -1454,6 +1455,31 @@ function resolveSchema(spec, schema, seen = /* @__PURE__ */ new Set()) {
1454
1455
  seen.add(schema.$ref);
1455
1456
  return resolveSchema(spec, resolveOpenApiRef$1(spec, schema.$ref), seen) ?? schema;
1456
1457
  }
1458
+ function mergeAllOfSchemas(spec, schemas) {
1459
+ const merged = {};
1460
+ const properties = {};
1461
+ const required = /* @__PURE__ */ new Set();
1462
+ for (const schema of schemas) {
1463
+ const resolved = resolveRequestSchema(spec, schema);
1464
+ if (!isRecord$1(resolved)) continue;
1465
+ Object.assign(merged, resolved);
1466
+ if (isRecord$1(resolved.properties)) Object.assign(properties, resolved.properties);
1467
+ if (Array.isArray(resolved.required)) resolved.required.forEach((name) => required.add(String(name)));
1468
+ }
1469
+ if (Object.keys(properties).length > 0) merged.properties = properties;
1470
+ if (required.size > 0) merged.required = [...required];
1471
+ delete merged.allOf;
1472
+ return merged;
1473
+ }
1474
+ function resolveRequestSchema(spec, schema) {
1475
+ const resolved = resolveSchema(spec, schema);
1476
+ if (!isRecord$1(resolved)) return resolved;
1477
+ const ownSchema = { ...resolved };
1478
+ const allOf = Array.isArray(ownSchema.allOf) ? ownSchema.allOf : [];
1479
+ if (allOf.length === 0) return ownSchema;
1480
+ delete ownSchema.allOf;
1481
+ return mergeAllOfSchemas(spec, [...allOf, ownSchema]);
1482
+ }
1457
1483
  function getPathItem$1(spec, path) {
1458
1484
  return resolveObjectRef(spec, spec.paths?.[path]);
1459
1485
  }
@@ -1473,6 +1499,7 @@ function resolveObjectRef(spec, value) {
1473
1499
  }
1474
1500
  function schemaHasType(schema, type) {
1475
1501
  if (!isRecord$1(schema)) return false;
1502
+ if (type === "null" && schema.nullable === true) return true;
1476
1503
  return schema.type === type || Array.isArray(schema.type) && schema.type.includes(type);
1477
1504
  }
1478
1505
  function getOperationParameters(spec, path, operation, source = "path") {
@@ -1542,7 +1569,7 @@ function getExampleEntries(mediaType, spec) {
1542
1569
  title: "Example",
1543
1570
  value: mediaType.example
1544
1571
  }];
1545
- const generated = schemaToExample(spec ? resolveSchema(spec, mediaType.schema) : mediaType.schema);
1572
+ const generated = schemaToExample(spec ? resolveRequestSchema(spec, mediaType.schema) : mediaType.schema);
1546
1573
  return typeof generated === "undefined" ? [] : [{
1547
1574
  key: "schema",
1548
1575
  title: "schema",
@@ -1550,6 +1577,34 @@ function getExampleEntries(mediaType, spec) {
1550
1577
  generated: true
1551
1578
  }];
1552
1579
  }
1580
+ function getParameterExampleEntries(parameter) {
1581
+ if (isRecord$1(parameter.examples)) {
1582
+ const examples = [];
1583
+ for (const [key, example] of Object.entries(parameter.examples)) {
1584
+ const value = getExampleValue(example);
1585
+ if (typeof value === "undefined") continue;
1586
+ const { title, summary } = getExampleTitle(key, example);
1587
+ examples.push({
1588
+ key,
1589
+ title,
1590
+ summary,
1591
+ value
1592
+ });
1593
+ }
1594
+ if (examples.length > 0) return examples;
1595
+ }
1596
+ return typeof parameter.example === "undefined" ? [] : [{
1597
+ key: "default",
1598
+ title: "Example",
1599
+ value: parameter.example
1600
+ }];
1601
+ }
1602
+ function getRequestExampleEntries(parameters, mediaType) {
1603
+ const entries = /* @__PURE__ */ new Map();
1604
+ for (const example of getExampleEntries(mediaType).filter((entry) => !entry.generated)) entries.set(example.key, example);
1605
+ for (const parameter of parameters) for (const example of getParameterExampleEntries(parameter)) if (!entries.has(example.key)) entries.set(example.key, example);
1606
+ return [...entries.values()];
1607
+ }
1553
1608
  function getContentExample(mediaType) {
1554
1609
  return getExampleEntries(mediaType)[0]?.value;
1555
1610
  }
@@ -1563,7 +1618,8 @@ function schemaToType(schema) {
1563
1618
  if (Array.isArray(schema.allOf)) return schema.allOf.map((branch) => schemaToType(branch)).filter(Boolean).join(" & ");
1564
1619
  if (schemaHasType(schema, "array")) return `${schemaToType(schema.items) ?? "unknown"}[]`;
1565
1620
  const type = Array.isArray(schema.type) ? schema.type.map(String).join(" | ") : schema.type;
1566
- return typeof type === "string" ? [type, typeof schema.format === "string" ? `<${schema.format}>` : void 0].filter(Boolean).join("") : void 0;
1621
+ const nullableType = schema.nullable === true && type !== "null" ? [type, "null"].filter(Boolean).join(" | ") : type;
1622
+ return typeof nullableType === "string" ? [nullableType, typeof schema.format === "string" ? `<${schema.format}>` : void 0].filter(Boolean).join("") : void 0;
1567
1623
  }
1568
1624
  function schemaToExample(schema, depth = 0) {
1569
1625
  if (!isRecord$1(schema) || depth > 3) return void 0;
@@ -1571,10 +1627,12 @@ function schemaToExample(schema, depth = 0) {
1571
1627
  if (typeof schema.default !== "undefined") return schema.default;
1572
1628
  if (Array.isArray(schema.enum)) return schema.enum[0];
1573
1629
  if (isReference(schema)) return { id: resolveReferenceName(schema.$ref) };
1630
+ const variant = Array.isArray(schema.oneOf) ? schema.oneOf[0] : Array.isArray(schema.anyOf) ? schema.anyOf[0] : void 0;
1631
+ if (typeof variant !== "undefined") return schemaToExample(variant, depth + 1);
1574
1632
  if (schemaHasType(schema, "array")) return [schemaToExample(schema.items, depth + 1) ?? "string"];
1575
1633
  if (schemaHasType(schema, "object") || isRecord$1(schema.properties)) {
1576
1634
  const properties = isRecord$1(schema.properties) ? schema.properties : {};
1577
- return Object.fromEntries(Object.entries(properties).slice(0, 8).map(([name, propertySchema]) => [name, schemaToExample(propertySchema, depth + 1) ?? exampleForType(schemaToType(propertySchema))]));
1635
+ return Object.fromEntries(Object.entries(properties).filter(([, propertySchema]) => !isRecord$1(propertySchema) || propertySchema.readOnly !== true).slice(0, 8).map(([name, propertySchema]) => [name, schemaToExample(propertySchema, depth + 1) ?? exampleForType(schemaToType(propertySchema))]));
1578
1636
  }
1579
1637
  return exampleForType(schemaToType(schema));
1580
1638
  }
@@ -1812,10 +1870,10 @@ function getQueryString(parameters, auth = []) {
1812
1870
  });
1813
1871
  return queryString;
1814
1872
  }
1815
- function isFormMediaType(mediaType) {
1873
+ function isFormMediaType$1(mediaType) {
1816
1874
  return mediaType.includes("multipart/form-data") || mediaType.includes("application/x-www-form-urlencoded");
1817
1875
  }
1818
- function isBinarySchema(schema) {
1876
+ function isBinarySchema$1(schema) {
1819
1877
  return isRecord$1(schema) && schema.type === "string" && schema.format === "binary";
1820
1878
  }
1821
1879
  function getSchemaProperties(schema) {
@@ -1823,7 +1881,7 @@ function getSchemaProperties(schema) {
1823
1881
  }
1824
1882
  function getFieldValue(name, value, schema) {
1825
1883
  if (isRecord$1(value) && typeof value[name] !== "undefined") return value[name];
1826
- if (isBinarySchema(schema)) return `@${name}`;
1884
+ if (isBinarySchema$1(schema)) return `@${name}`;
1827
1885
  }
1828
1886
  function getFormParams(value, requestContent) {
1829
1887
  const properties = getSchemaProperties(requestContent.value.schema);
@@ -1845,7 +1903,7 @@ function getBodySize(requestBody) {
1845
1903
  function getRequestBody(requestContent) {
1846
1904
  const value = getContentExample(requestContent?.value);
1847
1905
  if (!requestContent || typeof value === "undefined") return void 0;
1848
- if (isFormMediaType(requestContent.mediaType)) {
1906
+ if (isFormMediaType$1(requestContent.mediaType)) {
1849
1907
  const params = getFormParams(value, requestContent);
1850
1908
  return params.length > 0 ? { params } : void 0;
1851
1909
  }
@@ -3164,7 +3222,7 @@ function OptionContent(arg0) {
3164
3222
  })] });
3165
3223
  }
3166
3224
  function InlineListbox(arg0) {
3167
- const { label, value, options, onChange, compact = false, buttonContent, buttonClassName, className, invalid, describedBy, disabled = false } = arg0;
3225
+ const { label, value, options, onChange, compact = false, buttonContent, buttonClassName, className, invalid, describedBy, disabled = false, title } = arg0;
3168
3226
  const selected = options.find((option) => option.value === value);
3169
3227
  return /* @__PURE__ */ jsx(Listbox, {
3170
3228
  value,
@@ -3176,6 +3234,7 @@ function InlineListbox(arg0) {
3176
3234
  "aria-label": label,
3177
3235
  "aria-invalid": invalid || void 0,
3178
3236
  "aria-describedby": describedBy,
3237
+ title,
3179
3238
  className: clsx(buttonClassName ?? defaultButtonClassName, buttonClassName ? null : compact ? "min-h-7 max-w-32 px-2 py-0.5 text-xs" : "min-h-8 w-full px-2 text-xs"),
3180
3239
  children: buttonContent ?? /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx("span", {
3181
3240
  className: "truncate",
@@ -3353,7 +3412,8 @@ function parseBodyObject(body) {
3353
3412
  return;
3354
3413
  }
3355
3414
  }
3356
- function buildRequestBody(body, mediaType) {
3415
+ function buildRequestBody(body, mediaType, files) {
3416
+ if (files[""] && !mediaType.includes("multipart/form-data")) return files[""];
3357
3417
  const values = parseBodyObject(body);
3358
3418
  if (mediaType.includes("application/x-www-form-urlencoded") && values) {
3359
3419
  const params = new URLSearchParams();
@@ -3362,7 +3422,18 @@ function buildRequestBody(body, mediaType) {
3362
3422
  }
3363
3423
  if (mediaType.includes("multipart/form-data") && values) {
3364
3424
  const form = new FormData();
3365
- Object.entries(values).forEach(([name, value]) => form.append(name, typeof value === "string" ? value : JSON.stringify(value)));
3425
+ Object.entries(values).forEach(([name, value]) => {
3426
+ const file = files[name];
3427
+ form.append(name, file ?? (typeof value === "string" ? value : JSON.stringify(value)));
3428
+ });
3429
+ Object.entries(files).forEach(([name, file]) => {
3430
+ if (name && !(name in values)) form.append(name, file);
3431
+ });
3432
+ return form;
3433
+ }
3434
+ if (mediaType.includes("multipart/form-data") && Object.keys(files).length > 0) {
3435
+ const form = new FormData();
3436
+ Object.entries(files).forEach(([name, file]) => form.append(name, file));
3366
3437
  return form;
3367
3438
  }
3368
3439
  return body;
@@ -3465,9 +3536,9 @@ function buildApiRequest(input) {
3465
3536
  }
3466
3537
  const url = new URL(joinPath(expandServerUrl(input.server, input.serverVariables ?? {}), path), input.baseUrl);
3467
3538
  query.forEach((value, key) => url.searchParams.append(key, value));
3468
- const body = input.body?.trim();
3539
+ const body = input.body?.trim() ?? "";
3469
3540
  const mediaType = input.mediaType || "application/json";
3470
- const requestBody = body && input.method.toUpperCase() !== "GET" && input.method.toUpperCase() !== "HEAD" ? buildRequestBody(body, mediaType) : void 0;
3541
+ const requestBody = (Boolean(body) || Object.keys(input.bodyFiles ?? {}).length > 0) && input.method.toUpperCase() !== "GET" && input.method.toUpperCase() !== "HEAD" ? buildRequestBody(body, mediaType, input.bodyFiles ?? {}) : void 0;
3471
3542
  if (requestBody && !(requestBody instanceof FormData)) headers.set("Content-Type", mediaType);
3472
3543
  return {
3473
3544
  url: url.toString(),
@@ -3526,6 +3597,157 @@ function OpenApiAuthPanel(arg0) {
3526
3597
  });
3527
3598
  }
3528
3599
  //#endregion
3600
+ //#region source/openapi/components/OpenApiRequestBodyEditor.tsx
3601
+ function parseBodyRecord(body) {
3602
+ try {
3603
+ const value = JSON.parse(body);
3604
+ return isRecord$1(value) ? value : {};
3605
+ } catch {
3606
+ return {};
3607
+ }
3608
+ }
3609
+ function isBinarySchema(schema) {
3610
+ return isRecord$1(schema) && schema.format === "binary";
3611
+ }
3612
+ function isTextMediaType(mediaType) {
3613
+ return mediaType.startsWith("text/") || mediaType.includes("json") || mediaType.includes("xml") || mediaType.includes("yaml") || mediaType.includes("javascript") || mediaType.includes("form");
3614
+ }
3615
+ function isFormMediaType(mediaType) {
3616
+ const normalized = mediaType.split(";", 1)[0].trim().toLowerCase();
3617
+ return normalized === "application/x-www-form-urlencoded" || normalized === "multipart/form-data";
3618
+ }
3619
+ function valueFromInput(schema, value) {
3620
+ if (!isRecord$1(schema)) return value;
3621
+ if (schemaHasType(schema, "integer")) return value === "" ? "" : Number.parseInt(value, 10);
3622
+ if (schemaHasType(schema, "number")) return value === "" ? "" : Number(value);
3623
+ if (schemaHasType(schema, "boolean")) return value === "true";
3624
+ if (schemaHasType(schema, "array") || schemaHasType(schema, "object")) try {
3625
+ return JSON.parse(value);
3626
+ } catch {
3627
+ return value;
3628
+ }
3629
+ return value;
3630
+ }
3631
+ function OpenApiRequestBodyEditor(arg0) {
3632
+ const { spec, mediaType, content, body, files, onBodyChange, onFileChange } = arg0;
3633
+ const schema = resolveSchema(spec, content?.schema);
3634
+ const schemaRecord = isRecord$1(schema) ? schema : void 0;
3635
+ const properties = isRecord$1(schemaRecord?.properties) ? schemaRecord.properties : void 0;
3636
+ const required = new Set(Array.isArray(schemaRecord?.required) ? schemaRecord.required.map(String) : []);
3637
+ const values = parseBodyRecord(body);
3638
+ function updateProperty(name, propertySchema, value) {
3639
+ onBodyChange(JSON.stringify({
3640
+ ...values,
3641
+ [name]: valueFromInput(propertySchema, value)
3642
+ }, null, 2));
3643
+ }
3644
+ function renderProperty(name, unresolvedSchema) {
3645
+ const propertySchema = resolveSchema(spec, unresolvedSchema);
3646
+ const propertyRecord = isRecord$1(propertySchema) ? propertySchema : void 0;
3647
+ const type = schemaToType(propertySchema) ?? "string";
3648
+ const value = values[name];
3649
+ const fieldId = `openapi-request-body-${name}`.replace(/[^a-zA-Z0-9_-]/g, "-");
3650
+ const options = Array.isArray(propertyRecord?.enum) ? propertyRecord.enum : [];
3651
+ const structured = schemaHasType(propertySchema, "array") || schemaHasType(propertySchema, "object");
3652
+ const serializedValue = structured && typeof value !== "undefined" ? JSON.stringify(value, null, 2) : String(value ?? "");
3653
+ let control;
3654
+ if (isBinarySchema(propertySchema)) control = /* @__PURE__ */ jsx("input", {
3655
+ id: fieldId,
3656
+ "aria-label": name,
3657
+ type: "file",
3658
+ required: required.has(name),
3659
+ onChange: (event) => onFileChange(name, event.target.files?.[0]),
3660
+ className: "min-h-8 w-full px-2 py-1 text-xs text-(--clarify-theme-tokens-colors-foreground) file:mr-2 file:rounded-(--clarify-theme-tokens-radius-md) file:border file:border-(--clarify-theme-tokens-colors-border) file:bg-(--clarify-ui-subtle-background) file:px-2 file:py-1 file:text-xs file:text-(--clarify-ui-text-strong)"
3661
+ });
3662
+ else if (options.length > 0) control = /* @__PURE__ */ jsxs("select", {
3663
+ id: fieldId,
3664
+ "aria-label": name,
3665
+ value: serializedValue,
3666
+ required: required.has(name),
3667
+ onChange: (event) => updateProperty(name, propertySchema, event.target.value),
3668
+ className: "h-8 w-full border-0 bg-transparent px-2 font-mono text-xs text-(--clarify-theme-tokens-colors-foreground) outline-hidden focus:bg-(--clarify-ui-hover-background)",
3669
+ children: [!required.has(name) ? /* @__PURE__ */ jsx("option", { value: "" }) : null, options.map((option) => /* @__PURE__ */ jsx("option", {
3670
+ value: String(option),
3671
+ children: String(option)
3672
+ }, String(option)))]
3673
+ });
3674
+ else if (schemaHasType(propertySchema, "boolean")) control = /* @__PURE__ */ jsx("input", {
3675
+ id: fieldId,
3676
+ "aria-label": name,
3677
+ type: "checkbox",
3678
+ checked: value === true,
3679
+ onChange: (event) => updateProperty(name, propertySchema, String(event.target.checked)),
3680
+ className: "size-4 accent-(--clarify-theme-tokens-colors-primary)"
3681
+ });
3682
+ else if (structured) control = /* @__PURE__ */ jsx("textarea", {
3683
+ id: fieldId,
3684
+ "aria-label": name,
3685
+ value: serializedValue,
3686
+ required: required.has(name),
3687
+ rows: 3,
3688
+ spellCheck: false,
3689
+ onChange: (event) => updateProperty(name, propertySchema, event.target.value),
3690
+ className: "w-full resize-y border-0 bg-transparent p-2 font-mono text-xs/5 text-(--clarify-theme-tokens-colors-foreground) outline-hidden focus:bg-(--clarify-ui-hover-background)"
3691
+ });
3692
+ else control = /* @__PURE__ */ jsx("input", {
3693
+ id: fieldId,
3694
+ "aria-label": name,
3695
+ value: serializedValue,
3696
+ type: schemaHasType(propertySchema, "integer") || schemaHasType(propertySchema, "number") ? "number" : propertyRecord?.format === "date" ? "date" : propertyRecord?.format === "date-time" ? "datetime-local" : "text",
3697
+ required: required.has(name),
3698
+ onChange: (event) => updateProperty(name, propertySchema, event.target.value),
3699
+ className: "h-8 w-full border-0 bg-transparent px-2 font-mono text-xs text-(--clarify-theme-tokens-colors-foreground) outline-hidden focus:bg-(--clarify-ui-hover-background)"
3700
+ });
3701
+ return /* @__PURE__ */ jsxs("div", {
3702
+ className: "grid min-w-0 grid-cols-[minmax(0,1fr)_minmax(0,1.3fr)]",
3703
+ children: [/* @__PURE__ */ jsxs("label", {
3704
+ htmlFor: fieldId,
3705
+ className: "flex min-h-8 min-w-0 items-center gap-1.5 border-r border-(--clarify-theme-tokens-colors-border) px-2 text-xs text-(--clarify-ui-text-strong)",
3706
+ children: [
3707
+ /* @__PURE__ */ jsx("span", {
3708
+ className: "truncate font-mono",
3709
+ children: name
3710
+ }),
3711
+ /* @__PURE__ */ jsx("span", {
3712
+ className: "font-mono text-2xs text-(--clarify-ui-text-faint)",
3713
+ children: type
3714
+ }),
3715
+ required.has(name) ? /* @__PURE__ */ jsx("span", {
3716
+ className: "text-(--clarify-error-accent-text)",
3717
+ children: "*"
3718
+ }) : null
3719
+ ]
3720
+ }), /* @__PURE__ */ jsxs("div", {
3721
+ className: "flex min-w-0 items-center",
3722
+ children: [control, files[name] ? /* @__PURE__ */ jsx("span", {
3723
+ className: "sr-only",
3724
+ children: files[name].name
3725
+ }) : null]
3726
+ })]
3727
+ }, name);
3728
+ }
3729
+ if (properties && isFormMediaType(mediaType)) return /* @__PURE__ */ jsx("div", {
3730
+ className: "divide-y divide-(--clarify-theme-tokens-colors-border)",
3731
+ children: Object.entries(properties).map(([name, propertySchema]) => renderProperty(name, propertySchema))
3732
+ });
3733
+ if (isBinarySchema(schema) || !isTextMediaType(mediaType)) return /* @__PURE__ */ jsx("div", {
3734
+ className: "flex min-h-44 items-start p-3",
3735
+ children: /* @__PURE__ */ jsx("input", {
3736
+ "aria-label": mediaType,
3737
+ type: "file",
3738
+ onChange: (event) => onFileChange("", event.target.files?.[0]),
3739
+ className: "w-full text-xs text-(--clarify-theme-tokens-colors-foreground) file:mr-2 file:rounded-(--clarify-theme-tokens-radius-md) file:border file:border-(--clarify-theme-tokens-colors-border) file:bg-(--clarify-ui-subtle-background) file:px-2 file:py-1 file:text-xs file:text-(--clarify-ui-text-strong)"
3740
+ })
3741
+ });
3742
+ return /* @__PURE__ */ jsx("textarea", {
3743
+ "aria-label": mediaType,
3744
+ value: body,
3745
+ onChange: (event) => onBodyChange(event.target.value),
3746
+ spellCheck: false,
3747
+ className: "block h-full min-h-44 w-full resize-none border-0 bg-(--clarify-code-background) p-3 font-mono text-xs/5 text-(--clarify-code-text) outline-hidden focus:ring-2 focus:ring-inset focus:ring-(--clarify-theme-tokens-colors-primary)"
3748
+ });
3749
+ }
3750
+ //#endregion
3529
3751
  //#region source/openapi/components/OpenApiRequestFields.tsx
3530
3752
  function RequestField(arg0) {
3531
3753
  const { spec, parameter, value, enabled, onChange, onEnabledChange, issue } = arg0;
@@ -3562,7 +3784,7 @@ function RequestField(arg0) {
3562
3784
  children: description
3563
3785
  }),
3564
3786
  side: "bottom",
3565
- className: "mr-1 shrink-0 [&>[role=tooltip]]:w-80 [&>[role=tooltip]]:max-w-[min(20rem,calc(100vw-2rem))] [&>[role=tooltip]]:border [&>[role=tooltip]]:border-(--clarify-theme-tokens-colors-border) [&>[role=tooltip]]:bg-(--clarify-theme-tokens-colors-surface) [&>[role=tooltip]]:p-3 [&>[role=tooltip]]:text-(--clarify-ui-text) [&>[role=tooltip]]:shadow-xl",
3787
+ className: "mr-1 shrink-0 *:[[role=tooltip]]:w-80 *:[[role=tooltip]]:max-w-[min(20rem,calc(100vw-2rem))] *:[[role=tooltip]]:border *:[[role=tooltip]]:border-(--clarify-theme-tokens-colors-border) *:[[role=tooltip]]:bg-(--clarify-theme-tokens-colors-surface) *:[[role=tooltip]]:p-3 *:[[role=tooltip]]:text-(--clarify-ui-text) *:[[role=tooltip]]:shadow-xl",
3566
3788
  triggerClassName: "clarify-field-description-trigger clarify-ui-control inline-flex size-7 items-center justify-center rounded-md !border-b-0 text-(--clarify-ui-text-faint) transition-colors",
3567
3789
  children: [/* @__PURE__ */ jsx(InfoIcon, {
3568
3790
  className: "size-4",
@@ -3608,7 +3830,7 @@ function RequestField(arg0) {
3608
3830
  })
3609
3831
  }),
3610
3832
  /* @__PURE__ */ jsxs("div", {
3611
- className: clsx("col-start-2 flex min-w-0 items-center border-t border-(--clarify-theme-tokens-colors-border) sm:col-start-3 sm:row-start-1 sm:border-t-0", !enabled && "opacity-45"),
3833
+ className: clsx("col-start-2 flex min-w-0 items-center border-t border-(--clarify-theme-tokens-colors-border) sm:col-start-3 sm:row-start-1 sm:border-t-0", !enabled && "bg-(--clarify-ui-subtle-background)"),
3612
3834
  children: [/* @__PURE__ */ jsx("div", {
3613
3835
  className: "min-w-0 flex-1",
3614
3836
  children: itemOptions.length > 0 ? /* @__PURE__ */ jsx(MultiInlineListbox, {
@@ -3721,6 +3943,57 @@ function parseJson(value) {
3721
3943
  return;
3722
3944
  }
3723
3945
  }
3946
+ var textLanguages = {
3947
+ "application/graphql": "graphql",
3948
+ "application/javascript": "javascript",
3949
+ "application/sql": "sql",
3950
+ "application/typescript": "typescript",
3951
+ "application/xml": "xml",
3952
+ "application/x-httpd-php": "php",
3953
+ "application/x-sh": "shellscript",
3954
+ "application/xhtml+xml": "html",
3955
+ "application/x-www-form-urlencoded": "http",
3956
+ "text/css": "css",
3957
+ "text/csv": "csv",
3958
+ "text/html": "html",
3959
+ "text/javascript": "javascript",
3960
+ "text/markdown": "markdown",
3961
+ "text/plain": "text",
3962
+ "text/xml": "xml"
3963
+ };
3964
+ function normalizedMediaType(contentType) {
3965
+ return contentType.split(";", 1)[0].trim().toLowerCase();
3966
+ }
3967
+ function getResponseTextPreview(contentType, body) {
3968
+ const mediaType = normalizedMediaType(contentType);
3969
+ if (mediaType === "application/json" || mediaType.endsWith("+json")) {
3970
+ const parsed = parseJson(body);
3971
+ return {
3972
+ code: typeof parsed === "undefined" ? body : JSON.stringify(parsed, null, 2),
3973
+ language: "json"
3974
+ };
3975
+ }
3976
+ if (mediaType === "application/yaml" || mediaType === "application/x-yaml" || mediaType === "text/yaml" || mediaType === "text/x-yaml" || mediaType.endsWith("+yaml")) try {
3977
+ return {
3978
+ code: stringify(parse(body)).trimEnd(),
3979
+ language: "yaml"
3980
+ };
3981
+ } catch {
3982
+ return {
3983
+ code: body,
3984
+ language: "yaml"
3985
+ };
3986
+ }
3987
+ const language = textLanguages[mediaType] ?? (mediaType.startsWith("text/") ? mediaType.slice(5) || "text" : void 0);
3988
+ return language ? {
3989
+ code: body,
3990
+ language
3991
+ } : void 0;
3992
+ }
3993
+ function canPreviewResponse(contentType) {
3994
+ const mediaType = normalizedMediaType(contentType);
3995
+ return Boolean(getResponseTextPreview(contentType, "") || mediaType.startsWith("image/") || mediaType.startsWith("audio/") || mediaType.startsWith("video/"));
3996
+ }
3724
3997
  function ResponseState(arg0) {
3725
3998
  const { icon: Icon, title, description, tone = "default" } = arg0;
3726
3999
  const error = tone === "error";
@@ -3749,38 +4022,6 @@ function ResponseState(arg0) {
3749
4022
  })
3750
4023
  });
3751
4024
  }
3752
- function JsonPreview(arg0) {
3753
- const { value } = arg0;
3754
- if (Array.isArray(value)) return /* @__PURE__ */ jsx("div", {
3755
- className: "space-y-1 border-l border-(--clarify-code-border) pl-3",
3756
- children: value.map((item, index) => /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("span", {
3757
- className: "mr-2 text-(--clarify-code-faint)",
3758
- children: index
3759
- }), /* @__PURE__ */ jsx(JsonPreview, { value: item })] }, index))
3760
- });
3761
- if (isRecord$1(value)) return /* @__PURE__ */ jsx("div", {
3762
- className: "space-y-1 border-l border-(--clarify-code-border) pl-3",
3763
- children: Object.entries(value).map(([key, item]) => /* @__PURE__ */ jsxs("div", {
3764
- className: "grid grid-cols-[minmax(5rem,auto)_1fr] gap-3",
3765
- children: [/* @__PURE__ */ jsx("span", {
3766
- className: "text-(--clarify-code-property)",
3767
- children: key
3768
- }), /* @__PURE__ */ jsx(JsonPreview, { value: item })]
3769
- }, key))
3770
- });
3771
- if (value === null) return /* @__PURE__ */ jsx("span", {
3772
- className: "text-(--clarify-code-faint)",
3773
- children: "null"
3774
- });
3775
- if (typeof value === "string") return /* @__PURE__ */ jsx("span", {
3776
- className: "wrap-break-word text-(--clarify-code-string)",
3777
- children: value
3778
- });
3779
- return /* @__PURE__ */ jsx("span", {
3780
- className: "text-(--clarify-code-number)",
3781
- children: String(value)
3782
- });
3783
- }
3784
4025
  function CopyButton(arg0) {
3785
4026
  const { value } = arg0;
3786
4027
  const t = useBuiltInText();
@@ -3837,22 +4078,12 @@ function ResponseMedia(arg0) {
3837
4078
  function ResponsePreview(arg0) {
3838
4079
  const { exchange } = arg0;
3839
4080
  const t = useBuiltInText();
3840
- const contentType = exchange.contentType.toLowerCase();
4081
+ const contentType = normalizedMediaType(exchange.contentType);
3841
4082
  if (!exchange.size) return /* @__PURE__ */ jsx(ResponseState, {
3842
4083
  icon: FileX2Icon,
3843
4084
  title: t("openapi.responseBodyEmptyTitle"),
3844
4085
  description: t("openapi.responseBodyEmpty")
3845
4086
  });
3846
- if (contentType.includes("json")) {
3847
- const parsed = parseJson(exchange.body);
3848
- return typeof parsed === "undefined" ? /* @__PURE__ */ jsx("pre", {
3849
- className: "whitespace-pre-wrap wrap-break-word font-mono text-xs/5",
3850
- children: exchange.body
3851
- }) : /* @__PURE__ */ jsx("div", {
3852
- className: "overflow-auto font-mono text-xs/5",
3853
- children: /* @__PURE__ */ jsx(JsonPreview, { value: parsed })
3854
- });
3855
- }
3856
4087
  if (contentType.startsWith("image/")) return /* @__PURE__ */ jsx(ResponseMedia, {
3857
4088
  blob: exchange.blob,
3858
4089
  type: "image"
@@ -3865,15 +4096,19 @@ function ResponsePreview(arg0) {
3865
4096
  blob: exchange.blob,
3866
4097
  type: "video"
3867
4098
  });
3868
- if (contentType.includes("html")) return /* @__PURE__ */ jsx("iframe", {
4099
+ if (contentType === "text/html" || contentType === "application/xhtml+xml") return /* @__PURE__ */ jsx("iframe", {
3869
4100
  srcDoc: exchange.body,
3870
4101
  sandbox: "",
3871
4102
  title: "Response preview",
3872
4103
  className: "h-96 w-full border-0 bg-white"
3873
4104
  });
3874
- if (contentType.startsWith("text/") || contentType.includes("xml") || contentType.includes("yaml")) return /* @__PURE__ */ jsx("pre", {
3875
- className: "whitespace-pre-wrap wrap-break-word font-mono text-xs/5",
3876
- children: exchange.body
4105
+ const textPreview = getResponseTextPreview(exchange.contentType, exchange.body);
4106
+ if (textPreview) return /* @__PURE__ */ jsx("pre", {
4107
+ className: "max-h-128 overflow-auto whitespace-pre-wrap wrap-break-word font-mono text-xs/5",
4108
+ children: /* @__PURE__ */ jsx(HighlightedCode, {
4109
+ code: textPreview.code,
4110
+ language: textPreview.language
4111
+ })
3877
4112
  });
3878
4113
  return /* @__PURE__ */ jsx("div", {
3879
4114
  className: "grid min-h-56 place-items-center text-xs text-(--clarify-code-faint)",
@@ -3980,7 +4215,10 @@ function HiddenCookies() {
3980
4215
  function OpenApiResponseViewer(arg0) {
3981
4216
  const { exchange, error } = arg0;
3982
4217
  const t = useBuiltInText();
3983
- const [bodyMode, setBodyMode] = useState("preview");
4218
+ const [bodyModeSelection, setBodyModeSelection] = useState();
4219
+ const previewAvailable = exchange ? canPreviewResponse(exchange.contentType) : false;
4220
+ const selectedBodyMode = bodyModeSelection && bodyModeSelection.exchange === exchange ? bodyModeSelection.mode : "preview";
4221
+ const activeBodyMode = previewAvailable ? selectedBodyMode : "raw";
3984
4222
  function downloadBody() {
3985
4223
  if (!exchange) return;
3986
4224
  const url = URL.createObjectURL(exchange.blob);
@@ -4062,12 +4300,15 @@ function OpenApiResponseViewer(arg0) {
4062
4300
  children: [/* @__PURE__ */ jsx("div", {
4063
4301
  role: "tablist",
4064
4302
  className: "flex",
4065
- children: ["preview", "raw"].map((mode) => /* @__PURE__ */ jsx("button", {
4303
+ children: ["preview", "raw"].filter((mode) => mode === "raw" || previewAvailable).map((mode) => /* @__PURE__ */ jsx("button", {
4066
4304
  type: "button",
4067
4305
  role: "tab",
4068
- "aria-selected": bodyMode === mode,
4069
- onClick: () => setBodyMode(mode),
4070
- className: clsx("border-b-2 px-2.5 py-1 text-2xs font-semibold", bodyMode === mode ? "border-(--clarify-theme-tokens-colors-primary) text-(--clarify-code-text)" : "border-transparent text-(--clarify-code-muted)"),
4306
+ "aria-selected": activeBodyMode === mode,
4307
+ onClick: () => setBodyModeSelection({
4308
+ exchange,
4309
+ mode
4310
+ }),
4311
+ className: clsx("border-b-2 px-2.5 py-1 text-2xs font-semibold", activeBodyMode === mode ? "border-(--clarify-theme-tokens-colors-primary) text-(--clarify-code-text)" : "border-transparent text-(--clarify-code-muted)"),
4071
4312
  children: mode === "preview" ? t("openapi.preview") : t("openapi.raw")
4072
4313
  }, mode))
4073
4314
  }), /* @__PURE__ */ jsxs("div", {
@@ -4086,7 +4327,7 @@ function OpenApiResponseViewer(arg0) {
4086
4327
  })]
4087
4328
  }), /* @__PURE__ */ jsx("div", {
4088
4329
  className: "p-4",
4089
- children: bodyMode === "preview" ? /* @__PURE__ */ jsx(ResponsePreview, { exchange }) : exchange.size ? /* @__PURE__ */ jsx("pre", {
4330
+ children: activeBodyMode === "preview" ? /* @__PURE__ */ jsx(ResponsePreview, { exchange }) : exchange.size ? /* @__PURE__ */ jsx("pre", {
4090
4331
  className: "max-h-128 overflow-auto whitespace-pre-wrap wrap-break-word font-mono text-xs/5",
4091
4332
  children: exchange.body
4092
4333
  }) : /* @__PURE__ */ jsx("div", {
@@ -4208,6 +4449,23 @@ function validateRequestParameters(spec, parameters, values) {
4208
4449
  }
4209
4450
  //#endregion
4210
4451
  //#region source/openapi/components/useOpenApiRequestState.ts
4452
+ function initialRequestBody(spec, content) {
4453
+ const example = getExampleEntries(content, spec)[0];
4454
+ if (!example?.generated) return stringifyExample(example?.value);
4455
+ const schema = resolveSchema(spec, content?.schema);
4456
+ if (isRecord$1(schema) && schema.format === "binary") return "";
4457
+ if (!isRecord$1(example.value) || !isRecord$1(schema) || !isRecord$1(schema.properties)) return stringifyExample(example.value);
4458
+ const value = { ...example.value };
4459
+ Object.entries(schema.properties).forEach(([name, propertySchema]) => {
4460
+ const resolved = resolveSchema(spec, propertySchema);
4461
+ if (isRecord$1(resolved) && resolved.format === "binary") delete value[name];
4462
+ });
4463
+ return stringifyExample(value);
4464
+ }
4465
+ function requestBodyForExample(spec, content, exampleKey) {
4466
+ const example = getExampleEntries(content, spec).find((entry) => !entry.generated && entry.key === exampleKey);
4467
+ return example ? stringifyExample(example.value) : initialRequestBody(spec, content);
4468
+ }
4211
4469
  function useOpenApiRequestTarget(spec, path, operation, operationSource) {
4212
4470
  const servers = getServers(spec, operation, path, operationSource);
4213
4471
  const [selectedServerKey, setSelectedServerKey] = useState(getServerKey(servers[0], 0));
@@ -4222,7 +4480,9 @@ function useOpenApiRequestTarget(spec, path, operation, operationSource) {
4222
4480
  const clearCredential = useOpenApiStore((state) => state.clearCredential);
4223
4481
  const requestContents = getMediaTypeEntries(getRequestBody$1(spec, operation)?.content, spec);
4224
4482
  const [mediaType, setMediaType] = useState(requestContents[0]?.mediaType ?? "");
4225
- const [body, setBody] = useState(stringifyExample(getExampleEntries((requestContents.find((entry) => entry.mediaType === mediaType) ?? requestContents[0])?.value, spec)[0]?.value));
4483
+ const selectedContent = requestContents.find((entry) => entry.mediaType === mediaType) ?? requestContents[0];
4484
+ const [body, setBody] = useState(initialRequestBody(spec, selectedContent?.value));
4485
+ const [bodyFiles, setBodyFiles] = useState({});
4226
4486
  function selectServer(value) {
4227
4487
  const nextServer = servers.find((server, index) => getServerKey(server, index) === value) ?? servers[0];
4228
4488
  setSelectedServerKey(value);
@@ -4231,7 +4491,20 @@ function useOpenApiRequestTarget(spec, path, operation, operationSource) {
4231
4491
  function selectMediaType(value) {
4232
4492
  const content = requestContents.find((entry) => entry.mediaType === value)?.value;
4233
4493
  setMediaType(value);
4234
- setBody(stringifyExample(getExampleEntries(content, spec)[0]?.value));
4494
+ setBody(initialRequestBody(spec, content));
4495
+ setBodyFiles({});
4496
+ }
4497
+ function applyBodyExample(exampleKey) {
4498
+ setBody(requestBodyForExample(spec, selectedContent?.value, exampleKey));
4499
+ setBodyFiles({});
4500
+ }
4501
+ function setBodyFile(name, file) {
4502
+ setBodyFiles((current) => {
4503
+ const next = { ...current };
4504
+ if (file) next[name] = file;
4505
+ else delete next[name];
4506
+ return next;
4507
+ });
4235
4508
  }
4236
4509
  return {
4237
4510
  servers,
@@ -4251,13 +4524,20 @@ function useOpenApiRequestTarget(spec, path, operation, operationSource) {
4251
4524
  clearCredential,
4252
4525
  requestContents,
4253
4526
  mediaType,
4527
+ selectedContent,
4254
4528
  body,
4255
4529
  setBody,
4530
+ bodyFiles,
4531
+ setBodyFile,
4532
+ applyBodyExample,
4256
4533
  selectMediaType
4257
4534
  };
4258
4535
  }
4259
- function useOpenApiParameterState(spec, parameters, initialParameterValue) {
4260
- const [parameterValues, setParameterValues] = useState(() => Object.fromEntries(parameters.map((parameter) => [parameterKey(parameter), initialParameterValue(parameter)])));
4536
+ function useOpenApiParameterState(spec, parameters, initialParameterValue, initialExampleKey = "") {
4537
+ const [parameterValues, setParameterValues] = useState(() => Object.fromEntries(parameters.map((parameter) => {
4538
+ const example = getParameterExampleEntries(parameter).find((entry) => entry.key === initialExampleKey);
4539
+ return [parameterKey(parameter), example ? stringifyExample(example.value) : initialParameterValue(parameter)];
4540
+ })));
4261
4541
  const [parameterEnabled, setParameterEnabled] = useState(() => Object.fromEntries(parameters.map((parameter) => [parameterKey(parameter), true])));
4262
4542
  const [parameterIssues, setParameterIssues] = useState({});
4263
4543
  function setParameterGroupValues(grouped, mode) {
@@ -4292,6 +4572,13 @@ function useOpenApiParameterState(spec, parameters, initialParameterValue) {
4292
4572
  return next;
4293
4573
  });
4294
4574
  }
4575
+ function applyParameterExample(exampleKey) {
4576
+ setParameterValues(Object.fromEntries(parameters.map((parameter) => {
4577
+ const example = getParameterExampleEntries(parameter).find((entry) => entry.key === exampleKey);
4578
+ return [parameterKey(parameter), example ? stringifyExample(example.value) : initialParameterValue(parameter)];
4579
+ })));
4580
+ setParameterIssues({});
4581
+ }
4295
4582
  function validate(parametersToValidate) {
4296
4583
  const issues = validateRequestParameters(spec, parametersToValidate, parameterValues);
4297
4584
  setParameterIssues(issues);
@@ -4304,6 +4591,7 @@ function useOpenApiParameterState(spec, parameters, initialParameterValue) {
4304
4591
  setParameterGroupValues,
4305
4592
  setParameterIncluded,
4306
4593
  updateParameterValue,
4594
+ applyParameterExample,
4307
4595
  validate
4308
4596
  };
4309
4597
  }
@@ -4343,6 +4631,7 @@ function useOpenApiRequestExecution() {
4343
4631
  //#endregion
4344
4632
  //#region source/openapi/components/OpenApiRequest.tsx
4345
4633
  function initialParameterValue(spec, parameter) {
4634
+ if (typeof parameter.example !== "undefined") return stringifyExample(parameter.example);
4346
4635
  const schema = resolveSchema(spec, parameter.schema);
4347
4636
  if (!isRecord$1(schema)) return "";
4348
4637
  return stringifyExample(schema.example ?? schema.default ?? (Array.isArray(schema.enum) ? schema.enum[0] : void 0));
@@ -4357,9 +4646,12 @@ function OpenApiRequestWorkbench(arg0) {
4357
4646
  const { spec, path, method, operation, operationSource = "path", compact = false, onClose } = arg0;
4358
4647
  const t = useBuiltInText();
4359
4648
  const parameters = getOperationParameters(spec, path, operation, operationSource);
4360
- const { servers, selectedServer, selectedServerKey, serverVariables, setServerVariables, serverVariableEntries, selectServer, authOptions, selectedAuthName, setSelectedAuthName, selectedAuth, credentialScope, credentials, setCredential, clearCredential, requestContents, mediaType, body, setBody, selectMediaType } = useOpenApiRequestTarget(spec, path, operation, operationSource);
4361
- const parameterState = useOpenApiParameterState(spec, parameters, (parameter) => initialParameterValue(spec, parameter));
4362
- const { parameterValues, parameterEnabled, parameterIssues, setParameterGroupValues, setParameterIncluded, updateParameterValue } = parameterState;
4649
+ const { servers, selectedServer, selectedServerKey, serverVariables, setServerVariables, serverVariableEntries, selectServer, authOptions, selectedAuthName, setSelectedAuthName, selectedAuth, credentialScope, credentials, setCredential, clearCredential, requestContents, mediaType, selectedContent, body, setBody, bodyFiles, setBodyFile, applyBodyExample, selectMediaType } = useOpenApiRequestTarget(spec, path, operation, operationSource);
4650
+ const requestExamples = getRequestExampleEntries(parameters, selectedContent?.value);
4651
+ const [selectedRequestExampleKey, setSelectedRequestExampleKey] = useState(requestExamples[0]?.key ?? "");
4652
+ const currentRequestExampleKey = requestExamples.some((example) => example.key === selectedRequestExampleKey) ? selectedRequestExampleKey : requestExamples[0]?.key ?? "";
4653
+ const parameterState = useOpenApiParameterState(spec, parameters, (parameter) => initialParameterValue(spec, parameter), currentRequestExampleKey);
4654
+ const { parameterValues, parameterEnabled, parameterIssues, setParameterGroupValues, setParameterIncluded, updateParameterValue, applyParameterExample } = parameterState;
4363
4655
  const { exchange, error, sending, execute } = useOpenApiRequestExecution();
4364
4656
  const parameterGroups = [
4365
4657
  "cookie",
@@ -4371,6 +4663,18 @@ function OpenApiRequestWorkbench(arg0) {
4371
4663
  })).filter((group) => group.parameters.length > 0);
4372
4664
  const pathParameters = parameters.filter((parameter) => parameter.in === "path");
4373
4665
  const hasRequestConfiguration = authOptions.length > 0 || serverVariableEntries.length > 0 || parameters.length > 0 || requestContents.length > 0;
4666
+ function applyRequestExample(exampleKey) {
4667
+ setSelectedRequestExampleKey(exampleKey);
4668
+ applyParameterExample(exampleKey);
4669
+ applyBodyExample(exampleKey);
4670
+ }
4671
+ function selectRequestMediaType(value) {
4672
+ const content = requestContents.find((entry) => entry.mediaType === value)?.value;
4673
+ const nextExampleKey = getRequestExampleEntries(parameters, content)[0]?.key ?? "";
4674
+ selectMediaType(value);
4675
+ setSelectedRequestExampleKey(nextExampleKey);
4676
+ applyParameterExample(nextExampleKey);
4677
+ }
4374
4678
  async function sendRequest() {
4375
4679
  const enabledParameters = parameters.filter((parameter) => parameterEnabled[parameterKey(parameter)] !== false);
4376
4680
  const issues = parameterState.validate(enabledParameters);
@@ -4389,6 +4693,7 @@ function OpenApiRequestWorkbench(arg0) {
4389
4693
  })),
4390
4694
  mediaType,
4391
4695
  body,
4696
+ bodyFiles,
4392
4697
  baseUrl: window.location.href
4393
4698
  }), t("openapi.requestCorsHint"));
4394
4699
  }
@@ -4439,44 +4744,84 @@ function OpenApiRequestWorkbench(arg0) {
4439
4744
  }, location);
4440
4745
  }
4441
4746
  function renderHeader() {
4442
- return /* @__PURE__ */ jsxs("div", {
4443
- className: "flex min-w-0 items-center gap-1.5 border-b border-(--clarify-theme-tokens-colors-border) bg-(--clarify-theme-tokens-colors-surface) px-2.5 py-2",
4444
- children: [
4445
- /* @__PURE__ */ jsx(EndpointMethodBadge, { method: method.toUpperCase() }),
4446
- servers.length > 0 ? /* @__PURE__ */ jsx(InlineListbox, {
4447
- label: t("openapi.server"),
4448
- value: selectedServerKey,
4449
- options: servers.map((server, index) => ({
4450
- value: getServerKey(server, index),
4451
- label: server.url ?? `Server ${index + 1}`,
4452
- description: server.description
4453
- })),
4454
- onChange: selectServer,
4455
- className: "min-w-0 max-w-48 shrink sm:max-w-48",
4456
- buttonClassName: "flex h-8 min-w-0 max-w-full items-center gap-1 rounded-(--clarify-theme-tokens-radius-md) px-2 text-xs font-medium text-(--clarify-ui-text-strong) outline-hidden transition hover:bg-(--clarify-ui-hover-background) focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-(--clarify-theme-tokens-colors-primary)"
4457
- }) : null,
4458
- /* @__PURE__ */ jsx("span", {
4459
- className: "min-w-0 flex-1 overflow-x-auto border-l border-(--clarify-theme-tokens-colors-border) pl-2 font-mono text-xs text-(--clarify-theme-tokens-colors-foreground)",
4460
- children: path || "/"
4461
- }),
4462
- /* @__PURE__ */ jsx(SendRequestButton, {
4463
- label: sending ? t("openapi.sendingRequest") : t("openapi.sendRequest"),
4464
- busy: sending,
4465
- text: t("openapi.sendRequest"),
4466
- onClick: sendRequest
4467
- }),
4468
- onClose ? /* @__PURE__ */ jsx("button", {
4469
- type: "button",
4470
- onClick: onClose,
4471
- "aria-label": t("openapi.closeRequest"),
4472
- title: t("openapi.closeRequest"),
4473
- className: "grid size-8 shrink-0 place-items-center rounded-(--clarify-theme-tokens-radius-md) text-(--clarify-ui-text-soft) transition hover:bg-(--clarify-ui-hover-background) hover:text-(--clarify-theme-tokens-colors-foreground) focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-(--clarify-theme-tokens-colors-primary)",
4474
- children: /* @__PURE__ */ jsx(XIcon, {
4475
- className: "size-4",
4476
- "aria-hidden": "true"
4477
- })
4478
- }) : null
4479
- ]
4747
+ return /* @__PURE__ */ jsx("div", {
4748
+ className: "border-b border-(--clarify-theme-tokens-colors-border) bg-(--clarify-theme-tokens-colors-surface)",
4749
+ children: /* @__PURE__ */ jsxs("div", {
4750
+ className: "grid min-w-0 grid-cols-[auto_auto_minmax(0,1fr)_auto_auto] items-center gap-1.5 px-2.5 py-2 lg:grid-cols-[auto_auto_minmax(0,1fr)_minmax(0,14rem)_auto_auto]",
4751
+ children: [
4752
+ /* @__PURE__ */ jsx("div", {
4753
+ className: "col-start-1 row-start-1",
4754
+ children: /* @__PURE__ */ jsx(EndpointMethodBadge, { method: method.toUpperCase() })
4755
+ }),
4756
+ servers.length > 0 ? /* @__PURE__ */ jsx(InlineListbox, {
4757
+ label: t("openapi.server"),
4758
+ value: selectedServerKey,
4759
+ options: servers.map((server, index) => ({
4760
+ value: getServerKey(server, index),
4761
+ label: server.url ?? `Server ${index + 1}`,
4762
+ description: server.description
4763
+ })),
4764
+ onChange: selectServer,
4765
+ title: selectedServer.url ?? t("openapi.server"),
4766
+ buttonContent: /* @__PURE__ */ jsx(ServerIcon, {
4767
+ className: "size-4",
4768
+ "aria-hidden": "true"
4769
+ }),
4770
+ className: "col-start-2 row-start-1 size-8 shrink-0",
4771
+ buttonClassName: "grid size-8 place-items-center rounded-(--clarify-theme-tokens-radius-md) bg-(--clarify-ui-subtle-background) text-(--clarify-ui-text-soft) outline-hidden transition hover:bg-(--clarify-ui-hover-background) hover:text-(--clarify-ui-text-strong) focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-(--clarify-theme-tokens-colors-primary) data-open:bg-(--clarify-ui-active-background)"
4772
+ }) : null,
4773
+ /* @__PURE__ */ jsx("span", {
4774
+ className: "col-start-3 row-start-1 min-w-0 truncate border-l border-(--clarify-theme-tokens-colors-border) pl-2 font-mono text-xs text-(--clarify-theme-tokens-colors-foreground)",
4775
+ title: path || "/",
4776
+ children: path || "/"
4777
+ }),
4778
+ requestExamples.length > 1 ? /* @__PURE__ */ jsxs("div", {
4779
+ className: "col-span-full row-start-2 flex min-w-0 items-center gap-0.5 border-t border-(--clarify-theme-tokens-colors-border) pt-2 lg:col-span-1 lg:col-start-4 lg:row-start-1 lg:border-t-0 lg:pt-0",
4780
+ children: [/* @__PURE__ */ jsx(InlineListbox, {
4781
+ label: t("openapi.requestExample"),
4782
+ value: currentRequestExampleKey,
4783
+ options: requestExamples.map((example) => ({
4784
+ value: example.key,
4785
+ label: example.title,
4786
+ description: example.summary
4787
+ })),
4788
+ onChange: applyRequestExample,
4789
+ className: "min-w-0 flex-1",
4790
+ buttonClassName: "flex h-8 w-full min-w-0 max-w-full items-center gap-1 rounded-(--clarify-theme-tokens-radius-md) px-2 text-xs font-medium text-(--clarify-ui-text-strong) outline-hidden transition hover:bg-(--clarify-ui-hover-background) focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-(--clarify-theme-tokens-colors-primary)"
4791
+ }), /* @__PURE__ */ jsx("button", {
4792
+ type: "button",
4793
+ title: t("openapi.resetToExample"),
4794
+ "aria-label": t("openapi.resetToExample"),
4795
+ onClick: () => applyRequestExample(currentRequestExampleKey),
4796
+ className: "grid size-8 shrink-0 place-items-center rounded-(--clarify-theme-tokens-radius-md) text-(--clarify-ui-text-faint) hover:bg-(--clarify-ui-hover-background) hover:text-(--clarify-ui-text-strong) focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-(--clarify-theme-tokens-colors-primary)",
4797
+ children: /* @__PURE__ */ jsx(RotateCcwIcon, {
4798
+ className: "size-3.5",
4799
+ "aria-hidden": "true"
4800
+ })
4801
+ })]
4802
+ }) : null,
4803
+ /* @__PURE__ */ jsx("div", {
4804
+ className: "col-start-4 row-start-1 lg:col-start-5",
4805
+ children: /* @__PURE__ */ jsx(SendRequestButton, {
4806
+ label: sending ? t("openapi.sendingRequest") : t("openapi.sendRequest"),
4807
+ busy: sending,
4808
+ text: t("openapi.sendRequest"),
4809
+ onClick: sendRequest
4810
+ })
4811
+ }),
4812
+ onClose ? /* @__PURE__ */ jsx("button", {
4813
+ type: "button",
4814
+ onClick: onClose,
4815
+ "aria-label": t("openapi.closeRequest"),
4816
+ title: t("openapi.closeRequest"),
4817
+ className: "col-start-5 row-start-1 grid size-8 shrink-0 place-items-center rounded-(--clarify-theme-tokens-radius-md) text-(--clarify-ui-text-soft) transition hover:bg-(--clarify-ui-hover-background) hover:text-(--clarify-theme-tokens-colors-foreground) focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-(--clarify-theme-tokens-colors-primary) lg:col-start-6",
4818
+ children: /* @__PURE__ */ jsx(XIcon, {
4819
+ className: "size-4",
4820
+ "aria-hidden": "true"
4821
+ })
4822
+ }) : null
4823
+ ]
4824
+ })
4480
4825
  });
4481
4826
  }
4482
4827
  function renderVariables() {
@@ -4516,13 +4861,15 @@ function OpenApiRequestWorkbench(arg0) {
4516
4861
  value: entry.mediaType,
4517
4862
  label: entry.mediaType
4518
4863
  })),
4519
- onChange: selectMediaType
4520
- }) }) : null, /* @__PURE__ */ jsx("textarea", {
4521
- "aria-label": t("openapi.requestBody"),
4522
- value: body,
4523
- onChange: (event) => setBody(event.target.value),
4524
- spellCheck: false,
4525
- className: "block h-full min-h-44 w-full resize-none border-0 bg-(--clarify-code-background) p-3 font-mono text-xs/5 text-(--clarify-code-text) outline-hidden focus:ring-2 focus:ring-inset focus:ring-(--clarify-theme-tokens-colors-primary)"
4864
+ onChange: selectRequestMediaType
4865
+ }) }) : null, /* @__PURE__ */ jsx(OpenApiRequestBodyEditor, {
4866
+ spec,
4867
+ mediaType,
4868
+ content: selectedContent?.value,
4869
+ body,
4870
+ files: bodyFiles,
4871
+ onBodyChange: setBody,
4872
+ onFileChange: setBodyFile
4526
4873
  })]
4527
4874
  });
4528
4875
  }
@@ -4929,4 +5276,4 @@ function OpenApiOperation(arg0) {
4929
5276
  //#endregion
4930
5277
  export { Code as A, GridPattern as C, Tag as D, Heading as E, CardGroup as F, Callout as I, Button as L, Pre as M, Mermaid as N, Feedback as O, Card as P, Prose as S, Logo as T, WebFrame as _, ResponseExamplesPanel as a, Step as b, getAuthOptions as c, getOpenApiOperationEntry as d, listOpenApiOperations as f, primitives_exports as g, Markdown as h, RequestExamplesPanel as i, CodeGroup as j, Collapse as k, getServerKey as l, getRequestBody$1 as m, OpenApiOperation as n, authPlaceholder as o, getMediaTypeEntries as p, OpenApiRequestWorkbench as r, defaultServerVariables as s, EndpointIdentity as t, getServers as u, TabItem as v, HeroPattern as w, Steps as x, Tabs as y };
4931
5278
 
4932
- //# sourceMappingURL=OpenApiOperation-C2vJztWZ.js.map
5279
+ //# sourceMappingURL=OpenApiOperation-CFo6_otd.js.map