@grafana/openapi-to-k6 0.2.6 → 0.3.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/README.md +5 -1
- package/dist/constants.js +7 -3
- package/dist/generator/index.js +13 -6
- package/dist/generator/k6Client.js +8 -56
- package/dist/generator/k6ScriptBuilder.js +256 -0
- package/dist/helper.js +16 -0
- package/examples/basic_schema/schema.json +2 -1
- package/examples/basic_schema/single/k6-script.sample.ts +3 -2
- package/examples/basic_schema/single/simpleAPI.ts +4 -1
- package/examples/basic_schema/split/k6-script.sample.ts +3 -2
- package/examples/basic_schema/split/simpleAPI.schemas.ts +2 -1
- package/examples/basic_schema/split/simpleAPI.ts +3 -1
- package/examples/basic_schema/tags/default.ts +3 -1
- package/examples/basic_schema/tags/k6-script.sample.ts +4 -3
- package/examples/basic_schema/tags/simpleAPI.schemas.ts +2 -1
- package/examples/form_data_schema/schema.json +6 -3
- package/examples/form_data_schema/single/formDataAPI.ts +8 -6
- package/examples/form_data_schema/single/k6-script.sample.ts +10 -2
- package/examples/form_data_schema/split/formDataAPI.schemas.ts +5 -5
- package/examples/form_data_schema/split/formDataAPI.ts +4 -2
- package/examples/form_data_schema/split/k6-script.sample.ts +10 -2
- package/examples/form_data_schema/tags/default.ts +4 -2
- package/examples/form_data_schema/tags/formDataAPI.schemas.ts +5 -5
- package/examples/form_data_schema/tags/k6-script.sample.ts +11 -3
- package/examples/form_url_encoded_data_schema/schema.json +6 -3
- package/examples/form_url_encoded_data_schema/single/formURLEncodedAPI.ts +8 -6
- package/examples/form_url_encoded_data_schema/single/k6-script.sample.ts +11 -2
- package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.schemas.ts +5 -5
- package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.ts +4 -2
- package/examples/form_url_encoded_data_schema/split/k6-script.sample.ts +11 -2
- package/examples/form_url_encoded_data_schema/tags/default.ts +4 -2
- package/examples/form_url_encoded_data_schema/tags/formURLEncodedAPI.schemas.ts +5 -5
- package/examples/form_url_encoded_data_schema/tags/k6-script.sample.ts +12 -3
- package/examples/form_url_encoded_data_with_query_params_schema/schema.json +8 -4
- package/examples/form_url_encoded_data_with_query_params_schema/single/formURLEncodedAPIWithQueryParameters.ts +8 -6
- package/examples/form_url_encoded_data_with_query_params_schema/single/k6-script.sample.ts +19 -6
- package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.schemas.ts +5 -5
- package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.ts +4 -2
- package/examples/form_url_encoded_data_with_query_params_schema/split/k6-script.sample.ts +19 -6
- package/examples/form_url_encoded_data_with_query_params_schema/tags/default.ts +4 -2
- package/examples/form_url_encoded_data_with_query_params_schema/tags/formURLEncodedAPIWithQueryParameters.schemas.ts +5 -5
- package/examples/form_url_encoded_data_with_query_params_schema/tags/k6-script.sample.ts +14 -3
- package/examples/get_request_with_path_parameters_schema/schema.json +2 -1
- package/examples/get_request_with_path_parameters_schema/single/k6-script.sample.ts +6 -2
- package/examples/get_request_with_path_parameters_schema/single/simpleAPI.ts +4 -2
- package/examples/get_request_with_path_parameters_schema/split/k6-script.sample.ts +6 -2
- package/examples/get_request_with_path_parameters_schema/split/simpleAPI.schemas.ts +2 -2
- package/examples/get_request_with_path_parameters_schema/split/simpleAPI.ts +3 -1
- package/examples/get_request_with_path_parameters_schema/tags/default.ts +3 -1
- package/examples/get_request_with_path_parameters_schema/tags/k6-script.sample.ts +7 -3
- package/examples/get_request_with_path_parameters_schema/tags/simpleAPI.schemas.ts +2 -2
- package/examples/headers_schema/schema.json +2 -1
- package/examples/headers_schema/single/headerDemoAPI.ts +5 -3
- package/examples/headers_schema/single/k6-script.sample.ts +15 -4
- package/examples/headers_schema/split/headerDemoAPI.schemas.ts +1 -1
- package/examples/headers_schema/split/headerDemoAPI.ts +5 -3
- package/examples/headers_schema/split/k6-script.sample.ts +15 -4
- package/examples/headers_schema/tags/default.ts +5 -3
- package/examples/headers_schema/tags/headerDemoAPI.schemas.ts +1 -1
- package/examples/headers_schema/tags/k6-script.sample.ts +16 -5
- package/examples/no_title_schema/single/k6-script.sample.ts +3 -2
- package/examples/no_title_schema/single/k6Client.ts +3 -1
- package/examples/no_title_schema/split/k6-script.sample.ts +3 -2
- package/examples/no_title_schema/split/k6Client.schemas.ts +1 -1
- package/examples/no_title_schema/split/k6Client.ts +3 -1
- package/examples/no_title_schema/tags/default.ts +3 -1
- package/examples/no_title_schema/tags/k6-script.sample.ts +4 -3
- package/examples/no_title_schema/tags/k6Client.schemas.ts +1 -1
- package/examples/post_request_with_query_params/schema.json +14 -7
- package/examples/post_request_with_query_params/single/exampleAPI.ts +8 -6
- package/examples/post_request_with_query_params/single/k6-script.sample.ts +11 -2
- package/examples/post_request_with_query_params/split/exampleAPI.schemas.ts +5 -5
- package/examples/post_request_with_query_params/split/exampleAPI.ts +4 -2
- package/examples/post_request_with_query_params/split/k6-script.sample.ts +11 -2
- package/examples/post_request_with_query_params/tags/default.ts +4 -2
- package/examples/post_request_with_query_params/tags/exampleAPI.schemas.ts +5 -5
- package/examples/post_request_with_query_params/tags/k6-script.sample.ts +12 -3
- package/examples/query_params_schema/schema.json +20 -10
- package/examples/query_params_schema/single/exampleAPI.ts +5 -3
- package/examples/query_params_schema/single/k6-script.sample.ts +8 -2
- package/examples/query_params_schema/split/exampleAPI.schemas.ts +3 -3
- package/examples/query_params_schema/split/exampleAPI.ts +3 -1
- package/examples/query_params_schema/split/k6-script.sample.ts +8 -2
- package/examples/query_params_schema/tags/default.ts +3 -1
- package/examples/query_params_schema/tags/exampleAPI.schemas.ts +3 -3
- package/examples/query_params_schema/tags/k6-script.sample.ts +9 -3
- package/examples/simple_post_request_schema/schema.json +30 -15
- package/examples/simple_post_request_schema/single/exampleAPI.ts +14 -12
- package/examples/simple_post_request_schema/single/k6-script.sample.ts +16 -2
- package/examples/simple_post_request_schema/split/exampleAPI.schemas.ts +11 -11
- package/examples/simple_post_request_schema/split/exampleAPI.ts +4 -2
- package/examples/simple_post_request_schema/split/k6-script.sample.ts +16 -2
- package/examples/simple_post_request_schema/tags/default.ts +4 -2
- package/examples/simple_post_request_schema/tags/exampleAPI.schemas.ts +11 -11
- package/examples/simple_post_request_schema/tags/k6-script.sample.ts +17 -3
- package/package.json +5 -2
- package/src/constants.ts +7 -3
- package/src/generator/index.ts +20 -7
- package/src/generator/k6Client.ts +6 -73
- package/src/generator/k6ScriptBuilder.ts +328 -0
- package/src/helper.ts +17 -0
- package/tests/e2e/schema.json +135 -18
- package/tests/e2e/single/k6Script.ts +54 -1
- package/tests/functional-tests/helper.ts +16 -0
- package/tests/functional-tests/test-generator/fixtures/basic_parameter_in_ref.json +59 -0
- package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/form_data_schema.json +1 -1
- package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/form_url_encoded_data_schema.json +1 -1
- package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/headers_schema.json +2 -2
- package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/simple_post_request_schema.json +1 -1
- package/tests/functional-tests/test-generator/generator.test.ts +154 -0
- package/tests/functional-tests/test-sample-k6-scripts/fixtures/schema_using_ref_models.json +394 -0
- package/tests/functional-tests/test-sample-k6-scripts/fixtures/schema_with_examples.json +416 -0
- package/tests/functional-tests/test-sample-k6-scripts/fixtures/schema_with_no_variables.json +32 -0
- package/tests/functional-tests/test-sample-k6-scripts/sampleK6Scripts.test.ts +248 -0
- package/tests/functional-tests/test-tags-filtering/tagsFiltering.test.ts +166 -0
- package/{vite.config.js → vite.config.mjs} +4 -0
- package/tests/functional-tests/generator.test.ts +0 -319
- /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/basic_schema.json +0 -0
- /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/form_url_encoded_data_with_query_params_schema.json +0 -0
- /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/get_request_with_path_parameters_schema.json +0 -0
- /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/no_title_schema.json +0 -0
- /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/post_request_with_query_params.json +0 -0
- /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/query_params_schema.json +0 -0
- /package/tests/functional-tests/{fixtures → test-tags-filtering/fixtures}/tags_filtering.json +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.1
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of data in the POST request body
|
|
@@ -14,14 +14,14 @@ export type CreateExampleData201Meta = {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export type CreateExampleData201 = {
|
|
17
|
-
age?: number
|
|
18
|
-
date?: string
|
|
19
17
|
/** The unique ID of the created resource */
|
|
20
18
|
id?: string
|
|
21
|
-
isActive?: boolean
|
|
22
|
-
meta?: CreateExampleData201Meta
|
|
23
19
|
name?: string
|
|
20
|
+
age?: number
|
|
21
|
+
isActive?: boolean
|
|
24
22
|
tags?: string[]
|
|
23
|
+
date?: string
|
|
24
|
+
meta?: CreateExampleData201Meta
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
@@ -35,18 +35,18 @@ export type CreateExampleDataBodyMeta = {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
export type CreateExampleDataBody = {
|
|
38
|
+
/** A string parameter */
|
|
39
|
+
name: string
|
|
38
40
|
/** An integer parameter */
|
|
39
41
|
age: number
|
|
40
|
-
/** A date parameter in YYYY-MM-DD format */
|
|
41
|
-
date?: string
|
|
42
42
|
/** A boolean parameter */
|
|
43
43
|
isActive: boolean
|
|
44
|
-
/** An object parameter containing metadata */
|
|
45
|
-
meta?: CreateExampleDataBodyMeta
|
|
46
|
-
/** A string parameter */
|
|
47
|
-
name: string
|
|
48
44
|
/** An array of strings */
|
|
49
45
|
tags?: string[]
|
|
46
|
+
/** A date parameter in YYYY-MM-DD format */
|
|
47
|
+
date?: string
|
|
48
|
+
/** An object parameter containing metadata */
|
|
49
|
+
meta?: CreateExampleDataBodyMeta
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
@@ -61,6 +61,8 @@ export class ExampleAPIClient {
|
|
|
61
61
|
commonRequestParameters?: Params
|
|
62
62
|
}) {
|
|
63
63
|
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
64
|
+
|
|
65
|
+
this.commonRequestParameters = clientOptions.commonRequestParameters || {}
|
|
64
66
|
}
|
|
65
67
|
|
|
66
68
|
/**
|
|
@@ -86,8 +88,8 @@ export class ExampleAPIClient {
|
|
|
86
88
|
{
|
|
87
89
|
...mergedRequestParameters,
|
|
88
90
|
headers: {
|
|
89
|
-
'Content-Type': 'application/json',
|
|
90
91
|
...mergedRequestParameters?.headers,
|
|
92
|
+
'Content-Type': 'application/json',
|
|
91
93
|
},
|
|
92
94
|
}
|
|
93
95
|
)
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import { ExampleAPIClient } from './exampleAPI.ts'
|
|
2
2
|
|
|
3
3
|
const baseUrl = '<BASE_URL>'
|
|
4
|
-
const
|
|
4
|
+
const exampleAPIClient = new ExampleAPIClient({ baseUrl })
|
|
5
5
|
|
|
6
6
|
export default function () {
|
|
7
|
+
let createExampleDataBody
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* Create example data
|
|
9
11
|
*/
|
|
10
|
-
|
|
12
|
+
createExampleDataBody = {
|
|
13
|
+
name: 'John Doe',
|
|
14
|
+
age: '25',
|
|
15
|
+
isActive: 'true',
|
|
16
|
+
tags: 'tag1,tag2',
|
|
17
|
+
date: '2024-01-01',
|
|
18
|
+
meta: {
|
|
19
|
+
createdBy: 'John Doe',
|
|
20
|
+
updatedBy: 'Jane Doe',
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const createExampleDataResponseData = exampleAPIClient.createExampleData(
|
|
11
25
|
createExampleDataBody
|
|
12
26
|
)
|
|
13
27
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.1
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of data in the POST request body
|
|
@@ -11,14 +11,14 @@ export type CreateExampleData201Meta = {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export type CreateExampleData201 = {
|
|
14
|
-
age?: number
|
|
15
|
-
date?: string
|
|
16
14
|
/** The unique ID of the created resource */
|
|
17
15
|
id?: string
|
|
18
|
-
isActive?: boolean
|
|
19
|
-
meta?: CreateExampleData201Meta
|
|
20
16
|
name?: string
|
|
17
|
+
age?: number
|
|
18
|
+
isActive?: boolean
|
|
21
19
|
tags?: string[]
|
|
20
|
+
date?: string
|
|
21
|
+
meta?: CreateExampleData201Meta
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -32,16 +32,16 @@ export type CreateExampleDataBodyMeta = {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export type CreateExampleDataBody = {
|
|
35
|
+
/** A string parameter */
|
|
36
|
+
name: string
|
|
35
37
|
/** An integer parameter */
|
|
36
38
|
age: number
|
|
37
|
-
/** A date parameter in YYYY-MM-DD format */
|
|
38
|
-
date?: string
|
|
39
39
|
/** A boolean parameter */
|
|
40
40
|
isActive: boolean
|
|
41
|
-
/** An object parameter containing metadata */
|
|
42
|
-
meta?: CreateExampleDataBodyMeta
|
|
43
|
-
/** A string parameter */
|
|
44
|
-
name: string
|
|
45
41
|
/** An array of strings */
|
|
46
42
|
tags?: string[]
|
|
43
|
+
/** A date parameter in YYYY-MM-DD format */
|
|
44
|
+
date?: string
|
|
45
|
+
/** An object parameter containing metadata */
|
|
46
|
+
meta?: CreateExampleDataBodyMeta
|
|
47
47
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.1
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of data in the POST request body
|
|
@@ -25,6 +25,8 @@ export class ExampleAPIClient {
|
|
|
25
25
|
commonRequestParameters?: Params
|
|
26
26
|
}) {
|
|
27
27
|
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
28
|
+
|
|
29
|
+
this.commonRequestParameters = clientOptions.commonRequestParameters || {}
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
/**
|
|
@@ -50,8 +52,8 @@ export class ExampleAPIClient {
|
|
|
50
52
|
{
|
|
51
53
|
...mergedRequestParameters,
|
|
52
54
|
headers: {
|
|
53
|
-
'Content-Type': 'application/json',
|
|
54
55
|
...mergedRequestParameters?.headers,
|
|
56
|
+
'Content-Type': 'application/json',
|
|
55
57
|
},
|
|
56
58
|
}
|
|
57
59
|
)
|
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import { ExampleAPIClient } from './exampleAPI.ts'
|
|
2
2
|
|
|
3
3
|
const baseUrl = '<BASE_URL>'
|
|
4
|
-
const
|
|
4
|
+
const exampleAPIClient = new ExampleAPIClient({ baseUrl })
|
|
5
5
|
|
|
6
6
|
export default function () {
|
|
7
|
+
let createExampleDataBody
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* Create example data
|
|
9
11
|
*/
|
|
10
|
-
|
|
12
|
+
createExampleDataBody = {
|
|
13
|
+
name: 'John Doe',
|
|
14
|
+
age: '25',
|
|
15
|
+
isActive: 'true',
|
|
16
|
+
tags: 'tag1,tag2',
|
|
17
|
+
date: '2024-01-01',
|
|
18
|
+
meta: {
|
|
19
|
+
createdBy: 'John Doe',
|
|
20
|
+
updatedBy: 'Jane Doe',
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const createExampleDataResponseData = exampleAPIClient.createExampleData(
|
|
11
25
|
createExampleDataBody
|
|
12
26
|
)
|
|
13
27
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.1
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of data in the POST request body
|
|
@@ -25,6 +25,8 @@ export class DefaultClient {
|
|
|
25
25
|
commonRequestParameters?: Params
|
|
26
26
|
}) {
|
|
27
27
|
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
28
|
+
|
|
29
|
+
this.commonRequestParameters = clientOptions.commonRequestParameters || {}
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
/**
|
|
@@ -50,8 +52,8 @@ export class DefaultClient {
|
|
|
50
52
|
{
|
|
51
53
|
...mergedRequestParameters,
|
|
52
54
|
headers: {
|
|
53
|
-
'Content-Type': 'application/json',
|
|
54
55
|
...mergedRequestParameters?.headers,
|
|
56
|
+
'Content-Type': 'application/json',
|
|
55
57
|
},
|
|
56
58
|
}
|
|
57
59
|
)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.1
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of data in the POST request body
|
|
@@ -11,14 +11,14 @@ export type CreateExampleData201Meta = {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export type CreateExampleData201 = {
|
|
14
|
-
age?: number
|
|
15
|
-
date?: string
|
|
16
14
|
/** The unique ID of the created resource */
|
|
17
15
|
id?: string
|
|
18
|
-
isActive?: boolean
|
|
19
|
-
meta?: CreateExampleData201Meta
|
|
20
16
|
name?: string
|
|
17
|
+
age?: number
|
|
18
|
+
isActive?: boolean
|
|
21
19
|
tags?: string[]
|
|
20
|
+
date?: string
|
|
21
|
+
meta?: CreateExampleData201Meta
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -32,16 +32,16 @@ export type CreateExampleDataBodyMeta = {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export type CreateExampleDataBody = {
|
|
35
|
+
/** A string parameter */
|
|
36
|
+
name: string
|
|
35
37
|
/** An integer parameter */
|
|
36
38
|
age: number
|
|
37
|
-
/** A date parameter in YYYY-MM-DD format */
|
|
38
|
-
date?: string
|
|
39
39
|
/** A boolean parameter */
|
|
40
40
|
isActive: boolean
|
|
41
|
-
/** An object parameter containing metadata */
|
|
42
|
-
meta?: CreateExampleDataBodyMeta
|
|
43
|
-
/** A string parameter */
|
|
44
|
-
name: string
|
|
45
41
|
/** An array of strings */
|
|
46
42
|
tags?: string[]
|
|
43
|
+
/** A date parameter in YYYY-MM-DD format */
|
|
44
|
+
date?: string
|
|
45
|
+
/** An object parameter containing metadata */
|
|
46
|
+
meta?: CreateExampleDataBodyMeta
|
|
47
47
|
}
|
|
@@ -1,13 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DefaultClient } from './default.ts'
|
|
2
2
|
|
|
3
3
|
const baseUrl = '<BASE_URL>'
|
|
4
|
-
const
|
|
4
|
+
const defaultClient = new DefaultClient({ baseUrl })
|
|
5
5
|
|
|
6
6
|
export default function () {
|
|
7
|
+
let createExampleDataBody
|
|
8
|
+
|
|
7
9
|
/**
|
|
8
10
|
* Create example data
|
|
9
11
|
*/
|
|
10
|
-
|
|
12
|
+
createExampleDataBody = {
|
|
13
|
+
name: 'John Doe',
|
|
14
|
+
age: '25',
|
|
15
|
+
isActive: 'true',
|
|
16
|
+
tags: 'tag1,tag2',
|
|
17
|
+
date: '2024-01-01',
|
|
18
|
+
meta: {
|
|
19
|
+
createdBy: 'John Doe',
|
|
20
|
+
updatedBy: 'Jane Doe',
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const createExampleDataResponseData = defaultClient.createExampleData(
|
|
11
25
|
createExampleDataBody
|
|
12
26
|
)
|
|
13
27
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/openapi-to-k6",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "A CLI tool to generate helper modules for K6 from OpenAPI schema",
|
|
5
5
|
"main": "dist/cli.js",
|
|
6
6
|
"bin": {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
"scripts": {
|
|
10
10
|
"build": "tsc",
|
|
11
11
|
"dev": "DISABLE_ANALYTICS=true ts-node src/cli.ts",
|
|
12
|
+
"dev:inspect": "DISABLE_ANALYTICS=true node --inspect-brk --require ts-node/register src/cli.ts",
|
|
12
13
|
"test": "vitest run --coverage",
|
|
13
14
|
"lint": "eslint --ext .ts,.tsx .",
|
|
14
15
|
"lint:fix": "eslint --ext .ts,.tsx . --fix",
|
|
@@ -20,13 +21,14 @@
|
|
|
20
21
|
"repository": "http://github.com/grafana/openapi-to-k6",
|
|
21
22
|
"license": "AGPL-3.0",
|
|
22
23
|
"dependencies": {
|
|
24
|
+
"@faker-js/faker": "^9.2.0",
|
|
23
25
|
"@types/k6": "^0.54.0",
|
|
24
26
|
"axios": "^1.7.7",
|
|
25
27
|
"chalk": "^4.1.2",
|
|
26
28
|
"commander": "^12.1.0",
|
|
27
29
|
"handlebars": "^4.7.8",
|
|
28
30
|
"openapi-typescript": "^7.4.1",
|
|
29
|
-
"orval": "^7.
|
|
31
|
+
"orval": "^7.4.1",
|
|
30
32
|
"prettier": "^3.3.3",
|
|
31
33
|
"uuid": "^10.0.0"
|
|
32
34
|
},
|
|
@@ -45,6 +47,7 @@
|
|
|
45
47
|
"prettier": "^3.3.3",
|
|
46
48
|
"ts-node": "^10.9.2",
|
|
47
49
|
"typescript": "^5.6.2",
|
|
50
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
48
51
|
"vitest": "^2.1.3"
|
|
49
52
|
},
|
|
50
53
|
"lint-staged": {
|
package/src/constants.ts
CHANGED
|
@@ -2,17 +2,21 @@ export const DEFAULT_SCHEMA_TITLE = 'K6Client'
|
|
|
2
2
|
|
|
3
3
|
export const SAMPLE_K6_SCRIPT_FILE_NAME = 'k6-script.sample.ts'
|
|
4
4
|
export const K6_SCRIPT_TEMPLATE = `
|
|
5
|
-
|
|
5
|
+
{{{importStatements}}}
|
|
6
6
|
|
|
7
7
|
const baseUrl = '<BASE_URL>';
|
|
8
|
-
|
|
8
|
+
{{{clientInitializationStatement}}}
|
|
9
|
+
|
|
9
10
|
|
|
10
11
|
export default function () {
|
|
12
|
+
{{{this.variableDefinition}}}
|
|
13
|
+
|
|
11
14
|
{{#each clientFunctionsList}}
|
|
12
15
|
/**
|
|
13
16
|
* {{this.summary}}
|
|
14
17
|
*/
|
|
15
|
-
|
|
18
|
+
{{{this.exampleValues}}}
|
|
19
|
+
const {{this.operationName}}ResponseData = {{clientObjectName}}.{{this.operationName}}({{this.requiredParametersString}});
|
|
16
20
|
|
|
17
21
|
{{/each}}
|
|
18
22
|
}
|
package/src/generator/index.ts
CHANGED
|
@@ -27,7 +27,10 @@ const generatedFileHeaderGenerator = (info: InfoObject) => {
|
|
|
27
27
|
]
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const afterAllFilesWriteHandler = async (
|
|
30
|
+
const afterAllFilesWriteHandler = async (
|
|
31
|
+
filePaths: string[],
|
|
32
|
+
outputOverrider: OutputOverrider
|
|
33
|
+
) => {
|
|
31
34
|
const removeSingleFile = (filePath: string) => {
|
|
32
35
|
try {
|
|
33
36
|
fs.unlinkSync(filePath)
|
|
@@ -53,8 +56,13 @@ const afterAllFilesWriteHandler = async (filePaths: string[]) => {
|
|
|
53
56
|
removeSingleFile(filePath)
|
|
54
57
|
continue
|
|
55
58
|
}
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
try {
|
|
60
|
+
await formatFileWithPrettier(filePath)
|
|
61
|
+
} catch (error) {
|
|
62
|
+
await outputOverrider.temporarilyWriteToStdoutAndStderr(async () => {
|
|
63
|
+
logger.error(`Error in formatting file ${filePath}: ${error}`)
|
|
64
|
+
})
|
|
65
|
+
}
|
|
58
66
|
|
|
59
67
|
const fileName = path.basename(filePath)
|
|
60
68
|
|
|
@@ -125,7 +133,10 @@ export default async ({
|
|
|
125
133
|
},
|
|
126
134
|
hooks: {
|
|
127
135
|
afterAllFilesWrite: async (filePaths: string[]) => {
|
|
128
|
-
const filteredFilePaths = await afterAllFilesWriteHandler(
|
|
136
|
+
const filteredFilePaths = await afterAllFilesWriteHandler(
|
|
137
|
+
filePaths,
|
|
138
|
+
outputOverrider
|
|
139
|
+
)
|
|
129
140
|
generatedFilePaths.push(...filteredFilePaths)
|
|
130
141
|
},
|
|
131
142
|
},
|
|
@@ -135,8 +146,10 @@ export default async ({
|
|
|
135
146
|
if (generatedFilePaths.length === 0) {
|
|
136
147
|
const tagsMessage =
|
|
137
148
|
tags?.length && tags.length > 0
|
|
138
|
-
? ` Applied tag filter(s): ${tags.join(', ')}`
|
|
139
|
-
: ''
|
|
140
|
-
throw new NoFilesGeneratedError(
|
|
149
|
+
? ` Applied tag filter(s): ${tags.join(', ')}. `
|
|
150
|
+
: ' '
|
|
151
|
+
throw new NoFilesGeneratedError(
|
|
152
|
+
`No files were generated.${tagsMessage}Try running with --verbose flag to get more details.`
|
|
153
|
+
)
|
|
141
154
|
}
|
|
142
155
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ClientDependenciesBuilder,
|
|
3
|
-
ClientExtraFilesBuilder,
|
|
4
3
|
ClientFooterBuilder,
|
|
5
4
|
ClientGeneratorsBuilder,
|
|
6
5
|
ClientHeaderBuilder,
|
|
@@ -17,17 +16,9 @@ import {
|
|
|
17
16
|
sanitize,
|
|
18
17
|
toObjectString,
|
|
19
18
|
} from '@orval/core'
|
|
20
|
-
import
|
|
21
|
-
import path from 'path'
|
|
22
|
-
import {
|
|
23
|
-
DEFAULT_SCHEMA_TITLE,
|
|
24
|
-
K6_SCRIPT_TEMPLATE,
|
|
25
|
-
SAMPLE_K6_SCRIPT_FILE_NAME,
|
|
26
|
-
} from '../constants'
|
|
27
|
-
import { getDirectoryForPath, getGeneratedClientPath } from '../helper'
|
|
28
|
-
import { logger } from '../logger'
|
|
19
|
+
import { DEFAULT_SCHEMA_TITLE } from '../constants'
|
|
29
20
|
import { AnalyticsData } from '../type'
|
|
30
|
-
|
|
21
|
+
import { k6ScriptBuilder } from './k6ScriptBuilder'
|
|
31
22
|
/**
|
|
32
23
|
* In case the supplied schema does not have a title set, it will set the default title to ensure
|
|
33
24
|
* proper client generation
|
|
@@ -111,6 +102,7 @@ const _getRequestParamsValue = ({
|
|
|
111
102
|
// Expand the headers
|
|
112
103
|
if (body.contentType || headers) {
|
|
113
104
|
let headersValue = `\n headers: {`
|
|
105
|
+
headersValue += '\n...mergedRequestParameters?.headers,'
|
|
114
106
|
if (body.contentType) {
|
|
115
107
|
if (body.formData) {
|
|
116
108
|
headersValue += `\n'Content-Type': '${body.contentType}; boundary=' + formData.boundary,`
|
|
@@ -124,7 +116,7 @@ const _getRequestParamsValue = ({
|
|
|
124
116
|
headersValue += `\n...Object.fromEntries(Object.entries(headers || {}).map(([key, value]) => [key, String(value)])),`
|
|
125
117
|
}
|
|
126
118
|
|
|
127
|
-
headersValue += `\n
|
|
119
|
+
headersValue += `\n},`
|
|
128
120
|
value += headersValue
|
|
129
121
|
}
|
|
130
122
|
|
|
@@ -260,7 +252,7 @@ const generateK6Implementation = (
|
|
|
260
252
|
`
|
|
261
253
|
}
|
|
262
254
|
|
|
263
|
-
const generateTitle: ClientTitleBuilder = (title) => {
|
|
255
|
+
export const generateTitle: ClientTitleBuilder = (title) => {
|
|
264
256
|
const sanTitle = sanitize(title || DEFAULT_SCHEMA_TITLE)
|
|
265
257
|
return `${pascal(sanTitle)}Client`
|
|
266
258
|
}
|
|
@@ -279,6 +271,7 @@ const generateK6Header: ClientHeaderBuilder = ({ title }) => {
|
|
|
279
271
|
commonRequestParameters?: Params
|
|
280
272
|
}) {
|
|
281
273
|
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\\/+$/, '');\n
|
|
274
|
+
this.commonRequestParameters = clientOptions.commonRequestParameters || {};
|
|
282
275
|
}\n
|
|
283
276
|
`
|
|
284
277
|
}
|
|
@@ -295,66 +288,6 @@ const generateFooter: ClientFooterBuilder = () => {
|
|
|
295
288
|
return footer
|
|
296
289
|
}
|
|
297
290
|
|
|
298
|
-
const k6ScriptBuilder: ClientExtraFilesBuilder = async (
|
|
299
|
-
verbOptions,
|
|
300
|
-
output,
|
|
301
|
-
context
|
|
302
|
-
) => {
|
|
303
|
-
const schemaTitle =
|
|
304
|
-
context.specs[context.specKey]?.info.title || DEFAULT_SCHEMA_TITLE
|
|
305
|
-
const {
|
|
306
|
-
path: pathOfGeneratedClient,
|
|
307
|
-
filename,
|
|
308
|
-
extension,
|
|
309
|
-
} = await getGeneratedClientPath(output.target!, schemaTitle)
|
|
310
|
-
const directoryPath = getDirectoryForPath(pathOfGeneratedClient)
|
|
311
|
-
const generateScriptPath = path.join(
|
|
312
|
-
directoryPath,
|
|
313
|
-
SAMPLE_K6_SCRIPT_FILE_NAME
|
|
314
|
-
)
|
|
315
|
-
|
|
316
|
-
logger.debug(
|
|
317
|
-
`k6ScriptBuilder ~ Generating sample K6 Script\n${JSON.stringify(
|
|
318
|
-
{
|
|
319
|
-
pathOfGeneratedClient,
|
|
320
|
-
filename,
|
|
321
|
-
extension,
|
|
322
|
-
schemaTitle,
|
|
323
|
-
directoryPath,
|
|
324
|
-
generateScriptPath,
|
|
325
|
-
},
|
|
326
|
-
null,
|
|
327
|
-
2
|
|
328
|
-
)}`
|
|
329
|
-
)
|
|
330
|
-
|
|
331
|
-
const clientFunctionsList = []
|
|
332
|
-
|
|
333
|
-
for (const verbOption of Object.values(verbOptions)) {
|
|
334
|
-
const { operationName, summary, props } = verbOption
|
|
335
|
-
const requiredProps = props.filter((prop) => prop.required)
|
|
336
|
-
clientFunctionsList.push({
|
|
337
|
-
operationName,
|
|
338
|
-
summary,
|
|
339
|
-
requiredParametersString: toObjectString(requiredProps, 'name'),
|
|
340
|
-
})
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
const scriptContentData = {
|
|
344
|
-
clientFunctionName: generateTitle(schemaTitle),
|
|
345
|
-
clientPath: `./${filename}${extension}`,
|
|
346
|
-
clientFunctionsList,
|
|
347
|
-
}
|
|
348
|
-
const template = Handlebars.compile(K6_SCRIPT_TEMPLATE)
|
|
349
|
-
|
|
350
|
-
return [
|
|
351
|
-
{
|
|
352
|
-
path: generateScriptPath,
|
|
353
|
-
content: template(scriptContentData),
|
|
354
|
-
},
|
|
355
|
-
]
|
|
356
|
-
}
|
|
357
|
-
|
|
358
291
|
function getK6Client(analyticsData?: AnalyticsData) {
|
|
359
292
|
return function (
|
|
360
293
|
verbOptions: GeneratorVerbOptions,
|