@scalar/blocks 0.5.2 → 0.5.3

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 (104) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/code-example/helpers/operation-to-har/process-body.d.ts.map +1 -1
  3. package/dist/code-example/helpers/operation-to-har/process-body.js +42 -42
  4. package/dist/code-example/helpers/operation-to-har/process-body.js.map +1 -1
  5. package/dist/constants.js +1 -1
  6. package/dist/schema/Schema.vue.d.ts.map +1 -1
  7. package/dist/schema/Schema.vue.js +1 -1
  8. package/dist/schema/Schema.vue.js.map +1 -1
  9. package/dist/schema/Schema.vue.script.js +122 -116
  10. package/dist/schema/Schema.vue.script.js.map +1 -1
  11. package/dist/schema/SchemaComposition.vue.d.ts.map +1 -1
  12. package/dist/schema/SchemaComposition.vue.js +1 -1
  13. package/dist/schema/SchemaComposition.vue.js.map +1 -1
  14. package/dist/schema/SchemaComposition.vue.script.js +110 -106
  15. package/dist/schema/SchemaComposition.vue.script.js.map +1 -1
  16. package/dist/schema/SchemaEnumPropertyItem.vue.js.map +1 -1
  17. package/dist/schema/SchemaEnumPropertyItem.vue.script.js +2 -2
  18. package/dist/schema/SchemaEnumPropertyItem.vue.script.js.map +1 -1
  19. package/dist/schema/SchemaProperty.vue.d.ts +1 -1
  20. package/dist/schema/SchemaProperty.vue.d.ts.map +1 -1
  21. package/dist/schema/SchemaProperty.vue.js +1 -1
  22. package/dist/schema/SchemaProperty.vue.js.map +1 -1
  23. package/dist/schema/SchemaProperty.vue.script.js +179 -167
  24. package/dist/schema/SchemaProperty.vue.script.js.map +1 -1
  25. package/dist/schema/SchemaPropertyHeading.vue.d.ts +5 -3
  26. package/dist/schema/SchemaPropertyHeading.vue.d.ts.map +1 -1
  27. package/dist/schema/SchemaPropertyHeading.vue.js +1 -1
  28. package/dist/schema/SchemaPropertyHeading.vue.js.map +1 -1
  29. package/dist/schema/SchemaPropertyHeading.vue.script.js +122 -117
  30. package/dist/schema/SchemaPropertyHeading.vue.script.js.map +1 -1
  31. package/dist/schema/SchemaPropertyPattern.vue.js +1 -1
  32. package/dist/schema/SchemaPropertyPattern.vue.js.map +1 -1
  33. package/dist/schema/SchemaPropertyPattern.vue.script.js +1 -1
  34. package/dist/schema/SchemaPropertyPattern.vue.script.js.map +1 -1
  35. package/dist/schema/discriminator-metadata.d.ts +13 -0
  36. package/dist/schema/discriminator-metadata.d.ts.map +1 -0
  37. package/dist/schema/discriminator-metadata.js +6 -0
  38. package/dist/schema/discriminator-metadata.js.map +1 -0
  39. package/dist/schema/helpers/get-compositions-to-render.d.ts +3 -1
  40. package/dist/schema/helpers/get-compositions-to-render.d.ts.map +1 -1
  41. package/dist/schema/helpers/get-compositions-to-render.js +25 -24
  42. package/dist/schema/helpers/get-compositions-to-render.js.map +1 -1
  43. package/dist/schema/helpers/get-property-description.d.ts +6 -3
  44. package/dist/schema/helpers/get-property-description.d.ts.map +1 -1
  45. package/dist/schema/helpers/get-property-description.js +10 -10
  46. package/dist/schema/helpers/get-property-description.js.map +1 -1
  47. package/dist/schema/helpers/optimize-value-for-display.d.ts.map +1 -1
  48. package/dist/schema/helpers/optimize-value-for-display.js +34 -33
  49. package/dist/schema/helpers/optimize-value-for-display.js.map +1 -1
  50. package/dist/schema/index.d.ts +2 -0
  51. package/dist/schema/index.d.ts.map +1 -1
  52. package/dist/schema/index.js +13 -11
  53. package/dist/schema/localization/index.d.ts +11 -1
  54. package/dist/schema/localization/index.d.ts.map +1 -1
  55. package/dist/schema/localization/locales/ar.d.ts +10 -0
  56. package/dist/schema/localization/locales/ar.d.ts.map +1 -1
  57. package/dist/schema/localization/locales/ar.js +11 -1
  58. package/dist/schema/localization/locales/ar.js.map +1 -1
  59. package/dist/schema/localization/locales/de.d.ts +10 -0
  60. package/dist/schema/localization/locales/de.d.ts.map +1 -1
  61. package/dist/schema/localization/locales/de.js +11 -1
  62. package/dist/schema/localization/locales/de.js.map +1 -1
  63. package/dist/schema/localization/locales/en.d.ts +10 -0
  64. package/dist/schema/localization/locales/en.d.ts.map +1 -1
  65. package/dist/schema/localization/locales/en.js +11 -1
  66. package/dist/schema/localization/locales/en.js.map +1 -1
  67. package/dist/schema/localization/locales/es.d.ts +10 -0
  68. package/dist/schema/localization/locales/es.d.ts.map +1 -1
  69. package/dist/schema/localization/locales/es.js +11 -1
  70. package/dist/schema/localization/locales/es.js.map +1 -1
  71. package/dist/schema/localization/locales/fr.d.ts +10 -0
  72. package/dist/schema/localization/locales/fr.d.ts.map +1 -1
  73. package/dist/schema/localization/locales/fr.js +11 -1
  74. package/dist/schema/localization/locales/fr.js.map +1 -1
  75. package/dist/schema/localization/locales/pt.d.ts +10 -0
  76. package/dist/schema/localization/locales/pt.d.ts.map +1 -1
  77. package/dist/schema/localization/locales/pt.js +11 -1
  78. package/dist/schema/localization/locales/pt.js.map +1 -1
  79. package/dist/schema/localization/locales/ru.d.ts +10 -0
  80. package/dist/schema/localization/locales/ru.d.ts.map +1 -1
  81. package/dist/schema/localization/locales/ru.js +11 -1
  82. package/dist/schema/localization/locales/ru.js.map +1 -1
  83. package/dist/schema/localization/locales/zh-cn.d.ts +10 -0
  84. package/dist/schema/localization/locales/zh-cn.d.ts.map +1 -1
  85. package/dist/schema/localization/locales/zh-cn.js +11 -1
  86. package/dist/schema/localization/locales/zh-cn.js.map +1 -1
  87. package/dist/schema/localization/locales/zh-tw.d.ts +10 -0
  88. package/dist/schema/localization/locales/zh-tw.d.ts.map +1 -1
  89. package/dist/schema/localization/locales/zh-tw.js +11 -1
  90. package/dist/schema/localization/locales/zh-tw.js.map +1 -1
  91. package/dist/schema/localization/translations.d.ts +90 -0
  92. package/dist/schema/localization/translations.d.ts.map +1 -1
  93. package/dist/shared/ExternalDocs.vue.d.ts +9 -0
  94. package/dist/shared/ExternalDocs.vue.d.ts.map +1 -0
  95. package/dist/shared/ExternalDocs.vue.js +7 -0
  96. package/dist/shared/ExternalDocs.vue.js.map +1 -0
  97. package/dist/shared/ExternalDocs.vue.script.js +46 -0
  98. package/dist/shared/ExternalDocs.vue.script.js.map +1 -0
  99. package/dist/shared/index.d.ts +1 -0
  100. package/dist/shared/index.d.ts.map +1 -1
  101. package/dist/shared/index.js +4 -3
  102. package/dist/style.css +55 -10
  103. package/dist/vue-styles.css +1 -1
  104. package/package.json +10 -10
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # @scalar/blocks
2
2
 
