@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.
@@ -1819,10 +1819,17 @@ function getOpenApiOperationEntryById(spec, operationId) {
1819
1819
  const matches = listOpenApiOperations(spec).filter(({ operation }) => operation.operationId === operationId);
1820
1820
  return matches.length === 1 ? matches[0] : void 0;
1821
1821
  }
1822
- function listOpenApiOperations(spec) {
1822
+ function listOpenApiOperations(spec, operationOrder) {
1823
1823
  const paths = spec.paths ?? {};
1824
1824
  const webhooks = spec.webhooks;
1825
- return [...listOperationsFromPathItems(paths, "path", spec), ...isRecord(webhooks) ? listOperationsFromPathItems(webhooks, "webhook", spec) : []];
1825
+ const operations = [...listOperationsFromPathItems(paths, "path", spec), ...isRecord(webhooks) ? listOperationsFromPathItems(webhooks, "webhook", spec) : []];
1826
+ if (!operationOrder?.length) return operations;
1827
+ const orderByOperationId = new Map(operationOrder.map((operationId, index) => [operationId, index]));
1828
+ return operations.map((entry, index) => ({
1829
+ entry,
1830
+ index,
1831
+ order: entry.operation.operationId ? orderByOperationId.get(entry.operation.operationId) : void 0
1832
+ })).sort((left, right) => (left.order ?? operationOrder.length) - (right.order ?? operationOrder.length) || left.index - right.index).map(({ entry }) => entry);
1826
1833
  }
1827
1834
  //#endregion
1828
1835
  //#region source/openapi/components/EndpointMethodBadge.tsx
@@ -2900,16 +2907,41 @@ function OpenApiAuthDocumentation(props) {
2900
2907
  });
2901
2908
  }
2902
2909
  //#endregion
2903
- //#region source/openapi/components/SchemaProperties.tsx
2904
- function getEnumDescriptions(schema) {
2905
- const descriptions = schema["x-enumDescriptions"];
2906
- if (Array.isArray(descriptions)) return descriptions.map((value) => typeof value === "string" ? value : void 0);
2907
- if (isRecord$1(descriptions)) return Array.isArray(schema.enum) ? schema.enum.map((value) => {
2908
- const description = descriptions[String(value)];
2909
- return typeof description === "string" ? description : void 0;
2910
- }) : [];
2911
- return [];
2910
+ //#region source/openapi/lib/enum-options.ts
2911
+ function enumValueKey(value) {
2912
+ return `${value === null ? "null" : typeof value}:${JSON.stringify(value)}`;
2913
+ }
2914
+ function enumMetadata(schema, keys, values) {
2915
+ const metadata = keys.map((key) => schema[key]).find((value) => Array.isArray(value) || isRecord$1(value));
2916
+ if (Array.isArray(metadata)) return values.map((_, index) => typeof metadata[index] === "string" ? metadata[index] : void 0);
2917
+ if (isRecord$1(metadata)) return values.map((value) => {
2918
+ const item = metadata[String(value)];
2919
+ return typeof item === "string" ? item : void 0;
2920
+ });
2921
+ return values.map(() => void 0);
2922
+ }
2923
+ function getEnumOptions(schema) {
2924
+ if (!isRecord$1(schema) || !Array.isArray(schema.enum)) return [];
2925
+ const values = schema.enum;
2926
+ const labels = enumMetadata(schema, [
2927
+ "x-enumLabels",
2928
+ "x-enumNames",
2929
+ "x-enum-varnames"
2930
+ ], values);
2931
+ const descriptions = enumMetadata(schema, ["x-enumDescriptions"], values);
2932
+ return values.map((value, index) => {
2933
+ const valueText = String(value);
2934
+ return {
2935
+ key: enumValueKey(value),
2936
+ value,
2937
+ valueText,
2938
+ label: labels[index] ?? valueText,
2939
+ description: descriptions[index]
2940
+ };
2941
+ });
2912
2942
  }
2943
+ //#endregion
2944
+ //#region source/openapi/components/SchemaProperties.tsx
2913
2945
  function getSchemaDetails(schema) {
2914
2946
  const details = [
2915
2947
  typeof schema.const !== "undefined" ? `const: ${String(schema.const)}` : void 0,
@@ -2929,12 +2961,11 @@ function getSchemaNodeType(schema) {
2929
2961
  }
2930
2962
  function getEnumChildren(schema, path) {
2931
2963
  if (!Array.isArray(schema.enum) || schema.enum.length === 0) return [];
2932
- const descriptions = getEnumDescriptions(schema);
2933
- return schema.enum.map((value, index) => ({
2934
- key: `${path || "root"}.enum[${index}]`,
2935
- name: String(value),
2964
+ return getEnumOptions(schema).map((option) => ({
2965
+ key: `${path || "root"}.enum.${option.key}`,
2966
+ name: option.valueText,
2936
2967
  kind: "enum",
2937
- description: descriptions[index],
2968
+ description: option.description,
2938
2969
  required: false,
2939
2970
  children: []
2940
2971
  }));
@@ -3095,6 +3126,9 @@ function getRootSchemaNode(spec, schema, defaultExpanded) {
3095
3126
  })
3096
3127
  };
3097
3128
  }
3129
+ function shouldToggleSchemaRow(interactiveTarget, selectionInRow) {
3130
+ return !interactiveTarget && !selectionInRow;
3131
+ }
3098
3132
  function EnumValueWithDescription(arg0) {
3099
3133
  const { node } = arg0;
3100
3134
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("li", {
@@ -3153,8 +3187,8 @@ function SchemaNode(arg0) {
3153
3187
  const type = [node.type, node.required ? t("openapi.requiredBadge") : void 0].filter(Boolean).join(", ") || void 0;
3154
3188
  const fallbackDescription = hasChildren ? void 0 : node.required ? t("openapi.required") : t("openapi.optional");
3155
3189
  const rowClassName = "flex w-full min-w-0 items-start rounded-(--clarify-theme-tokens-radius-md) px-2 py-2 text-left";
3156
- const content = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3157
- className: "min-w-0 flex-1",
3190
+ const content = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3191
+ className: "min-w-0 flex-1 select-text",
3158
3192
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3159
3193
  className: "flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5",
3160
3194
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
@@ -3174,20 +3208,25 @@ function SchemaNode(arg0) {
3174
3208
  children: node.details
3175
3209
  }) : null]
3176
3210
  })]
3177
- }), hasChildren ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
3178
- className: "ml-2 flex h-5 w-5 flex-none items-center justify-center text-(--clarify-ui-text-faint)",
3179
- "aria-hidden": "true",
3180
- children: expanded ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDown, { className: "h-4 w-4" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronRight, { className: "h-4 w-4" })
3181
- }) : null] });
3211
+ });
3182
3212
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", {
3183
3213
  className: (0, clsx.default)("clarify-schema-node m-0 p-0", node.visible === false && "hidden"),
