@grafana/openapi-to-k6 0.3.0 → 0.3.2
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/dist/generator/index.js +13 -6
- package/dist/generator/k6Client.js +3 -1
- package/dist/helper.js +16 -0
- package/examples/basic_schema/schema.json +2 -1
- package/examples/basic_schema/single/simpleAPI.ts +4 -1
- 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/simpleAPI.schemas.ts +2 -1
- package/examples/form_data_schema/single/formDataAPI.ts +15 -13
- package/examples/form_data_schema/split/formDataAPI.schemas.ts +12 -12
- package/examples/form_data_schema/split/formDataAPI.ts +4 -2
- package/examples/form_data_schema/tags/default.ts +4 -2
- package/examples/form_data_schema/tags/formDataAPI.schemas.ts +12 -12
- package/examples/form_url_encoded_data_schema/single/formURLEncodedAPI.ts +15 -13
- package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.schemas.ts +12 -12
- package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.ts +4 -2
- package/examples/form_url_encoded_data_schema/tags/default.ts +4 -2
- package/examples/form_url_encoded_data_schema/tags/formURLEncodedAPI.schemas.ts +12 -12
- package/examples/form_url_encoded_data_with_query_params_schema/single/formURLEncodedAPIWithQueryParameters.ts +23 -21
- package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.schemas.ts +20 -20
- 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/tags/default.ts +4 -2
- package/examples/form_url_encoded_data_with_query_params_schema/tags/formURLEncodedAPIWithQueryParameters.schemas.ts +20 -20
- package/examples/get_request_with_path_parameters_schema/single/simpleAPI.ts +4 -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/simpleAPI.schemas.ts +2 -2
- package/examples/headers_schema/single/headerDemoAPI.ts +16 -14
- package/examples/headers_schema/split/headerDemoAPI.schemas.ts +12 -12
- package/examples/headers_schema/split/headerDemoAPI.ts +5 -3
- package/examples/headers_schema/tags/default.ts +5 -3
- package/examples/headers_schema/tags/headerDemoAPI.schemas.ts +12 -12
- package/examples/no_title_schema/single/k6Client.ts +3 -1
- 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/k6Client.schemas.ts +1 -1
- package/examples/post_request_with_query_params/single/exampleAPI.ts +20 -18
- package/examples/post_request_with_query_params/split/exampleAPI.schemas.ts +17 -17
- package/examples/post_request_with_query_params/split/exampleAPI.ts +4 -2
- package/examples/post_request_with_query_params/tags/default.ts +4 -2
- package/examples/post_request_with_query_params/tags/exampleAPI.schemas.ts +17 -17
- package/examples/query_params_schema/single/exampleAPI.ts +11 -9
- package/examples/query_params_schema/split/exampleAPI.schemas.ts +9 -9
- package/examples/query_params_schema/split/exampleAPI.ts +3 -1
- package/examples/query_params_schema/tags/default.ts +3 -1
- package/examples/query_params_schema/tags/exampleAPI.schemas.ts +9 -9
- package/examples/simple_post_request_schema/single/exampleAPI.ts +25 -23
- package/examples/simple_post_request_schema/split/exampleAPI.schemas.ts +22 -22
- package/examples/simple_post_request_schema/split/exampleAPI.ts +4 -2
- package/examples/simple_post_request_schema/tags/default.ts +4 -2
- package/examples/simple_post_request_schema/tags/exampleAPI.schemas.ts +22 -22
- package/package.json +3 -2
- package/src/generator/index.ts +20 -7
- package/src/generator/k6Client.ts +3 -1
- package/src/helper.ts +17 -0
- package/tests/e2e/single/k6Script.ts +54 -1
- package/tests/functional-tests/test-generator/fixtures/basic_parameter_in_ref.json +59 -0
- package/tests/functional-tests/test-generator/fixtures/form_data_schema.json +1 -1
- package/tests/functional-tests/test-generator/fixtures/form_url_encoded_data_schema.json +1 -1
- package/tests/functional-tests/test-generator/fixtures/headers_schema.json +2 -2
- package/tests/functional-tests/test-generator/fixtures/simple_post_request_schema.json +1 -1
- package/{vite.config.js → vite.config.mjs} +4 -0
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.2
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with a POST request having an object as the body and query parameters
|
|
6
6
|
* Service version: 1.0.0
|
|
7
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
8
|
export type CreateExampleDataParams = {
|
|
25
9
|
/**
|
|
26
10
|
* A string query parameter for user ID
|
|
@@ -31,3 +15,19 @@ export type CreateExampleDataParams = {
|
|
|
31
15
|
*/
|
|
32
16
|
isActive?: boolean
|
|
33
17
|
}
|
|
18
|
+
|
|
19
|
+
export type CreateExampleDataBody = {
|
|
20
|
+
/** A string field representing data */
|
|
21
|
+
data: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type CreateExampleData201 = {
|
|
25
|
+
/** The user ID from the query parameter */
|
|
26
|
+
userId?: string
|
|
27
|
+
/** The active status from the query parameter */
|
|
28
|
+
isActive?: boolean
|
|
29
|
+
/** The data from the body */
|
|
30
|
+
data?: string
|
|
31
|
+
/** Response status */
|
|
32
|
+
status?: string
|
|
33
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.2
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with a POST request having an object as the body and query parameters
|
|
@@ -26,6 +26,8 @@ export class ExampleAPIClient {
|
|
|
26
26
|
commonRequestParameters?: Params
|
|
27
27
|
}) {
|
|
28
28
|
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
29
|
+
|
|
30
|
+
this.commonRequestParameters = clientOptions.commonRequestParameters || {}
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/**
|
|
@@ -56,8 +58,8 @@ export class ExampleAPIClient {
|
|
|
56
58
|
{
|
|
57
59
|
...mergedRequestParameters,
|
|
58
60
|
headers: {
|
|
59
|
-
'Content-Type': 'application/json',
|
|
60
61
|
...mergedRequestParameters?.headers,
|
|
62
|
+
'Content-Type': 'application/json',
|
|
61
63
|
},
|
|
62
64
|
}
|
|
63
65
|
)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.2
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with a POST request having an object as the body and query parameters
|
|
@@ -26,6 +26,8 @@ export class DefaultClient {
|
|
|
26
26
|
commonRequestParameters?: Params
|
|
27
27
|
}) {
|
|
28
28
|
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
29
|
+
|
|
30
|
+
this.commonRequestParameters = clientOptions.commonRequestParameters || {}
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
/**
|
|
@@ -56,8 +58,8 @@ export class DefaultClient {
|
|
|
56
58
|
{
|
|
57
59
|
...mergedRequestParameters,
|
|
58
60
|
headers: {
|
|
59
|
-
'Content-Type': 'application/json',
|
|
60
61
|
...mergedRequestParameters?.headers,
|
|
62
|
+
'Content-Type': 'application/json',
|
|
61
63
|
},
|
|
62
64
|
}
|
|
63
65
|
)
|
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.2
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with a POST request having an object as the body and query parameters
|
|
6
6
|
* Service version: 1.0.0
|
|
7
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
8
|
export type CreateExampleDataParams = {
|
|
25
9
|
/**
|
|
26
10
|
* A string query parameter for user ID
|
|
@@ -31,3 +15,19 @@ export type CreateExampleDataParams = {
|
|
|
31
15
|
*/
|
|
32
16
|
isActive?: boolean
|
|
33
17
|
}
|
|
18
|
+
|
|
19
|
+
export type CreateExampleDataBody = {
|
|
20
|
+
/** A string field representing data */
|
|
21
|
+
data: string
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type CreateExampleData201 = {
|
|
25
|
+
/** The user ID from the query parameter */
|
|
26
|
+
userId?: string
|
|
27
|
+
/** The active status from the query parameter */
|
|
28
|
+
isActive?: boolean
|
|
29
|
+
/** The data from the body */
|
|
30
|
+
data?: string
|
|
31
|
+
/** Response status */
|
|
32
|
+
status?: string
|
|
33
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.2
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of query parameters
|
|
@@ -8,14 +8,6 @@
|
|
|
8
8
|
import { URL, URLSearchParams } from 'https://jslib.k6.io/url/1.0.0/index.js'
|
|
9
9
|
import http from 'k6/http'
|
|
10
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
11
|
export type GetExampleDataParams = {
|
|
20
12
|
/**
|
|
21
13
|
* A string parameter
|
|
@@ -39,6 +31,14 @@ export type GetExampleDataParams = {
|
|
|
39
31
|
date?: string
|
|
40
32
|
}
|
|
41
33
|
|
|
34
|
+
export type GetExampleData200 = {
|
|
35
|
+
name?: string
|
|
36
|
+
age?: number
|
|
37
|
+
isActive?: boolean
|
|
38
|
+
tags?: string[]
|
|
39
|
+
date?: string
|
|
40
|
+
}
|
|
41
|
+
|
|
42
42
|
/**
|
|
43
43
|
* This is the base client to use for interacting with the API.
|
|
44
44
|
*/
|
|
@@ -51,6 +51,8 @@ export class ExampleAPIClient {
|
|
|
51
51
|
commonRequestParameters?: Params
|
|
52
52
|
}) {
|
|
53
53
|
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
54
|
+
|
|
55
|
+
this.commonRequestParameters = clientOptions.commonRequestParameters || {}
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
/**
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.2
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of query parameters
|
|
6
6
|
* Service version: 1.0.0
|
|
7
7
|
*/
|
|
8
|
-
export type GetExampleData200 = {
|
|
9
|
-
age?: number
|
|
10
|
-
date?: string
|
|
11
|
-
isActive?: boolean
|
|
12
|
-
name?: string
|
|
13
|
-
tags?: string[]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
8
|
export type GetExampleDataParams = {
|
|
17
9
|
/**
|
|
18
10
|
* A string parameter
|
|
@@ -35,3 +27,11 @@ export type GetExampleDataParams = {
|
|
|
35
27
|
*/
|
|
36
28
|
date?: string
|
|
37
29
|
}
|
|
30
|
+
|
|
31
|
+
export type GetExampleData200 = {
|
|
32
|
+
name?: string
|
|
33
|
+
age?: number
|
|
34
|
+
isActive?: boolean
|
|
35
|
+
tags?: string[]
|
|
36
|
+
date?: string
|
|
37
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.2
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of query parameters
|
|
@@ -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
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.2
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of query parameters
|
|
@@ -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
|
/**
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.2
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of query parameters
|
|
6
6
|
* Service version: 1.0.0
|
|
7
7
|
*/
|
|
8
|
-
export type GetExampleData200 = {
|
|
9
|
-
age?: number
|
|
10
|
-
date?: string
|
|
11
|
-
isActive?: boolean
|
|
12
|
-
name?: string
|
|
13
|
-
tags?: string[]
|
|
14
|
-
}
|
|
15
|
-
|
|
16
8
|
export type GetExampleDataParams = {
|
|
17
9
|
/**
|
|
18
10
|
* A string parameter
|
|
@@ -35,3 +27,11 @@ export type GetExampleDataParams = {
|
|
|
35
27
|
*/
|
|
36
28
|
date?: string
|
|
37
29
|
}
|
|
30
|
+
|
|
31
|
+
export type GetExampleData200 = {
|
|
32
|
+
name?: string
|
|
33
|
+
age?: number
|
|
34
|
+
isActive?: boolean
|
|
35
|
+
tags?: string[]
|
|
36
|
+
date?: string
|
|
37
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.2
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of data in the POST request body
|
|
@@ -8,22 +8,6 @@
|
|
|
8
8
|
import { URL } from 'https://jslib.k6.io/url/1.0.0/index.js'
|
|
9
9
|
import http from 'k6/http'
|
|
10
10
|
import type { Params, Response } from 'k6/http'
|
|
11
|
-
export type CreateExampleData201Meta = {
|
|
12
|
-
createdBy?: string
|
|
13
|
-
updatedBy?: string
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export type CreateExampleData201 = {
|
|
17
|
-
age?: number
|
|
18
|
-
date?: string
|
|
19
|
-
/** The unique ID of the created resource */
|
|
20
|
-
id?: string
|
|
21
|
-
isActive?: boolean
|
|
22
|
-
meta?: CreateExampleData201Meta
|
|
23
|
-
name?: string
|
|
24
|
-
tags?: string[]
|
|
25
|
-
}
|
|
26
|
-
|
|
27
11
|
/**
|
|
28
12
|
* An object parameter containing metadata
|
|
29
13
|
*/
|
|
@@ -35,18 +19,34 @@ export type CreateExampleDataBodyMeta = {
|
|
|
35
19
|
}
|
|
36
20
|
|
|
37
21
|
export type CreateExampleDataBody = {
|
|
22
|
+
/** A string parameter */
|
|
23
|
+
name: string
|
|
38
24
|
/** An integer parameter */
|
|
39
25
|
age: number
|
|
40
|
-
/** A date parameter in YYYY-MM-DD format */
|
|
41
|
-
date?: string
|
|
42
26
|
/** A boolean parameter */
|
|
43
27
|
isActive: boolean
|
|
28
|
+
/** An array of strings */
|
|
29
|
+
tags?: string[]
|
|
30
|
+
/** A date parameter in YYYY-MM-DD format */
|
|
31
|
+
date?: string
|
|
44
32
|
/** An object parameter containing metadata */
|
|
45
33
|
meta?: CreateExampleDataBodyMeta
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type CreateExampleData201Meta = {
|
|
37
|
+
createdBy?: string
|
|
38
|
+
updatedBy?: string
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type CreateExampleData201 = {
|
|
42
|
+
/** The unique ID of the created resource */
|
|
43
|
+
id?: string
|
|
44
|
+
name?: string
|
|
45
|
+
age?: number
|
|
46
|
+
isActive?: boolean
|
|
49
47
|
tags?: string[]
|
|
48
|
+
date?: string
|
|
49
|
+
meta?: CreateExampleData201Meta
|
|
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,26 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.2
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of data in the POST request body
|
|
6
6
|
* Service version: 1.0.0
|
|
7
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
8
|
/**
|
|
25
9
|
* An object parameter containing metadata
|
|
26
10
|
*/
|
|
@@ -32,16 +16,32 @@ export type CreateExampleDataBodyMeta = {
|
|
|
32
16
|
}
|
|
33
17
|
|
|
34
18
|
export type CreateExampleDataBody = {
|
|
19
|
+
/** A string parameter */
|
|
20
|
+
name: string
|
|
35
21
|
/** An integer parameter */
|
|
36
22
|
age: number
|
|
37
|
-
/** A date parameter in YYYY-MM-DD format */
|
|
38
|
-
date?: string
|
|
39
23
|
/** A boolean parameter */
|
|
40
24
|
isActive: boolean
|
|
25
|
+
/** An array of strings */
|
|
26
|
+
tags?: string[]
|
|
27
|
+
/** A date parameter in YYYY-MM-DD format */
|
|
28
|
+
date?: string
|
|
41
29
|
/** An object parameter containing metadata */
|
|
42
30
|
meta?: CreateExampleDataBodyMeta
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type CreateExampleData201Meta = {
|
|
34
|
+
createdBy?: string
|
|
35
|
+
updatedBy?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type CreateExampleData201 = {
|
|
39
|
+
/** The unique ID of the created resource */
|
|
40
|
+
id?: string
|
|
41
|
+
name?: string
|
|
42
|
+
age?: number
|
|
43
|
+
isActive?: boolean
|
|
46
44
|
tags?: string[]
|
|
45
|
+
date?: string
|
|
46
|
+
meta?: CreateExampleData201Meta
|
|
47
47
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.2
|
|
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,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.2
|
|
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,26 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.2
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of data in the POST request body
|
|
6
6
|
* Service version: 1.0.0
|
|
7
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
8
|
/**
|
|
25
9
|
* An object parameter containing metadata
|
|
26
10
|
*/
|
|
@@ -32,16 +16,32 @@ export type CreateExampleDataBodyMeta = {
|
|
|
32
16
|
}
|
|
33
17
|
|
|
34
18
|
export type CreateExampleDataBody = {
|
|
19
|
+
/** A string parameter */
|
|
20
|
+
name: string
|
|
35
21
|
/** An integer parameter */
|
|
36
22
|
age: number
|
|
37
|
-
/** A date parameter in YYYY-MM-DD format */
|
|
38
|
-
date?: string
|
|
39
23
|
/** A boolean parameter */
|
|
40
24
|
isActive: boolean
|
|
25
|
+
/** An array of strings */
|
|
26
|
+
tags?: string[]
|
|
27
|
+
/** A date parameter in YYYY-MM-DD format */
|
|
28
|
+
date?: string
|
|
41
29
|
/** An object parameter containing metadata */
|
|
42
30
|
meta?: CreateExampleDataBodyMeta
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type CreateExampleData201Meta = {
|
|
34
|
+
createdBy?: string
|
|
35
|
+
updatedBy?: string
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type CreateExampleData201 = {
|
|
39
|
+
/** The unique ID of the created resource */
|
|
40
|
+
id?: string
|
|
41
|
+
name?: string
|
|
42
|
+
age?: number
|
|
43
|
+
isActive?: boolean
|
|
46
44
|
tags?: string[]
|
|
45
|
+
date?: string
|
|
46
|
+
meta?: CreateExampleData201Meta
|
|
47
47
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/openapi-to-k6",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "A CLI tool to generate helper modules for K6 from OpenAPI schema",
|
|
5
5
|
"main": "dist/cli.js",
|
|
6
6
|
"bin": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"commander": "^12.1.0",
|
|
29
29
|
"handlebars": "^4.7.8",
|
|
30
30
|
"openapi-typescript": "^7.4.1",
|
|
31
|
-
"orval": "^7.
|
|
31
|
+
"orval": "^7.5.0",
|
|
32
32
|
"prettier": "^3.3.3",
|
|
33
33
|
"uuid": "^10.0.0"
|
|
34
34
|
},
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"prettier": "^3.3.3",
|
|
48
48
|
"ts-node": "^10.9.2",
|
|
49
49
|
"typescript": "^5.6.2",
|
|
50
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
50
51
|
"vitest": "^2.1.3"
|
|
51
52
|
},
|
|
52
53
|
"lint-staged": {
|
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
|
}
|
|
@@ -102,6 +102,7 @@ const _getRequestParamsValue = ({
|
|
|
102
102
|
// Expand the headers
|
|
103
103
|
if (body.contentType || headers) {
|
|
104
104
|
let headersValue = `\n headers: {`
|
|
105
|
+
headersValue += '\n...mergedRequestParameters?.headers,'
|
|
105
106
|
if (body.contentType) {
|
|
106
107
|
if (body.formData) {
|
|
107
108
|
headersValue += `\n'Content-Type': '${body.contentType}; boundary=' + formData.boundary,`
|
|
@@ -115,7 +116,7 @@ const _getRequestParamsValue = ({
|
|
|
115
116
|
headersValue += `\n...Object.fromEntries(Object.entries(headers || {}).map(([key, value]) => [key, String(value)])),`
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
headersValue += `\n
|
|
119
|
+
headersValue += `\n},`
|
|
119
120
|
value += headersValue
|
|
120
121
|
}
|
|
121
122
|
|
|
@@ -270,6 +271,7 @@ const generateK6Header: ClientHeaderBuilder = ({ title }) => {
|
|
|
270
271
|
commonRequestParameters?: Params
|
|
271
272
|
}) {
|
|
272
273
|
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\\/+$/, '');\n
|
|
274
|
+
this.commonRequestParameters = clientOptions.commonRequestParameters || {};
|
|
273
275
|
}\n
|
|
274
276
|
`
|
|
275
277
|
}
|
package/src/helper.ts
CHANGED
|
@@ -123,6 +123,23 @@ export class OutputOverrider {
|
|
|
123
123
|
process.stdout.write = this.originalStdoutWrite
|
|
124
124
|
process.stderr.write = this.originalStderrWrite
|
|
125
125
|
}
|
|
126
|
+
|
|
127
|
+
// Method to temporarily write to stdout and stderr
|
|
128
|
+
public async temporarilyWriteToStdoutAndStderr(
|
|
129
|
+
callback: () => Promise<void>
|
|
130
|
+
) {
|
|
131
|
+
const currentStdoutWrite = process.stdout.write
|
|
132
|
+
const currentStderrWrite = process.stderr.write
|
|
133
|
+
|
|
134
|
+
process.stdout.write = this.originalStdoutWrite
|
|
135
|
+
process.stderr.write = this.originalStderrWrite
|
|
136
|
+
try {
|
|
137
|
+
await callback()
|
|
138
|
+
} finally {
|
|
139
|
+
process.stdout.write = currentStdoutWrite
|
|
140
|
+
process.stderr.write = currentStderrWrite
|
|
141
|
+
}
|
|
142
|
+
}
|
|
126
143
|
}
|
|
127
144
|
|
|
128
145
|
/**
|