@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
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.1.2
|
|
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, ResponseBody } 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
|
-
export type CreateExampleAPIOptions = {
|
|
39
|
-
baseUrl: string
|
|
40
|
-
commonRequestParameters?: Params
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* This is the base client to use for interacting with the API.
|
|
45
|
-
*/
|
|
46
|
-
export const createExampleAPI = (clientOptions: CreateExampleAPIOptions) => {
|
|
47
|
-
const cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
48
|
-
/**
|
|
49
|
-
* This endpoint demonstrates a POST request with query parameters and a single field object in the body
|
|
50
|
-
* @summary Create example data
|
|
51
|
-
*/
|
|
52
|
-
const createExampleData = (
|
|
53
|
-
createExampleDataBody: CreateExampleDataBody,
|
|
54
|
-
params: CreateExampleDataParams,
|
|
55
|
-
requestParameters?: Params
|
|
56
|
-
): CreateExampleDataResponse => {
|
|
57
|
-
const url = new URL(
|
|
58
|
-
cleanBaseUrl + `/example` + `?${new URLSearchParams(params).toString()}`
|
|
59
|
-
)
|
|
60
|
-
const mergedRequestParameters = _mergeRequestParameters(
|
|
61
|
-
requestParameters || {},
|
|
62
|
-
clientOptions.commonRequestParameters
|
|
63
|
-
)
|
|
64
|
-
const response = http.request(
|
|
65
|
-
'POST',
|
|
66
|
-
url.toString(),
|
|
67
|
-
JSON.stringify(createExampleDataBody),
|
|
68
|
-
{
|
|
69
|
-
...mergedRequestParameters,
|
|
70
|
-
headers: {
|
|
71
|
-
'Content-Type': 'application/json',
|
|
72
|
-
...mergedRequestParameters?.headers,
|
|
73
|
-
},
|
|
74
|
-
}
|
|
75
|
-
)
|
|
76
|
-
let data
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
data = response.json()
|
|
80
|
-
} catch (error) {
|
|
81
|
-
data = response.body
|
|
82
|
-
}
|
|
83
|
-
return {
|
|
84
|
-
response,
|
|
85
|
-
data,
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return { createExampleData }
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
export type CreateExampleDataResponse = {
|
|
93
|
-
response: Response
|
|
94
|
-
data: CreateExampleData201 | ResponseBody
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Merges the provided request parameters with default parameters for the client.
|
|
99
|
-
*
|
|
100
|
-
* @param {Params} requestParameters - The parameters provided specifically for the request
|
|
101
|
-
* @param {Params} commonRequestParameters - Common parameters for all requests
|
|
102
|
-
* @returns {Params} - The merged parameters
|
|
103
|
-
*/
|
|
104
|
-
const _mergeRequestParameters = (
|
|
105
|
-
requestParameters?: Params,
|
|
106
|
-
commonRequestParameters?: Params
|
|
107
|
-
): Params => {
|
|
108
|
-
return {
|
|
109
|
-
...commonRequestParameters, // Default to common parameters
|
|
110
|
-
...requestParameters, // Override with request-specific parameters
|
|
111
|
-
headers: {
|
|
112
|
-
...(commonRequestParameters?.headers || {}), // Ensure headers are defined
|
|
113
|
-
...(requestParameters?.headers || {}),
|
|
114
|
-
},
|
|
115
|
-
cookies: {
|
|
116
|
-
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
117
|
-
...(requestParameters?.cookies || {}),
|
|
118
|
-
},
|
|
119
|
-
tags: {
|
|
120
|
-
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
121
|
-
...(requestParameters?.tags || {}),
|
|
122
|
-
},
|
|
123
|
-
}
|
|
124
|
-
}
|
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.1.2
|
|
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, ResponseBody } 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
|
-
export type CreateExampleAPIOptions = {
|
|
43
|
-
baseUrl: string
|
|
44
|
-
commonRequestParameters?: Params
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* This is the base client to use for interacting with the API.
|
|
49
|
-
*/
|
|
50
|
-
export const createExampleAPI = (clientOptions: CreateExampleAPIOptions) => {
|
|
51
|
-
const cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
52
|
-
/**
|
|
53
|
-
* This endpoint demonstrates the use of various query parameters
|
|
54
|
-
* @summary Get example data
|
|
55
|
-
*/
|
|
56
|
-
const getExampleData = (
|
|
57
|
-
params: GetExampleDataParams,
|
|
58
|
-
requestParameters?: Params
|
|
59
|
-
): GetExampleDataResponse => {
|
|
60
|
-
const url = new URL(
|
|
61
|
-
cleanBaseUrl + `/example` + `?${new URLSearchParams(params).toString()}`
|
|
62
|
-
)
|
|
63
|
-
const mergedRequestParameters = _mergeRequestParameters(
|
|
64
|
-
requestParameters || {},
|
|
65
|
-
clientOptions.commonRequestParameters
|
|
66
|
-
)
|
|
67
|
-
const response = http.request('GET', url.toString(), undefined, {
|
|
68
|
-
...mergedRequestParameters,
|
|
69
|
-
})
|
|
70
|
-
let data
|
|
71
|
-
|
|
72
|
-
try {
|
|
73
|
-
data = response.json()
|
|
74
|
-
} catch (error) {
|
|
75
|
-
data = response.body
|
|
76
|
-
}
|
|
77
|
-
return {
|
|
78
|
-
response,
|
|
79
|
-
data,
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return { getExampleData }
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export type GetExampleDataResponse = {
|
|
87
|
-
response: Response
|
|
88
|
-
data: GetExampleData200 | ResponseBody
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Merges the provided request parameters with default parameters for the client.
|
|
93
|
-
*
|
|
94
|
-
* @param {Params} requestParameters - The parameters provided specifically for the request
|
|
95
|
-
* @param {Params} commonRequestParameters - Common parameters for all requests
|
|
96
|
-
* @returns {Params} - The merged parameters
|
|
97
|
-
*/
|
|
98
|
-
const _mergeRequestParameters = (
|
|
99
|
-
requestParameters?: Params,
|
|
100
|
-
commonRequestParameters?: Params
|
|
101
|
-
): Params => {
|
|
102
|
-
return {
|
|
103
|
-
...commonRequestParameters, // Default to common parameters
|
|
104
|
-
...requestParameters, // Override with request-specific parameters
|
|
105
|
-
headers: {
|
|
106
|
-
...(commonRequestParameters?.headers || {}), // Ensure headers are defined
|
|
107
|
-
...(requestParameters?.headers || {}),
|
|
108
|
-
},
|
|
109
|
-
cookies: {
|
|
110
|
-
...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
|
|
111
|
-
...(requestParameters?.cookies || {}),
|
|
112
|
-
},
|
|
113
|
-
tags: {
|
|
114
|
-
...(commonRequestParameters?.tags || {}), // Ensure tags are defined
|
|
115
|
-
...(requestParameters?.tags || {}),
|
|
116
|
-
},
|
|
117
|
-
}
|
|
118
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
|
|
3
|
-
# Define the base directory
|
|
4
|
-
BASE_DIR="examples"
|
|
5
|
-
|
|
6
|
-
# Iterate through all folders in the base directory
|
|
7
|
-
for dir in "$BASE_DIR"/*/; do
|
|
8
|
-
# Check if the directory contains a schema.json file
|
|
9
|
-
if [ -f "$dir/schema.json" ]; then
|
|
10
|
-
# Change to the directory
|
|
11
|
-
cd "$dir" || continue
|
|
12
|
-
|
|
13
|
-
# Run the openapi-to-k6 command
|
|
14
|
-
npm run dev -- schema.json ./
|
|
15
|
-
|
|
16
|
-
# Change back to the base directory
|
|
17
|
-
cd - || exit
|
|
18
|
-
fi
|
|
19
|
-
done
|
|
20
|
-
|
|
21
|
-
echo "Processing complete."
|