3184
- children: [hasChildren ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
3185
- type: "button",
3186
- "aria-label": expanded ? t("openapi.collapse") : t("openapi.expand"),
3187
- "aria-expanded": expanded,
3188
- onClick: () => setLocallyExpanded((value) => !value),
3189
- className: (0, clsx.default)(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)"),
3190
- children: content
3214
+ children: [hasChildren ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
3215
+ onClick: (event) => {
3216
+ const target = event.target instanceof Element ? event.target : void 0;
3217
+ const interactiveTarget = Boolean(target?.closest("button, a, input, select, textarea, [role=\"button\"]"));
3218
+ const selection = window.getSelection();
3219
+ if (shouldToggleSchemaRow(interactiveTarget, Boolean(selection && !selection.isCollapsed && selection.containsNode(event.currentTarget, true)))) setLocallyExpanded((value) => !value);
3220
+ },
3221
+ className: (0, clsx.default)(rowClassName, "cursor-pointer transition hover:bg-(--clarify-ui-hover-background)"),
3222
+ children: [content, /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
3223
+ type: "button",
3224
+ "aria-label": `${expanded ? t("openapi.collapse") : t("openapi.expand")}: ${node.name}`,
3225
+ "aria-expanded": expanded,
3226
+ onClick: () => setLocallyExpanded((value) => !value),
3227
+ 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)",
3228
+ children: expanded ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronDown, { className: "h-4 w-4" }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(lucide_react.ChevronRight, { className: "h-4 w-4" })
3229
+ })]
3191
3230
  }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
3192
3231
  className: rowClassName,
3193
3232
  children: content
@@ -3969,6 +4008,8 @@ function isFormMediaType(mediaType) {
3969
4008
  }
3970
4009
  function valueFromInput(schema, value) {
3971
4010
  if (!isRecord$1(schema)) return value;
4011
+ const enumOption = getEnumOptions(schema).find((option) => option.valueText === value);
4012
+ if (enumOption) return enumOption.value;
3972
4013
  if (schemaHasType(schema, "integer")) return value === "" ? "" : Number.parseInt(value, 10);
3973
4014
  if (schemaHasType(schema, "number")) return value === "" ? "" : Number(value);
3974
4015
  if (schemaHasType(schema, "boolean")) return value === "true";
@@ -3998,7 +4039,7 @@ function OpenApiRequestBodyEditor(arg0) {
3998
4039
  const type = schemaToType(propertySchema) ?? "string";
3999
4040
  const value = values[name];
4000
4041
  const fieldId = `openapi-request-body-${name}`.replace(/[^a-zA-Z0-9_-]/g, "-");
4001
- const options = Array.isArray(propertyRecord?.enum) ? propertyRecord.enum : [];
4042
+ const options = getEnumOptions(propertySchema);
4002
4043
  const structured = schemaHasType(propertySchema, "array") || schemaHasType(propertySchema, "object");
4003
4044
  const serializedValue = structured && typeof value !== "undefined" ? JSON.stringify(value, null, 2) : String(value ?? "");
4004
4045
  let control;
@@ -4018,9 +4059,9 @@ function OpenApiRequestBodyEditor(arg0) {
4018
4059
  onChange: (event) => updateProperty(name, propertySchema, event.target.value),
4019
4060
  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)",
4020
4061
  children: [!required.has(name) ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", { value: "" }) : null, options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
4021
- value: String(option),
4022
- children: String(option)
4023
- }, String(option)))]
4062
+ value: option.valueText,
4063
+ children: option.label
4064
+ }, option.key))]
4024
4065
  });
