@grafana/openapi-to-k6 0.3.1 → 0.4.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.
Files changed (67) hide show
  1. package/.github/workflows/publish.yaml +39 -13
  2. package/.github/workflows/tests.yaml +23 -10
  3. package/.nvmrc +1 -1
  4. package/CODEOWNERS +2 -0
  5. package/README.md +34 -39
  6. package/catalog-info.yaml +13 -0
  7. package/dist/generator/k6Client.js +7 -4
  8. package/examples/basic_schema/single/simpleAPI.ts +5 -3
  9. package/examples/basic_schema/split/simpleAPI.schemas.ts +1 -1
  10. package/examples/basic_schema/split/simpleAPI.ts +5 -3
  11. package/examples/basic_schema/tags/default.ts +5 -3
  12. package/examples/basic_schema/tags/simpleAPI.schemas.ts +1 -1
  13. package/examples/form_data_schema/single/formDataAPI.ts +15 -13
  14. package/examples/form_data_schema/split/formDataAPI.schemas.ts +11 -11
  15. package/examples/form_data_schema/split/formDataAPI.ts +5 -3
  16. package/examples/form_data_schema/tags/default.ts +5 -3
  17. package/examples/form_data_schema/tags/formDataAPI.schemas.ts +11 -11
  18. package/examples/form_url_encoded_data_schema/single/formURLEncodedAPI.ts +15 -13
  19. package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.schemas.ts +11 -11
  20. package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.ts +5 -3
  21. package/examples/form_url_encoded_data_schema/tags/default.ts +5 -3
  22. package/examples/form_url_encoded_data_schema/tags/formURLEncodedAPI.schemas.ts +11 -11
  23. package/examples/form_url_encoded_data_with_query_params_schema/single/formURLEncodedAPIWithQueryParameters.ts +22 -20
  24. package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.schemas.ts +18 -18
  25. package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.ts +5 -3
  26. package/examples/form_url_encoded_data_with_query_params_schema/tags/default.ts +5 -3
  27. package/examples/form_url_encoded_data_with_query_params_schema/tags/formURLEncodedAPIWithQueryParameters.schemas.ts +18 -18
  28. package/examples/get_request_with_path_parameters_schema/single/simpleAPI.ts +5 -3
  29. package/examples/get_request_with_path_parameters_schema/split/simpleAPI.schemas.ts +1 -1
  30. package/examples/get_request_with_path_parameters_schema/split/simpleAPI.ts +5 -3
  31. package/examples/get_request_with_path_parameters_schema/tags/default.ts +5 -3
  32. package/examples/get_request_with_path_parameters_schema/tags/simpleAPI.schemas.ts +1 -1
  33. package/examples/headers_schema/single/headerDemoAPI.ts +24 -18
  34. package/examples/headers_schema/split/headerDemoAPI.schemas.ts +12 -12
  35. package/examples/headers_schema/split/headerDemoAPI.ts +13 -7
  36. package/examples/headers_schema/tags/default.ts +13 -7
  37. package/examples/headers_schema/tags/headerDemoAPI.schemas.ts +12 -12
  38. package/examples/no_title_schema/single/k6Client.ts +5 -3
  39. package/examples/no_title_schema/split/k6Client.schemas.ts +1 -1
  40. package/examples/no_title_schema/split/k6Client.ts +5 -3
  41. package/examples/no_title_schema/tags/default.ts +5 -3
  42. package/examples/no_title_schema/tags/k6Client.schemas.ts +1 -1
  43. package/examples/post_request_with_query_params/single/exampleAPI.ts +21 -19
  44. package/examples/post_request_with_query_params/split/exampleAPI.schemas.ts +17 -17
  45. package/examples/post_request_with_query_params/split/exampleAPI.ts +5 -3
  46. package/examples/post_request_with_query_params/tags/default.ts +5 -3
  47. package/examples/post_request_with_query_params/tags/exampleAPI.schemas.ts +17 -17
  48. package/examples/query_params_schema/single/exampleAPI.ts +13 -11
  49. package/examples/query_params_schema/split/exampleAPI.schemas.ts +9 -9
  50. package/examples/query_params_schema/split/exampleAPI.ts +5 -3
  51. package/examples/query_params_schema/tags/default.ts +5 -3
  52. package/examples/query_params_schema/tags/exampleAPI.schemas.ts +9 -9
  53. package/examples/simple_post_request_schema/single/exampleAPI.ts +21 -19
  54. package/examples/simple_post_request_schema/split/exampleAPI.schemas.ts +17 -17
  55. package/examples/simple_post_request_schema/split/exampleAPI.ts +5 -3
  56. package/examples/simple_post_request_schema/tags/default.ts +5 -3
  57. package/examples/simple_post_request_schema/tags/exampleAPI.schemas.ts +17 -17
  58. package/package.json +20 -20
  59. package/renovate.json +6 -0
  60. package/src/generator/k6Client.ts +9 -3
  61. package/tests/functional-tests/test-generator/fixtures/form_data_schema.json +2 -2
  62. package/tests/functional-tests/test-generator/fixtures/form_url_encoded_data_schema.json +2 -2
  63. package/tests/functional-tests/test-generator/fixtures/form_url_encoded_data_with_query_params_schema.json +1 -1
  64. package/tests/functional-tests/test-generator/fixtures/get_request_with_path_parameters_schema.json +1 -1
  65. package/tests/functional-tests/test-generator/fixtures/headers_schema.json +6 -6
  66. package/tests/functional-tests/test-generator/fixtures/simple_post_request_schema.json +1 -1
  67. package/tests/functional-tests/test-generator/generator.test.ts +9 -1
