@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,182 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Header Demo API
|
|
5
|
+
* An API demonstrating the use of headers in different ways
|
|
6
|
+
* OpenAPI spec version: 1.0.0
|
|
7
|
+
*/
|
|
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 {
|
|
12
|
+
GetExampleGet200,
|
|
13
|
+
GetExampleGetHeaders,
|
|
14
|
+
GetExampleResponseHeaders200,
|
|
15
|
+
PostExamplePostBody,
|
|
16
|
+
PostExamplePostHeaders,
|
|
17
|
+
} from './headerDemoAPI.schemas'
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* This is the base client to use for interacting with the API.
|
|
21
|
+
*/
|
|
22
|
+
export class DefaultClient {
|
|
23
|
+
private cleanBaseUrl: string
|
|
24
|
+
private commonRequestParameters: Params
|
|
25
|
+
|
|
26
|
+
constructor(clientOptions: {
|
|
27
|
+
baseUrl: string
|
|
28
|
+
commonRequestParameters?: Params
|
|
29
|
+
}) {
|
|
30
|
+
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* This GET request demonstrates the use of custom request headers
|
|
35
|
+
* @summary GET request with headers
|
|
36
|
+
*/
|
|
37
|
+
getExampleGet(
|
|
38
|
+
headers?: GetExampleGetHeaders,
|
|
39
|
+
requestParameters?: Params
|
|
40
|
+
): {
|
|
41
|
+
response: Response
|
|
42
|
+
data: GetExampleGet200
|
|
43
|
+
} {
|
|
44
|
+
const url = new URL(this.cleanBaseUrl + `/example-get`)
|
|
45
|
+
const mergedRequestParameters = this._mergeRequestParameters(
|
|
46
|
+
requestParameters || {},
|
|
47
|
+
this.commonRequestParameters
|
|
48
|
+
)
|
|
49
|
+
const response = http.request('GET', url.toString(), undefined, {
|
|
50
|
+
...mergedRequestParameters,
|
|
51
|
+
headers: {
|
|
52
|
+
// In the schema, headers can be of any type like number but k6 accepts only strings as headers, hence converting all headers to string
|
|
53
|
+
...Object.fromEntries(
|
|
54
|
+
Object.entries(headers || {}).map(([key, value]) => [
|
|
55
|
+
key,
|
|
56
|
+
String(value),
|
|
57
|
+
])
|
|
58
|
+
),
|
|
59
|
+
...mergedRequestParameters?.headers,
|
|
60
|
+
},
|
|
61
|
+
})
|
|
62
|
+
let data
|
|
63
|
+
|
|
64
|
+
try {
|
|
65
|
+
data = response.json()
|
|
66
|
+
} catch {
|
|
67
|
+
data = response.body
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
response,
|
|
71
|
+
data,
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* This POST request uses a security header for authentication
|
|
76
|
+
* @summary POST request with security headers
|
|
77
|
+
*/
|
|
78
|
+
postExamplePost(
|
|
79
|
+
postExamplePostBody: PostExamplePostBody,
|
|
80
|
+
headers: PostExamplePostHeaders,
|
|
81
|
+
requestParameters?: Params
|
|
82
|
+
): {
|
|
83
|
+
response: Response
|
|
84
|
+
data: void
|
|
85
|
+
} {
|
|
86
|
+
const url = new URL(this.cleanBaseUrl + `/example-post`)
|
|
87
|
+
const mergedRequestParameters = this._mergeRequestParameters(
|
|
88
|
+
requestParameters || {},
|
|
89
|
+
this.commonRequestParameters
|
|
90
|
+
)
|
|
91
|
+
const response = http.request(
|
|
92
|
+
'POST',
|
|
93
|
+
url.toString(),
|
|
94
|
+
JSON.stringify(postExamplePostBody),
|
|
95
|
+
{
|
|
96
|
+
...mergedRequestParameters,
|
|
97
|
+
headers: {
|
|
98
|
+
'Content-Type': 'application/json',
|
|
99
|
+
// In the schema, headers can be of any type like number but k6 accepts only strings as headers, hence converting all headers to string
|
|
100
|
+
...Object.fromEntries(
|
|
101
|
+
Object.entries(headers || {}).map(([key, value]) => [
|
|
102
|
+
key,
|
|
103
|
+
String(value),
|
|
104
|
+
])
|
|
105
|
+
),
|
|
106
|
+
...mergedRequestParameters?.headers,
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
let data
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
data = response.json()
|
|
114
|
+
} catch {
|
|
115
|
+
data = response.body
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
response,
|
|
119
|
+
data,
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* This GET request returns custom response headers
|
|
124
|
+
* @summary GET request with response headers only
|
|
125
|
+
*/
|
|
126
|
+
getExampleResponseHeaders(requestParameters?: Params): {
|
|
127
|
+
response: Response
|
|
128
|
+
data: GetExampleResponseHeaders200
|
|
129
|
+
} {
|
|
130
|
+
const url = new URL(this.cleanBaseUrl + `/example-response-headers`)
|
|
131
|
+
const mergedRequestParameters = this._mergeRequestParameters(
|
|
132
|
+
requestParameters || {},
|
|
133
|
+
this.commonRequestParameters
|
|
134
|
+
)
|
|
135
|
+
const response = http.request(
|
|
136
|
+
'GET',
|
|
137
|
+
url.toString(),
|
|
138
|
+
undefined,
|
|
139
|
+
mergedRequestParameters
|
|
140
|
+
)
|
|
141
|
+
let data
|
|
142
|
+
|
|
143
|
+
try {
|
|
144
|
+
data = response.json()
|
|
145
|
+
} catch {
|
|
146
|
+
data = response.body
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
response,
|
|
150
|
+
data,
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Merges the provided request parameters with default parameters for the client.
|
|
156
|
+
*
|
|
157
|
+
* @param {Params} requestParameters - The parameters provided specifically for the request
|
|
158
|
+
* @param {Params} commonRequestParameters - Common parameters for all requests
|
|
159
|
+
* @returns {Params} - The merged parameters
|
|
160
|
+
*/
|
|
161
|
+
private _mergeRequestParameters(
|
|
162
|
+
requestParameters?: Params,
|
|
163
|
+
commonRequestParameters?: Params
|
|
164
|
+
): Params {
|
|
165
|
+
return {
|
|
166
|
+
...commonRequestParameters, // Default to common parameters
|
|
167
|
+
...requestParameters, // Override with request-specific parameters
|
|
168
|
+
headers: {
|
|
169
|
+
...(commonRequestParameters?.headers || {}), // Ensure headers are defined
|
|
170
|
+
...(requestParameters?.headers || {}),
|
|
171
|
+
},
|
|
172
|
+
cookies: {
|
|
173
|
+
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
174
|
+
...(requestParameters?.cookies || {}),
|
|
175
|
+
},
|
|
176
|
+
tags: {
|
|
177
|
+
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
178
|
+
...(requestParameters?.tags || {}),
|
|
179
|
+
},
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Header Demo API
|
|
5
|
+
* An API demonstrating the use of headers in different ways
|
|
6
|
+
* OpenAPI spec version: 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
export type GetExampleResponseHeaders200 = {
|
|
9
|
+
status?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type PostExamplePostBody = {
|
|
13
|
+
data?: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type PostExamplePostHeaders = {
|
|
17
|
+
/**
|
|
18
|
+
* Bearer token for authorization
|
|
19
|
+
*/
|
|
20
|
+
Authorization: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export type GetExampleGet200 = {
|
|
24
|
+
message?: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type GetExampleGetHeaders = {
|
|
28
|
+
/**
|
|
29
|
+
* A custom header for this request
|
|
30
|
+
*/
|
|
31
|
+
'X-Custom-Header'?: string
|
|
32
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { HeaderDemoAPIClient } from './headerDemoAPI.ts'
|
|
2
|
+
|
|
3
|
+
const baseUrl = '<BASE_URL>'
|
|
4
|
+
const client = new HeaderDemoAPIClient({ baseUrl })
|
|
5
|
+
|
|
6
|
+
export default function () {
|
|
7
|
+
/**
|
|
8
|
+
* GET request with headers
|
|
9
|
+
*/
|
|
10
|
+
const getExampleGetResponseData = client.getExampleGet()
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* POST request with security headers
|
|
14
|
+
*/
|
|
15
|
+
const postExamplePostResponseData = client.postExamplePost(
|
|
16
|
+
postExamplePostBody,
|
|
17
|
+
headers
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* GET request with response headers only
|
|
22
|
+
*/
|
|
23
|
+
const getExampleResponseHeadersResponseData =
|
|
24
|
+
client.getExampleResponseHeaders()
|
|
25
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* K6Client
|
|
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 GetExample200 = {
|
|
11
|
+
message?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* This is the base client to use for interacting with the API.
|
|
16
|
+
*/
|
|
17
|
+
export class K6ClientClient {
|
|
18
|
+
private cleanBaseUrl: string
|
|
19
|
+
private commonRequestParameters: Params
|
|
20
|
+
|
|
21
|
+
constructor(clientOptions: {
|
|
22
|
+
baseUrl: string
|
|
23
|
+
commonRequestParameters?: Params
|
|
24
|
+
}) {
|
|
25
|
+
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* @summary Retrieve example data
|
|
30
|
+
*/
|
|
31
|
+
getExample(requestParameters?: Params): {
|
|
32
|
+
response: Response
|
|
33
|
+
data: GetExample200
|
|
34
|
+
} {
|
|
35
|
+
const url = new URL(this.cleanBaseUrl + `/example`)
|
|
36
|
+
const mergedRequestParameters = this._mergeRequestParameters(
|
|
37
|
+
requestParameters || {},
|
|
38
|
+
this.commonRequestParameters
|
|
39
|
+
)
|
|
40
|
+
const response = http.request(
|
|
41
|
+
'GET',
|
|
42
|
+
url.toString(),
|
|
43
|
+
undefined,
|
|
44
|
+
mergedRequestParameters
|
|
45
|
+
)
|
|
46
|
+
let data
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
data = response.json()
|
|
50
|
+
} catch {
|
|
51
|
+
data = response.body
|
|
52
|
+
}
|
|
53
|
+
return {
|
|
54
|
+
response,
|
|
55
|
+
data,
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Merges the provided request parameters with default parameters for the client.
|
|
61
|
+
*
|
|
62
|
+
* @param {Params} requestParameters - The parameters provided specifically for the request
|
|
63
|
+
* @param {Params} commonRequestParameters - Common parameters for all requests
|
|
64
|
+
* @returns {Params} - The merged parameters
|
|
65
|
+
*/
|
|
66
|
+
private _mergeRequestParameters(
|
|
67
|
+
requestParameters?: Params,
|
|
68
|
+
commonRequestParameters?: Params
|
|
69
|
+
): Params {
|
|
70
|
+
return {
|
|
71
|
+
...commonRequestParameters, // Default to common parameters
|
|
72
|
+
...requestParameters, // Override with request-specific parameters
|
|
73
|
+
headers: {
|
|
74
|
+
...(commonRequestParameters?.headers || {}), // Ensure headers are defined
|
|
75
|
+
...(requestParameters?.headers || {}),
|
|
76
|
+
},
|
|
77
|
+
cookies: {
|
|
78
|
+
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
79
|
+
...(requestParameters?.cookies || {}),
|
|
80
|
+
},
|
|
81
|
+
tags: {
|
|
82
|
+
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
83
|
+
...(requestParameters?.tags || {}),
|
|
84
|
+
},
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { K6ClientClient } from './k6Client.ts'
|
|
2
2
|
|
|
3
3
|
const baseUrl = '<BASE_URL>'
|
|
4
|
-
const client =
|
|
4
|
+
const client = new K6ClientClient({ baseUrl })
|
|
5
5
|
|
|
6
6
|
export default function () {
|
|
7
7
|
/**
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* K6Client
|
|
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 { GetExample200 } from './k6Client.schemas'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* This is the base client to use for interacting with the API.
|
|
14
|
+
*/
|
|
15
|
+
export class K6ClientClient {
|
|
16
|
+
private cleanBaseUrl: string
|
|
17
|
+
private commonRequestParameters: Params
|
|
18
|
+
|
|
19
|
+
constructor(clientOptions: {
|
|
20
|
+
baseUrl: string
|
|
21
|
+
commonRequestParameters?: Params
|
|
22
|
+
}) {
|
|
23
|
+
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @summary Retrieve example data
|
|
28
|
+
*/
|
|
29
|
+
getExample(requestParameters?: Params): {
|
|
30
|
+
response: Response
|
|
31
|
+
data: GetExample200
|
|
32
|
+
} {
|
|
33
|
+
const url = new URL(this.cleanBaseUrl + `/example`)
|
|
34
|
+
const mergedRequestParameters = this._mergeRequestParameters(
|
|
35
|
+
requestParameters || {},
|
|
36
|
+
this.commonRequestParameters
|
|
37
|
+
)
|
|
38
|
+
const response = http.request(
|
|
39
|
+
'GET',
|
|
40
|
+
url.toString(),
|
|
41
|
+
undefined,
|
|
42
|
+
mergedRequestParameters
|
|
43
|
+
)
|
|
44
|
+
let data
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
data = response.json()
|
|
48
|
+
} catch {
|
|
49
|
+
data = response.body
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
response,
|
|
53
|
+
data,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Merges the provided request parameters with default parameters for the client.
|
|
59
|
+
*
|
|
60
|
+
* @param {Params} requestParameters - The parameters provided specifically for the request
|
|
61
|
+
* @param {Params} commonRequestParameters - Common parameters for all requests
|
|
62
|
+
* @returns {Params} - The merged parameters
|
|
63
|
+
*/
|
|
64
|
+
private _mergeRequestParameters(
|
|
65
|
+
requestParameters?: Params,
|
|
66
|
+
commonRequestParameters?: Params
|
|
67
|
+
): Params {
|
|
68
|
+
return {
|
|
69
|
+
...commonRequestParameters, // Default to common parameters
|
|
70
|
+
...requestParameters, // Override with request-specific parameters
|
|
71
|
+
headers: {
|
|
72
|
+
...(commonRequestParameters?.headers || {}), // Ensure headers are defined
|
|
73
|
+
...(requestParameters?.headers || {}),
|
|
74
|
+
},
|
|
75
|
+
cookies: {
|
|
76
|
+
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
77
|
+
...(requestParameters?.cookies || {}),
|
|
78
|
+
},
|
|
79
|
+
tags: {
|
|
80
|
+
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
81
|
+
...(requestParameters?.tags || {}),
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* K6Client
|
|
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 { GetExample200 } from './k6Client.schemas'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* This is the base client to use for interacting with the API.
|
|
14
|
+
*/
|
|
15
|
+
export class DefaultClient {
|
|
16
|
+
private cleanBaseUrl: string
|
|
17
|
+
private commonRequestParameters: Params
|
|
18
|
+
|
|
19
|
+
constructor(clientOptions: {
|
|
20
|
+
baseUrl: string
|
|
21
|
+
commonRequestParameters?: Params
|
|
22
|
+
}) {
|
|
23
|
+
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @summary Retrieve example data
|
|
28
|
+
*/
|
|
29
|
+
getExample(requestParameters?: Params): {
|
|
30
|
+
response: Response
|
|
31
|
+
data: GetExample200
|
|
32
|
+
} {
|
|
33
|
+
const url = new URL(this.cleanBaseUrl + `/example`)
|
|
34
|
+
const mergedRequestParameters = this._mergeRequestParameters(
|
|
35
|
+
requestParameters || {},
|
|
36
|
+
this.commonRequestParameters
|
|
37
|
+
)
|
|
38
|
+
const response = http.request(
|
|
39
|
+
'GET',
|
|
40
|
+
url.toString(),
|
|
41
|
+
undefined,
|
|
42
|
+
mergedRequestParameters
|
|
43
|
+
)
|
|
44
|
+
let data
|
|
45
|
+
|
|
46
|
+
try {
|
|
47
|
+
data = response.json()
|
|
48
|
+
} catch {
|
|
49
|
+
data = response.body
|
|
50
|
+
}
|
|
51
|
+
return {
|
|
52
|
+
response,
|
|
53
|
+
data,
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Merges the provided request parameters with default parameters for the client.
|
|
59
|
+
*
|
|
60
|
+
* @param {Params} requestParameters - The parameters provided specifically for the request
|
|
61
|
+
* @param {Params} commonRequestParameters - Common parameters for all requests
|
|
62
|
+
* @returns {Params} - The merged parameters
|
|
63
|
+
*/
|
|
64
|
+
private _mergeRequestParameters(
|
|
65
|
+
requestParameters?: Params,
|
|
66
|
+
commonRequestParameters?: Params
|
|
67
|
+
): Params {
|
|
68
|
+
return {
|
|
69
|
+
...commonRequestParameters, // Default to common parameters
|
|
70
|
+
...requestParameters, // Override with request-specific parameters
|
|
71
|
+
headers: {
|
|
72
|
+
...(commonRequestParameters?.headers || {}), // Ensure headers are defined
|
|
73
|
+
...(requestParameters?.headers || {}),
|
|
74
|
+
},
|
|
75
|
+
cookies: {
|
|
76
|
+
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
77
|
+
...(requestParameters?.cookies || {}),
|
|
78
|
+
},
|
|
79
|
+
tags: {
|
|
80
|
+
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
81
|
+
...(requestParameters?.tags || {}),
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Example API
|
|
5
|
+
* API with a POST request having an object as the body and query parameters
|
|
6
|
+
* OpenAPI spec version: 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
import { URL, URLSearchParams } 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 CreateExampleData201 = {
|
|
12
|
+
/** The data from the body */
|
|
13
|
+
data?: string
|
|
14
|
+
/** The active status from the query parameter */
|
|
15
|
+
isActive?: boolean
|
|
16
|
+
/** Response status */
|
|
17
|
+
status?: string
|
|
18
|
+
/** The user ID from the query parameter */
|
|
19
|
+
userId?: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type CreateExampleDataBody = {
|
|
23
|
+
/** A string field representing data */
|
|
24
|
+
data: string
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export type CreateExampleDataParams = {
|
|
28
|
+
/**
|
|
29
|
+
* A string query parameter for user ID
|
|
30
|
+
*/
|
|
31
|
+
userId: string
|
|
32
|
+
/**
|
|
33
|
+
* A boolean query parameter
|
|
34
|
+
*/
|
|
35
|
+
isActive?: boolean
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* This is the base client to use for interacting with the API.
|
|
40
|
+
*/
|
|
41
|
+
export class ExampleAPIClient {
|
|
42
|
+
private cleanBaseUrl: string
|
|
43
|
+
private commonRequestParameters: Params
|
|
44
|
+
|
|
45
|
+
constructor(clientOptions: {
|
|
46
|
+
baseUrl: string
|
|
47
|
+
commonRequestParameters?: Params
|
|
48
|
+
}) {
|
|
49
|
+
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* This endpoint demonstrates a POST request with query parameters and a single field object in the body
|
|
54
|
+
* @summary Create example data
|
|
55
|
+
*/
|
|
56
|
+
createExampleData(
|
|
57
|
+
createExampleDataBody: CreateExampleDataBody,
|
|
58
|
+
params: CreateExampleDataParams,
|
|
59
|
+
requestParameters?: Params
|
|
60
|
+
): {
|
|
61
|
+
response: Response
|
|
62
|
+
data: CreateExampleData201
|
|
63
|
+
} {
|
|
64
|
+
const url = new URL(
|
|
65
|
+
this.cleanBaseUrl +
|
|
66
|
+
`/example` +
|
|
67
|
+
`?${new URLSearchParams(params).toString()}`
|
|
68
|
+
)
|
|
69
|
+
const mergedRequestParameters = this._mergeRequestParameters(
|
|
70
|
+
requestParameters || {},
|
|
71
|
+
this.commonRequestParameters
|
|
72
|
+
)
|
|
73
|
+
const response = http.request(
|
|
74
|
+
'POST',
|
|
75
|
+
url.toString(),
|
|
76
|
+
JSON.stringify(createExampleDataBody),
|
|
77
|
+
{
|
|
78
|
+
...mergedRequestParameters,
|
|
79
|
+
headers: {
|
|
80
|
+
'Content-Type': 'application/json',
|
|
81
|
+
...mergedRequestParameters?.headers,
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
)
|
|
85
|
+
let data
|
|
86
|
+
|
|
87
|
+
try {
|
|
88
|
+
data = response.json()
|
|
89
|
+
} catch {
|
|
90
|
+
data = response.body
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
response,
|
|
94
|
+
data,
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Merges the provided request parameters with default parameters for the client.
|
|
100
|
+
*
|
|
101
|
+
* @param {Params} requestParameters - The parameters provided specifically for the request
|
|
102
|
+
* @param {Params} commonRequestParameters - Common parameters for all requests
|
|
103
|
+
* @returns {Params} - The merged parameters
|
|
104
|
+
*/
|
|
105
|
+
private _mergeRequestParameters(
|
|
106
|
+
requestParameters?: Params,
|
|
107
|
+
commonRequestParameters?: Params
|
|
108
|
+
): Params {
|
|
109
|
+
return {
|
|
110
|
+
...commonRequestParameters, // Default to common parameters
|
|
111
|
+
...requestParameters, // Override with request-specific parameters
|
|
112
|
+
headers: {
|
|
113
|
+
...(commonRequestParameters?.headers || {}), // Ensure headers are defined
|
|
114
|
+
...(requestParameters?.headers || {}),
|
|
115
|
+
},
|
|
116
|
+
cookies: {
|
|
117
|
+
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
118
|
+
...(requestParameters?.cookies || {}),
|
|
119
|
+
},
|
|
120
|
+
tags: {
|
|
121
|
+
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
122
|
+
...(requestParameters?.tags || {}),
|
|
123
|
+
},
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
package/examples/post_request_with_query_params/{k6-script.sample.ts → single/k6-script.sample.ts}
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ExampleAPIClient } from './exampleAPI.ts'
|
|
2
2
|
|
|
3
3
|
const baseUrl = '<BASE_URL>'
|
|
4
|
-
const client =
|
|
4
|
+
const client = new ExampleAPIClient({ baseUrl })
|
|
5
5
|
|
|
6
6
|
export default function () {
|
|
7
7
|
/**
|