4025
4066
  else if (schemaHasType(propertySchema, "boolean")) control = /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
4026
4067
  id: fieldId,
@@ -4106,8 +4147,16 @@ function RequestField(arg0) {
4106
4147
  const schema = resolveSchema(spec, parameter.schema);
4107
4148
  const schemaRecord = isRecord$1(schema) ? schema : void 0;
4108
4149
  const itemSchema = isRecord$1(schemaRecord?.items) ? schemaRecord.items : void 0;
4109
- const options = Array.isArray(schemaRecord?.enum) ? schemaRecord.enum.map(String) : [];
4110
- const itemOptions = Array.isArray(itemSchema?.enum) ? itemSchema.enum.map(String) : [];
4150
+ const options = getEnumOptions(schema).map(({ valueText, label, description }) => ({
4151
+ value: valueText,
4152
+ label,
4153
+ description
4154
+ }));
4155
+ const itemOptions = getEnumOptions(itemSchema).map(({ valueText, label, description }) => ({
4156
+ value: valueText,
4157
+ label,
4158
+ description
4159
+ }));
4111
4160
  const type = schemaToType(schema) ?? "string";
4112
4161
  const description = parameter.description ?? (typeof schemaRecord?.description === "string" ? schemaRecord.description : void 0);
4113
4162
  const structured = type.includes("[]") || type.includes("object");
@@ -4187,10 +4236,7 @@ function RequestField(arg0) {
4187
4236
  children: itemOptions.length > 0 ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MultiInlineListbox, {
4188
4237
  label: parameter.name ?? "",
4189
4238
  value: arrayValue,
4190
- options: itemOptions.map((option) => ({
4191
- value: option,
4192
- label: option
4193
- })),
4239
+ options: itemOptions,
4194
4240
  onChange: (next) => onChange(JSON.stringify(next)),
4195
4241
  invalid: Boolean(issue),
4196
4242
  describedBy: issue ? `${fieldId}-issue` : void 0,
@@ -4201,10 +4247,7 @@ function RequestField(arg0) {
4201
4247
  options: [...parameter.required ? [] : [{
4202
4248
  value: "",
4203
4249
  label: t("openapi.none")
4204
- }], ...options.map((option) => ({
4205
- value: option,
4206
- label: option
4207
- }))],
4250
+ }], ...options],
4208
4251
  onChange,
4209
4252
  invalid: Boolean(issue),
4210
4253
  describedBy: issue ? `${fieldId}-issue` : void 0,
@@ -4838,7 +4881,7 @@ function validateRequestParameter(spec, parameter, value) {
4838
4881
  const schema = resolveSchema(spec, parameter.schema);
4839
4882
  const schemaRecord = isRecord$1(schema) ? schema : void 0;
4840
4883
  const type = schemaToType(schema) ?? "string";
4841
- const options = Array.isArray(schemaRecord?.enum) ? schemaRecord.enum.map(String) : [];
4884
+ const options = getEnumOptions(schema).map(({ valueText }) => valueText);
4842
4885
  if (options.length > 0 && !options.includes(value)) return "invalidEnum";
4843
4886
  return structuredIssue(value, type) ?? scalarIssue(value, type, schemaRecord?.format);
4844
4887
  }
@@ -5363,7 +5406,7 @@ function EndpointPath(arg0) {
5363
5406
  className: "min-w-0 flex-1 overflow-x-auto text-sm font-bold leading-6 whitespace-nowrap",
5364
5407
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
5365
5408
  className: "select-text font-mono text-(--clarify-theme-tokens-colors-foreground)",
5366
- children: path || "/"
5409
+ children: path ? path.startsWith("/") ? path : `/${path}` : "/"
5367
5410
  })
5368
5411
  }), onCopy ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
5369
5412
  type: "button",
@@ -5937,4 +5980,4 @@ Object.defineProperty(exports, "primitives_exports", {
5937
5980
  }
5938
5981
  });
5939
5982
 
5940
- //# sourceMappingURL=OpenApiOperation-DxJl8ziP.cjs.map
5983
+ //# sourceMappingURL=OpenApiOperation-Cv4N92VL.cjs.map