@grafana/openapi-to-k6 0.1.2 → 0.2.1
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/.github/workflows/publish.yaml +2 -2
- package/.github/workflows/tests.yaml +14 -6
- package/README.md +54 -14
- package/dist/analytics.js +2 -1
- package/dist/cli.js +20 -6
- package/dist/constants.js +8 -2
- package/dist/{generator.js → generator/index.js} +7 -13
- package/dist/{k6SdkClient.js → generator/k6Client.js} +148 -161
- package/examples/basic_schema/single/k6-script.sample.ts +11 -0
- package/examples/basic_schema/single/simpleAPI.ts +87 -0
- package/examples/basic_schema/split/k6-script.sample.ts +11 -0
- package/examples/basic_schema/split/simpleAPI.schemas.ts +9 -0
- package/examples/basic_schema/split/simpleAPI.ts +85 -0
- package/examples/basic_schema/tags/default.ts +85 -0
- package/examples/basic_schema/tags/k6-script.sample.ts +11 -0
- package/examples/basic_schema/tags/simpleAPI.schemas.ts +9 -0
- package/examples/form_data_schema/single/formDataAPI.ts +115 -0
- package/examples/form_data_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/form_data_schema/split/formDataAPI.schemas.ts +24 -0
- package/examples/form_data_schema/split/formDataAPI.ts +98 -0
- package/examples/form_data_schema/split/k6-script.sample.ts +11 -0
- package/examples/form_data_schema/tags/default.ts +98 -0
- package/examples/form_data_schema/tags/formDataAPI.schemas.ts +24 -0
- package/examples/form_data_schema/tags/k6-script.sample.ts +11 -0
- package/examples/form_url_encoded_data_schema/single/formURLEncodedAPI.ts +112 -0
- package/examples/form_url_encoded_data_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.schemas.ts +24 -0
- package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.ts +98 -0
- package/examples/form_url_encoded_data_schema/split/k6-script.sample.ts +11 -0
- package/examples/form_url_encoded_data_schema/tags/default.ts +98 -0
- package/examples/form_url_encoded_data_schema/tags/formURLEncodedAPI.schemas.ts +24 -0
- package/examples/form_url_encoded_data_schema/tags/k6-script.sample.ts +11 -0
- package/examples/form_url_encoded_data_with_query_params_schema/single/formURLEncodedAPIWithQueryParameters.ts +128 -0
- package/examples/form_url_encoded_data_with_query_params_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.schemas.ts +35 -0
- package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.ts +104 -0
- package/examples/form_url_encoded_data_with_query_params_schema/split/k6-script.sample.ts +14 -0
- package/examples/form_url_encoded_data_with_query_params_schema/tags/default.ts +104 -0
- package/examples/form_url_encoded_data_with_query_params_schema/tags/formURLEncodedAPIWithQueryParameters.schemas.ts +35 -0
- package/examples/form_url_encoded_data_with_query_params_schema/tags/k6-script.sample.ts +14 -0
- package/examples/get_request_with_path_parameters_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/get_request_with_path_parameters_schema/single/simpleAPI.ts +94 -0
- package/examples/get_request_with_path_parameters_schema/split/k6-script.sample.ts +11 -0
- package/examples/get_request_with_path_parameters_schema/split/simpleAPI.schemas.ts +12 -0
- package/examples/get_request_with_path_parameters_schema/split/simpleAPI.ts +90 -0
- package/examples/get_request_with_path_parameters_schema/tags/default.ts +90 -0
- package/examples/get_request_with_path_parameters_schema/tags/k6-script.sample.ts +11 -0
- package/examples/get_request_with_path_parameters_schema/tags/simpleAPI.schemas.ts +12 -0
- package/examples/headers_schema/single/headerDemoAPI.ts +202 -0
- package/examples/headers_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/headers_schema/split/headerDemoAPI.schemas.ts +32 -0
- package/examples/headers_schema/split/headerDemoAPI.ts +184 -0
- package/examples/headers_schema/split/k6-script.sample.ts +25 -0
- package/examples/headers_schema/tags/default.ts +182 -0
- package/examples/headers_schema/tags/headerDemoAPI.schemas.ts +32 -0
- package/examples/headers_schema/tags/k6-script.sample.ts +25 -0
- package/examples/no_title_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/no_title_schema/single/k6Client.ts +87 -0
- package/examples/{basic_schema → no_title_schema/split}/k6-script.sample.ts +2 -2
- package/examples/no_title_schema/split/k6Client.schemas.ts +9 -0
- package/examples/no_title_schema/split/k6Client.ts +85 -0
- package/examples/no_title_schema/tags/default.ts +85 -0
- package/examples/no_title_schema/tags/k6-script.sample.ts +11 -0
- package/examples/no_title_schema/tags/k6Client.schemas.ts +9 -0
- package/examples/post_request_with_query_params/single/exampleAPI.ts +126 -0
- package/examples/post_request_with_query_params/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/post_request_with_query_params/split/exampleAPI.schemas.ts +33 -0
- package/examples/post_request_with_query_params/split/exampleAPI.ts +105 -0
- package/examples/post_request_with_query_params/split/k6-script.sample.ts +14 -0
- package/examples/post_request_with_query_params/tags/default.ts +105 -0
- package/examples/post_request_with_query_params/tags/exampleAPI.schemas.ts +33 -0
- package/examples/post_request_with_query_params/tags/k6-script.sample.ts +14 -0
- package/examples/query_params_schema/single/exampleAPI.ts +120 -0
- package/examples/query_params_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/query_params_schema/split/exampleAPI.schemas.ts +37 -0
- package/examples/query_params_schema/split/exampleAPI.ts +94 -0
- package/examples/query_params_schema/split/k6-script.sample.ts +11 -0
- package/examples/query_params_schema/tags/default.ts +94 -0
- package/examples/query_params_schema/tags/exampleAPI.schemas.ts +37 -0
- package/examples/query_params_schema/tags/k6-script.sample.ts +11 -0
- package/examples/simple_post_request_schema/{exampleAPI.ts → single/exampleAPI.ts} +49 -49
- package/examples/simple_post_request_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/simple_post_request_schema/split/exampleAPI.schemas.ts +47 -0
- package/examples/simple_post_request_schema/split/exampleAPI.ts +99 -0
- package/examples/simple_post_request_schema/split/k6-script.sample.ts +13 -0
- package/examples/simple_post_request_schema/tags/default.ts +99 -0
- package/examples/simple_post_request_schema/tags/exampleAPI.schemas.ts +47 -0
- package/examples/simple_post_request_schema/tags/k6-script.sample.ts +13 -0
- package/images/openapi-to-k6.png +0 -0
- package/package.json +2 -2
- package/src/analytics.ts +3 -1
- package/src/cli.ts +34 -8
- package/src/constants.ts +7 -1
- package/src/{generator.ts → generator/index.ts} +8 -21
- package/src/{k6SdkClient.ts → generator/k6Client.ts} +174 -222
- package/src/type.d.ts +4 -4
- package/tests/e2e/schema.json +8 -0
- package/tests/e2e/{k6Script.ts → single/k6Script.ts} +7 -2
- package/tests/e2e/split/k6Script.ts +82 -0
- package/tests/e2e/tags/k6Script.ts +106 -0
- package/tests/functional-tests/fixtures/schemas/basic_schema.json +1 -4
- package/tests/functional-tests/fixtures/schemas/form_data_schema.json +4 -4
- package/tests/functional-tests/fixtures/schemas/form_url_encoded_data_schema.json +3 -3
- package/tests/functional-tests/fixtures/schemas/form_url_encoded_data_with_query_params_schema.json +2 -2
- package/tests/functional-tests/fixtures/schemas/get_request_with_path_parameters_schema.json +2 -2
- package/tests/functional-tests/fixtures/schemas/headers_schema.json +7 -8
- package/tests/functional-tests/fixtures/schemas/no_title_schema.json +2 -5
- package/tests/functional-tests/fixtures/schemas/post_request_with_query_params.json +3 -4
- package/tests/functional-tests/fixtures/schemas/query_params_schema.json +3 -3
- package/tests/functional-tests/fixtures/schemas/simple_post_request_schema.json +3 -5
- package/tests/functional-tests/generator.test.ts +46 -5
- package/examples/basic_schema/simpleAPI.ts +0 -87
- package/examples/form_data_schema/formDataAPI.ts +0 -115
- package/examples/form_url_encoded_data_schema/formURLEncodedAPI.ts +0 -114
- package/examples/form_url_encoded_data_with_query_params_schema/formURLEncodedAPIWithQueryParameters.ts +0 -130
- package/examples/get_request_with_path_parameters_schema/simpleAPI.ts +0 -94
- package/examples/headers_schema/headerDemoAPI.ts +0 -196
- package/examples/no_title_schema/K6Client.ts +0 -86
- package/examples/post_request_with_query_params/exampleAPI.ts +0 -124
- package/examples/query_params_schema/exampleAPI.ts +0 -118
- package/examples/update_examples.sh +0 -21
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Form Data API
|
|
5
|
+
* OpenAPI spec version: 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
import { FormData } from 'https://jslib.k6.io/formdata/0.0.2/index.js'
|
|
8
|
+
import { URL } from 'https://jslib.k6.io/url/1.0.0/index.js'
|
|
9
|
+
import http from 'k6/http'
|
|
10
|
+
import type { Params, Response } from 'k6/http'
|
|
11
|
+
export type PostUpload400 = {
|
|
12
|
+
error?: string
|
|
13
|
+
success?: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type PostUpload200 = {
|
|
17
|
+
message?: string
|
|
18
|
+
success?: boolean
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export type PostUploadBody = {
|
|
22
|
+
/** Description of the file */
|
|
23
|
+
description?: string
|
|
24
|
+
/** File to upload */
|
|
25
|
+
file: Blob
|
|
26
|
+
/** User ID associated with the upload */
|
|
27
|
+
userId: string
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* This is the base client to use for interacting with the API.
|
|
32
|
+
*/
|
|
33
|
+
export class FormDataAPIClient {
|
|
34
|
+
private cleanBaseUrl: string
|
|
35
|
+
private commonRequestParameters: Params
|
|
36
|
+
|
|
37
|
+
constructor(clientOptions: {
|
|
38
|
+
baseUrl: string
|
|
39
|
+
commonRequestParameters?: Params
|
|
40
|
+
}) {
|
|
41
|
+
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* This endpoint accepts form data and file uploads.
|
|
46
|
+
* @summary Upload files and data
|
|
47
|
+
*/
|
|
48
|
+
postUpload(
|
|
49
|
+
postUploadBody: PostUploadBody,
|
|
50
|
+
requestParameters?: Params
|
|
51
|
+
): {
|
|
52
|
+
response: Response
|
|
53
|
+
data: PostUpload200
|
|
54
|
+
} {
|
|
55
|
+
const formData = new FormData()
|
|
56
|
+
formData.append('file', postUploadBody.file)
|
|
57
|
+
if (postUploadBody.description !== undefined) {
|
|
58
|
+
formData.append('description', postUploadBody.description)
|
|
59
|
+
}
|
|
60
|
+
formData.append('userId', postUploadBody.userId)
|
|
61
|
+
|
|
62
|
+
const url = new URL(this.cleanBaseUrl + `/upload`)
|
|
63
|
+
const mergedRequestParameters = this._mergeRequestParameters(
|
|
64
|
+
requestParameters || {},
|
|
65
|
+
this.commonRequestParameters
|
|
66
|
+
)
|
|
67
|
+
const response = http.request('POST', url.toString(), formData.body(), {
|
|
68
|
+
...mergedRequestParameters,
|
|
69
|
+
headers: {
|
|
70
|
+
'Content-Type': 'multipart/form-data; boundary=' + formData.boundary,
|
|
71
|
+
...mergedRequestParameters?.headers,
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
let data
|
|
75
|
+
|
|
76
|
+
try {
|
|
77
|
+
data = response.json()
|
|
78
|
+
} catch {
|
|
79
|
+
data = response.body
|
|
80
|
+
}
|
|
81
|
+
return {
|
|
82
|
+
response,
|
|
83
|
+
data,
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Merges the provided request parameters with default parameters for the client.
|
|
89
|
+
*
|
|
90
|
+
* @param {Params} requestParameters - The parameters provided specifically for the request
|
|
91
|
+
* @param {Params} commonRequestParameters - Common parameters for all requests
|
|
92
|
+
* @returns {Params} - The merged parameters
|
|
93
|
+
*/
|
|
94
|
+
private _mergeRequestParameters(
|
|
95
|
+
requestParameters?: Params,
|
|
96
|
+
commonRequestParameters?: Params
|
|
97
|
+
): Params {
|
|
98
|
+
return {
|
|
99
|
+
...commonRequestParameters, // Default to common parameters
|
|
100
|
+
...requestParameters, // Override with request-specific parameters
|
|
101
|
+
headers: {
|
|
102
|
+
...(commonRequestParameters?.headers || {}), // Ensure headers are defined
|
|
103
|
+
...(requestParameters?.headers || {}),
|
|
104
|
+
},
|
|
105
|
+
cookies: {
|
|
106
|
+
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
107
|
+
...(requestParameters?.cookies || {}),
|
|
108
|
+
},
|
|
109
|
+
tags: {
|
|
110
|
+
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
111
|
+
...(requestParameters?.tags || {}),
|
|
112
|
+
},
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FormDataAPIClient } from './formDataAPI.ts'
|
|
2
2
|
|
|
3
3
|
const baseUrl = '<BASE_URL>'
|
|
4
|
-
const client =
|
|
4
|
+
const client = new FormDataAPIClient({ baseUrl })
|
|
5
5
|
|
|
6
6
|
export default function () {
|
|
7
7
|
/**
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Form Data API
|
|
5
|
+
* OpenAPI spec version: 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
export type PostUpload400 = {
|
|
8
|
+
error?: string
|
|
9
|
+
success?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type PostUpload200 = {
|
|
13
|
+
message?: string
|
|
14
|
+
success?: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type PostUploadBody = {
|
|
18
|
+
/** Description of the file */
|
|
19
|
+
description?: string
|
|
20
|
+
/** File to upload */
|
|
21
|
+
file: Blob
|
|
22
|
+
/** User ID associated with the upload */
|
|
23
|
+
userId: string
|
|
24
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Form Data API
|
|
5
|
+
* OpenAPI spec version: 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
import { FormData } from 'https://jslib.k6.io/formdata/0.0.2/index.js'
|
|
8
|
+
import { URL } from 'https://jslib.k6.io/url/1.0.0/index.js'
|
|
9
|
+
import http from 'k6/http'
|
|
10
|
+
import type { Params, Response } from 'k6/http'
|
|
11
|
+
import type { PostUpload200, PostUploadBody } from './formDataAPI.schemas'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* This is the base client to use for interacting with the API.
|
|
15
|
+
*/
|
|
16
|
+
export class FormDataAPIClient {
|
|
17
|
+
private cleanBaseUrl: string
|
|
18
|
+
private commonRequestParameters: Params
|
|
19
|
+
|
|
20
|
+
constructor(clientOptions: {
|
|
21
|
+
baseUrl: string
|
|
22
|
+
commonRequestParameters?: Params
|
|
23
|
+
}) {
|
|
24
|
+
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* This endpoint accepts form data and file uploads.
|
|
29
|
+
* @summary Upload files and data
|
|
30
|
+
*/
|
|
31
|
+
postUpload(
|
|
32
|
+
postUploadBody: PostUploadBody,
|
|
33
|
+
requestParameters?: Params
|
|
34
|
+
): {
|
|
35
|
+
response: Response
|
|
36
|
+
data: PostUpload200
|
|
37
|
+
} {
|
|
38
|
+
const formData = new FormData()
|
|
39
|
+
formData.append('file', postUploadBody.file)
|
|
40
|
+
if (postUploadBody.description !== undefined) {
|
|
41
|
+
formData.append('description', postUploadBody.description)
|
|
42
|
+
}
|
|
43
|
+
formData.append('userId', postUploadBody.userId)
|
|
44
|
+
|
|
45
|
+
const url = new URL(this.cleanBaseUrl + `/upload`)
|
|
46
|
+
const mergedRequestParameters = this._mergeRequestParameters(
|
|
47
|
+
requestParameters || {},
|
|
48
|
+
this.commonRequestParameters
|
|
49
|
+
)
|
|
50
|
+
const response = http.request('POST', url.toString(), formData.body(), {
|
|
51
|
+
...mergedRequestParameters,
|
|
52
|
+
headers: {
|
|
53
|
+
'Content-Type': 'multipart/form-data; boundary=' + formData.boundary,
|
|
54
|
+
...mergedRequestParameters?.headers,
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
let data
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
data = response.json()
|
|
61
|
+
} catch {
|
|
62
|
+
data = response.body
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
response,
|
|
66
|
+
data,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Merges the provided request parameters with default parameters for the client.
|
|
72
|
+
*
|
|
73
|
+
* @param {Params} requestParameters - The parameters provided specifically for the request
|
|
74
|
+
* @param {Params} commonRequestParameters - Common parameters for all requests
|
|
75
|
+
* @returns {Params} - The merged parameters
|
|
76
|
+
*/
|
|
77
|
+
private _mergeRequestParameters(
|
|
78
|
+
requestParameters?: Params,
|
|
79
|
+
commonRequestParameters?: Params
|
|
80
|
+
): Params {
|
|
81
|
+
return {
|
|
82
|
+
...commonRequestParameters, // Default to common parameters
|
|
83
|
+
...requestParameters, // Override with request-specific parameters
|
|
84
|
+
headers: {
|
|
85
|
+
...(commonRequestParameters?.headers || {}), // Ensure headers are defined
|
|
86
|
+
...(requestParameters?.headers || {}),
|
|
87
|
+
},
|
|
88
|
+
cookies: {
|
|
89
|
+
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
90
|
+
...(requestParameters?.cookies || {}),
|
|
91
|
+
},
|
|
92
|
+
tags: {
|
|
93
|
+
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
94
|
+
...(requestParameters?.tags || {}),
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FormDataAPIClient } from './formDataAPI.ts'
|
|
2
|
+
|
|
3
|
+
const baseUrl = '<BASE_URL>'
|
|
4
|
+
const client = new FormDataAPIClient({ baseUrl })
|
|
5
|
+
|
|
6
|
+
export default function () {
|
|
7
|
+
/**
|
|
8
|
+
* Upload files and data
|
|
9
|
+
*/
|
|
10
|
+
const postUploadResponseData = client.postUpload(postUploadBody)
|
|
11
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Form Data API
|
|
5
|
+
* OpenAPI spec version: 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
import { FormData } from 'https://jslib.k6.io/formdata/0.0.2/index.js'
|
|
8
|
+
import { URL } from 'https://jslib.k6.io/url/1.0.0/index.js'
|
|
9
|
+
import http from 'k6/http'
|
|
10
|
+
import type { Params, Response } from 'k6/http'
|
|
11
|
+
import type { PostUpload200, PostUploadBody } from './formDataAPI.schemas'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* This is the base client to use for interacting with the API.
|
|
15
|
+
*/
|
|
16
|
+
export class DefaultClient {
|
|
17
|
+
private cleanBaseUrl: string
|
|
18
|
+
private commonRequestParameters: Params
|
|
19
|
+
|
|
20
|
+
constructor(clientOptions: {
|
|
21
|
+
baseUrl: string
|
|
22
|
+
commonRequestParameters?: Params
|
|
23
|
+
}) {
|
|
24
|
+
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* This endpoint accepts form data and file uploads.
|
|
29
|
+
* @summary Upload files and data
|
|
30
|
+
*/
|
|
31
|
+
postUpload(
|
|
32
|
+
postUploadBody: PostUploadBody,
|
|
33
|
+
requestParameters?: Params
|
|
34
|
+
): {
|
|
35
|
+
response: Response
|
|
36
|
+
data: PostUpload200
|
|
37
|
+
} {
|
|
38
|
+
const formData = new FormData()
|
|
39
|
+
formData.append('file', postUploadBody.file)
|
|
40
|
+
if (postUploadBody.description !== undefined) {
|
|
41
|
+
formData.append('description', postUploadBody.description)
|
|
42
|
+
}
|
|
43
|
+
formData.append('userId', postUploadBody.userId)
|
|
44
|
+
|
|
45
|
+
const url = new URL(this.cleanBaseUrl + `/upload`)
|
|
46
|
+
const mergedRequestParameters = this._mergeRequestParameters(
|
|
47
|
+
requestParameters || {},
|
|
48
|
+
this.commonRequestParameters
|
|
49
|
+
)
|
|
50
|
+
const response = http.request('POST', url.toString(), formData.body(), {
|
|
51
|
+
...mergedRequestParameters,
|
|
52
|
+
headers: {
|
|
53
|
+
'Content-Type': 'multipart/form-data; boundary=' + formData.boundary,
|
|
54
|
+
...mergedRequestParameters?.headers,
|
|
55
|
+
},
|
|
56
|
+
})
|
|
57
|
+
let data
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
data = response.json()
|
|
61
|
+
} catch {
|
|
62
|
+
data = response.body
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
response,
|
|
66
|
+
data,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Merges the provided request parameters with default parameters for the client.
|
|
72
|
+
*
|
|
73
|
+
* @param {Params} requestParameters - The parameters provided specifically for the request
|
|
74
|
+
* @param {Params} commonRequestParameters - Common parameters for all requests
|
|
75
|
+
* @returns {Params} - The merged parameters
|
|
76
|
+
*/
|
|
77
|
+
private _mergeRequestParameters(
|
|
78
|
+
requestParameters?: Params,
|
|
79
|
+
commonRequestParameters?: Params
|
|
80
|
+
): Params {
|
|
81
|
+
return {
|
|
82
|
+
...commonRequestParameters, // Default to common parameters
|
|
83
|
+
...requestParameters, // Override with request-specific parameters
|
|
84
|
+
headers: {
|
|
85
|
+
...(commonRequestParameters?.headers || {}), // Ensure headers are defined
|
|
86
|
+
...(requestParameters?.headers || {}),
|
|
87
|
+
},
|
|
88
|
+
cookies: {
|
|
89
|
+
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
90
|
+
...(requestParameters?.cookies || {}),
|
|
91
|
+
},
|
|
92
|
+
tags: {
|
|
93
|
+
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
94
|
+
...(requestParameters?.tags || {}),
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Form Data API
|
|
5
|
+
* OpenAPI spec version: 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
export type PostUpload400 = {
|
|
8
|
+
error?: string
|
|
9
|
+
success?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type PostUpload200 = {
|
|
13
|
+
message?: string
|
|
14
|
+
success?: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type PostUploadBody = {
|
|
18
|
+
/** Description of the file */
|
|
19
|
+
description?: string
|
|
20
|
+
/** File to upload */
|
|
21
|
+
file: Blob
|
|
22
|
+
/** User ID associated with the upload */
|
|
23
|
+
userId: string
|
|
24
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FormDataAPIClient } from './formDataAPI.ts'
|
|
2
|
+
|
|
3
|
+
const baseUrl = '<BASE_URL>'
|
|
4
|
+
const client = new FormDataAPIClient({ baseUrl })
|
|
5
|
+
|
|
6
|
+
export default function () {
|
|
7
|
+
/**
|
|
8
|
+
* Upload files and data
|
|
9
|
+
*/
|
|
10
|
+
const postUploadResponseData = client.postUpload(postUploadBody)
|
|
11
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Form URL Encoded API
|
|
5
|
+
* OpenAPI spec version: 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
import { URL } from 'https://jslib.k6.io/url/1.0.0/index.js'
|
|
8
|
+
import http from 'k6/http'
|
|
9
|
+
import type { Params, Response } from 'k6/http'
|
|
10
|
+
export type PostSubmitForm400 = {
|
|
11
|
+
error?: string
|
|
12
|
+
success?: boolean
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type PostSubmitForm200 = {
|
|
16
|
+
message?: string
|
|
17
|
+
success?: boolean
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export type PostSubmitFormBody = {
|
|
21
|
+
/** Age of the user */
|
|
22
|
+
age?: number
|
|
23
|
+
/** Email address of the user */
|
|
24
|
+
email: string
|
|
25
|
+
/** Name of the user */
|
|
26
|
+
name: string
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* This is the base client to use for interacting with the API.
|
|
31
|
+
*/
|
|
32
|
+
export class FormURLEncodedAPIClient {
|
|
33
|
+
private cleanBaseUrl: string
|
|
34
|
+
private commonRequestParameters: Params
|
|
35
|
+
|
|
36
|
+
constructor(clientOptions: {
|
|
37
|
+
baseUrl: string
|
|
38
|
+
commonRequestParameters?: Params
|
|
39
|
+
}) {
|
|
40
|
+
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* This endpoint accepts form URL-encoded data.
|
|
45
|
+
* @summary Submit form data
|
|
46
|
+
*/
|
|
47
|
+
postSubmitForm(
|
|
48
|
+
postSubmitFormBody: PostSubmitFormBody,
|
|
49
|
+
requestParameters?: Params
|
|
50
|
+
): {
|
|
51
|
+
response: Response
|
|
52
|
+
data: PostSubmitForm200
|
|
53
|
+
} {
|
|
54
|
+
const url = new URL(this.cleanBaseUrl + `/submit-form`)
|
|
55
|
+
const mergedRequestParameters = this._mergeRequestParameters(
|
|
56
|
+
requestParameters || {},
|
|
57
|
+
this.commonRequestParameters
|
|
58
|
+
)
|
|
59
|
+
const response = http.request(
|
|
60
|
+
'POST',
|
|
61
|
+
url.toString(),
|
|
62
|
+
JSON.stringify(postSubmitFormBody),
|
|
63
|
+
{
|
|
64
|
+
...mergedRequestParameters,
|
|
65
|
+
headers: {
|
|
66
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
67
|
+
...mergedRequestParameters?.headers,
|
|
68
|
+
},
|
|
69
|
+
}
|
|
70
|
+
)
|
|
71
|
+
let data
|
|
72
|
+
|
|
73
|
+
try {
|
|
74
|
+
data = response.json()
|
|
75
|
+
} catch {
|
|
76
|
+
data = response.body
|
|
77
|
+
}
|
|
78
|
+
return {
|
|
79
|
+
response,
|
|
80
|
+
data,
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Merges the provided request parameters with default parameters for the client.
|
|
86
|
+
*
|
|
87
|
+
* @param {Params} requestParameters - The parameters provided specifically for the request
|
|
88
|
+
* @param {Params} commonRequestParameters - Common parameters for all requests
|
|
89
|
+
* @returns {Params} - The merged parameters
|
|
90
|
+
*/
|
|
91
|
+
private _mergeRequestParameters(
|
|
92
|
+
requestParameters?: Params,
|
|
93
|
+
commonRequestParameters?: Params
|
|
94
|
+
): Params {
|
|
95
|
+
return {
|
|
96
|
+
...commonRequestParameters, // Default to common parameters
|
|
97
|
+
...requestParameters, // Override with request-specific parameters
|
|
98
|
+
headers: {
|
|
99
|
+
...(commonRequestParameters?.headers || {}), // Ensure headers are defined
|
|
100
|
+
...(requestParameters?.headers || {}),
|
|
101
|
+
},
|
|
102
|
+
cookies: {
|
|
103
|
+
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
104
|
+
...(requestParameters?.cookies || {}),
|
|
105
|
+
},
|
|
106
|
+
tags: {
|
|
107
|
+
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
108
|
+
...(requestParameters?.tags || {}),
|
|
109
|
+
},
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
package/examples/form_url_encoded_data_schema/{k6-script.sample.ts → single/k6-script.sample.ts}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { FormURLEncodedAPIClient } from './formURLEncodedAPI.ts'
|
|
2
2
|
|
|
3
3
|
const baseUrl = '<BASE_URL>'
|
|
4
|
-
const client =
|
|
4
|
+
const client = new FormURLEncodedAPIClient({ baseUrl })
|
|
5
5
|
|
|
6
6
|
export default function () {
|
|
7
7
|
/**
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Form URL Encoded API
|
|
5
|
+
* OpenAPI spec version: 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
export type PostSubmitForm400 = {
|
|
8
|
+
error?: string
|
|
9
|
+
success?: boolean
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type PostSubmitForm200 = {
|
|
13
|
+
message?: string
|
|
14
|
+
success?: boolean
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type PostSubmitFormBody = {
|
|
18
|
+
/** Age of the user */
|
|
19
|
+
age?: number
|
|
20
|
+
/** Email address of the user */
|
|
21
|
+
email: string
|
|
22
|
+
/** Name of the user */
|
|
23
|
+
name: string
|
|
24
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Form URL Encoded API
|
|
5
|
+
* OpenAPI spec version: 1.0.0
|
|
6
|
+
*/
|
|
7
|
+
import { URL } from 'https://jslib.k6.io/url/1.0.0/index.js'
|
|
8
|
+
import http from 'k6/http'
|
|
9
|
+
import type { Params, Response } from 'k6/http'
|
|
10
|
+
import type {
|
|
11
|
+
PostSubmitForm200,
|
|
12
|
+
PostSubmitFormBody,
|
|
13
|
+
} from './formURLEncodedAPI.schemas'
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* This is the base client to use for interacting with the API.
|
|
17
|
+
*/
|
|
18
|
+
export class FormURLEncodedAPIClient {
|
|
19
|
+
private cleanBaseUrl: string
|
|
20
|
+
private commonRequestParameters: Params
|
|
21
|
+
|
|
22
|
+
constructor(clientOptions: {
|
|
23
|
+
baseUrl: string
|
|
24
|
+
commonRequestParameters?: Params
|
|
25
|
+
}) {
|
|
26
|
+
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* This endpoint accepts form URL-encoded data.
|
|
31
|
+
* @summary Submit form data
|
|
32
|
+
*/
|
|
33
|
+
postSubmitForm(
|
|
34
|
+
postSubmitFormBody: PostSubmitFormBody,
|
|
35
|
+
requestParameters?: Params
|
|
36
|
+
): {
|
|
37
|
+
response: Response
|
|
38
|
+
data: PostSubmitForm200
|
|
39
|
+
} {
|
|
40
|
+
const url = new URL(this.cleanBaseUrl + `/submit-form`)
|
|
41
|
+
const mergedRequestParameters = this._mergeRequestParameters(
|
|
42
|
+
requestParameters || {},
|
|
43
|
+
this.commonRequestParameters
|
|
44
|
+
)
|
|
45
|
+
const response = http.request(
|
|
46
|
+
'POST',
|
|
47
|
+
url.toString(),
|
|
48
|
+
JSON.stringify(postSubmitFormBody),
|
|
49
|
+
{
|
|
50
|
+
...mergedRequestParameters,
|
|
51
|
+
headers: {
|
|
52
|
+
'Content-Type': 'application/x-www-form-urlencoded',
|
|
53
|
+
...mergedRequestParameters?.headers,
|
|
54
|
+
},
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
let data
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
data = response.json()
|
|
61
|
+
} catch {
|
|
62
|
+
data = response.body
|
|
63
|
+
}
|
|
64
|
+
return {
|
|
65
|
+
response,
|
|
66
|
+
data,
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Merges the provided request parameters with default parameters for the client.
|
|
72
|
+
*
|
|
73
|
+
* @param {Params} requestParameters - The parameters provided specifically for the request
|
|
74
|
+
* @param {Params} commonRequestParameters - Common parameters for all requests
|
|
75
|
+
* @returns {Params} - The merged parameters
|
|
76
|
+
*/
|
|
77
|
+
private _mergeRequestParameters(
|
|
78
|
+
requestParameters?: Params,
|
|
79
|
+
commonRequestParameters?: Params
|
|
80
|
+
): Params {
|
|
81
|
+
return {
|
|
82
|
+
...commonRequestParameters, // Default to common parameters
|
|
83
|
+
...requestParameters, // Override with request-specific parameters
|
|
84
|
+
headers: {
|
|
85
|
+
...(commonRequestParameters?.headers || {}), // Ensure headers are defined
|
|
86
|
+
...(requestParameters?.headers || {}),
|
|
87
|
+
},
|
|
88
|
+
cookies: {
|
|
89
|
+
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
90
|
+
...(requestParameters?.cookies || {}),
|
|
91
|
+
},
|
|
92
|
+
tags: {
|
|
93
|
+
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
94
|
+
...(requestParameters?.tags || {}),
|
|
95
|
+
},
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { FormURLEncodedAPIClient } from './formURLEncodedAPI.ts'
|
|
2
|
+
|
|
3
|
+
const baseUrl = '<BASE_URL>'
|
|
4
|
+
const client = new FormURLEncodedAPIClient({ baseUrl })
|
|
5
|
+
|
|
6
|
+
export default function () {
|
|
7
|
+
/**
|
|
8
|
+
* Submit form data
|
|
9
|
+
*/
|
|
10
|
+
const postSubmitFormResponseData = client.postSubmitForm(postSubmitFormBody)
|
|
11
|
+
}
|