@clarify-labs/renderer 0.11.17 → 0.11.19

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.
@@ -1827,10 +1827,17 @@ function getOpenApiOperationEntryById(spec, operationId) {
1827
1827
  const matches = listOpenApiOperations(spec).filter(({ operation }) => operation.operationId === operationId);
1828
1828
  return matches.length === 1 ? matches[0] : void 0;
1829
1829
  }
1830
- function listOpenApiOperations(spec) {
1830
+ function listOpenApiOperations(spec, operationOrder) {
1831
1831
  const paths = spec.paths ?? {};
1832
1832
  const webhooks = spec.webhooks;
1833
- return [...listOperationsFromPathItems(paths, "path", spec), ...isRecord(webhooks) ? listOperationsFromPathItems(webhooks, "webhook", spec) : []];
1833
+ const operations = [...listOperationsFromPathItems(paths, "path", spec), ...isRecord(webhooks) ? listOperationsFromPathItems(webhooks, "webhook", spec) : []];
1834
+ if (!operationOrder?.length) return operations;
1835
+ const orderByOperationId = new Map(operationOrder.map((operationId, index) => [operationId, index]));
1836
+ return operations.map((entry, index) => ({
1837
+ entry,
1838
+ index,
1839
+ order: entry.operation.operationId ? orderByOperationId.get(entry.operation.operationId) : void 0
1840
+ })).sort((left, right) => (left.order ?? operationOrder.length) - (right.order ?? operationOrder.length) || left.index - right.index).map(({ entry }) => entry);
1834
1841
  }
1835
1842
  //#endregion
1836
1843
  //#region source/openapi/components/EndpointMethodBadge.tsx
@@ -2908,16 +2915,41 @@ function OpenApiAuthDocumentation(props) {
2908
2915
  });
2909
2916
  }
2910
2917
  //#endregion