3
+ ## 0.5.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#10597](https://github.com/scalar/scalar/pull/10597): Render AsyncAPI string discriminators with inherited schema variants and effective discriminator values.
8
+ - [#10530](https://github.com/scalar/scalar/pull/10530): Render AsyncAPI external documentation on servers, channels, operations, messages, tags, and schemas, with referenced objects and descriptions, using the existing OpenAPI link presentation.
9
+
10
+ Keep AsyncAPI messages searchable when navigation renders them beneath operations.
11
+
12
+ - [#10599](https://github.com/scalar/scalar/pull/10599): Preserve recursive schemas when generating request bodies, code samples, and response examples instead of replacing recursion points with null or empty arrays.
13
+ - [#10640](https://github.com/scalar/scalar/pull/10640): Translate the built-in descriptions of integer and string formats (`int32`, `date-time`, `binary` and others) into the configured locale.
14
+ - [#10614](https://github.com/scalar/scalar/pull/10614): Clean up lint warnings while preserving runtime behavior, and document intentional schema and type syntax.
15
+
3
16
  ## 0.5.2
4
17
 
5
18
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"process-body.d.ts","sourceRoot":"","sources":["../../../../src/code-example/helpers/operation-to-har/process-body.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAEV,iBAAiB,EAElB,MAAM,8DAA8D,CAAA;AACrE,OAAO,KAAK,EAAS,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAE7D,KAAK,gBAAgB,GAAG,IAAI,CAC1B,mBAAmB,EACnB,aAAa,GAAG,SAAS,GAAG,iCAAiC,GAAG,gBAAgB,CACjF,GAAG;IACF,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AA0LD;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,yFAMzB,gBAAgB,KAAG,QAAQ,GAAG,SAoIhC,CAAA"}
1
+ {"version":3,"file":"process-body.d.ts","sourceRoot":"","sources":["../../../../src/code-example/helpers/operation-to-har/process-body.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAEV,iBAAiB,EAElB,MAAM,8DAA8D,CAAA;AACrE,OAAO,KAAK,EAAS,QAAQ,EAAE,MAAM,YAAY,CAAA;AAEjD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAA;AAE7D,KAAK,gBAAgB,GAAG,IAAI,CAC1B,mBAAmB,EACnB,aAAa,GAAG,SAAS,GAAG,iCAAiC,GAAG,gBAAgB,CACjF,GAAG;IACF,WAAW,EAAE,iBAAiB,CAAA;CAC/B,CAAA;AA0LD;;;GAGG;AACH,eAAO,MAAM,WAAW,GAAI,yFAMzB,gBAAgB,KAAG,QAAQ,GAAG,SAmIhC,CAAA"}
@@ -1,9 +1,9 @@
1
- import { getResolvedRefDeep as e } from "@scalar/workspace-store/helpers/get-resolved-ref-deep";
2
- import { getResolvedRef as t, mergeSiblingReferences as n } from "@scalar/workspace-store/helpers/get-resolved-ref";
3
- import { buildRequestBody as r, coerceLeafValueToSchemaType as i, getExample as a, getExampleFromBody as o, getExampleFromSchema as s, needsMultipartEncoding as c, resolveLeafSchema as l, serializeFormPropertyWithEncoding as u, serializeMultipartArray as d, serializeMultipartBody as f } from "@scalar/workspace-store/request-example";
4
- import { isXmlMediaType as p } from "@scalar/helpers/http/is-xml-media-type";
5
- import { getExampleValue as m, getExplicitExampleText as h } from "@scalar/workspace-store/helpers/get-example-value";
6
- import { serializeStreamExample as g } from "@scalar/workspace-store/helpers/serialize-stream-example";
1
+ import { getResolvedRef as e, mergeSiblingReferences as t } from "@scalar/workspace-store/helpers/get-resolved-ref";
2
+ import { buildRequestBody as n, coerceLeafValueToSchemaType as r, getExample as i, getExampleFromBody as a, getExampleFromSchema as o, needsMultipartEncoding as s, resolveLeafSchema as c, serializeFormPropertyWithEncoding as l, serializeMultipartArray as u, serializeMultipartBody as d } from "@scalar/workspace-store/request-example";
3
+ import { isXmlMediaType as f } from "@scalar/helpers/http/is-xml-media-type";
4
+ import { getExampleValue as p, getExplicitExampleText as m } from "@scalar/workspace-store/helpers/get-example-value";
5
+ import { serializeStreamExample as h } from "@scalar/workspace-store/helpers/serialize-stream-example";
6
+ import { snapshotSchema as g } from "@scalar/workspace-store/helpers/snapshot-schema";
7
7
  import { unpackProxyObject as _ } from "@scalar/workspace-store/helpers/unpack-proxy";
8
8
  //#region src/code-example/helpers/operation-to-har/process-body.ts
9
9
  var v = (e, t, n) => ({
@@ -11,13 +11,13 @@ var v = (e, t, n) => ({
11
11
  value: `@${t}`,
12
12
  fileName: t,
13
13
  ...n ? { contentType: n } : {}
14
- }), y = (e) => !!e && "type" in e && e.type === "string" && "format" in e && e.format === "binary", b = (e, t) => typeof e == "string" && e.startsWith("@") && y(t) ? e.slice(1) : void 0, x = (e, t, n, r = !1, a) => {
14
+ }), y = (e) => !!e && "type" in e && e.type === "string" && "format" in e && e.format === "binary", b = (e, t) => typeof e == "string" && e.startsWith("@") && y(t) ? e.slice(1) : void 0, x = (e, t, n, i = !1, a) => {
15
15
  let o = [], s = Array.isArray(e) ? e.filter((e) => !e.isDisabled).map((e) => [String(e.name), e.value]) : Object.entries(e);
16
- for (let [c, f] of s) {
16
+ for (let [d, f] of s) {
17
17
  if (f == null) continue;
18
- let s = n ? void 0 : t?.[c];
19
- if (r && !n) {
20
- let t = Array.isArray(e) ? i(f, l(a, [c])) : f, n = d(c, Array.isArray(t) ? t : f, s);
18
+ let s = n ? void 0 : t?.[d];
19
+ if (i && !n) {
20
+ let t = Array.isArray(e) ? r(f, c(a, [d])) : f, n = u(d, Array.isArray(t) ? t : f, s);
21
21
  if (n) {
22
22
  for (let e of n) {
23
23
  if (e.value instanceof File) {
@@ -33,54 +33,54 @@ var v = (e, t, n) => ({
33
33
  continue;
34
34
  }
35
35
  }
36
- let p = s && (s.style !== void 0 || s.explode !== void 0 || s.allowReserved !== void 0), m = p || !r ? void 0 : s?.contentType, h = r && !n ? b(f, l(a, [c])) : void 0, g = n ? null : u(c, f, s);
36
+ let p = s && (s.style !== void 0 || s.explode !== void 0 || s.allowReserved !== void 0), m = p || !i ? void 0 : s?.contentType, h = i && !n ? b(f, c(a, [d])) : void 0, g = n ? null : l(d, f, s);
37
37
  if (g) for (let e of g) o.push({
38
38
  name: e.key,
39
39
  value: e.value
40
40
  });
41
41
  else if (f instanceof File) {
42
42
  let e = _(f);
43
- o.push(v(c, e.name, m ?? (r ? e.type : void 0)));
44
- } else if (h !== void 0) o.push(v(c, h, m));
43
+ o.push(v(d, e.name, m ?? (i ? e.type : void 0)));
44
+ } else if (h !== void 0) o.push(v(d, h, m));
45
45
  else if (m && typeof f == "object") o.push({
46
- name: c,
46
+ name: d,
47
47
  value: JSON.stringify(_(f)),
48
48
  contentType: m
49
49
  });
50
- else if (r && !n && !p && typeof f == "object" && !Array.isArray(f)) o.push({
51
- name: c,
50
+ else if (i && !n && !p && typeof f == "object" && !Array.isArray(f)) o.push({
51
+ name: d,
52
52
  value: JSON.stringify(_(f)),
53
53
  contentType: "application/json"
54
54
  });
55
55
  else if (Array.isArray(f)) for (let e of f) if (e instanceof File) {
56
56
  let t = _(e);
57
- o.push(v(c, t.name, r ? t.type : void 0));
57
+ o.push(v(d, t.name, i ? t.type : void 0));
58
58
  } else o.push({
59
- name: c,
59
+ name: d,
60
60
  value: String(e)
61
61
  });
62
62
  else if (typeof f == "object") {
63
- let e = x(f, void 0, c);
63
+ let e = x(f, void 0, d);
64
64
  for (let t of e) o.push({
65
- name: `${c}.${t.name}`,
65
+ name: `${d}.${t.name}`,
66
66
  value: t.value
67
67
  });
68
68
  } else o.push({
69
- name: c,
69
+ name: d,
70
70
  value: String(f),
71
71
  ...m ? { contentType: m } : {}
72
72
  });
73
73
  }
74
74
  return o;
75
- }, S = ({ requestBody: i, contentType: l, example: u, openapiVersion: d, requestBodyCompositionSelection: v }) => {
76
- let y = l || Object.keys(i.content)[0] || "", b = y === "other" ? "" : y, S = (e) => `@${_(e).name || "filename"}`, C = i.content[y]?.encoding, w = i.content[y];
77
- if (w && c(y, w)) {
78
- let e = u ?? Object.keys(w.examples ?? {})[0] ?? "default", t = r({
79
- ...i,
75
+ }, S = ({ requestBody: r, contentType: c, example: l, openapiVersion: u, requestBodyCompositionSelection: v }) => {
76
+ let y = c || Object.keys(r.content)[0] || "", b = y === "other" ? "" : y, S = (e) => `@${_(e).name || "filename"}`, C = r.content[y]?.encoding, w = r.content[y];
77
+ if (w && s(y, w)) {
78
+ let e = l ?? Object.keys(w.examples ?? {})[0] ?? "default", t = n({
79
+ ...r,
80
80
  "x-scalar-selected-content-type": { [e]: y }
81
81
  }, e, v);
82
82
  if (t?.mode === "multipart") {
83
- let e = f(t.value, t.contentType);
83
+ let e = d(t.value, t.contentType);
84
84
  return {
85
85
  mimeType: e.contentType,
86
86
  text: e.chunks.map((e) => e instanceof File ? S(e) : e instanceof Blob ? "BINARY" : String(e)).join("")
@@ -88,45 +88,45 @@ var v = (e, t, n) => ({
88
88
  }
89
89
  }
90
90
  let T = y === "multipart/form-data" || y === "application/x-www-form-urlencoded";
91
- if (p(y)) {
92
- let e = o(i, y, u ?? "", v, d);
91
+ if (f(y)) {
92
+ let e = a(r, y, l ?? "", v, u);
93
93
  return e ? {
94
94
  mimeType: b,
95
95
  text: e.value
96
96
  } : void 0;
97
97
  }
98
- let E = m(a(i, u, l)), D = h(E, y);
98
+ let E = p(i(r, l, c)), D = m(E, y);
99
99
  if (D !== void 0) return {
100
100
  mimeType: b,
101
101
  text: D
102
102
  };
103
103
  let O = E?.value;
104
104
  if (O !== void 0) {
105
- let e = typeof O == "object" && O ? _(O) : O;
106
- return T && typeof e == "object" && e ? {
105
+ let n = typeof O == "object" && O ? _(O) : O;
106
+ return T && typeof n == "object" && n ? {
107
107
  mimeType: b,
108
- params: x(e, C, void 0, y === "multipart/form-data", t(i.content[y]?.schema, n))
109
- } : e instanceof File ? {
108
+ params: x(n, C, void 0, y === "multipart/form-data", e(r.content[y]?.schema, t))
109
+ } : n instanceof File ? {
110
110
  mimeType: b,
111
- text: S(e)
111
+ text: S(n)
112
112
  } : {
113
113
  mimeType: b,
114
- text: typeof e == "string" ? e : g(e, y, !1) ?? JSON.stringify(e)
114
+ text: typeof n == "string" ? n : h(n, y, !1) ?? JSON.stringify(n)
115
115
  };
116
116
  }
117
- let k = i.content[y], A = t(k?.schema ?? k?.itemSchema);
117
+ let k = r.content[y], A = e(k?.schema ?? k?.itemSchema);
118
118
  if (A !== void 0) {
119
- let t = e(A), n = s(t, {
119
+ let e = o(g(A), {
120
120
  compositionSelection: v,
121
121
  mode: "write",
122
122
  binaryAsFile: y === "multipart/form-data"
123
123
  }, { schemaPath: ["requestBody"] });
124
- if (n !== void 0) return T && typeof n == "object" && n ? {
124
+ if (e !== void 0) return T && typeof e == "object" && e ? {
125
125
  mimeType: b,
126
- params: x(n, C, void 0, y === "multipart/form-data", t)
126
+ params: x(e, C, void 0, y === "multipart/form-data", A)
127
127
  } : {
128
128
  mimeType: b,
129
- text: g(n, y, k?.schema === void 0) ?? (typeof n == "string" ? n : JSON.stringify(n))
129
+ text: h(e, y, k?.schema === void 0) ?? (typeof e == "string" ? e : JSON.stringify(e))
130
130
  };
131
131
  }
132
132
  };
@@ -1 +1 @@
1
- {"version":3,"file":"process-body.js","names":[],"sources":["../../../../src/code-example/helpers/operation-to-har/process-body.ts"],"sourcesContent":["import { isXmlMediaType } from '@scalar/helpers/http/is-xml-media-type'\nimport { getExampleValue, getExplicitExampleText } from '@scalar/workspace-store/helpers/get-example-value'\nimport { getResolvedRef, mergeSiblingReferences } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { getResolvedRefDeep } from '@scalar/workspace-store/helpers/get-resolved-ref-deep'\nimport { serializeStreamExample } from '@scalar/workspace-store/helpers/serialize-stream-example'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport {\n buildRequestBody,\n coerceLeafValueToSchemaType,\n getExample,\n getExampleFromBody,\n getExampleFromSchema,\n needsMultipartEncoding,\n resolveLeafSchema,\n serializeFormPropertyWithEncoding,\n serializeMultipartArray,\n serializeMultipartBody,\n} from '@scalar/workspace-store/request-example'\nimport type {\n MediaTypeObject,\n RequestBodyObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport type { Param, PostData } from 'har-format'\n\nimport type { OperationToHarProps } from './operation-to-har'\n\ntype ProcessBodyProps = Pick<\n OperationToHarProps,\n 'contentType' | 'example' | 'requestBodyCompositionSelection' | 'openapiVersion'\n> & {\n requestBody: RequestBodyObject\n}\n\ntype MultipartEncodingMap = MediaTypeObject['encoding']\n\n/**\n * Builds a HAR param for an uploaded file. `fileName` is what snippet generators read to emit real\n * file handling (for example `files=` in Python or `new Blob` in fetch). `value` keeps the\n * `@filename` placeholder for consumers that only read the text value.\n */\nconst buildFileParam = (name: string, fileName: string, contentType?: string): Param => ({\n name,\n value: `@${fileName}`,\n fileName,\n ...(contentType ? { contentType } : {}),\n})\n\n/** True when the schema describes a binary file (`type: string, format: binary`). */\nconst isBinarySchema = (schema: SchemaObject | undefined): boolean =>\n !!schema && 'type' in schema && schema.type === 'string' && 'format' in schema && schema.format === 'binary'\n\n/**\n * Example generation turns a binary property into the `@filename` placeholder string.\n * Use the schema to tell that apart from a normal text field that happens to start with `@`.\n */\nconst getBinaryPlaceholderFileName = (value: unknown, schema: SchemaObject | undefined): string | undefined =>\n typeof value === 'string' && value.startsWith('@') && isBinarySchema(schema) ? value.slice(1) : undefined\n\n/**\n * Converts a form-data body into HAR `Param[]` entries for `multipart/form-data`\n * and `application/x-www-form-urlencoded` requests.\n *\n * Per OpenAPI 3.1.x Encoding Object, each property's serialization is governed\n * by an optional Encoding entry. When `style` / `explode` / `allowReserved` is\n * set, the value is serialized RFC6570-style and `contentType` is ignored.\n * Multipart arrays apply the encoding to each item and repeat the property name.\n * Object items default to JSON, and uploaded files retain their filename references.\n *\n * @param obj - The form-data payload, either an object keyed by property name\n * or a HAR-style `{ name, value, isDisabled }[]` array.\n * @param encoding - The `encoding` map from the Media Type Object, if any.\n * Used only at the top level (`parentKey` undefined).\n * @param parentKey - When set, we are flattening a nested object inside another\n * property; encoding is ignored and keys are joined with `.` (legacy default).\n * @param isMultipart - True for `multipart/form-data`. Gates the spec defaults\n * for object properties and array items. Urlencoded bodies retain their existing\n * serialization and flattening behavior.\n */\nconst objectToFormParams = (\n obj: object | { name: string; value: unknown; isDisabled: boolean }[],\n encoding?: MultipartEncodingMap,\n parentKey?: string,\n isMultipart = false,\n schema?: SchemaObject,\n): Param[] => {\n const params: Param[] = []\n\n /** Ensure we do not include disabled items */\n const entries: [string, unknown][] = Array.isArray(obj)\n ? obj.filter((item) => !item.isDisabled).map((item) => [String(item.name), item.value])\n : Object.entries(obj)\n\n for (const [key, value] of entries) {\n if (value === undefined || value === null) {\n continue\n }\n\n const partEncoding = parentKey ? undefined : encoding?.[key]\n\n if (isMultipart && !parentKey) {\n const restored = Array.isArray(obj) ? coerceLeafValueToSchemaType(value, resolveLeafSchema(schema, [key])) : value\n const arrayParts = serializeMultipartArray(key, Array.isArray(restored) ? restored : value, partEncoding)\n if (arrayParts) {\n for (const part of arrayParts) {\n if (part.value instanceof File) {\n params.push(buildFileParam(part.key, part.value.name, part.contentType ?? part.value.type))\n continue\n }\n params.push({\n name: part.key,\n value: part.value,\n ...(part.contentType ? { contentType: part.contentType } : {}),\n })\n }\n continue\n }\n }\n /**\n * Per OpenAPI 3.1.1: when style, explode, or allowReserved is explicitly set on the\n * encoding entry, contentType (implicit or explicit) is ignored and the value is\n * serialized as if it were a query-style parameter.\n */\n const hasFormStyle =\n partEncoding &&\n (partEncoding.style !== undefined ||\n partEncoding.explode !== undefined ||\n partEncoding.allowReserved !== undefined)\n /**\n * Per OAS 3.1.x Encoding Object: `contentType` SHALL be ignored if the request body\n * media type is not a multipart. For `application/x-www-form-urlencoded` we still\n * honor `style`/`explode`/`allowReserved` (handled above), but a `contentType`-only\n * entry has no effect — values fall through to the dotted-key flattening default.\n */\n const explicitContentType = hasFormStyle || !isMultipart ? undefined : partEncoding?.contentType\n\n /**\n * When the encoding sets style/explode/allowReserved, serialize the value RFC6570-style\n * (bracket/exploded notation) and ignore contentType. See `serializeFormPropertyWithEncoding`\n * for the per-style rules; it returns null for primitives, Files, and arrays of Files, which\n * then fall through to the dedicated branches below. HAR represents multipart and urlencoded\n * the same way via `PostData.params`, so the resulting parts work for both.\n */\n const binaryPlaceholderFileName =\n isMultipart && !parentKey ? getBinaryPlaceholderFileName(value, resolveLeafSchema(schema, [key])) : undefined\n const styleParams = parentKey ? null : serializeFormPropertyWithEncoding(key, value, partEncoding)\n if (styleParams) {\n for (const param of styleParams) {\n params.push({ name: param.key, value: param.value })\n }\n } else if (value instanceof File) {\n /**\n * File values render as `@filename` references, the conventional cURL syntax for an\n * attached file. Picked up by snippet renderers downstream (e.g. `--form 'x=@file.png'`).\n */\n const file = unpackProxyObject(value)\n params.push(buildFileParam(key, file.name, explicitContentType ?? (isMultipart ? file.type : undefined)))\n } else if (binaryPlaceholderFileName !== undefined) {\n /** A binary property filled in by example generation, so it is a file and not a text field. */\n params.push(buildFileParam(key, binaryPlaceholderFileName, explicitContentType))\n } else if (explicitContentType && typeof value === 'object') {\n /**\n * Per OAS 3.1.x Encoding Object: an explicit `encoding[key].contentType` on a\n * complex value overrides the default and emits a single part containing the value\n * JSON-stringified into that media type. Only reachable when style/explode/allowReserved\n * are unset (otherwise contentType is ignored — see the style branch above).\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: explicitContentType,\n })\n } else if (isMultipart && !parentKey && !hasFormStyle && typeof value === 'object' && !Array.isArray(value)) {\n /**\n * Per OpenAPI 3.x: a top-level multipart property whose value is an object (and not a File)\n * defaults to a single part encoded as application/json, rather than being flattened\n * into multiple parts with dotted keys.\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: 'application/json',\n })\n } else if (Array.isArray(value)) {\n for (const item of value) {\n if (item instanceof File) {\n const file = unpackProxyObject(item)\n params.push(buildFileParam(key, file.name, isMultipart ? file.type : undefined))\n } else {\n params.push({ name: key, value: String(item) })\n }\n }\n } else if (typeof value === 'object') {\n /**\n * Legacy fallback: flatten nested objects into dotted-key parts. Reached when the\n * multipart JSON-default branches above don't apply — i.e. either inside a recursive\n * call (`parentKey` set) or on `application/x-www-form-urlencoded` bodies without an\n * explicit encoding entry. Strict OAS 3.1.x would use `style: form, explode: true` as\n * the urlencoded default (inner keys become top-level params); we keep dotted keys for\n * backwards compatibility with consumers that already parse this shape.\n */\n const nestedParams = objectToFormParams(value, undefined, key)\n\n for (const param of nestedParams) {\n params.push({ name: `${key}.${param.name}`, value: param.value })\n }\n } else {\n params.push({\n name: key,\n value: String(value),\n ...(explicitContentType ? { contentType: explicitContentType } : {}),\n })\n }\n }\n\n return params\n}\n\n/**\n * Processes the request body and returns the processed data\n * Returns undefined if no example is found\n */\nexport const processBody = ({\n requestBody,\n contentType,\n example,\n openapiVersion,\n requestBodyCompositionSelection,\n}: ProcessBodyProps): PostData | undefined => {\n const _contentType = contentType || Object.keys(requestBody.content)[0] || ''\n /** Empty when \"Other\" is selected so snippets do not inject `Content-Type: other`. */\n const harMimeType = _contentType === 'other' ? '' : _contentType\n const formatBinaryFile = (file: File) => {\n const unwrappedFile = unpackProxyObject(file)\n return `@${unwrappedFile.name || 'filename'}`\n }\n const encoding = requestBody.content[_contentType]?.encoding\n\n const media = requestBody.content[_contentType]\n if (media && needsMultipartEncoding(_contentType, media)) {\n const exampleName = example ?? Object.keys(media.examples ?? {})[0] ?? 'default'\n const body = buildRequestBody(\n { ...requestBody, 'x-scalar-selected-content-type': { [exampleName]: _contentType } },\n exampleName,\n requestBodyCompositionSelection,\n )\n if (body?.mode === 'multipart') {\n const encoded = serializeMultipartBody(body.value, body.contentType)\n return {\n mimeType: encoded.contentType,\n // HAR text cannot embed file bytes synchronously. Keep visible file placeholders.\n text: encoded.chunks\n .map((chunk) => {\n if (chunk instanceof File) {\n return formatBinaryFile(chunk)\n }\n return chunk instanceof Blob ? 'BINARY' : String(chunk)\n })\n .join(''),\n }\n }\n }\n\n // Check if this is a form data content type\n const isFormData = _contentType === 'multipart/form-data' || _contentType === 'application/x-www-form-urlencoded'\n\n // Check if this is an XML content type\n if (isXmlMediaType(_contentType)) {\n const xmlExample = getExampleFromBody(\n requestBody,\n _contentType,\n example ?? '',\n requestBodyCompositionSelection,\n openapiVersion,\n )\n return xmlExample ? { mimeType: harMimeType, text: xmlExample.value as string } : undefined\n }\n\n // Get the example value\n const selected = getExampleValue(getExample(requestBody, example, contentType))\n const explicitText = getExplicitExampleText(selected, _contentType)\n if (explicitText !== undefined) {\n return { mimeType: harMimeType, text: explicitText }\n }\n const _example = selected?.value\n\n // Return the provided top level example\n if (typeof _example !== 'undefined') {\n const exampleValue = _example !== null && typeof _example === 'object' ? unpackProxyObject(_example) : _example\n\n if (isFormData && typeof exampleValue === 'object' && exampleValue !== null) {\n return {\n mimeType: harMimeType,\n params: objectToFormParams(\n exampleValue,\n encoding,\n undefined,\n _contentType === 'multipart/form-data',\n getResolvedRef(requestBody.content[_contentType]?.schema, mergeSiblingReferences),\n ),\n }\n }\n\n if (exampleValue instanceof File) {\n return {\n mimeType: harMimeType,\n text: formatBinaryFile(exampleValue),\n }\n }\n\n return {\n mimeType: harMimeType,\n text:\n typeof exampleValue === 'string'\n ? exampleValue\n : (serializeStreamExample(exampleValue, _contentType, false) ?? JSON.stringify(exampleValue)),\n }\n }\n\n // Try to extract examples from the schema\n const mediaType = requestBody.content[_contentType]\n const contentSchema = getResolvedRef(mediaType?.schema ?? mediaType?.itemSchema)\n if (typeof contentSchema !== 'undefined') {\n const resolvedContentSchema = getResolvedRefDeep(contentSchema) as SchemaObject\n const extractedExample = getExampleFromSchema(\n resolvedContentSchema,\n {\n compositionSelection: requestBodyCompositionSelection,\n mode: 'write',\n binaryAsFile: _contentType === 'multipart/form-data',\n },\n {\n schemaPath: ['requestBody'],\n },\n )\n\n if (extractedExample !== undefined) {\n if (isFormData && typeof extractedExample === 'object' && extractedExample !== null) {\n return {\n mimeType: harMimeType,\n params: objectToFormParams(\n extractedExample,\n encoding,\n undefined,\n _contentType === 'multipart/form-data',\n resolvedContentSchema,\n ),\n }\n }\n\n return {\n mimeType: harMimeType,\n text:\n serializeStreamExample(extractedExample, _contentType, mediaType?.schema === undefined) ??\n (typeof extractedExample === 'string' ? extractedExample : JSON.stringify(extractedExample)),\n }\n }\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;AAyCA,IAAM,KAAkB,GAAc,GAAkB,OAAiC;CACvF;CACA,OAAO,IAAI;CACX;CACA,GAAI,IAAc,EAAE,eAAY,IAAI,CAAC;AACvC,IAGM,KAAkB,MACtB,CAAC,CAAC,KAAU,UAAU,KAAU,EAAO,SAAS,YAAY,YAAY,KAAU,EAAO,WAAW,UAMhG,KAAgC,GAAgB,MACpD,OAAO,KAAU,YAAY,EAAM,WAAW,GAAG,KAAK,EAAe,CAAM,IAAI,EAAM,MAAM,CAAC,IAAI,KAAA,GAsB5F,KACJ,GACA,GACA,GACA,IAAc,IACd,MACY;CACZ,IAAM,IAAkB,CAAC,GAGnB,IAA+B,MAAM,QAAQ,CAAG,IAClD,EAAI,QAAQ,MAAS,CAAC,EAAK,UAAU,CAAC,CAAC,KAAK,MAAS,CAAC,OAAO,EAAK,IAAI,GAAG,EAAK,KAAK,CAAC,IACpF,OAAO,QAAQ,CAAG;CAEtB,KAAK,IAAM,CAAC,GAAK,MAAU,GAAS;EAClC,IAAI,KAAiC,MACnC;EAGF,IAAM,IAAe,IAAY,KAAA,IAAY,IAAW;EAExD,IAAI,KAAe,CAAC,GAAW;GAC7B,IAAM,IA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vB,GACA;GACE,sBAAsB;GACtB,MAAM;GACN,cAAc,MAAiB;EACjC,GACA,EACE,YAAY,CAAC,aAAa,EAC5B,CACF;EAEA,IAAI,MAAqB,KAAA,GAcvB,OAbI,KAAc,OAAO,KAAqB,YAAY,IACjD;GACL,UAAU;GACV,QAAQ,EACN,GACA,GACA,KAAA,GACA,MAAiB,uBACjB,CACF;EACF,IAGK;GACL,UAAU;GACV,MACE,EAAuB,GAAkB,GAAc,GAAW,WAAW,KAAA,CAAS,MACrF,OAAO,KAAqB,WAAW,IAAmB,KAAK,UAAU,CAAgB;EAC9F;CAEJ;AAGF"}
1
+ {"version":3,"file":"process-body.js","names":[],"sources":["../../../../src/code-example/helpers/operation-to-har/process-body.ts"],"sourcesContent":["import { isXmlMediaType } from '@scalar/helpers/http/is-xml-media-type'\nimport { getExampleValue, getExplicitExampleText } from '@scalar/workspace-store/helpers/get-example-value'\nimport { getResolvedRef, mergeSiblingReferences } from '@scalar/workspace-store/helpers/get-resolved-ref'\nimport { serializeStreamExample } from '@scalar/workspace-store/helpers/serialize-stream-example'\nimport { snapshotSchema } from '@scalar/workspace-store/helpers/snapshot-schema'\nimport { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy'\nimport {\n buildRequestBody,\n coerceLeafValueToSchemaType,\n getExample,\n getExampleFromBody,\n getExampleFromSchema,\n needsMultipartEncoding,\n resolveLeafSchema,\n serializeFormPropertyWithEncoding,\n serializeMultipartArray,\n serializeMultipartBody,\n} from '@scalar/workspace-store/request-example'\nimport type {\n MediaTypeObject,\n RequestBodyObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport type { Param, PostData } from 'har-format'\n\nimport type { OperationToHarProps } from './operation-to-har'\n\ntype ProcessBodyProps = Pick<\n OperationToHarProps,\n 'contentType' | 'example' | 'requestBodyCompositionSelection' | 'openapiVersion'\n> & {\n requestBody: RequestBodyObject\n}\n\ntype MultipartEncodingMap = MediaTypeObject['encoding']\n\n/**\n * Builds a HAR param for an uploaded file. `fileName` is what snippet generators read to emit real\n * file handling (for example `files=` in Python or `new Blob` in fetch). `value` keeps the\n * `@filename` placeholder for consumers that only read the text value.\n */\nconst buildFileParam = (name: string, fileName: string, contentType?: string): Param => ({\n name,\n value: `@${fileName}`,\n fileName,\n ...(contentType ? { contentType } : {}),\n})\n\n/** True when the schema describes a binary file (`type: string, format: binary`). */\nconst isBinarySchema = (schema: SchemaObject | undefined): boolean =>\n !!schema && 'type' in schema && schema.type === 'string' && 'format' in schema && schema.format === 'binary'\n\n/**\n * Example generation turns a binary property into the `@filename` placeholder string.\n * Use the schema to tell that apart from a normal text field that happens to start with `@`.\n */\nconst getBinaryPlaceholderFileName = (value: unknown, schema: SchemaObject | undefined): string | undefined =>\n typeof value === 'string' && value.startsWith('@') && isBinarySchema(schema) ? value.slice(1) : undefined\n\n/**\n * Converts a form-data body into HAR `Param[]` entries for `multipart/form-data`\n * and `application/x-www-form-urlencoded` requests.\n *\n * Per OpenAPI 3.1.x Encoding Object, each property's serialization is governed\n * by an optional Encoding entry. When `style` / `explode` / `allowReserved` is\n * set, the value is serialized RFC6570-style and `contentType` is ignored.\n * Multipart arrays apply the encoding to each item and repeat the property name.\n * Object items default to JSON, and uploaded files retain their filename references.\n *\n * @param obj - The form-data payload, either an object keyed by property name\n * or a HAR-style `{ name, value, isDisabled }[]` array.\n * @param encoding - The `encoding` map from the Media Type Object, if any.\n * Used only at the top level (`parentKey` undefined).\n * @param parentKey - When set, we are flattening a nested object inside another\n * property; encoding is ignored and keys are joined with `.` (legacy default).\n * @param isMultipart - True for `multipart/form-data`. Gates the spec defaults\n * for object properties and array items. Urlencoded bodies retain their existing\n * serialization and flattening behavior.\n */\nconst objectToFormParams = (\n obj: object | { name: string; value: unknown; isDisabled: boolean }[],\n encoding?: MultipartEncodingMap,\n parentKey?: string,\n isMultipart = false,\n schema?: SchemaObject,\n): Param[] => {\n const params: Param[] = []\n\n /** Ensure we do not include disabled items */\n const entries: [string, unknown][] = Array.isArray(obj)\n ? obj.filter((item) => !item.isDisabled).map((item) => [String(item.name), item.value])\n : Object.entries(obj)\n\n for (const [key, value] of entries) {\n if (value === undefined || value === null) {\n continue\n }\n\n const partEncoding = parentKey ? undefined : encoding?.[key]\n\n if (isMultipart && !parentKey) {\n const restored = Array.isArray(obj) ? coerceLeafValueToSchemaType(value, resolveLeafSchema(schema, [key])) : value\n const arrayParts = serializeMultipartArray(key, Array.isArray(restored) ? restored : value, partEncoding)\n if (arrayParts) {\n for (const part of arrayParts) {\n if (part.value instanceof File) {\n params.push(buildFileParam(part.key, part.value.name, part.contentType ?? part.value.type))\n continue\n }\n params.push({\n name: part.key,\n value: part.value,\n ...(part.contentType ? { contentType: part.contentType } : {}),\n })\n }\n continue\n }\n }\n /**\n * Per OpenAPI 3.1.1: when style, explode, or allowReserved is explicitly set on the\n * encoding entry, contentType (implicit or explicit) is ignored and the value is\n * serialized as if it were a query-style parameter.\n */\n const hasFormStyle =\n partEncoding &&\n (partEncoding.style !== undefined ||\n partEncoding.explode !== undefined ||\n partEncoding.allowReserved !== undefined)\n /**\n * Per OAS 3.1.x Encoding Object: `contentType` SHALL be ignored if the request body\n * media type is not a multipart. For `application/x-www-form-urlencoded` we still\n * honor `style`/`explode`/`allowReserved` (handled above), but a `contentType`-only\n * entry has no effect — values fall through to the dotted-key flattening default.\n */\n const explicitContentType = hasFormStyle || !isMultipart ? undefined : partEncoding?.contentType\n\n /**\n * When the encoding sets style/explode/allowReserved, serialize the value RFC6570-style\n * (bracket/exploded notation) and ignore contentType. See `serializeFormPropertyWithEncoding`\n * for the per-style rules; it returns null for primitives, Files, and arrays of Files, which\n * then fall through to the dedicated branches below. HAR represents multipart and urlencoded\n * the same way via `PostData.params`, so the resulting parts work for both.\n */\n const binaryPlaceholderFileName =\n isMultipart && !parentKey ? getBinaryPlaceholderFileName(value, resolveLeafSchema(schema, [key])) : undefined\n const styleParams = parentKey ? null : serializeFormPropertyWithEncoding(key, value, partEncoding)\n if (styleParams) {\n for (const param of styleParams) {\n params.push({ name: param.key, value: param.value })\n }\n } else if (value instanceof File) {\n /**\n * File values render as `@filename` references, the conventional cURL syntax for an\n * attached file. Picked up by snippet renderers downstream (e.g. `--form 'x=@file.png'`).\n */\n const file = unpackProxyObject(value)\n params.push(buildFileParam(key, file.name, explicitContentType ?? (isMultipart ? file.type : undefined)))\n } else if (binaryPlaceholderFileName !== undefined) {\n /** A binary property filled in by example generation, so it is a file and not a text field. */\n params.push(buildFileParam(key, binaryPlaceholderFileName, explicitContentType))\n } else if (explicitContentType && typeof value === 'object') {\n /**\n * Per OAS 3.1.x Encoding Object: an explicit `encoding[key].contentType` on a\n * complex value overrides the default and emits a single part containing the value\n * JSON-stringified into that media type. Only reachable when style/explode/allowReserved\n * are unset (otherwise contentType is ignored — see the style branch above).\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: explicitContentType,\n })\n } else if (isMultipart && !parentKey && !hasFormStyle && typeof value === 'object' && !Array.isArray(value)) {\n /**\n * Per OpenAPI 3.x: a top-level multipart property whose value is an object (and not a File)\n * defaults to a single part encoded as application/json, rather than being flattened\n * into multiple parts with dotted keys.\n */\n params.push({\n name: key,\n value: JSON.stringify(unpackProxyObject(value)),\n contentType: 'application/json',\n })\n } else if (Array.isArray(value)) {\n for (const item of value) {\n if (item instanceof File) {\n const file = unpackProxyObject(item)\n params.push(buildFileParam(key, file.name, isMultipart ? file.type : undefined))\n } else {\n params.push({ name: key, value: String(item) })\n }\n }\n } else if (typeof value === 'object') {\n /**\n * Legacy fallback: flatten nested objects into dotted-key parts. Reached when the\n * multipart JSON-default branches above don't apply — i.e. either inside a recursive\n * call (`parentKey` set) or on `application/x-www-form-urlencoded` bodies without an\n * explicit encoding entry. Strict OAS 3.1.x would use `style: form, explode: true` as\n * the urlencoded default (inner keys become top-level params); we keep dotted keys for\n * backwards compatibility with consumers that already parse this shape.\n */\n const nestedParams = objectToFormParams(value, undefined, key)\n\n for (const param of nestedParams) {\n params.push({ name: `${key}.${param.name}`, value: param.value })\n }\n } else {\n params.push({\n name: key,\n value: String(value),\n ...(explicitContentType ? { contentType: explicitContentType } : {}),\n })\n }\n }\n\n return params\n}\n\n/**\n * Processes the request body and returns the processed data\n * Returns undefined if no example is found\n */\nexport const processBody = ({\n requestBody,\n contentType,\n example,\n openapiVersion,\n requestBodyCompositionSelection,\n}: ProcessBodyProps): PostData | undefined => {\n const _contentType = contentType || Object.keys(requestBody.content)[0] || ''\n /** Empty when \"Other\" is selected so snippets do not inject `Content-Type: other`. */\n const harMimeType = _contentType === 'other' ? '' : _contentType\n const formatBinaryFile = (file: File) => {\n const unwrappedFile = unpackProxyObject(file)\n return `@${unwrappedFile.name || 'filename'}`\n }\n const encoding = requestBody.content[_contentType]?.encoding\n\n const media = requestBody.content[_contentType]\n if (media && needsMultipartEncoding(_contentType, media)) {\n const exampleName = example ?? Object.keys(media.examples ?? {})[0] ?? 'default'\n const body = buildRequestBody(\n { ...requestBody, 'x-scalar-selected-content-type': { [exampleName]: _contentType } },\n exampleName,\n requestBodyCompositionSelection,\n )\n if (body?.mode === 'multipart') {\n const encoded = serializeMultipartBody(body.value, body.contentType)\n return {\n mimeType: encoded.contentType,\n // HAR text cannot embed file bytes synchronously. Keep visible file placeholders.\n text: encoded.chunks\n .map((chunk) => {\n if (chunk instanceof File) {\n return formatBinaryFile(chunk)\n }\n return chunk instanceof Blob ? 'BINARY' : String(chunk)\n })\n .join(''),\n }\n }\n }\n\n // Check if this is a form data content type\n const isFormData = _contentType === 'multipart/form-data' || _contentType === 'application/x-www-form-urlencoded'\n\n // Check if this is an XML content type\n if (isXmlMediaType(_contentType)) {\n const xmlExample = getExampleFromBody(\n requestBody,\n _contentType,\n example ?? '',\n requestBodyCompositionSelection,\n openapiVersion,\n )\n return xmlExample ? { mimeType: harMimeType, text: xmlExample.value as string } : undefined\n }\n\n // Get the example value\n const selected = getExampleValue(getExample(requestBody, example, contentType))\n const explicitText = getExplicitExampleText(selected, _contentType)\n if (explicitText !== undefined) {\n return { mimeType: harMimeType, text: explicitText }\n }\n const _example = selected?.value\n\n // Return the provided top level example\n if (typeof _example !== 'undefined') {\n const exampleValue = _example !== null && typeof _example === 'object' ? unpackProxyObject(_example) : _example\n\n if (isFormData && typeof exampleValue === 'object' && exampleValue !== null) {\n return {\n mimeType: harMimeType,\n params: objectToFormParams(\n exampleValue,\n encoding,\n undefined,\n _contentType === 'multipart/form-data',\n getResolvedRef(requestBody.content[_contentType]?.schema, mergeSiblingReferences),\n ),\n }\n }\n\n if (exampleValue instanceof File) {\n return {\n mimeType: harMimeType,\n text: formatBinaryFile(exampleValue),\n }\n }\n\n return {\n mimeType: harMimeType,\n text:\n typeof exampleValue === 'string'\n ? exampleValue\n : (serializeStreamExample(exampleValue, _contentType, false) ?? JSON.stringify(exampleValue)),\n }\n }\n\n // Try to extract examples from the schema\n const mediaType = requestBody.content[_contentType]\n const contentSchema = getResolvedRef(mediaType?.schema ?? mediaType?.itemSchema)\n if (typeof contentSchema !== 'undefined') {\n const extractedExample = getExampleFromSchema(\n snapshotSchema(contentSchema),\n {\n compositionSelection: requestBodyCompositionSelection,\n mode: 'write',\n binaryAsFile: _contentType === 'multipart/form-data',\n },\n {\n schemaPath: ['requestBody'],\n },\n )\n\n if (extractedExample !== undefined) {\n if (isFormData && typeof extractedExample === 'object' && extractedExample !== null) {\n return {\n mimeType: harMimeType,\n params: objectToFormParams(\n extractedExample,\n encoding,\n undefined,\n _contentType === 'multipart/form-data',\n contentSchema,\n ),\n }\n }\n\n return {\n mimeType: harMimeType,\n text:\n serializeStreamExample(extractedExample, _contentType, mediaType?.schema === undefined) ??\n (typeof extractedExample === 'string' ? extractedExample : JSON.stringify(extractedExample)),\n }\n }\n }\n\n return undefined\n}\n"],"mappings":";;;;;;;;AAyCA,IAAM,KAAkB,GAAc,GAAkB,OAAiC;CACvF;CACA,OAAO,IAAI;CACX;CACA,GAAI,IAAc,EAAE,eAAY,IAAI,CAAC;AACvC,IA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CAAa;CAErD,IAAM,IAAW,GAAU;CAG3B,IAAW,MAAa,QAAa;EACnC,IAAM,IAAoC,OAAO,KAAa,YAAzC,IAAoD,EAAkB,CAAQ,IAAI;EAsBvG,OApBI,KAAc,OAAO,KAAiB,YAAY,IAC7C;GACL,UAAU;GACV,QAAQ,EACN,GACA,GACA,KAAA,GACA,MAAiB,uBACjB,EAAe,EAAY,QAAQ,EAAa,EAAE,QAAQ,CAAsB,CAClF;EACF,IAGE,aAAwB,OACnB;GACL,UAAU;GACV,MAAM,EAAiB,CAAY;EACrC,IAGK;GACL,UAAU;GACV,MACE,OAAO,KAAiB,WACpB,IACC,EAAuB,GAAc,GAAc,EAAK,KAAK,KAAK,UAAU,CAAY;EACjG;CACF;CAGA,IAAM,IAAY,EAAY,QAAQ,IAChC,IAAgB,EAAe,GAAW,UAAU,GAAW,UAAU;CAC/E,IAAW,MAAkB,QAAa;EACxC,IAAM,IAAmB,EACvB,EAAe,CAAa,GAC5B;GACE,sBAAsB;GACtB,MAAM;GACN,cAAc,MAAiB;EACjC,GACA,EACE,YAAY,CAAC,aAAa,EAC5B,CACF;EAEA,IAAI,MAAqB,KAAA,GAcvB,OAbI,KAAc,OAAO,KAAqB,YAAY,IACjD;GACL,UAAU;GACV,QAAQ,EACN,GACA,GACA,KAAA,GACA,MAAiB,uBACjB,CACF;EACF,IAGK;GACL,UAAU;GACV,MACE,EAAuB,GAAkB,GAAc,GAAW,WAAW,KAAA,CAAS,MACrF,OAAO,KAAqB,WAAW,IAAmB,KAAK,UAAU,CAAgB;EAC9F;CAEJ;AAGF"}
package/dist/constants.js CHANGED
@@ -1,5 +1,5 @@
1
1
  //#region src/constants.ts
2
- var e = typeof OVERRIDE_PACKAGE_VERSION < "u" ? OVERRIDE_PACKAGE_VERSION : "0.5.2";
2
+ var e = typeof OVERRIDE_PACKAGE_VERSION < "u" ? OVERRIDE_PACKAGE_VERSION : "0.5.3";
3
3
  //#endregion
4
4
  export { e as APP_VERSION };
5
5
 
@@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CAAC,EAAE,MAAM,EAAE,CAAA;IAC1B;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,GAAG,oBAAoB,CAAC;AAgrB3B,QAAA,MAAM,YAAY,kSAEhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
@@ -2,7 +2,7 @@ import e from "../_virtual/_plugin-vue_export-helper.js";
2
2
  import t from "./Schema.vue.script.js";
3
3
  /* empty css */
4
4
  //#region src/schema/Schema.vue
5
- var n = /*#__PURE__*/ e(t, [["__scopeId", "data-v-8f822427"]]);
5
+ var n = /*#__PURE__*/ e(t, [["__scopeId", "data-v-86862f28"]]);
6
6
  //#endregion
7
7
  export { n as default };
8
8
 
@@ -1 +1 @@
1
- {"version":3,"file":"Schema.vue.js","names":[],"sources":["../../src/schema/Schema.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { ScalarMarkdown } from '@scalar/components/markdown'\nimport type { WorkspaceEventBus } from '@scalar/workspace-store/events'\nimport { pushDynamicScope } from '@scalar/workspace-store/helpers/dynamic-ref'\nimport { resolve } from '@scalar/workspace-store/resolve'\nimport type {\n DiscriminatorObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { computed, inject, provide, toRef, useId } from 'vue'\n\nimport ScreenReader from '../shared/ScreenReader.vue'\nimport {\n resolveDynamicSchema,\n SCHEMA_DYNAMIC_SCOPE_SYMBOL,\n useDynamicScope,\n} from './helpers/dynamic-scope'\nimport { inferDiscriminatorMappingComposition } from './helpers/get-compositions-to-render'\nimport { isEmptySchemaObject } from './helpers/is-empty-schema-object'\nimport { isOnSchemaTargetPath } from './helpers/is-on-schema-target-path'\nimport { isTypeObject } from './helpers/is-type-object'\nimport { mergeAllOfSchemas } from './helpers/merge-all-of-schemas'\nimport { partitionAllOfCompositions } from './helpers/partition-all-of-compositions'\nimport { SCHEMA_ANCESTORS_SYMBOL } from './helpers/schema-cycle'\nimport {\n SCHEMA_TREE_ROOT_SYMBOL,\n toNodeKey,\n useSchemaExpansion,\n} from './helpers/schema-expansion'\nimport { handleTreeKeydown } from './helpers/schema-keyboard-nav'\nimport { unwrapForRead } from './helpers/unwrap-for-read'\nimport { useLocalization } from './localization'\nimport SchemaComposition from './SchemaComposition.vue'\nimport SchemaGlyphPuck from './SchemaGlyphPuck.vue'\nimport SchemaObjectProperties from './SchemaObjectProperties.vue'\nimport SchemaProperty from './SchemaProperty.vue'\nimport type { SchemaOptions, SchemaRenderingProps } from './types'\n\nconst {\n scrollTargetId,\n expansion: expansionProp,\n schema: schemaProp,\n level = 0,\n depth = 0,\n name,\n compact,\n noncollapsible = false,\n hideHeading,\n hideDescription = false,\n additionalProperties,\n additionalPropertyCount,\n discriminator,\n breadcrumb,\n hideModelNames: hideModelNamesProp = false,\n options,\n schemaContext,\n compositionPath,\n cycleKey,\n} = defineProps<\n {\n schema?: SchemaObject\n /** Track how deep we've gone */\n level?: number\n /**\n * Real nesting depth. Not derived from `level`, whose stride differs per\n * edge (object +2, composition +1, non-object root +0).\n */\n depth?: number\n /* Show as a heading */\n name?: string\n /** A tighter layout with less borders and without a heading */\n compact?: boolean\n /** Shows a toggle to hide/show children */\n noncollapsible?: boolean\n /** Hide the heading */\n hideHeading?: boolean\n /** Hide the schema description */\n hideDescription?: boolean\n /** Show a special one way toggle for additional properties, also has a top border when open */\n additionalProperties?: boolean\n /** Number of request body properties hidden behind the overflow control. */\n additionalPropertyCount?: number\n /** Hide model names in type display */\n hideModelNames?: boolean\n /** Discriminator object */\n discriminator?: DiscriminatorObject\n /** Breadcrumb for the schema */\n breadcrumb?: string[]\n /** Event bus emitting actions */\n eventBus: WorkspaceEventBus | null\n /** Move the options into a single prop so they are easy to pass around */\n options: SchemaOptions\n /** When \"requestBody\", composition dropdown selection is synced with the example snippet */\n schemaContext?: string\n /** Internal path used to sync nested request body compositions with the code sample */\n compositionPath?: string[]\n /**\n * Stable identity of this schema node, derived from its raw (unresolved)\n * value by the parent. Used to detect self-referential cycles. See\n * {@link getCycleKey}.\n */\n cycleKey?: unknown\n } & SchemaRenderingProps\n>()\nconst { translate } = useLocalization()\n\nconst additionalPropertiesLabel = computed((): string => {\n if (additionalPropertyCount === undefined) {\n return translate('schema.showAdditionalProperties')\n }\n return translate(\n additionalPropertyCount === 1\n ? 'schema.showOneMoreProperty'\n : 'schema.showMoreProperties',\n { count: additionalPropertyCount },\n )\n})\n\nconst hideModelNames = computed(\n (): boolean => hideModelNamesProp || !!options.hideModelNames,\n)\n\n/**\n * The dynamic scope inherited from ancestor schema resources.\n *\n * Used to bind JSON Schema 2020-12 `$dynamicRef`s to the active `$dynamicAnchor` while walking the\n * tree. Empty at the root. See {@link useDynamicScope}.\n */\nconst dynamicScope = useDynamicScope()\n\n/**\n * The schema subtree, read through the magic and overrides proxies only.\n *\n * Everything below this point walks the subtree read-only, so the Vue reactive and\n * detect-changes layers are peeled off once here instead of being paid for on every nested\n * property access. See {@link unwrapForRead} for why that is safe and why the other two\n * layers stay. Reactivity on the prop itself is kept: the computed tracks the `schema` prop,\n * so replacing or switching the document still re-renders.\n */\nconst schema = computed((): SchemaObject | undefined =>\n unwrapForRead(schemaProp),\n)\n\n/**\n * The schema this node actually renders.\n *\n * Two normalizations happen here, both no-ops for ordinary schemas:\n * - A top-level `$dynamicRef` is bound to its concrete type via the inherited dynamic scope.\n * - A resource that extends a template through a root `$ref` (JSON Schema 2020-12 `$ref` alongside\n * `$defs`, e.g. a `PaginatedResponse` binding) is merged so its inherited properties render.\n */\nconst resolvedSchema = computed((): SchemaObject | undefined => {\n const value = schema.value\n\n if (!value || typeof value !== 'object') {\n return value\n }\n\n const bound = resolveDynamicSchema(value, dynamicScope)\n return '$ref' in bound ? resolve.schema(bound) : bound\n})\n\n/**\n * Re-provide the dynamic scope grown with this resource so nested `$dynamicRef`s bind here.\n *\n * Built once at setup from the resource's stable identity (like the ancestor set below);\n * `pushDynamicScope` only grows the scope for schemas that can carry a `$dynamicAnchor`.\n *\n * The raw schema is pushed, not the merged {@link resolvedSchema}: merging through `resolve.schema`\n * coerces the node and drops the resolved `$ref-value` from entries inside `$defs`, which\n * `$dynamicAnchor` resolution relies on to dereference the bound type (e.g. `User`).\n */\nconst scopeSchema = schema.value\n ? resolveDynamicSchema(schema.value, dynamicScope)\n : undefined\nprovide(\n SCHEMA_DYNAMIC_SCOPE_SYMBOL,\n scopeSchema ? pushDynamicScope(dynamicScope, scopeSchema) : dynamicScope,\n)\n\n/**\n * Cycle-safe `expandAllSchemaProperties`.\n *\n * We track ancestor schema keys along the current render path. A node is\n * treated as cyclic when its key is already present in the ancestor set, which\n * indicates that rendering has looped back onto a self-referential schema.\n *\n * This lets us default-expand finite branches while stopping automatic\n * expansion only at cycle boundaries, preventing infinite recursion.\n */\nconst ancestors = inject(SCHEMA_ANCESTORS_SYMBOL, undefined)\n\nconst isCyclic = computed(\n (): boolean => cycleKey != null && !!ancestors?.has(cycleKey),\n)\n\n// Re-provide the ancestor set augmented with this node so descendants can\n// detect cycles back to it. Built once at setup; a node's key is stable.\nconst childAncestors = new Set<unknown>(ancestors ?? [])\nif (cycleKey != null) {\n childAncestors.add(cycleKey)\n}\nprovide(SCHEMA_ANCESTORS_SYMBOL, childAncestors)\n\nconst shouldForceExpand = computed(\n (): boolean => !!options.expandAllSchemaProperties && !isCyclic.value,\n)\n\n/**\n * Whether this schema sits on the path to the current anchor/scroll target.\n *\n * Property anchors are dot-joined breadcrumbs, so every disclosure that wraps\n * the target has a breadcrumb that is a prefix of the target id. Opening those\n * disclosures is what makes deep links to collapsed (hidden) properties work\n * without forcing every schema open via `expandAllSchemaProperties`.\n */\nconst isOnTargetPath = computed((): boolean =>\n isOnSchemaTargetPath(toNodeKey(breadcrumb), scrollTargetId ?? ''),\n)\n\n/**\n * Whether the disclosure starts expanded. Non-collapsible schemas are always\n * open. When `expandAllSchemaProperties` is enabled, finite branches start\n * expanded by default while cyclic branches remain collapsed to avoid recursion\n * loops. We also open any disclosure on the path to the current scroll target so\n * deep links resolve even when the property is collapsed.\n *\n * This is only the last step of the store's resolution order: it applies when\n * nobody has touched this node and no bulk action or baseline covers it.\n */\nconst defaultOpen = computed(\n (): boolean =>\n noncollapsible || shouldForceExpand.value || isOnTargetPath.value,\n)\n\n/** Gets the description to show for the schema */\nconst schemaDescription = computed(() => {\n const value = resolvedSchema.value\n\n if (hideDescription) {\n return null\n }\n\n const rawSchema = schema.value\n\n // For the request body we want to show the description of the merged allOf schema.\n // Merging keeps the base description (when set) and otherwise lets the last allOf\n // member win, matching how the merged composition is rendered below. The nested\n // merged Schema in `SchemaComposition` hides its own description in this case so\n // the text is not rendered twice.\n if (\n rawSchema?.allOf &&\n rawSchema.allOf.length > 0 &&\n name === 'Request Body'\n ) {\n return mergeAllOfSchemas(rawSchema)?.description || null\n }\n\n // Don't show description if there's no description or it's not a string\n if (!value?.description || typeof value.description !== 'string') {\n return null\n }\n\n // Don't show description for enum schemas (they have special handling)\n if (value.enum) {\n return null\n }\n\n // Will be shown in the properties anyway. A composed schema is the exception:\n // its members render as their own cards with their own descriptions, so the\n // schema's own description has nowhere else to go.\n if (\n !('properties' in value) &&\n !('patternProperties' in value) &&\n !('additionalProperties' in value) &&\n !('allOf' in value)\n ) {\n return null\n }\n\n // An allOf object segment already displays the merged description. Keep a\n // distinct outer description, but do not repeat text carried by that segment.\n if (\n rawSchema?.allOf &&\n partitionAllOfCompositions(rawSchema).segments.some(\n (segment) =>\n segment.kind === 'object' &&\n segment.schema.description === value.description &&\n ('properties' in segment.schema ||\n 'patternProperties' in segment.schema ||\n 'additionalProperties' in segment.schema) &&\n !segment.schema.enum,\n )\n ) {\n return null\n }\n\n // Return the schema's own description\n return value.description\n})\n\n/**\n * Infer a selector for mapped discriminators that do not declare `oneOf`.\n * Threaded discriminators skip inference to avoid recursive allOf variants.\n */\nconst inferredDiscriminatorComposition = computed(() =>\n schema.value && !discriminator && isTypeObject(schema.value)\n ? inferDiscriminatorMappingComposition(schema.value, options.document)\n : null,\n)\n\n/**\n * Whether the panel holds the schema's property rows. Mirrors the branches in\n * the panel below: any other root (a composition, a primitive, an array)\n * renders a single nameless passthrough row that carries the real property\n * list inside it, and a list of one row is structure the eye never sees.\n * Announcing it makes assistive tech read \"list with 1 item\" before the list\n * the reader actually wanted, so that wrapper is presentational instead.\n */\nconst rendersPropertyRows = computed(\n (): boolean =>\n !inferredDiscriminatorComposition.value &&\n isTypeObject(resolvedSchema.value),\n)\n\n/**\n * Whether an enclosing Schema already established a tree root. `depth === 0`\n * alone is not enough: a nested Schema can mount at depth 0 (an `allOf`\n * member, or a caller that omits `depth`), and a second root would mount a\n * second sticky strip and keydown root, firing every arrow key twice.\n */\nconst hasTreeRootAbove = inject(SCHEMA_TREE_ROOT_SYMBOL, false)\n\n/** The root-only features (glyph tokens, keyboard navigation) live on the outermost tree root only */\nconst isTreeRoot = computed((): boolean => depth === 0 && !hasTreeRootAbove)\n\n// Descendants must know a root exists above them, whatever depth they mount at.\nprovide(SCHEMA_TREE_ROOT_SYMBOL, true)\n\n/** Delegated arrow-key navigation, active only when the flag is on */\nconst onTreeKeydown = (event: KeyboardEvent): void => {\n if (isTreeRoot.value && options.schemaKeyboardNav) {\n handleTreeKeydown(event)\n }\n}\n\nconst expansion =\n expansionProp ?? useSchemaExpansion(toRef(() => scrollTargetId ?? ''))\n\n/**\n * Fallback identity for nodes mounted without a breadcrumb (models, AsyncAPI\n * messages, the classic layouts). Until those surfaces pass real breadcrumbs,\n * this keeps them from all resolving to the empty key and toggling as one node.\n */\nconst anonymousKey = useId()\n\nconst nodeKey = computed(\n (): string => toNodeKey(breadcrumb) || `~anonymous-${anonymousKey}`,\n)\n\n/**\n * Whether this disclosure is open. Resolved from the store on every read, not\n * latched at mount, so a second deep link into an already-rendered operation\n * works and expansion survives the composition variant remount.\n */\nconst open = computed(\n (): boolean =>\n noncollapsible ||\n expansion.isExpanded(nodeKey.value, {\n cyclic: isCyclic.value,\n defaultOpen: defaultOpen.value,\n }),\n)\n\n/** Additional-property panels hide until opened; every other panel always renders */\nconst panelRendered = computed(\n (): boolean => !additionalProperties || open.value,\n)\n\nconst toggleId = useId()\nconst panelId = useId()\n\n/**\n * The reveal is one-way: its button hides once the panel opens, so nothing\n * here can collapse a subtree that holds focus. The rows inside handle that\n * themselves (see `toggleTree` in SchemaProperty.vue).\n */\nconst toggle = (): void => {\n if (noncollapsible) {\n return\n }\n\n expansion.setExpanded(nodeKey.value, !open.value)\n}\n</script>\n<template>\n <!--\n Not a Headless UI `<Disclosure>`: it has no controlled mode, and expansion\n is driven from the store, so the button and the panel are owned directly.\n -->\n <div\n v-if=\"resolvedSchema && Object.keys(resolvedSchema).length\"\n class=\"schema-card\"\n :class=\"[\n `schema-card--level-${level}`,\n { 'schema-card--compact': compact, 'schema-card--open': open },\n /*\n * No margin of its own: the row above already ends with its own 6px pad,\n * so the reveal keeps the tree's row-to-row rhythm exactly.\n */\n { 'additional-card--tree': additionalProperties },\n 'schema-card--tree',\n /*\n * Tree-local tokens, namespaced --schema-* so no preset or user theme\n * breaks. WCAG 1.4.11 wants 3:1 for the glyph; --scalar-color-3 measures\n * 3.28:1 only before opacity, so the glyph reads color-2. The narrow\n * container tightens the indent and the control sizes, but that lives at\n * app scope (styles/tailwind.config.css) with the other rail tokens: the\n * surfaces above a tree root draw rails too, and they must tighten with\n * it or their glyphs land on a different line.\n */\n {\n 'schema-tree [--schema-glyph-background:var(--scalar-background-1)] [--schema-glyph-color:var(--scalar-color-2)]':\n isTreeRoot,\n },\n ]\"\n @keydown=\"onTreeKeydown\">\n <!-- Schema description -->\n <!-- Without a card box the level-0 divider (and its negative-margin tuck)\n would be a stray line, so the whole treatment is switched off -->\n <div\n v-if=\"schemaDescription\"\n class=\"schema-card-description [.schema-card--level-0:nth-of-type(1)>&]:has-[+.schema-properties]:mb-0! [.schema-card--level-0:nth-of-type(1)>&]:has-[+.schema-properties]:border-b-0! [.schema-card--level-0:nth-of-type(1)>&]:has-[+.schema-properties]:pb-0!\">\n <ScalarMarkdown :value=\"schemaDescription\" />\n </div>\n <div\n v-if=\"isEmptySchemaObject(resolvedSchema)\"\n class=\"text-c-2 py-1.5\">\n {{ translate('schema.emptyObject') }}\n </div>\n <!-- A rail per depth instead of a bordered box per level, so the card\n chrome is switched off. 6px under a description keeps the 12px row\n rhythm; at level 0 the divider is gone, so even that 6px would double\n up with the first row's own padding. -->\n <div\n class=\"schema-properties\"\n :class=\"[\n { 'schema-properties-open': open },\n 'w-full! rounded-none! border-0! [.schema-card--level-0:nth-of-type(1)>.schema-card-description+&]:mt-0! [.schema-card-description+&]:mt-1.5!',\n ]\">\n <!-- Toggle to collapse/expand long lists of properties -->\n <div\n v-if=\"additionalProperties\"\n v-show=\"!open\"\n class=\"schema-properties w-full! rounded-none! border-0!\">\n <!-- The reveal reads as one more row — mono label flush with the\n sibling rows' text, a plus puck centred on the sibling toggles'\n line. `min-h-8` is the row's own 32px: the label then centres in\n the same 20px slot a heading gets, so the first revealed property\n lands exactly where the label was instead of 2.5px below it. -->\n <button\n :id=\"toggleId\"\n :aria-controls=\"panelRendered ? panelId : undefined\"\n :aria-expanded=\"open\"\n class=\"schema-card-title schema-card-title--compact group/tree-control additional-toggle--tree font-code text-c-1! relative flex h-auto min-h-8 items-center gap-0! px-0! py-[var(--schema-row-pad,6px)]! text-sm! font-bold!\"\n type=\"button\"\n @click=\"toggle\">\n <!-- The reveal is one more row of the tree, so its plus is the same\n puck the row toggles draw, on the same gutter line -->\n <SchemaGlyphPuck class=\"additional-toggle-glyph\" />\n <span class=\"additional-toggle-label\">\n {{ additionalPropertiesLabel }}\n <ScreenReader v-if=\"name\">\n {{ translate('schema.forName', { name }) }}\n </ScreenReader>\n </span>\n </button>\n </div>\n\n <!-- The theme reset strips list-style, which makes Safari and VoiceOver\n drop list semantics; an explicit role restores them. When the panel\n holds a single passthrough row instead of property rows, the wrapper\n is presentational so only the real list nested inside it is\n announced. -->\n <ul\n v-if=\"panelRendered\"\n :id=\"panelId\"\n :role=\"rendersPropertyRows ? 'list' : 'presentation'\">\n <!-- Variant selector inferred from a discriminator mapping -->\n <SchemaComposition\n v-if=\"inferredDiscriminatorComposition\"\n :breadcrumb\n :compact\n composition=\"oneOf\"\n :compositionPath=\"compositionPath\"\n :depth=\"depth\"\n :discriminator=\"schema?.discriminator\"\n :eventBus=\"eventBus\"\n :expansion=\"expansion\"\n :hideHeading\n :hideModelNames\n :level=\"level\"\n :name=\"name\"\n :options\n :schema=\"inferredDiscriminatorComposition\"\n :schemaContext=\"schemaContext\"\n :scrollTargetId=\"scrollTargetId\"\n :specificationExtension=\"specificationExtension\" />\n <!-- Object properties -->\n <SchemaObjectProperties\n v-else-if=\"isTypeObject(resolvedSchema)\"\n :breadcrumb\n :compact\n :compositionPath=\"compositionPath\"\n :depth=\"depth\"\n :discriminator\n :eventBus=\"eventBus\"\n :expansion=\"expansion\"\n :hideHeading\n :hideModelNames\n :level=\"level + 1\"\n :options\n :schema=\"resolvedSchema\"\n :schemaContext=\"schemaContext\"\n :scrollTargetId=\"scrollTargetId\"\n :specificationExtension=\"specificationExtension\" />\n <!-- Not an object -->\n <template v-else>\n <SchemaProperty\n v-if=\"resolvedSchema\"\n :breadcrumb\n :compact\n :compositionPath=\"compositionPath\"\n :depth=\"depth\"\n :discriminator\n :eventBus=\"eventBus\"\n :expansion=\"expansion\"\n :hideHeading\n :hideModelNames\n :level\n :options\n :schema=\"resolvedSchema\"\n :schemaContext=\"schemaContext\"\n :scrollTargetId=\"scrollTargetId\"\n :specificationExtension=\"specificationExtension\" />\n </template>\n </ul>\n </div>\n </div>\n</template>\n<style scoped>\n.error {\n background-color: var(--scalar-color-red);\n}\n.schema-card {\n font-size: var(--scalar-font-size-4);\n color: var(--scalar-color-1);\n}\n.schema-card-title {\n height: var(--schema-title-height);\n\n padding: 6px 8px;\n\n display: flex;\n align-items: center;\n gap: 4px;\n\n color: var(--scalar-color-2);\n font-weight: var(--scalar-semibold);\n font-size: var(--scalar-mini);\n border-bottom: var(--scalar-border-width) solid transparent;\n}\nbutton.schema-card-title {\n cursor: pointer;\n}\nbutton.schema-card-title:hover {\n color: var(--scalar-color-1);\n}\n.schema-properties-open > .schema-card-title {\n border-bottom-left-radius: 0;\n border-bottom-right-radius: 0;\n border-bottom: var(--scalar-border-width) solid var(--scalar-border-color);\n}\n.schema-properties-open > .schema-properties {\n width: fit-content;\n}\n.schema-card-description {\n color: var(--scalar-color-2);\n}\n.schema-card-description + .schema-properties {\n width: fit-content;\n}\n.schema-card-description + .schema-properties {\n margin-top: 8px;\n}\n.schema-card--level-0:nth-of-type(1)\n > .schema-card-description:has(+ .schema-properties) {\n margin-bottom: -8px;\n padding-bottom: 8px;\n border-bottom: var(--scalar-border-width) solid var(--scalar-border-color);\n}\n.schema-card--level-0\n ~ .schema-card--level-0\n > .schema-card-description:has(+ .schema-properties) {\n padding-top: 8px;\n}\n\n.schema-properties-open.schema-properties,\n.schema-properties-open > .schema-card--open {\n width: 100%;\n}\n.schema-properties {\n display: flex;\n flex-direction: column;\n\n border: var(--scalar-border-width) solid var(--scalar-border-color);\n border-radius: var(--scalar-radius-lg);\n width: fit-content;\n}\n.schema-properties-name {\n width: 100%;\n}\n.schema-properties .schema-properties {\n border-radius: 13.5px;\n}\n.schema-properties .schema-properties.schema-properties-open {\n border-radius: var(--scalar-radius-lg);\n}\n.schema-properties-open {\n width: 100%;\n}\n.schema-card--compact {\n align-self: flex-start;\n}\n.schema-card--compact.schema-card--open {\n align-self: initial;\n}\n.schema-card-title--compact {\n color: var(--scalar-color-2);\n padding: 6px 10px 6px 8px;\n height: auto;\n border-bottom: none;\n}\n.schema-properties-open > .schema-card-title--compact {\n position: static;\n}\n.property--level-0\n > .schema-properties\n > .schema-card--level-0\n > .schema-properties {\n border: none;\n}\n.property--level-0\n .schema-card--level-0:not(.schema-card--compact)\n .property--level-1 {\n padding: 0 0 8px;\n}\n:not(.composition-panel)\n > .schema-card--compact.schema-card--level-0\n > .schema-properties {\n border: none;\n}\n:deep(.schema-card-description) p {\n font-size: var(--scalar-small, var(--scalar-paragraph));\n color: var(--scalar-color-2);\n margin-bottom: 0;\n display: block;\n margin-bottom: 6px;\n}\n.children .schema-card-description:first-of-type {\n padding-top: 0;\n}\n</style>\n"],"mappings":""}
1
+ {"version":3,"file":"Schema.vue.js","names":[],"sources":["../../src/schema/Schema.vue"],"sourcesContent":["<script lang=\"ts\" setup>\nimport { ScalarMarkdown } from '@scalar/components/markdown'\nimport type { WorkspaceEventBus } from '@scalar/workspace-store/events'\nimport { pushDynamicScope } from '@scalar/workspace-store/helpers/dynamic-ref'\nimport { resolve } from '@scalar/workspace-store/resolve'\nimport type {\n DiscriminatorObject,\n SchemaObject,\n} from '@scalar/workspace-store/schemas/v3.2/strict/openapi-document'\nimport { computed, inject, provide, toRef, useId } from 'vue'\n\nimport ExternalDocs from '../shared/ExternalDocs.vue'\nimport ScreenReader from '../shared/ScreenReader.vue'\nimport {\n resolveDynamicSchema,\n SCHEMA_DYNAMIC_SCOPE_SYMBOL,\n useDynamicScope,\n} from './helpers/dynamic-scope'\nimport { inferDiscriminatorMappingComposition } from './helpers/get-compositions-to-render'\nimport { isEmptySchemaObject } from './helpers/is-empty-schema-object'\nimport { isOnSchemaTargetPath } from './helpers/is-on-schema-target-path'\nimport { isTypeObject } from './helpers/is-type-object'\nimport { mergeAllOfSchemas } from './helpers/merge-all-of-schemas'\nimport { partitionAllOfCompositions } from './helpers/partition-all-of-compositions'\nimport { SCHEMA_ANCESTORS_SYMBOL } from './helpers/schema-cycle'\nimport {\n SCHEMA_TREE_ROOT_SYMBOL,\n toNodeKey,\n useSchemaExpansion,\n} from './helpers/schema-expansion'\nimport { handleTreeKeydown } from './helpers/schema-keyboard-nav'\nimport { unwrapForRead } from './helpers/unwrap-for-read'\nimport { useLocalization } from './localization'\nimport SchemaComposition from './SchemaComposition.vue'\nimport SchemaGlyphPuck from './SchemaGlyphPuck.vue'\nimport SchemaObjectProperties from './SchemaObjectProperties.vue'\nimport SchemaProperty from './SchemaProperty.vue'\nimport type { SchemaOptions, SchemaRenderingProps } from './types'\n\nconst {\n scrollTargetId,\n expansion: expansionProp,\n schema: schemaProp,\n level = 0,\n depth = 0,\n name,\n compact,\n noncollapsible = false,\n hideHeading,\n hideDescription = false,\n additionalProperties,\n additionalPropertyCount,\n discriminator,\n breadcrumb,\n hideModelNames: hideModelNamesProp = false,\n options,\n schemaContext,\n compositionPath,\n cycleKey,\n} = defineProps<\n {\n schema?: SchemaObject\n /** Track how deep we've gone */\n level?: number\n /**\n * Real nesting depth. Not derived from `level`, whose stride differs per\n * edge (object +2, composition +1, non-object root +0).\n */\n depth?: number\n /* Show as a heading */\n name?: string\n /** A tighter layout with less borders and without a heading */\n compact?: boolean\n /** Shows a toggle to hide/show children */\n noncollapsible?: boolean\n /** Hide the heading */\n hideHeading?: boolean\n /** Hide the schema description */\n hideDescription?: boolean\n /** Show a special one way toggle for additional properties, also has a top border when open */\n additionalProperties?: boolean\n /** Number of request body properties hidden behind the overflow control. */\n additionalPropertyCount?: number\n /** Hide model names in type display */\n hideModelNames?: boolean\n /** Discriminator object */\n discriminator?: DiscriminatorObject\n /** Breadcrumb for the schema */\n breadcrumb?: string[]\n /** Event bus emitting actions */\n eventBus: WorkspaceEventBus | null\n /** Move the options into a single prop so they are easy to pass around */\n options: SchemaOptions\n /** When \"requestBody\", composition dropdown selection is synced with the example snippet */\n schemaContext?: string\n /** Internal path used to sync nested request body compositions with the code sample */\n compositionPath?: string[]\n /**\n * Stable identity of this schema node, derived from its raw (unresolved)\n * value by the parent. Used to detect self-referential cycles. See\n * {@link getCycleKey}.\n */\n cycleKey?: unknown\n } & SchemaRenderingProps\n>()\nconst { translate } = useLocalization()\n\nconst additionalPropertiesLabel = computed((): string => {\n if (additionalPropertyCount === undefined) {\n return translate('schema.showAdditionalProperties')\n }\n return translate(\n additionalPropertyCount === 1\n ? 'schema.showOneMoreProperty'\n : 'schema.showMoreProperties',\n { count: additionalPropertyCount },\n )\n})\n\nconst hideModelNames = computed(\n (): boolean => hideModelNamesProp || !!options.hideModelNames,\n)\n\n/**\n * The dynamic scope inherited from ancestor schema resources.\n *\n * Used to bind JSON Schema 2020-12 `$dynamicRef`s to the active `$dynamicAnchor` while walking the\n * tree. Empty at the root. See {@link useDynamicScope}.\n */\nconst dynamicScope = useDynamicScope()\n\n/**\n * The schema subtree, read through the magic and overrides proxies only.\n *\n * Everything below this point walks the subtree read-only, so the Vue reactive and\n * detect-changes layers are peeled off once here instead of being paid for on every nested\n * property access. See {@link unwrapForRead} for why that is safe and why the other two\n * layers stay. Reactivity on the prop itself is kept: the computed tracks the `schema` prop,\n * so replacing or switching the document still re-renders.\n */\nconst schema = computed((): SchemaObject | undefined =>\n unwrapForRead(schemaProp),\n)\n\n/**\n * The schema this node actually renders.\n *\n * Two normalizations happen here, both no-ops for ordinary schemas:\n * - A top-level `$dynamicRef` is bound to its concrete type via the inherited dynamic scope.\n * - A resource that extends a template through a root `$ref` (JSON Schema 2020-12 `$ref` alongside\n * `$defs`, e.g. a `PaginatedResponse` binding) is merged so its inherited properties render.\n */\nconst resolvedSchema = computed((): SchemaObject | undefined => {\n const value = schema.value\n\n if (!value || typeof value !== 'object') {\n return value\n }\n\n const bound = resolveDynamicSchema(value, dynamicScope)\n return '$ref' in bound ? resolve.schema(bound) : bound\n})\n\n/**\n * Re-provide the dynamic scope grown with this resource so nested `$dynamicRef`s bind here.\n *\n * Built once at setup from the resource's stable identity (like the ancestor set below);\n * `pushDynamicScope` only grows the scope for schemas that can carry a `$dynamicAnchor`.\n *\n * The raw schema is pushed, not the merged {@link resolvedSchema}: merging through `resolve.schema`\n * coerces the node and drops the resolved `$ref-value` from entries inside `$defs`, which\n * `$dynamicAnchor` resolution relies on to dereference the bound type (e.g. `User`).\n */\nconst scopeSchema = schema.value\n ? resolveDynamicSchema(schema.value, dynamicScope)\n : undefined\nprovide(\n SCHEMA_DYNAMIC_SCOPE_SYMBOL,\n scopeSchema ? pushDynamicScope(dynamicScope, scopeSchema) : dynamicScope,\n)\n\n/**\n * Cycle-safe `expandAllSchemaProperties`.\n *\n * We track ancestor schema keys along the current render path. A node is\n * treated as cyclic when its key is already present in the ancestor set, which\n * indicates that rendering has looped back onto a self-referential schema.\n *\n * This lets us default-expand finite branches while stopping automatic\n * expansion only at cycle boundaries, preventing infinite recursion.\n */\nconst ancestors = inject(SCHEMA_ANCESTORS_SYMBOL, undefined)\n\nconst isCyclic = computed(\n (): boolean => cycleKey != null && !!ancestors?.has(cycleKey),\n)\n\n// Re-provide the ancestor set augmented with this node so descendants can\n// detect cycles back to it. Built once at setup; a node's key is stable.\nconst childAncestors = new Set<unknown>(ancestors ?? [])\nif (cycleKey != null) {\n childAncestors.add(cycleKey)\n}\nprovide(SCHEMA_ANCESTORS_SYMBOL, childAncestors)\n\nconst shouldForceExpand = computed(\n (): boolean => !!options.expandAllSchemaProperties && !isCyclic.value,\n)\n\n/**\n * Whether this schema sits on the path to the current anchor/scroll target.\n *\n * Property anchors are dot-joined breadcrumbs, so every disclosure that wraps\n * the target has a breadcrumb that is a prefix of the target id. Opening those\n * disclosures is what makes deep links to collapsed (hidden) properties work\n * without forcing every schema open via `expandAllSchemaProperties`.\n */\nconst isOnTargetPath = computed((): boolean =>\n isOnSchemaTargetPath(toNodeKey(breadcrumb), scrollTargetId ?? ''),\n)\n\n/**\n * Whether the disclosure starts expanded. Non-collapsible schemas are always\n * open. When `expandAllSchemaProperties` is enabled, finite branches start\n * expanded by default while cyclic branches remain collapsed to avoid recursion\n * loops. We also open any disclosure on the path to the current scroll target so\n * deep links resolve even when the property is collapsed.\n *\n * This is only the last step of the store's resolution order: it applies when\n * nobody has touched this node and no bulk action or baseline covers it.\n */\nconst defaultOpen = computed(\n (): boolean =>\n noncollapsible || shouldForceExpand.value || isOnTargetPath.value,\n)\n\n/** Gets the description to show for the schema */\nconst schemaDescription = computed(() => {\n const value = resolvedSchema.value\n\n if (hideDescription) {\n return null\n }\n\n const rawSchema = schema.value\n\n // For the request body we want to show the description of the merged allOf schema.\n // Merging keeps the base description (when set) and otherwise lets the last allOf\n // member win, matching how the merged composition is rendered below. The nested\n // merged Schema in `SchemaComposition` hides its own description in this case so\n // the text is not rendered twice.\n if (\n rawSchema?.allOf &&\n rawSchema.allOf.length > 0 &&\n name === 'Request Body'\n ) {\n return mergeAllOfSchemas(rawSchema)?.description || null\n }\n\n // Don't show description if there's no description or it's not a string\n if (!value?.description || typeof value.description !== 'string') {\n return null\n }\n\n // Don't show description for enum schemas (they have special handling)\n if (value.enum) {\n return null\n }\n\n // Will be shown in the properties anyway. A composed schema is the exception:\n // its members render as their own cards with their own descriptions, so the\n // schema's own description has nowhere else to go.\n if (\n !('properties' in value) &&\n !('patternProperties' in value) &&\n !('additionalProperties' in value) &&\n !('allOf' in value)\n ) {\n return null\n }\n\n // An allOf object segment already displays the merged description. Keep a\n // distinct outer description, but do not repeat text carried by that segment.\n if (\n rawSchema?.allOf &&\n partitionAllOfCompositions(rawSchema).segments.some(\n (segment) =>\n segment.kind === 'object' &&\n segment.schema.description === value.description &&\n ('properties' in segment.schema ||\n 'patternProperties' in segment.schema ||\n 'additionalProperties' in segment.schema) &&\n !segment.schema.enum,\n )\n ) {\n return null\n }\n\n // Return the schema's own description\n return value.description\n})\n\n/**\n * Infer a selector for mapped discriminators that do not declare `oneOf`.\n * Threaded discriminators skip inference to avoid recursive allOf variants.\n */\nconst inferredDiscriminatorComposition = computed(() =>\n schema.value && !discriminator && isTypeObject(schema.value)\n ? inferDiscriminatorMappingComposition(schema.value, options.document)\n : null,\n)\n\n/**\n * Whether the panel holds the schema's property rows. Mirrors the branches in\n * the panel below: any other root (a composition, a primitive, an array)\n * renders a single nameless passthrough row that carries the real property\n * list inside it, and a list of one row is structure the eye never sees.\n * Announcing it makes assistive tech read \"list with 1 item\" before the list\n * the reader actually wanted, so that wrapper is presentational instead.\n */\nconst rendersPropertyRows = computed(\n (): boolean =>\n !inferredDiscriminatorComposition.value &&\n isTypeObject(resolvedSchema.value),\n)\n\n/**\n * Whether an enclosing Schema already established a tree root. `depth === 0`\n * alone is not enough: a nested Schema can mount at depth 0 (an `allOf`\n * member, or a caller that omits `depth`), and a second root would mount a\n * second sticky strip and keydown root, firing every arrow key twice.\n */\nconst hasTreeRootAbove = inject(SCHEMA_TREE_ROOT_SYMBOL, false)\n\n/** The root-only features (glyph tokens, keyboard navigation) live on the outermost tree root only */\nconst isTreeRoot = computed((): boolean => depth === 0 && !hasTreeRootAbove)\n\n// Descendants must know a root exists above them, whatever depth they mount at.\nprovide(SCHEMA_TREE_ROOT_SYMBOL, true)\n\n/** Delegated arrow-key navigation, active only when the flag is on */\nconst onTreeKeydown = (event: KeyboardEvent): void => {\n if (isTreeRoot.value && options.schemaKeyboardNav) {\n handleTreeKeydown(event)\n }\n}\n\nconst expansion =\n expansionProp ?? useSchemaExpansion(toRef(() => scrollTargetId ?? ''))\n\n/**\n * Fallback identity for nodes mounted without a breadcrumb (models, AsyncAPI\n * messages, the classic layouts). Until those surfaces pass real breadcrumbs,\n * this keeps them from all resolving to the empty key and toggling as one node.\n */\nconst anonymousKey = useId()\n\nconst nodeKey = computed(\n (): string => toNodeKey(breadcrumb) || `~anonymous-${anonymousKey}`,\n)\n\n/**\n * Whether this disclosure is open. Resolved from the store on every read, not\n * latched at mount, so a second deep link into an already-rendered operation\n * works and expansion survives the composition variant remount.\n */\nconst open = computed(\n (): boolean =>\n noncollapsible ||\n expansion.isExpanded(nodeKey.value, {\n cyclic: isCyclic.value,\n defaultOpen: defaultOpen.value,\n }),\n)\n\n/** Additional-property panels hide until opened; every other panel always renders */\nconst panelRendered = computed(\n (): boolean => !additionalProperties || open.value,\n)\n\nconst toggleId = useId()\nconst panelId = useId()\n\n/**\n * The reveal is one-way: its button hides once the panel opens, so nothing\n * here can collapse a subtree that holds focus. The rows inside handle that\n * themselves (see `toggleTree` in SchemaProperty.vue).\n */\nconst toggle = (): void => {\n if (noncollapsible) {\n return\n }\n\n expansion.setExpanded(nodeKey.value, !open.value)\n}\n</script>\n<template>\n <!--\n Not a Headless UI `<Disclosure>`: it has no controlled mode, and expansion\n is driven from the store, so the button and the panel are owned directly.\n -->\n <div\n v-if=\"resolvedSchema && Object.keys(resolvedSchema).length\"\n class=\"schema-card\"\n :class=\"[\n `schema-card--level-${level}`,\n { 'schema-card--compact': compact, 'schema-card--open': open },\n /*\n * No margin of its own: the row above already ends with its own 6px pad,\n * so the reveal keeps the tree's row-to-row rhythm exactly.\n */\n { 'additional-card--tree': additionalProperties },\n 'schema-card--tree',\n /*\n * Tree-local tokens, namespaced --schema-* so no preset or user theme\n * breaks. WCAG 1.4.11 wants 3:1 for the glyph; --scalar-color-3 measures\n * 3.28:1 only before opacity, so the glyph reads color-2. The narrow\n * container tightens the indent and the control sizes, but that lives at\n * app scope (styles/tailwind.config.css) with the other rail tokens: the\n * surfaces above a tree root draw rails too, and they must tighten with\n * it or their glyphs land on a different line.\n */\n {\n 'schema-tree [--schema-glyph-background:var(--scalar-background-1)] [--schema-glyph-color:var(--scalar-color-2)]':\n isTreeRoot,\n },\n ]\"\n @keydown=\"onTreeKeydown\">\n <ExternalDocs\n v-if=\"isTypeObject(resolvedSchema)\"\n class=\"my-2\"\n :value=\"resolvedSchema.externalDocs\" />\n <!-- Schema description -->\n <!-- Without a card box the level-0 divider (and its negative-margin tuck)\n would be a stray line, so the whole treatment is switched off -->\n <div\n v-if=\"schemaDescription\"\n class=\"schema-card-description [.schema-card--level-0:nth-of-type(1)>&]:has-[+.schema-properties]:mb-0! [.schema-card--level-0:nth-of-type(1)>&]:has-[+.schema-properties]:border-b-0! [.schema-card--level-0:nth-of-type(1)>&]:has-[+.schema-properties]:pb-0!\">\n <ScalarMarkdown :value=\"schemaDescription\" />\n </div>\n <div\n v-if=\"isEmptySchemaObject(resolvedSchema)\"\n class=\"text-c-2 py-1.5\">\n {{ translate('schema.emptyObject') }}\n </div>\n <!-- A rail per depth instead of a bordered box per level, so the card\n chrome is switched off. 6px under a description keeps the 12px row\n rhythm; at level 0 the divider is gone, so even that 6px would double\n up with the first row's own padding. -->\n <div\n class=\"schema-properties\"\n :class=\"[\n { 'schema-properties-open': open },\n 'w-full! rounded-none! border-0! [.schema-card--level-0:nth-of-type(1)>.schema-card-description+&]:mt-0! [.schema-card-description+&]:mt-1.5!',\n ]\">\n <!-- Toggle to collapse/expand long lists of properties -->\n <div\n v-if=\"additionalProperties\"\n v-show=\"!open\"\n class=\"schema-properties w-full! rounded-none! border-0!\">\n <!-- The reveal reads as one more row — mono label flush with the\n sibling rows' text, a plus puck centred on the sibling toggles'\n line. `min-h-8` is the row's own 32px: the label then centres in\n the same 20px slot a heading gets, so the first revealed property\n lands exactly where the label was instead of 2.5px below it. -->\n <button\n :id=\"toggleId\"\n :aria-controls=\"panelRendered ? panelId : undefined\"\n :aria-expanded=\"open\"\n class=\"schema-card-title schema-card-title--compact group/tree-control additional-toggle--tree font-code text-c-1! relative flex h-auto min-h-8 items-center gap-0! px-0! py-[var(--schema-row-pad,6px)]! text-sm! font-bold!\"\n type=\"button\"\n @click=\"toggle\">\n <!-- The reveal is one more row of the tree, so its plus is the same\n puck the row toggles draw, on the same gutter line -->\n <SchemaGlyphPuck class=\"additional-toggle-glyph\" />\n <span class=\"additional-toggle-label\">\n {{ additionalPropertiesLabel }}\n <ScreenReader v-if=\"name\">\n {{ translate('schema.forName', { name }) }}\n </ScreenReader>\n </span>\n </button>\n </div>\n\n <!-- The theme reset strips list-style, which makes Safari and VoiceOver\n drop list semantics; an explicit role restores them. When the panel\n holds a single passthrough row instead of property rows, the wrapper\n is presentational so only the real list nested inside it is\n announced. -->\n <ul\n v-if=\"panelRendered\"\n :id=\"panelId\"\n :role=\"rendersPropertyRows ? 'list' : 'presentation'\">\n <!-- Variant selector inferred from a discriminator mapping -->\n <SchemaComposition\n v-if=\"inferredDiscriminatorComposition\"\n :breadcrumb\n :compact\n composition=\"oneOf\"\n :compositionPath=\"compositionPath\"\n :depth=\"depth\"\n :discriminator=\"schema?.discriminator\"\n :eventBus=\"eventBus\"\n :expansion=\"expansion\"\n :hideHeading\n :hideModelNames\n :level=\"level\"\n :name=\"name\"\n :options\n :schema=\"inferredDiscriminatorComposition\"\n :schemaContext=\"schemaContext\"\n :scrollTargetId=\"scrollTargetId\"\n :specificationExtension=\"specificationExtension\" />\n <!-- Object properties -->\n <SchemaObjectProperties\n v-else-if=\"isTypeObject(resolvedSchema)\"\n :breadcrumb\n :compact\n :compositionPath=\"compositionPath\"\n :depth=\"depth\"\n :discriminator=\"discriminator ?? resolvedSchema?.discriminator\"\n :eventBus=\"eventBus\"\n :expansion=\"expansion\"\n :hideHeading\n :hideModelNames\n :level=\"level + 1\"\n :options\n :schema=\"resolvedSchema\"\n :schemaContext=\"schemaContext\"\n :scrollTargetId=\"scrollTargetId\"\n :specificationExtension=\"specificationExtension\" />\n <!-- Not an object -->\n <template v-else>\n <SchemaProperty\n v-if=\"resolvedSchema\"\n :breadcrumb\n :compact\n :compositionPath=\"compositionPath\"\n :depth=\"depth\"\n :discriminator\n :eventBus=\"eventBus\"\n :expansion=\"expansion\"\n :hideHeading\n :hideModelNames\n :level\n :options\n :schema=\"resolvedSchema\"\n :schemaContext=\"schemaContext\"\n :scrollTargetId=\"scrollTargetId\"\n :specificationExtension=\"specificationExtension\" />\n </template>\n </ul>\n </div>\n </div>\n</template>\n<style scoped>\n.error {\n background-color: var(--scalar-color-red);\n}\n.schema-card {\n font-size: var(--scalar-font-size-4);\n color: var(--scalar-color-1);\n}\n.schema-card-title {\n height: var(--schema-title-height);\n\n padding: 6px 8px;\n\n display: flex;\n align-items: center;\n gap: 4px;\n\n color: var(--scalar-color-2);\n font-weight: var(--scalar-semibold);\n font-size: var(--scalar-mini);\n border-bottom: var(--scalar-border-width) solid transparent;\n}\nbutton.schema-card-title {\n cursor: pointer;\n}\nbutton.schema-card-title:hover {\n color: var(--scalar-color-1);\n}\n.schema-properties-open > .schema-card-title {\n border-bottom-left-radius: 0;\n border-bottom-right-radius: 0;\n border-bottom: var(--scalar-border-width) solid var(--scalar-border-color);\n}\n.schema-properties-open > .schema-properties {\n width: fit-content;\n}\n.schema-card-description {\n color: var(--scalar-color-2);\n}\n.schema-card-description + .schema-properties {\n width: fit-content;\n}\n.schema-card-description + .schema-properties {\n margin-top: 8px;\n}\n.schema-card--level-0:nth-of-type(1)\n > .schema-card-description:has(+ .schema-properties) {\n margin-bottom: -8px;\n padding-bottom: 8px;\n border-bottom: var(--scalar-border-width) solid var(--scalar-border-color);\n}\n.schema-card--level-0\n ~ .schema-card--level-0\n > .schema-card-description:has(+ .schema-properties) {\n padding-top: 8px;\n}\n\n.schema-properties-open.schema-properties,\n.schema-properties-open > .schema-card--open {\n width: 100%;\n}\n.schema-properties {\n display: flex;\n flex-direction: column;\n\n border: var(--scalar-border-width) solid var(--scalar-border-color);\n border-radius: var(--scalar-radius-lg);\n width: fit-content;\n}\n.schema-properties-name {\n width: 100%;\n}\n.schema-properties .schema-properties {\n border-radius: 13.5px;\n}\n.schema-properties .schema-properties.schema-properties-open {\n border-radius: var(--scalar-radius-lg);\n}\n.schema-properties-open {\n width: 100%;\n}\n.schema-card--compact {\n align-self: flex-start;\n}\n.schema-card--compact.schema-card--open {\n align-self: initial;\n}\n.schema-card-title--compact {\n color: var(--scalar-color-2);\n padding: 6px 10px 6px 8px;\n height: auto;\n border-bottom: none;\n}\n.schema-properties-open > .schema-card-title--compact {\n position: static;\n}\n.property--level-0\n > .schema-properties\n > .schema-card--level-0\n > .schema-properties {\n border: none;\n}\n.property--level-0\n .schema-card--level-0:not(.schema-card--compact)\n .property--level-1 {\n padding: 0 0 8px;\n}\n:not(.composition-panel)\n > .schema-card--compact.schema-card--level-0\n > .schema-properties {\n border: none;\n}\n:deep(.schema-card-description) p {\n font-size: var(--scalar-small, var(--scalar-paragraph));\n color: var(--scalar-color-2);\n margin-bottom: 0;\n display: block;\n margin-bottom: 6px;\n}\n.children .schema-card-description:first-of-type {\n padding-top: 0;\n}\n</style>\n"],"mappings":""}