@grafana/openapi-to-k6 0.1.2 → 0.2.0
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 -0
- package/.github/workflows/tests.yaml +14 -6
- package/README.md +49 -14
- package/dist/cli.js +18 -2
- 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/cli.ts +28 -2
- 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 +3 -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,33 @@
|
|
|
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
|
+
export type CreateExampleData201 = {
|
|
9
|
+
/** The data from the body */
|
|
10
|
+
data?: string
|
|
11
|
+
/** The active status from the query parameter */
|
|
12
|
+
isActive?: boolean
|
|
13
|
+
/** Response status */
|
|
14
|
+
status?: string
|
|
15
|
+
/** The user ID from the query parameter */
|
|
16
|
+
userId?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type CreateExampleDataBody = {
|
|
20
|
+
/** A string field representing data */
|
|
21
|
+
data: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type CreateExampleDataParams = {
|
|
25
|
+
/**
|
|
26
|
+
* A string query parameter for user ID
|
|
27
|
+
*/
|
|
28
|
+
userId: string
|
|
29
|
+
/**
|
|
30
|
+
* A boolean query parameter
|
|
31
|
+
*/
|
|
32
|
+
isActive?: boolean
|
|
33
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ExampleAPIClient } from './exampleAPI.ts'
|
|
2
|
+
|
|
3
|
+
const baseUrl = '<BASE_URL>'
|
|
4
|
+
const client = new ExampleAPIClient({ baseUrl })
|
|
5
|
+
|
|
6
|
+
export default function () {
|
|
7
|
+
/**
|
|
8
|
+
* Create example data
|
|
9
|
+
*/
|
|
10
|
+
const createExampleDataResponseData = client.createExampleData(
|
|
11
|
+
createExampleDataBody,
|
|
12
|
+
params
|
|
13
|
+
)
|
|
14
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Example API
|
|
5
|
+
* API with all formats of 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 GetExampleData200 = {
|
|
12
|
+
age?: number
|
|
13
|
+
date?: string
|
|
14
|
+
isActive?: boolean
|
|
15
|
+
name?: string
|
|
16
|
+
tags?: string[]
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type GetExampleDataParams = {
|
|
20
|
+
/**
|
|
21
|
+
* A string parameter
|
|
22
|
+
*/
|
|
23
|
+
name: string
|
|
24
|
+
/**
|
|
25
|
+
* An integer parameter
|
|
26
|
+
*/
|
|
27
|
+
age?: number
|
|
28
|
+
/**
|
|
29
|
+
* A boolean parameter
|
|
30
|
+
*/
|
|
31
|
+
isActive?: boolean
|
|
32
|
+
/**
|
|
33
|
+
* An array of strings parameter
|
|
34
|
+
*/
|
|
35
|
+
tags?: string[]
|
|
36
|
+
/**
|
|
37
|
+
* A date parameter in YYYY-MM-DD format
|
|
38
|
+
*/
|
|
39
|
+
date?: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* This is the base client to use for interacting with the API.
|
|
44
|
+
*/
|
|
45
|
+
export class ExampleAPIClient {
|
|
46
|
+
private cleanBaseUrl: string
|
|
47
|
+
private commonRequestParameters: Params
|
|
48
|
+
|
|
49
|
+
constructor(clientOptions: {
|
|
50
|
+
baseUrl: string
|
|
51
|
+
commonRequestParameters?: Params
|
|
52
|
+
}) {
|
|
53
|
+
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* This endpoint demonstrates the use of various query parameters
|
|
58
|
+
* @summary Get example data
|
|
59
|
+
*/
|
|
60
|
+
getExampleData(
|
|
61
|
+
params: GetExampleDataParams,
|
|
62
|
+
requestParameters?: Params
|
|
63
|
+
): {
|
|
64
|
+
response: Response
|
|
65
|
+
data: GetExampleData200
|
|
66
|
+
} {
|
|
67
|
+
const url = new URL(
|
|
68
|
+
this.cleanBaseUrl +
|
|
69
|
+
`/example` +
|
|
70
|
+
`?${new URLSearchParams(params).toString()}`
|
|
71
|
+
)
|
|
72
|
+
const mergedRequestParameters = this._mergeRequestParameters(
|
|
73
|
+
requestParameters || {},
|
|
74
|
+
this.commonRequestParameters
|
|
75
|
+
)
|
|
76
|
+
const response = http.request('GET', url.toString(), undefined, {
|
|
77
|
+
...mergedRequestParameters,
|
|
78
|
+
})
|
|
79
|
+
let data
|
|
80
|
+
|
|
81
|
+
try {
|
|
82
|
+
data = response.json()
|
|
83
|
+
} catch {
|
|
84
|
+
data = response.body
|
|
85
|
+
}
|
|
86
|
+
return {
|
|
87
|
+
response,
|
|
88
|
+
data,
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Merges the provided request parameters with default parameters for the client.
|
|
94
|
+
*
|
|
95
|
+
* @param {Params} requestParameters - The parameters provided specifically for the request
|
|
96
|
+
* @param {Params} commonRequestParameters - Common parameters for all requests
|
|
97
|
+
* @returns {Params} - The merged parameters
|
|
98
|
+
*/
|
|
99
|
+
private _mergeRequestParameters(
|
|
100
|
+
requestParameters?: Params,
|
|
101
|
+
commonRequestParameters?: Params
|
|
102
|
+
): Params {
|
|
103
|
+
return {
|
|
104
|
+
...commonRequestParameters, // Default to common parameters
|
|
105
|
+
...requestParameters, // Override with request-specific parameters
|
|
106
|
+
headers: {
|
|
107
|
+
...(commonRequestParameters?.headers || {}), // Ensure headers are defined
|
|
108
|
+
...(requestParameters?.headers || {}),
|
|
109
|
+
},
|
|
110
|
+
cookies: {
|
|
111
|
+
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
112
|
+
...(requestParameters?.cookies || {}),
|
|
113
|
+
},
|
|
114
|
+
tags: {
|
|
115
|
+
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
116
|
+
...(requestParameters?.tags || {}),
|
|
117
|
+
},
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
@@ -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
|
/**
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Example API
|
|
5
|
+
* API with all formats of query parameters
|
|
6
|
+
* OpenAPI spec version: 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
export type GetExampleData200 = {
|
|
9
|
+
age?: number
|
|
10
|
+
date?: string
|
|
11
|
+
isActive?: boolean
|
|
12
|
+
name?: string
|
|
13
|
+
tags?: string[]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type GetExampleDataParams = {
|
|
17
|
+
/**
|
|
18
|
+
* A string parameter
|
|
19
|
+
*/
|
|
20
|
+
name: string
|
|
21
|
+
/**
|
|
22
|
+
* An integer parameter
|
|
23
|
+
*/
|
|
24
|
+
age?: number
|
|
25
|
+
/**
|
|
26
|
+
* A boolean parameter
|
|
27
|
+
*/
|
|
28
|
+
isActive?: boolean
|
|
29
|
+
/**
|
|
30
|
+
* An array of strings parameter
|
|
31
|
+
*/
|
|
32
|
+
tags?: string[]
|
|
33
|
+
/**
|
|
34
|
+
* A date parameter in YYYY-MM-DD format
|
|
35
|
+
*/
|
|
36
|
+
date?: string
|
|
37
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Example API
|
|
5
|
+
* API with all formats of 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
|
+
import type {
|
|
12
|
+
GetExampleData200,
|
|
13
|
+
GetExampleDataParams,
|
|
14
|
+
} from './exampleAPI.schemas'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* This is the base client to use for interacting with the API.
|
|
18
|
+
*/
|
|
19
|
+
export class ExampleAPIClient {
|
|
20
|
+
private cleanBaseUrl: string
|
|
21
|
+
private commonRequestParameters: Params
|
|
22
|
+
|
|
23
|
+
constructor(clientOptions: {
|
|
24
|
+
baseUrl: string
|
|
25
|
+
commonRequestParameters?: Params
|
|
26
|
+
}) {
|
|
27
|
+
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* This endpoint demonstrates the use of various query parameters
|
|
32
|
+
* @summary Get example data
|
|
33
|
+
*/
|
|
34
|
+
getExampleData(
|
|
35
|
+
params: GetExampleDataParams,
|
|
36
|
+
requestParameters?: Params
|
|
37
|
+
): {
|
|
38
|
+
response: Response
|
|
39
|
+
data: GetExampleData200
|
|
40
|
+
} {
|
|
41
|
+
const url = new URL(
|
|
42
|
+
this.cleanBaseUrl +
|
|
43
|
+
`/example` +
|
|
44
|
+
`?${new URLSearchParams(params).toString()}`
|
|
45
|
+
)
|
|
46
|
+
const mergedRequestParameters = this._mergeRequestParameters(
|
|
47
|
+
requestParameters || {},
|
|
48
|
+
this.commonRequestParameters
|
|
49
|
+
)
|
|
50
|
+
const response = http.request('GET', url.toString(), undefined, {
|
|
51
|
+
...mergedRequestParameters,
|
|
52
|
+
})
|
|
53
|
+
let data
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
data = response.json()
|
|
57
|
+
} catch {
|
|
58
|
+
data = response.body
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
response,
|
|
62
|
+
data,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Merges the provided request parameters with default parameters for the client.
|
|
68
|
+
*
|
|
69
|
+
* @param {Params} requestParameters - The parameters provided specifically for the request
|
|
70
|
+
* @param {Params} commonRequestParameters - Common parameters for all requests
|
|
71
|
+
* @returns {Params} - The merged parameters
|
|
72
|
+
*/
|
|
73
|
+
private _mergeRequestParameters(
|
|
74
|
+
requestParameters?: Params,
|
|
75
|
+
commonRequestParameters?: Params
|
|
76
|
+
): Params {
|
|
77
|
+
return {
|
|
78
|
+
...commonRequestParameters, // Default to common parameters
|
|
79
|
+
...requestParameters, // Override with request-specific parameters
|
|
80
|
+
headers: {
|
|
81
|
+
...(commonRequestParameters?.headers || {}), // Ensure headers are defined
|
|
82
|
+
...(requestParameters?.headers || {}),
|
|
83
|
+
},
|
|
84
|
+
cookies: {
|
|
85
|
+
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
86
|
+
...(requestParameters?.cookies || {}),
|
|
87
|
+
},
|
|
88
|
+
tags: {
|
|
89
|
+
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
90
|
+
...(requestParameters?.tags || {}),
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ExampleAPIClient } from './exampleAPI.ts'
|
|
2
|
+
|
|
3
|
+
const baseUrl = '<BASE_URL>'
|
|
4
|
+
const client = new ExampleAPIClient({ baseUrl })
|
|
5
|
+
|
|
6
|
+
export default function () {
|
|
7
|
+
/**
|
|
8
|
+
* Get example data
|
|
9
|
+
*/
|
|
10
|
+
const getExampleDataResponseData = client.getExampleData(params)
|
|
11
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Example API
|
|
5
|
+
* API with all formats of 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
|
+
import type {
|
|
12
|
+
GetExampleData200,
|
|
13
|
+
GetExampleDataParams,
|
|
14
|
+
} from './exampleAPI.schemas'
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* This is the base client to use for interacting with the API.
|
|
18
|
+
*/
|
|
19
|
+
export class DefaultClient {
|
|
20
|
+
private cleanBaseUrl: string
|
|
21
|
+
private commonRequestParameters: Params
|
|
22
|
+
|
|
23
|
+
constructor(clientOptions: {
|
|
24
|
+
baseUrl: string
|
|
25
|
+
commonRequestParameters?: Params
|
|
26
|
+
}) {
|
|
27
|
+
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* This endpoint demonstrates the use of various query parameters
|
|
32
|
+
* @summary Get example data
|
|
33
|
+
*/
|
|
34
|
+
getExampleData(
|
|
35
|
+
params: GetExampleDataParams,
|
|
36
|
+
requestParameters?: Params
|
|
37
|
+
): {
|
|
38
|
+
response: Response
|
|
39
|
+
data: GetExampleData200
|
|
40
|
+
} {
|
|
41
|
+
const url = new URL(
|
|
42
|
+
this.cleanBaseUrl +
|
|
43
|
+
`/example` +
|
|
44
|
+
`?${new URLSearchParams(params).toString()}`
|
|
45
|
+
)
|
|
46
|
+
const mergedRequestParameters = this._mergeRequestParameters(
|
|
47
|
+
requestParameters || {},
|
|
48
|
+
this.commonRequestParameters
|
|
49
|
+
)
|
|
50
|
+
const response = http.request('GET', url.toString(), undefined, {
|
|
51
|
+
...mergedRequestParameters,
|
|
52
|
+
})
|
|
53
|
+
let data
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
data = response.json()
|
|
57
|
+
} catch {
|
|
58
|
+
data = response.body
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
response,
|
|
62
|
+
data,
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Merges the provided request parameters with default parameters for the client.
|
|
68
|
+
*
|
|
69
|
+
* @param {Params} requestParameters - The parameters provided specifically for the request
|
|
70
|
+
* @param {Params} commonRequestParameters - Common parameters for all requests
|
|
71
|
+
* @returns {Params} - The merged parameters
|
|
72
|
+
*/
|
|
73
|
+
private _mergeRequestParameters(
|
|
74
|
+
requestParameters?: Params,
|
|
75
|
+
commonRequestParameters?: Params
|
|
76
|
+
): Params {
|
|
77
|
+
return {
|
|
78
|
+
...commonRequestParameters, // Default to common parameters
|
|
79
|
+
...requestParameters, // Override with request-specific parameters
|
|
80
|
+
headers: {
|
|
81
|
+
...(commonRequestParameters?.headers || {}), // Ensure headers are defined
|
|
82
|
+
...(requestParameters?.headers || {}),
|
|
83
|
+
},
|
|
84
|
+
cookies: {
|
|
85
|
+
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
86
|
+
...(requestParameters?.cookies || {}),
|
|
87
|
+
},
|
|
88
|
+
tags: {
|
|
89
|
+
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
90
|
+
...(requestParameters?.tags || {}),
|
|
91
|
+
},
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Example API
|
|
5
|
+
* API with all formats of query parameters
|
|
6
|
+
* OpenAPI spec version: 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
export type GetExampleData200 = {
|
|
9
|
+
age?: number
|
|
10
|
+
date?: string
|
|
11
|
+
isActive?: boolean
|
|
12
|
+
name?: string
|
|
13
|
+
tags?: string[]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export type GetExampleDataParams = {
|
|
17
|
+
/**
|
|
18
|
+
* A string parameter
|
|
19
|
+
*/
|
|
20
|
+
name: string
|
|
21
|
+
/**
|
|
22
|
+
* An integer parameter
|
|
23
|
+
*/
|
|
24
|
+
age?: number
|
|
25
|
+
/**
|
|
26
|
+
* A boolean parameter
|
|
27
|
+
*/
|
|
28
|
+
isActive?: boolean
|
|
29
|
+
/**
|
|
30
|
+
* An array of strings parameter
|
|
31
|
+
*/
|
|
32
|
+
tags?: string[]
|
|
33
|
+
/**
|
|
34
|
+
* A date parameter in YYYY-MM-DD format
|
|
35
|
+
*/
|
|
36
|
+
date?: string
|
|
37
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ExampleAPIClient } from './exampleAPI.ts'
|
|
2
|
+
|
|
3
|
+
const baseUrl = '<BASE_URL>'
|
|
4
|
+
const client = new ExampleAPIClient({ baseUrl })
|
|
5
|
+
|
|
6
|
+
export default function () {
|
|
7
|
+
/**
|
|
8
|
+
* Get example data
|
|
9
|
+
*/
|
|
10
|
+
const getExampleDataResponseData = client.getExampleData(params)
|
|
11
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of data in the POST request body
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import { URL } from 'https://jslib.k6.io/url/1.0.0/index.js'
|
|
9
9
|
import http from 'k6/http'
|
|
10
|
-
import type { Params, Response
|
|
10
|
+
import type { Params, Response } from 'k6/http'
|
|
11
11
|
export type CreateExampleData201Meta = {
|
|
12
12
|
createdBy?: string
|
|
13
13
|
updatedBy?: string
|
|
@@ -49,28 +49,35 @@ export type CreateExampleDataBody = {
|
|
|
49
49
|
tags?: string[]
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export type CreateExampleAPIOptions = {
|
|
53
|
-
baseUrl: string
|
|
54
|
-
commonRequestParameters?: Params
|
|
55
|
-
}
|
|
56
|
-
|
|
57
52
|
/**
|
|
58
53
|
* This is the base client to use for interacting with the API.
|
|
59
54
|
*/
|
|
60
|
-
export
|
|
61
|
-
|
|
55
|
+
export class ExampleAPIClient {
|
|
56
|
+
private cleanBaseUrl: string
|
|
57
|
+
private commonRequestParameters: Params
|
|
58
|
+
|
|
59
|
+
constructor(clientOptions: {
|
|
60
|
+
baseUrl: string
|
|
61
|
+
commonRequestParameters?: Params
|
|
62
|
+
}) {
|
|
63
|
+
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
64
|
+
}
|
|
65
|
+
|
|
62
66
|
/**
|
|
63
67
|
* This endpoint demonstrates the use of various data formats in the input body
|
|
64
68
|
* @summary Create example data
|
|
65
69
|
*/
|
|
66
|
-
|
|
70
|
+
createExampleData(
|
|
67
71
|
createExampleDataBody: CreateExampleDataBody,
|
|
68
72
|
requestParameters?: Params
|
|
69
|
-
):
|
|
70
|
-
|
|
71
|
-
|
|
73
|
+
): {
|
|
74
|
+
response: Response
|
|
75
|
+
data: CreateExampleData201
|
|
76
|
+
} {
|
|
77
|
+
const url = new URL(this.cleanBaseUrl + `/example`)
|
|
78
|
+
const mergedRequestParameters = this._mergeRequestParameters(
|
|
72
79
|
requestParameters || {},
|
|
73
|
-
|
|
80
|
+
this.commonRequestParameters
|
|
74
81
|
)
|
|
75
82
|
const response = http.request(
|
|
76
83
|
'POST',
|
|
@@ -88,7 +95,7 @@ export const createExampleAPI = (clientOptions: CreateExampleAPIOptions) => {
|
|
|
88
95
|
|
|
89
96
|
try {
|
|
90
97
|
data = response.json()
|
|
91
|
-
} catch
|
|
98
|
+
} catch {
|
|
92
99
|
data = response.body
|
|
93
100
|
}
|
|
94
101
|
return {
|
|
@@ -97,39 +104,32 @@ export const createExampleAPI = (clientOptions: CreateExampleAPIOptions) => {
|
|
|
97
104
|
}
|
|
98
105
|
}
|
|
99
106
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
128
|
-
...(requestParameters?.cookies || {}),
|
|
129
|
-
},
|
|
130
|
-
tags: {
|
|
131
|
-
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
132
|
-
...(requestParameters?.tags || {}),
|
|
133
|
-
},
|
|
107
|
+
/**
|
|
108
|
+
* Merges the provided request parameters with default parameters for the client.
|
|
109
|
+
*
|
|
110
|
+
* @param {Params} requestParameters - The parameters provided specifically for the request
|
|
111
|
+
* @param {Params} commonRequestParameters - Common parameters for all requests
|
|
112
|
+
* @returns {Params} - The merged parameters
|
|
113
|
+
*/
|
|
114
|
+
private _mergeRequestParameters(
|
|
115
|
+
requestParameters?: Params,
|
|
116
|
+
commonRequestParameters?: Params
|
|
117
|
+
): Params {
|
|
118
|
+
return {
|
|
119
|
+
...commonRequestParameters, // Default to common parameters
|
|
120
|
+
...requestParameters, // Override with request-specific parameters
|
|
121
|
+
headers: {
|
|
122
|
+
...(commonRequestParameters?.headers || {}), // Ensure headers are defined
|
|
123
|
+
...(requestParameters?.headers || {}),
|
|
124
|
+
},
|
|
125
|
+
cookies: {
|
|
126
|
+
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
127
|
+
...(requestParameters?.cookies || {}),
|
|
128
|
+
},
|
|
129
|
+
tags: {
|
|
130
|
+
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
131
|
+
...(requestParameters?.tags || {}),
|
|
132
|
+
},
|
|
133
|
+
}
|
|
134
134
|
}
|
|
135
135
|
}
|
package/examples/simple_post_request_schema/{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
|
/**
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.2.0
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
* Example API
|
|
5
|
+
* API with all formats of data in the POST request body
|
|
6
|
+
* OpenAPI spec version: 1.0.0
|
|
7
|
+
*/
|
|
8
|
+
export type CreateExampleData201Meta = {
|
|
9
|
+
createdBy?: string
|
|
10
|
+
updatedBy?: string
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type CreateExampleData201 = {
|
|
14
|
+
age?: number
|
|
15
|
+
date?: string
|
|
16
|
+
/** The unique ID of the created resource */
|
|
17
|
+
id?: string
|
|
18
|
+
isActive?: boolean
|
|
19
|
+
meta?: CreateExampleData201Meta
|
|
20
|
+
name?: string
|
|
21
|
+
tags?: string[]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* An object parameter containing metadata
|
|
26
|
+
*/
|
|
27
|
+
export type CreateExampleDataBodyMeta = {
|
|
28
|
+
/** A string parameter for the creator's name */
|
|
29
|
+
createdBy?: string
|
|
30
|
+
/** A string parameter for the updater's name */
|
|
31
|
+
updatedBy?: string
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export type CreateExampleDataBody = {
|
|
35
|
+
/** An integer parameter */
|
|
36
|
+
age: number
|
|
37
|
+
/** A date parameter in YYYY-MM-DD format */
|
|
38
|
+
date?: string
|
|
39
|
+
/** A boolean parameter */
|
|
40
|
+
isActive: boolean
|
|
41
|
+
/** An object parameter containing metadata */
|
|
42
|
+
meta?: CreateExampleDataBodyMeta
|
|
43
|
+
/** A string parameter */
|
|
44
|
+
name: string
|
|
45
|
+
/** An array of strings */
|
|
46
|
+
tags?: string[]
|
|
47
|
+
}
|