2911
- //#region source/openapi/components/SchemaProperties.tsx
2912
- function getEnumDescriptions(schema) {
2913
- const descriptions = schema["x-enumDescriptions"];
2914
- if (Array.isArray(descriptions)) return descriptions.map((value) => typeof value === "string" ? value : void 0);
2915
- if (isRecord$1(descriptions)) return Array.isArray(schema.enum) ? schema.enum.map((value) => {
2916
- const description = descriptions[String(value)];
2917
- return typeof description === "string" ? description : void 0;
2918
- }) : [];
2919
- return [];
2918
+ //#region source/openapi/lib/enum-options.ts
2919
+ function enumValueKey(value) {
2920
+ return `${value === null ? "null" : typeof value}:${JSON.stringify(value)}`;
2921
+ }
2922
+ function enumMetadata(schema, keys, values) {
2923
+ const metadata = keys.map((key) => schema[key]).find((value) => Array.isArray(value) || isRecord$1(value));
2924
+ if (Array.isArray(metadata)) return values.map((_, index) => typeof metadata[index] === "string" ? metadata[index] : void 0);
2925
+ if (isRecord$1(metadata)) return values.map((value) => {
2926
+ const item = metadata[String(value)];
2927
+ return typeof item === "string" ? item : void 0;
2928
+ });
2929
+ return values.map(() => void 0);
2930
+ }
2931
+ function getEnumOptions(schema) {
2932
+ if (!isRecord$1(schema) || !Array.isArray(schema.enum)) return [];
2933
+ const values = schema.enum;
2934
+ const labels = enumMetadata(schema, [
2935
+ "x-enumLabels",
2936
+ "x-enumNames",
2937
+ "x-enum-varnames"
2938
+ ], values);
2939
+ const descriptions = enumMetadata(schema, ["x-enumDescriptions"], values);
2940
+ return values.map((value, index) => {
2941
+ const valueText = String(value);
2942
+ return {
2943
+ key: enumValueKey(value),
2944
+ value,
2945
+ valueText,
2946
+ label: labels[index] ?? valueText,
2947
+ description: descriptions[index]
2948
+ };
2949
+ });
2920
2950
  }
2951
+ //#endregion
2952
+ //#region source/openapi/components/SchemaProperties.tsx
2921
2953
  function getSchemaDetails(schema) {
2922
2954
  const details = [
2923
2955
  typeof schema.const !== "undefined" ? `const: ${String(schema.const)}` : void 0,
@@ -2937,12 +2969,11 @@ function getSchemaNodeType(schema) {
2937
2969
  }
2938
2970
  function getEnumChildren(schema, path) {
2939
2971
  if (!Array.isArray(schema.enum) || schema.enum.length === 0) return [];
2940
- const descriptions = getEnumDescriptions(schema);
2941
- return schema.enum.map((value, index) => ({
2942
- key: `${path || "root"}.enum[${index}]`,
2943
- name: String(value),
2972
+ return getEnumOptions(schema).map((option) => ({
2973
+ key: `${path || "root"}.enum.${option.key}`,
2974
+ name: option.valueText,
2944
2975
  kind: "enum",
2945
- description: descriptions[index],
2976
+ description: option.description,
2946
2977
  required: false,
2947
2978
  children: []
2948
2979
  }));
@@ -3103,6 +3134,9 @@ function getRootSchemaNode(spec, schema, defaultExpanded) {
3103
3134
  })
3104
3135
  };
3105
3136
  }
3137
+ function shouldToggleSchemaRow(interactiveTarget, selectionInRow) {
3138
+ return !interactiveTarget && !selectionInRow;
3139
+ }
3106
3140
  function EnumValueWithDescription(arg0) {
3107
3141
  const { node } = arg0;
3108
3142
  return /* @__PURE__ */ jsx("li", {
@@ -3161,8 +3195,8 @@ function SchemaNode(arg0) {
3161
3195
  const type = [node.type, node.required ? t("openapi.requiredBadge") : void 0].filter(Boolean).join(", ") || void 0;
3162
3196
  const fallbackDescription = hasChildren ? void 0 : node.required ? t("openapi.required") : t("openapi.optional");
3163
3197
  const rowClassName = "flex w-full min-w-0 items-start rounded-(--clarify-theme-tokens-radius-md) px-2 py-2 text-left";
3164
- const content = /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsxs("div", {
3165
- className: "min-w-0 flex-1",
3198
+ const content = /* @__PURE__ */ jsxs("div", {
3199
+ className: "min-w-0 flex-1 select-text",
3166
3200
  children: [/* @__PURE__ */ jsxs("div", {
3167
3201
  className: "flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5",
3168
3202
  children: [/* @__PURE__ */ jsx("span", {
@@ -3182,20 +3216,25 @@ function SchemaNode(arg0) {
3182
3216
  children: node.details
3183
3217
  }) : null]
3184
3218
  })]
3185
- }), hasChildren ? /* @__PURE__ */ jsx("span", {
3186
- className: "ml-2 flex h-5 w-5 flex-none items-center justify-center text-(--clarify-ui-text-faint)",
3187
- "aria-hidden": "true",
3188
- children: expanded ? /* @__PURE__ */ jsx(ChevronDown, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "h-4 w-4" })
3189
- }) : null] });
3219
+ });
3190
3220
  return /* @__PURE__ */ jsxs("li", {
3191
3221
  className: clsx("clarify-schema-node m-0 p-0", node.visible === false && "hidden"),
3192
- children: [hasChildren ? /* @__PURE__ */ jsx("button", {
3193
- type: "button",
3194
- "aria-label": expanded ? t("openapi.collapse") : t("openapi.expand"),
3195
- "aria-expanded": expanded,
3196
- onClick: () => setLocallyExpanded((value) => !value),
3197
- className: clsx(rowClassName, "cursor-pointer transition hover:bg-(--clarify-ui-hover-background) focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-(--clarify-theme-tokens-colors-primary)"),
3198
- children: content
3222
+ children: [hasChildren ? /* @__PURE__ */ jsxs("div", {
3223
+ onClick: (event) => {
3224
+ const target = event.target instanceof Element ? event.target : void 0;
3225
+ const interactiveTarget = Boolean(target?.closest("button, a, input, select, textarea, [role=\"button\"]"));
3226
+ const selection = window.getSelection();
3227
+ if (shouldToggleSchemaRow(interactiveTarget, Boolean(selection && !selection.isCollapsed && selection.containsNode(event.currentTarget, true)))) setLocallyExpanded((value) => !value);
3228
+ },
3229
+ className: clsx(rowClassName, "cursor-pointer transition hover:bg-(--clarify-ui-hover-background)"),
3230
+ children: [content, /* @__PURE__ */ jsx("button", {
3231
+ type: "button",
3232
+ "aria-label": `${expanded ? t("openapi.collapse") : t("openapi.expand")}: ${node.name}`,
3233
+ "aria-expanded": expanded,
3234
+ onClick: () => setLocallyExpanded((value) => !value),
3235
+ className: "ml-2 flex h-5 w-5 flex-none cursor-pointer items-center justify-center rounded-(--clarify-theme-tokens-radius-md) text-(--clarify-ui-text-faint) outline-hidden transition hover:bg-(--clarify-ui-active-background) focus-visible:ring-2 focus-visible:ring-(--clarify-theme-tokens-colors-primary)",
3236
+ children: expanded ? /* @__PURE__ */ jsx(ChevronDown, { className: "h-4 w-4" }) : /* @__PURE__ */ jsx(ChevronRight, { className: "h-4 w-4" })
3237
+ })]
3199
3238
  }) : /* @__PURE__ */ jsx("div", {
3200
3239
  className: rowClassName,
3201
3240
  children: content
@@ -3977,6 +4016,8 @@ function isFormMediaType(mediaType) {
3977
4016
  }
3978
4017
  function valueFromInput(schema, value) {
3979
4018
  if (!isRecord$1(schema)) return value;
4019
+ const enumOption = getEnumOptions(schema).find((option) => option.valueText === value);
4020
+ if (enumOption) return enumOption.value;
3980
4021
  if (schemaHasType(schema, "integer")) return value === "" ? "" : Number.parseInt(value, 10);
3981
4022
  if (schemaHasType(schema, "number")) return value === "" ? "" : Number(value);
3982
4023
  if (schemaHasType(schema, "boolean")) return value === "true";
@@ -4006,7 +4047,7 @@ function OpenApiRequestBodyEditor(arg0) {
4006
4047
  const type = schemaToType(propertySchema) ?? "string";
4007
4048
  const value = values[name];
4008
4049
  const fieldId = `openapi-request-body-${name}`.replace(/[^a-zA-Z0-9_-]/g, "-");
4009
- const options = Array.isArray(propertyRecord?.enum) ? propertyRecord.enum : [];
4050
+ const options = getEnumOptions(propertySchema);
4010
4051
  const structured = schemaHasType(propertySchema, "array") || schemaHasType(propertySchema, "object");
4011
4052
  const serializedValue = structured && typeof value !== "undefined" ? JSON.stringify(value, null, 2) : String(value ?? "");
4012
4053
  let control;
@@ -4026,9 +4067,9 @@ function OpenApiRequestBodyEditor(arg0) {
4026
4067
  onChange: (event) => updateProperty(name, propertySchema, event.target.value),
4027
4068
  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)",
4028
4069
  children: [!required.has(name) ? /* @__PURE__ */ jsx("option", { value: "" }) : null, options.map((option) => /* @__PURE__ */ jsx("option", {
4029
- value: String(option),
4030
- children: String(option)
4031
- }, String(option)))]
4070
+ value: option.valueText,
4071
+ children: option.label
4072
+ }, option.key))]
4032
4073
  });
4033
4074
  else if (schemaHasType(propertySchema, "boolean")) control = /* @__PURE__ */ jsx("input", {
4034
4075
  id: fieldId,
@@ -4114,8 +4155,16 @@ function RequestField(arg0) {
4114
4155
  const schema = resolveSchema(spec, parameter.schema);
4115
4156
  const schemaRecord = isRecord$1(schema) ? schema : void 0;
4116
4157
  const itemSchema = isRecord$1(schemaRecord?.items) ? schemaRecord.items : void 0;
4117
- const options = Array.isArray(schemaRecord?.enum) ? schemaRecord.enum.map(String) : [];
4118
- const itemOptions = Array.isArray(itemSchema?.enum) ? itemSchema.enum.map(String) : [];
4158
+ const options = getEnumOptions(schema).map(({ valueText, label, description }) => ({
4159
+ value: valueText,
4160
+ label,
4161
+ description
4162
+ }));
4163
+ const itemOptions = getEnumOptions(itemSchema).map(({ valueText, label, description }) => ({
4164
+ value: valueText,
4165
+ label,
4166
+ description
4167
+ }));
4119
4168
  const type = schemaToType(schema) ?? "string";
4120
4169
  const description = parameter.description ?? (typeof schemaRecord?.description === "string" ? schemaRecord.description : void 0);
4121
4170
  const structured = type.includes("[]") || type.includes("object");
@@ -4195,10 +4244,7 @@ function RequestField(arg0) {
4195
4244
  children: itemOptions.length > 0 ? /* @__PURE__ */ jsx(MultiInlineListbox, {
4196
4245
  label: parameter.name ?? "",
4197
4246
  value: arrayValue,
4198
- options: itemOptions.map((option) => ({
4199
- value: option,
4200
- label: option
4201
- })),
4247
+ options: itemOptions,
4202
4248
  onChange: (next) => onChange(JSON.stringify(next)),
4203
4249
  invalid: Boolean(issue),
4204
4250
  describedBy: issue ? `${fieldId}-issue` : void 0,
@@ -4209,10 +4255,7 @@ function RequestField(arg0) {
4209
4255
  options: [...parameter.required ? [] : [{
4210
4256
  value: "",
4211
4257
  label: t("openapi.none")
4212
- }], ...options.map((option) => ({
4213
- value: option,
4214
- label: option
4215
- }))],
4258
+ }], ...options],
4216
4259
  onChange,
4217
4260
  invalid: Boolean(issue),
4218
4261
  describedBy: issue ? `${fieldId}-issue` : void 0,
@@ -4846,7 +4889,7 @@ function validateRequestParameter(spec, parameter, value) {
4846
4889
  const schema = resolveSchema(spec, parameter.schema);
4847
4890
  const schemaRecord = isRecord$1(schema) ? schema : void 0;
4848
4891
  const type = schemaToType(schema) ?? "string";
4849
- const options = Array.isArray(schemaRecord?.enum) ? schemaRecord.enum.map(String) : [];
4892
+ const options = getEnumOptions(schema).map(({ valueText }) => valueText);
4850
4893
  if (options.length > 0 && !options.includes(value)) return "invalidEnum";
4851
4894
  return structuredIssue(value, type) ?? scalarIssue(value, type, schemaRecord?.format);
4852
4895
  }
@@ -5371,7 +5414,7 @@ function EndpointPath(arg0) {
5371
5414
  className: "min-w-0 flex-1 overflow-x-auto text-sm font-bold leading-6 whitespace-nowrap",
5372
5415
  children: /* @__PURE__ */ jsx("span", {
5373
5416
  className: "select-text font-mono text-(--clarify-theme-tokens-colors-foreground)",
5374
- children: path || "/"
5417
+ children: path ? path.startsWith("/") ? path : `/${path}` : "/"
5375
5418
  })
5376
5419
  }), onCopy ? /* @__PURE__ */ jsx("button", {
5377
5420
  type: "button",
@@ -5694,4 +5737,4 @@ function OpenApiOperation(arg0) {
5694
5737
  //#endregion
5695
5738
  export { Heading as A, Callout as B, Tabs as C, GridPattern as D, Prose as E, CodeGroup as F, LocalizedLink as H, Pre as I, Mermaid as L, Feedback as M, Collapse as N, HeroPattern as O, Code as P, Card as R, TabItem as S, Steps as T, Button as V, Markdown as _, ResponseExamplesPanel as a, primitives_exports as b, getAuthOptions as c, EndpointMethodBadge as d, getOpenApiOperationEntryById as f, getRequestBody$1 as g, getMediaTypeEntries as h, RequestExamplesPanel as i, Tag as j, Logo as k, getServerKey as l, listOpenApiOperations as m, OpenApiOperation as n, authPlaceholder as o, getOpenApiOperationSectionId as p, OpenApiRequestWorkbench as r, defaultServerVariables as s, EndpointIdentity as t, getServers as u, Release as v, Step as w, WebFrame as x, ReleaseItem as y, CardGroup as z };
5696
5739
 
5697
- //# sourceMappingURL=OpenApiOperation-kL4Fxi0g.js.map
5740
+ //# sourceMappingURL=OpenApiOperation-B68CqUJW.js.map