@@ -1,26 +1,10 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.1
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.4.1
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 user ID from the query parameter */
10
- userId?: string
11
- /** The active status from the query parameter */
12
- isActive?: boolean
13
- /** The data from the body */
14
- data?: string
15
- /** Response status */
16
- status?: 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.1
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.4.1
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
- name?: string
13
- age?: number
14
- isActive?: boolean
15
- tags?: string[]
16
- date?: 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
  */
@@ -65,8 +65,9 @@ export class ExampleAPIClient {
65
65
  ): {
66
66
  response: Response
67
67
  data: GetExampleData200
68
+ operationId: string
68
69
  } {
69
- const url = new URL(
70
+ const k6url = new URL(
70
71
  this.cleanBaseUrl +
71
72
  `/example` +
72
73
  `?${new URLSearchParams(params).toString()}`
@@ -75,7 +76,7 @@ export class ExampleAPIClient {
75
76
  requestParameters || {},
76
77
  this.commonRequestParameters
77
78
  )
78
- const response = http.request('GET', url.toString(), undefined, {
79
+ const response = http.request('GET', k6url.toString(), undefined, {
79
80
  ...mergedRequestParameters,
80
81
  })
81
82
  let data
@@ -88,6 +89,7 @@ export class ExampleAPIClient {
88
89
  return {
89
90
  response,
90
91
  data,
92
+ operationId: 'getExampleData',
91
93
  }
92
94
  }
93
95
 
@@ -1,18 +1,10 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.1
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.4.1
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
- name?: string
10
- age?: number
11
- isActive?: boolean
12
- tags?: string[]
13
- date?: 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.1
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.4.1
3
3
  * Do not edit manually.
4
4
  * Example API
5
5
  * API with all formats of query parameters
@@ -39,8 +39,9 @@ export class ExampleAPIClient {
39
39
  ): {
40
40
  response: Response
41
41
  data: GetExampleData200
42
+ operationId: string
42
43
  } {
43
- const url = new URL(
44
+ const k6url = new URL(
44
45
  this.cleanBaseUrl +
45
46
  `/example` +
46
47
  `?${new URLSearchParams(params).toString()}`
@@ -49,7 +50,7 @@ export class ExampleAPIClient {
49
50
  requestParameters || {},
50
51
  this.commonRequestParameters
51
52
  )
52
- const response = http.request('GET', url.toString(), undefined, {
53
+ const response = http.request('GET', k6url.toString(), undefined, {
53
54
  ...mergedRequestParameters,
54
55
  })
55
56
  let data
@@ -62,6 +63,7 @@ export class ExampleAPIClient {
62
63
  return {
63
64
  response,
64
65
  data,
66
+ operationId: 'getExampleData',
65
67
  }
66
68
  }
67
69
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.1
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.4.1
3
3
  * Do not edit manually.
4
4
  * Example API
5
5
  * API with all formats of query parameters
@@ -39,8 +39,9 @@ export class DefaultClient {
39
39
  ): {
40
40
  response: Response
41
41
  data: GetExampleData200
42
+ operationId: string
42
43
  } {
43
- const url = new URL(
44
+ const k6url = new URL(
44
45
  this.cleanBaseUrl +
45
46
  `/example` +
46
47
  `?${new URLSearchParams(params).toString()}`
@@ -49,7 +50,7 @@ export class DefaultClient {
49
50
  requestParameters || {},
50
51
  this.commonRequestParameters
51
52
  )
52
- const response = http.request('GET', url.toString(), undefined, {
53
+ const response = http.request('GET', k6url.toString(), undefined, {
53
54
  ...mergedRequestParameters,
54
55
  })
55
56
  let data
@@ -62,6 +63,7 @@ export class DefaultClient {
62
63
  return {
63
64
  response,
64
65
  data,
66
+ operationId: 'getExampleData',
65
67
  }
66
68
  }
67
69
 
@@ -1,18 +1,10 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.1
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.4.1
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
- name?: string
10
- age?: number
11
- isActive?: boolean
12
- tags?: string[]
13
- date?: 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.1
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.4.1
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
- /** The unique ID of the created resource */
18
- id?: string
19
- name?: string
20
- age?: number
21
- isActive?: boolean
22
- tags?: string[]
23
- date?: string
24
- meta?: CreateExampleData201Meta
25
- }
26
-
27
11
  /**
28
12
  * An object parameter containing metadata
29
13
  */
@@ -49,6 +33,22 @@ export type CreateExampleDataBody = {
49
33
  meta?: CreateExampleDataBodyMeta
50
34
  }
51
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
47
+ tags?: string[]
48
+ date?: string
49
+ meta?: CreateExampleData201Meta
50
+ }
51
+
52
52
  /**
53
53
  * This is the base client to use for interacting with the API.
54
54
  */
@@ -75,15 +75,16 @@ export class ExampleAPIClient {
75
75
  ): {
76
76
  response: Response
77
77
  data: CreateExampleData201
78
+ operationId: string
78
79
  } {
79
- const url = new URL(this.cleanBaseUrl + `/example`)
80
+ const k6url = new URL(this.cleanBaseUrl + `/example`)
80
81
  const mergedRequestParameters = this._mergeRequestParameters(
81
82
  requestParameters || {},
82
83
  this.commonRequestParameters
83
84
  )
84
85
  const response = http.request(
85
86
  'POST',
86
- url.toString(),
87
+ k6url.toString(),
87
88
  JSON.stringify(createExampleDataBody),
88
89
  {
89
90
  ...mergedRequestParameters,
@@ -103,6 +104,7 @@ export class ExampleAPIClient {
103
104
  return {
104
105
  response,
105
106
  data,
107
+ operationId: 'createExampleData',
106
108
  }
107
109
  }
108
110
 
@@ -1,26 +1,10 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.1
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.4.1
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
- /** The unique ID of the created resource */
15
- id?: string
16
- name?: string
17
- age?: number
18
- isActive?: boolean
19
- tags?: string[]
20
- date?: string
21
- meta?: CreateExampleData201Meta
22
- }
23
-
24
8
  /**
25
9
  * An object parameter containing metadata
26
10
  */
@@ -45,3 +29,19 @@ export type CreateExampleDataBody = {
45
29
  /** An object parameter containing metadata */
46
30
  meta?: CreateExampleDataBodyMeta
47
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
44
+ tags?: string[]
45
+ date?: string
46
+ meta?: CreateExampleData201Meta
47
+ }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.1
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.4.1
3
3
  * Do not edit manually.
4
4
  * Example API
5
5
  * API with all formats of data in the POST request body
@@ -39,15 +39,16 @@ export class ExampleAPIClient {
39
39
  ): {
40
40
  response: Response
41
41
  data: CreateExampleData201
42
+ operationId: string
42
43
  } {
43
- const url = new URL(this.cleanBaseUrl + `/example`)
44
+ const k6url = new URL(this.cleanBaseUrl + `/example`)
44
45
  const mergedRequestParameters = this._mergeRequestParameters(
45
46
  requestParameters || {},
46
47
  this.commonRequestParameters
47
48
  )
48
49
  const response = http.request(
49
50
  'POST',
50
- url.toString(),
51
+ k6url.toString(),
51
52
  JSON.stringify(createExampleDataBody),
52
53
  {
53
54
  ...mergedRequestParameters,
@@ -67,6 +68,7 @@ export class ExampleAPIClient {
67
68
  return {
68
69
  response,
69
70
  data,
71
+ operationId: 'createExampleData',
70
72
  }
71
73
  }
72
74
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.1
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.4.1
3
3
  * Do not edit manually.
4
4
  * Example API
5
5
  * API with all formats of data in the POST request body
@@ -39,15 +39,16 @@ export class DefaultClient {
39
39
  ): {
40
40
  response: Response
41
41
  data: CreateExampleData201
42
+ operationId: string
42
43
  } {
43
- const url = new URL(this.cleanBaseUrl + `/example`)
44
+ const k6url = new URL(this.cleanBaseUrl + `/example`)
44
45
  const mergedRequestParameters = this._mergeRequestParameters(
45
46
  requestParameters || {},
46
47
  this.commonRequestParameters
47
48
  )
48
49
  const response = http.request(
49
50
  'POST',
50
- url.toString(),
51
+ k6url.toString(),
51
52
  JSON.stringify(createExampleDataBody),
52
53
  {
53
54
  ...mergedRequestParameters,
@@ -67,6 +68,7 @@ export class DefaultClient {
67
68
  return {
68
69
  response,
69
70
  data,
71
+ operationId: 'createExampleData',
70
72
  }
71
73
  }
72
74
 
@@ -1,26 +1,10 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.1
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.4.1
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
- /** The unique ID of the created resource */
15
- id?: string
16
- name?: string
17
- age?: number
18
- isActive?: boolean
19
- tags?: string[]
20
- date?: string
21
- meta?: CreateExampleData201Meta
22
- }
23
-
24
8
  /**
25
9
  * An object parameter containing metadata
26
10
  */
@@ -45,3 +29,19 @@ export type CreateExampleDataBody = {
45
29
  /** An object parameter containing metadata */
46
30
  meta?: CreateExampleDataBodyMeta
47
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
44
+ tags?: string[]
45
+ date?: string
46
+ meta?: CreateExampleData201Meta
47
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/openapi-to-k6",
3
- "version": "0.3.1",
3
+ "version": "0.4.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": {
@@ -22,33 +22,33 @@
22
22
  "license": "AGPL-3.0",
23
23
  "dependencies": {
24
24
  "@faker-js/faker": "^9.2.0",
25
- "@types/k6": "^0.54.0",
25
+ "@types/k6": "^1.0.0",
26
26
  "axios": "^1.7.7",
27
27
  "chalk": "^4.1.2",
28
- "commander": "^12.1.0",
28
+ "commander": "^14.0.0",
29
29
  "handlebars": "^4.7.8",
30
30
  "openapi-typescript": "^7.4.1",
31
- "orval": "^7.4.1",
31
+ "orval": "^7.5.0",
32
32
  "prettier": "^3.3.3",
33
33
  "uuid": "^10.0.0"
34
34
  },
35
35
  "devDependencies": {
36
- "@types/uuid": "^10.0.0",
37
- "@typescript-eslint/eslint-plugin": "^8.8.1",
38
- "@vitest/coverage-v8": "^2.1.3",
39
- "eslint": "^8.57.0",
40
- "eslint-config-prettier": "^9.1.0",
41
- "eslint-import-resolver-typescript": "^3.6.3",
42
- "eslint-plugin-import": "^2.31.0",
43
- "eslint-plugin-prettier": "^5.2.1",
44
- "eslint-plugin-unused-imports": "^4.1.4",
45
- "husky": "^9.1.6",
46
- "lint-staged": "^15.2.10",
47
- "prettier": "^3.3.3",
48
- "ts-node": "^10.9.2",
49
- "typescript": "^5.6.2",
50
- "vite-tsconfig-paths": "^5.1.4",
51
- "vitest": "^2.1.3"
36
+ "@types/uuid": "10.0.0",
37
+ "@typescript-eslint/eslint-plugin": "8.53.0",
38
+ "@vitest/coverage-v8": "4.0.16",
39
+ "eslint": "8.57.1",
40
+ "eslint-config-prettier": "10.1.8",
41
+ "eslint-import-resolver-typescript": "4.4.4",
42
+ "eslint-plugin-import": "2.32.0",
43
+ "eslint-plugin-prettier": "5.5.5",
44
+ "eslint-plugin-unused-imports": "4.3.0",
45
+ "husky": "9.1.7",
46
+ "lint-staged": "16.2.7",
47
+ "prettier": "3.8.0",
48
+ "ts-node": "10.9.2",
49
+ "typescript": "5.9.3",
50
+ "vite-tsconfig-paths": "6.0.4",
51
+ "vitest": "4.0.16"
52
52
  },
53
53
  "lint-staged": {
54
54
  "*.{js,jsx,ts,tsx}": [
package/renovate.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "$schema": "https://docs.renovatebot.com/renovate-schema.json",
3
+ "extends": [
4
+ "github>grafana/grafana-renovate-config//presets/k6/k6-cloud-common"
5
+ ]
6
+ }
@@ -15,6 +15,7 @@ import {
15
15
  pascal,
16
16
  sanitize,
17
17
  toObjectString,
18
+ jsStringEscape,
18
19
  } from '@orval/core'
19
20
  import { DEFAULT_SCHEMA_TITLE } from '../constants'
20
21
  import { AnalyticsData } from '../type'
@@ -47,9 +48,12 @@ function _generateResponseTypeDefinition(response: GetterResponse): string {
47
48
  return `{
48
49
  response: Response
49
50
  data: ${responseDataType}
51
+ operationId: string
50
52
  }`
51
53
  }
52
54
 
55
+ const INTERNAL_URL_TOKEN = 'k6url'
56
+
53
57
  function _getRequestParametersMergerFunctionImplementation() {
54
58
  return `/**
55
59
  * Merges the provided request parameters with default parameters for the client.
@@ -147,7 +151,7 @@ const _getK6RequestOptions = (verbOptions: GeneratorVerbOptions) => {
147
151
  // 'GET', 'http://test.com/route', <body>, <options>
148
152
 
149
153
  return `"${verb.toUpperCase()}",
150
- url.toString(),
154
+ ${INTERNAL_URL_TOKEN}.toString(),
151
155
  ${fetchBodyOption},
152
156
  ${requestParametersValue}`
153
157
  }
@@ -205,6 +209,7 @@ const generateK6Implementation = (
205
209
  const {
206
210
  queryParams,
207
211
  operationName,
212
+ operationId,
208
213
  response,
209
214
  body,
210
215
  props,
@@ -229,7 +234,7 @@ const generateK6Implementation = (
229
234
  if (queryParams) {
230
235
  url += '+`?${new URLSearchParams(params).toString()}`'
231
236
  }
232
- const urlGeneration = `const url = new URL(${url});`
237
+ const urlGeneration = `const ${INTERNAL_URL_TOKEN} = new URL(${url});`
233
238
 
234
239
  const options = _getK6RequestOptions(verbOptions)
235
240
 
@@ -246,7 +251,8 @@ const generateK6Implementation = (
246
251
  }
247
252
  return {
248
253
  response,
249
- data
254
+ data,
255
+ operationId: '${jsStringEscape(operationId)}'
250
256
  }
251
257
  }
252
258
  `
@@ -87,8 +87,8 @@
87
87
  "expectedSubstrings": [
88
88
  "export class FormDataAPIClient",
89
89
  "const formData = new FormData(); formData.append(\"file\", postUploadBody.file); if (postUploadBody.description !== undefined) { formData.append(\"description\", postUploadBody.description); } formData.append(\"userId\", postUploadBody.userId);",
90
- "const url = new URL(this.cleanBaseUrl + `/upload`);",
91
- "const response = http.request(\"POST\", url.toString(), formData.body(), { ...mergedRequestParameters, headers: { ...mergedRequestParameters?.headers, \"Content-Type\": \"multipart/form-data; boundary=\" + formData.boundary, }, });"
90
+ "const k6url = new URL(this.cleanBaseUrl + `/upload`);",
91
+ "const response = http.request(\"POST\", k6url.toString(), formData.body(), { ...mergedRequestParameters, headers: { ...mergedRequestParameters?.headers, \"Content-Type\": \"multipart/form-data; boundary=\" + formData.boundary, }, });"
92
92
  ]
93
93
  }
94
94
  }
@@ -86,8 +86,8 @@
86
86
  "fileName": "formURLEncodedAPI.ts",
87
87
  "expectedSubstrings": [
88
88
  "export class FormURLEncodedAPIClient",
89
- "const url = new URL(this.cleanBaseUrl + `/submit-form`);",
90
- "const response = http.request( \"POST\", url.toString(), JSON.stringify(postSubmitFormBody), { ...mergedRequestParameters, headers: { ...mergedRequestParameters?.headers, \"Content-Type\": \"application/x-www-form-urlencoded\", }, }, );"
89
+ "const k6url = new URL(this.cleanBaseUrl + `/submit-form`);",
90
+ "const response = http.request( \"POST\", k6url.toString(), JSON.stringify(postSubmitFormBody), { ...mergedRequestParameters, headers: { ...mergedRequestParameters?.headers, \"Content-Type\": \"application/x-www-form-urlencoded\", }, }, );"
91
91
  ]
92
92
  }
93
93
  }
@@ -106,7 +106,7 @@
106
106
  "expected_sdk": {
107
107
  "fileName": "formURLEncodedAPIWithQueryParameters.ts",
108
108
  "expectedSubstrings": [
109
- "postSubmitForm( postSubmitFormBody: PostSubmitFormBody, params: PostSubmitFormParams, requestParameters?: Params, ): { response: Response; data: PostSubmitForm200; }",
109
+ "postSubmitForm( postSubmitFormBody: PostSubmitFormBody, params: PostSubmitFormParams, requestParameters?: Params, ): { response: Response; data: PostSubmitForm200; operationId: string; }",
110
110
  "new URL( this.cleanBaseUrl + `/submit-form` + `?${new URLSearchParams(params).toString()}`, );"
111
111
  ]
112
112
  }
@@ -60,7 +60,7 @@
60
60
  "fileName": "simpleAPI.ts",
61
61
  "expectedSubstrings": [
62
62
  "getItemById( id: string, requestParameters?: Params, ): ",
63
- "const url = new URL(this.cleanBaseUrl + `/items/${id}`);"
63
+ "const k6url = new URL(this.cleanBaseUrl + `/items/${id}`);"
64
64
  ]
65
65
  }
66
66
  }
@@ -151,12 +151,12 @@
151
151
  "fileName": "headerDemoAPI.ts",
152
152
  "expectedSubstrings": [
153
153
  "export class HeaderDemoAPIClient",
154
- "getExampleGet( headers?: GetExampleGetHeaders, requestParameters?: Params, ): { response: Response; data: GetExampleGet200; }",
155
- "response = http.request(\"GET\", url.toString(), undefined, { ...mergedRequestParameters, headers: { ...mergedRequestParameters?.headers, // In the schema, headers can be of any type like number but k6 accepts only strings as headers, hence converting all headers to string ...Object.fromEntries( Object.entries(headers || {}).map(([key, value]) => [ key, String(value), ]), ), }, });",
156
- "postExamplePost( postExamplePostBody: PostExamplePostBody, headers: PostExamplePostHeaders, requestParameters?: Params, ): { response: Response; data: void; }",
157
- "response = http.request( \"POST\", url.toString(), JSON.stringify(postExamplePostBody), { ...mergedRequestParameters, headers: { ...mergedRequestParameters?.headers, \"Content-Type\": \"application/json\", // In the schema, headers can be of any type like number but k6 accepts only strings as headers, hence converting all headers to string ...Object.fromEntries( Object.entries(headers || {}).map(([key, value]) => [ key, String(value), ]), ), }, }, );",
158
- "getExampleResponseHeaders(requestParameters?: Params): { response: Response; data: GetExampleResponseHeaders200; }",
159
- "response = http.request( \"GET\", url.toString(), undefined, mergedRequestParameters, );"
154
+ "getExampleGet( headers?: GetExampleGetHeaders, requestParameters?: Params, ): { response: Response; data: GetExampleGet200; operationId: string; }",
155
+ "response = http.request(\"GET\", k6url.toString(), undefined, { ...mergedRequestParameters, headers: { ...mergedRequestParameters?.headers, // In the schema, headers can be of any type like number but k6 accepts only strings as headers, hence converting all headers to string ...Object.fromEntries( Object.entries(headers || {}).map(([key, value]) => [ key, String(value), ]), ), }, });",
156
+ "postExamplePost( postExamplePostBody: PostExamplePostBody, headers: PostExamplePostHeaders, requestParameters?: Params, ): { response: Response; data: void; operationId: string; }",
157
+ "response = http.request( \"POST\", k6url.toString(), JSON.stringify(postExamplePostBody), { ...mergedRequestParameters, headers: { ...mergedRequestParameters?.headers, \"Content-Type\": \"application/json\", // In the schema, headers can be of any type like number but k6 accepts only strings as headers, hence converting all headers to string ...Object.fromEntries( Object.entries(headers || {}).map(([key, value]) => [ key, String(value), ]), ), }, }, );",
158
+ "getExampleResponseHeaders(requestParameters?: Params): { response: Response; data: GetExampleResponseHeaders200; operationId: string; }",
159
+ "response = http.request( \"GET\", k6url.toString(), undefined, mergedRequestParameters, );"
160
160
  ]
161
161
  }
162
162
  }