@scalar/workspace-store 0.49.2 → 0.49.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @scalar/workspace-store
2
2
 
3
+ ## 0.49.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#9054](https://github.com/scalar/scalar/pull/9054): fix multipart/form-data request body generation for schema-derived object examples
8
+
3
9
  ## 0.49.2
4
10
 
5
11
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"build-request-body.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/body/build-request-body.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0DAA0D,CAAA;AAKjG,KAAK,QAAQ,GAAG;IACd,IAAI,EAAE,UAAU,CAAA;IAChB,KAAK,EAAE,CACH;QACE,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,EAAE,MAAM,CAAA;QACX,KAAK,EAAE,MAAM,CAAA;KACd,GACD;QACE,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,EAAE,MAAM,CAAA;QACX,KAAK,EAAE,IAAI,CAAA;QACX,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB,GACD;QACE,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,EAAE,MAAM,CAAA;QACX,KAAK,EAAE,IAAI,CAAA;QACX,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB,CACJ,EAAE,CAAA;CACJ,CAAA;AAED,KAAK,UAAU,GAAG;IAChB,IAAI,EAAE,YAAY,CAAA;IAClB,KAAK,EAAE;QACL,GAAG,EAAE,MAAM,CAAA;QACX,KAAK,EAAE,MAAM,CAAA;KACd,EAAE,CAAA;CACJ,CAAA;AAED,KAAK,GAAG,GAAG;IACT,IAAI,EAAE,KAAK,CAAA;IACX,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAA;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,UAAU,GAAG,GAAG,CAAA;AAKrD;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAC3B,aAAa,iBAAiB,GAAG,SAAS;AAC1C,qCAAqC;AACrC,oBAAuB;AACvB,sEAAsE;AACtE,kCAAkC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACvD,WAAW,GAAG,IAqJhB,CAAA"}
1
+ {"version":3,"file":"build-request-body.d.ts","sourceRoot":"","sources":["../../../../src/request-example/builder/body/build-request-body.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,0DAA0D,CAAA;AAKjG,KAAK,QAAQ,GAAG;IACd,IAAI,EAAE,UAAU,CAAA;IAChB,KAAK,EAAE,CACH;QACE,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,EAAE,MAAM,CAAA;QACX,KAAK,EAAE,MAAM,CAAA;KACd,GACD;QACE,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,EAAE,MAAM,CAAA;QACX,KAAK,EAAE,IAAI,CAAA;QACX,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB,GACD;QACE,IAAI,EAAE,MAAM,CAAA;QACZ,GAAG,EAAE,MAAM,CAAA;QACX,KAAK,EAAE,IAAI,CAAA;QACX,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB,CACJ,EAAE,CAAA;CACJ,CAAA;AAED,KAAK,UAAU,GAAG;IAChB,IAAI,EAAE,YAAY,CAAA;IAClB,KAAK,EAAE;QACL,GAAG,EAAE,MAAM,CAAA;QACX,KAAK,EAAE,MAAM,CAAA;KACd,EAAE,CAAA;CACJ,CAAA;AAED,KAAK,GAAG,GAAG;IACT,IAAI,EAAE,KAAK,CAAA;IACX,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,IAAI,CAAA;IAC3B,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB,CAAA;AAED,MAAM,MAAM,WAAW,GAAG,QAAQ,GAAG,UAAU,GAAG,GAAG,CAAA;AAKrD;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAC3B,aAAa,iBAAiB,GAAG,SAAS;AAC1C,qCAAqC;AACrC,oBAAuB;AACvB,sEAAsE;AACtE,kCAAkC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KACvD,WAAW,GAAG,IAwMhB,CAAA"}
@@ -1,4 +1,5 @@
1
1
  // import { replaceEnvVariables } from '@scalar/helpers/regex/replace-variables'
2
+ import { isObject } from '@scalar/helpers/object/is-object';
2
3
  import { unpackProxyObject } from '@scalar/workspace-store/helpers/unpack-proxy';
3
4
  import { getExampleFromBody } from './get-request-body-example.js';
4
5
  import { getSelectedBodyContentType } from './get-selected-body-content-type.js';
@@ -88,10 +89,7 @@ requestBodyCompositionSelection) => {
88
89
  // Form data - object format (from schema examples)
89
90
  // When the example value is a plain object and content type is form-urlencoded,
90
91
  // convert to URLSearchParams instead of JSON stringifying
91
- if (bodyContentType === 'application/x-www-form-urlencoded' &&
92
- example.value !== null &&
93
- typeof example.value === 'object' &&
94
- !Array.isArray(example.value)) {
92
+ if (bodyContentType === 'application/x-www-form-urlencoded' && isObject(example.value)) {
95
93
  const result = {
96
94
  mode: 'urlencoded',
97
95
  value: [],
@@ -108,6 +106,51 @@ requestBodyCompositionSelection) => {
108
106
  }
109
107
  return result;
110
108
  }
109
+ // Form data - object format (from schema examples)
110
+ if (bodyContentType === 'multipart/form-data' && isObject(example.value)) {
111
+ const result = {
112
+ mode: 'formdata',
113
+ value: [],
114
+ };
115
+ for (const [key, value] of Object.entries(example.value)) {
116
+ if (!key || value === undefined || value === null) {
117
+ continue;
118
+ }
119
+ const partContentType = getMultipartEncodingContentType(requestBody, bodyContentType, key);
120
+ if (value instanceof File) {
121
+ const unwrappedValue = unpackProxyObject(value);
122
+ const encodedValue = partContentType && partContentType !== unwrappedValue.type
123
+ ? new File([unwrappedValue], unwrappedValue.name, {
124
+ type: partContentType,
125
+ lastModified: unwrappedValue.lastModified,
126
+ })
127
+ : unwrappedValue;
128
+ result.value.push({
129
+ type: 'file',
130
+ key,
131
+ value: encodedValue,
132
+ contentType: partContentType,
133
+ });
134
+ continue;
135
+ }
136
+ const serializedValue = typeof value === 'object' && value !== null ? JSON.stringify(unpackProxyObject(value)) : String(value);
137
+ if (partContentType) {
138
+ result.value.push({
139
+ type: 'blob',
140
+ key,
141
+ value: new Blob([serializedValue], { type: partContentType }),
142
+ contentType: partContentType,
143
+ });
144
+ continue;
145
+ }
146
+ result.value.push({
147
+ type: 'text',
148
+ key,
149
+ value: serializedValue,
150
+ });
151
+ }
152
+ return result;
153
+ }
111
154
  // Any other type
112
155
  const exampleValue = example.value !== null && typeof example.value === 'object' ? unpackProxyObject(example.value) : example.value;
113
156
  // File type
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "openapi",
17
17
  "scalar"
18
18
  ],
19
- "version": "0.49.2",
19
+ "version": "0.49.3",
20
20
  "engines": {
21
21
  "node": ">=22"
22
22
  },
@@ -144,11 +144,11 @@
144
144
  "vue": "^3.5.30",
145
145
  "yaml": "^2.8.3",
146
146
  "@scalar/helpers": "0.6.0",
147
+ "@scalar/openapi-upgrader": "0.2.7",
147
148
  "@scalar/json-magic": "0.12.12",
148
149
  "@scalar/snippetz": "0.9.6",
149
- "@scalar/validation": "0.3.2",
150
150
  "@scalar/types": "0.9.6",
151
- "@scalar/openapi-upgrader": "0.2.7"
151
+ "@scalar/validation": "0.3.2"
152
152
  },
153
153
  "devDependencies": {
154
154
  "@google-cloud/storage": "7.16.0",