Skip to content

Commit aa39472

Browse files
authored
Replace usages of Blob type with k6-compatible ArrayBuffer (#32)
1 parent 36107e3 commit aa39472

File tree

14 files changed

+149
-12
lines changed

14 files changed

+149
-12
lines changed

examples/form_data_schema/single/formDataAPI.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import http from 'k6/http'
1010
import type { Params, Response } from 'k6/http'
1111
export type PostUploadBody = {
1212
/** File to upload */
13-
file: Blob
13+
file: ArrayBuffer
1414
/** Description of the file */
1515
description?: string
1616
/** User ID associated with the upload */

examples/form_data_schema/split/formDataAPI.schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
export type PostUploadBody = {
88
/** File to upload */
9-
file: Blob
9+
file: ArrayBuffer
1010
/** Description of the file */
1111
description?: string
1212
/** User ID associated with the upload */

examples/form_data_schema/tags/formDataAPI.schemas.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
export type PostUploadBody = {
88
/** File to upload */
9-
file: Blob
9+
file: ArrayBuffer
1010
/** Description of the file */
1111
description?: string
1212
/** User ID associated with the upload */

examples/form_url_encoded_data_schema/single/formURLEncodedAPI.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,14 @@ export class FormURLEncodedAPIClient {
6262
const response = http.request(
6363
'POST',
6464
k6url.toString(),
65-
JSON.stringify(postSubmitFormBody),
65+
66+
// k6 accepts JS objects for form URL encoded requests, but all properties must be strings
67+
Object.fromEntries(
68+
Object.entries(postSubmitFormBody).map(([key, value]) => [
69+
key,
70+
String(value),
71+
])
72+
),
6673
{
6774
...mergedRequestParameters,
6875
headers: {

examples/form_url_encoded_data_schema/split/formURLEncodedAPI.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ export class FormURLEncodedAPIClient {
4848
const response = http.request(
4949
'POST',
5050
k6url.toString(),
51-
JSON.stringify(postSubmitFormBody),
51+
52+
// k6 accepts JS objects for form URL encoded requests, but all properties must be strings
53+
Object.fromEntries(
54+
Object.entries(postSubmitFormBody).map(([key, value]) => [
55+
key,
56+
String(value),
57+
])
58+
),
5259
{
5360
...mergedRequestParameters,
5461
headers: {

examples/form_url_encoded_data_schema/tags/default.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,14 @@ export class DefaultClient {
4848
const response = http.request(
4949
'POST',
5050
k6url.toString(),
51-
JSON.stringify(postSubmitFormBody),
51+
52+
// k6 accepts JS objects for form URL encoded requests, but all properties must be strings
53+
Object.fromEntries(
54+
Object.entries(postSubmitFormBody).map(([key, value]) => [
55+
key,
56+
String(value),
57+
])
58+
),
5259
{
5360
...mergedRequestParameters,
5461
headers: {

examples/form_url_encoded_data_with_query_params_schema/single/formURLEncodedAPIWithQueryParameters.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,14 @@ export class FormURLEncodedAPIWithQueryParametersClient {
7878
const response = http.request(
7979
'POST',
8080
k6url.toString(),
81-
JSON.stringify(postSubmitFormBody),
81+
82+
// k6 accepts JS objects for form URL encoded requests, but all properties must be strings
83+
Object.fromEntries(
84+
Object.entries(postSubmitFormBody).map(([key, value]) => [
85+
key,
86+
String(value),
87+
])
88+
),
8289
{
8390
...mergedRequestParameters,
8491
headers: {

examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ export class FormURLEncodedAPIWithQueryParametersClient {
5454
const response = http.request(
5555
'POST',
5656
k6url.toString(),
57-
JSON.stringify(postSubmitFormBody),
57+
58+
// k6 accepts JS objects for form URL encoded requests, but all properties must be strings
59+
Object.fromEntries(
60+
Object.entries(postSubmitFormBody).map(([key, value]) => [
61+
key,
62+
String(value),
63+
])
64+
),
5865
{
5966
...mergedRequestParameters,
6067
headers: {

examples/form_url_encoded_data_with_query_params_schema/tags/default.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,14 @@ export class DefaultClient {
5454
const response = http.request(
5555
'POST',
5656
k6url.toString(),
57-
JSON.stringify(postSubmitFormBody),
57+
58+
// k6 accepts JS objects for form URL encoded requests, but all properties must be strings
59+
Object.fromEntries(
60+
Object.entries(postSubmitFormBody).map(([key, value]) => [
61+
key,
62+
String(value),
63+
])
64+
),
5865
{
5966
...mergedRequestParameters,
6067
headers: {

src/generator/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,22 @@ const afterAllFilesWriteHandler = async (
5050
// Hence, we manually remove those empty files.
5151
// Issue link - https://github.com/orval-labs/orval/issues/1691
5252

53-
if (hasOnlyComments(fs.readFileSync(filePath, 'utf-8'))) {
53+
const fileContent = fs.readFileSync(filePath, 'utf-8')
54+
if (hasOnlyComments(fileContent)) {
5455
emptyFileList.push(filePath)
5556
// Delete the file
5657
removeSingleFile(filePath)
5758
continue
5859
}
60+
61+
// Replace usages of Blob type with the k6-compatible ArrayBuffer
62+
const newFileContent = fileContent.replaceAll(
63+
/(^|\W)Blob(?!\w)/g,
64+
'$1ArrayBuffer'
65+
)
66+
67+
fs.writeFileSync(filePath, newFileContent)
68+
5969
try {
6070
await formatFileWithPrettier(filePath)
6171
} catch (error) {

0 commit comments

Comments
 (0)