@grafana/openapi-to-k6 0.3.2 → 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 +5 -3
  14. package/examples/form_data_schema/split/formDataAPI.schemas.ts +1 -1
  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 +1 -1
  18. package/examples/form_url_encoded_data_schema/single/formURLEncodedAPI.ts +5 -3
  19. package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.schemas.ts +1 -1
  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 +1 -1
  23. package/examples/form_url_encoded_data_with_query_params_schema/single/formURLEncodedAPIWithQueryParameters.ts +5 -3
  24. package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.schemas.ts +1 -1
  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 +1 -1
  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 +13 -7
  34. package/examples/headers_schema/split/headerDemoAPI.schemas.ts +1 -1
  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 +1 -1
  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 +5 -3
  44. package/examples/post_request_with_query_params/split/exampleAPI.schemas.ts +1 -1
  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 +1 -1
  48. package/examples/query_params_schema/single/exampleAPI.ts +5 -3
  49. package/examples/query_params_schema/split/exampleAPI.schemas.ts +1 -1
  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 +1 -1
  53. package/examples/simple_post_request_schema/single/exampleAPI.ts +5 -3
  54. package/examples/simple_post_request_schema/split/exampleAPI.schemas.ts +1 -1
  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 +1 -1
  58. package/package.json +19 -19
  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,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.2
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.4.1
3
3
  * Do not edit manually.
4
4
  * K6Client
5
5
  * Service version: 1.0.0
@@ -31,15 +31,16 @@ export class K6ClientClient {
31
31
  getExample(requestParameters?: Params): {
32
32
  response: Response
33
33
  data: GetExample200
34
+ operationId: string
34
35
  } {
35
- const url = new URL(this.cleanBaseUrl + `/example`)
36
+ const k6url = new URL(this.cleanBaseUrl + `/example`)
36
37
  const mergedRequestParameters = this._mergeRequestParameters(
37
38
  requestParameters || {},
38
39
  this.commonRequestParameters
39
40
  )
40
41
  const response = http.request(
41
42
  'GET',
42
- url.toString(),
43
+ k6url.toString(),
43
44
  undefined,
44
45
  mergedRequestParameters
45
46
  )
@@ -53,6 +54,7 @@ export class K6ClientClient {
53
54
  return {
54
55
  response,
55
56
  data,
57
+ operationId: 'GetExample',
56
58
  }
57
59
  }
58
60
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.2
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.4.1
3
3
  * Do not edit manually.
4
4
  * K6Client
5
5
  * Service version: 1.0.0
@@ -31,15 +31,16 @@ export class DefaultClient {
31
31
  getExample(requestParameters?: Params): {
32
32
  response: Response
33
33
  data: GetExample200
34
+ operationId: string
34
35
  } {
35
- const url = new URL(this.cleanBaseUrl + `/example`)
36
+ const k6url = new URL(this.cleanBaseUrl + `/example`)
36
37
  const mergedRequestParameters = this._mergeRequestParameters(
37
38
  requestParameters || {},
38
39
  this.commonRequestParameters
39
40
  )
40
41
  const response = http.request(
41
42
  'GET',
42
- url.toString(),
43
+ k6url.toString(),
43
44
  undefined,
44
45
  mergedRequestParameters
45
46
  )
@@ -53,6 +54,7 @@ export class DefaultClient {
53
54
  return {
54
55
  response,
55
56
  data,
57
+ operationId: 'GetExample',
56
58
  }
57
59
  }
58
60
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.2
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.4.1
3
3
  * Do not edit manually.
4
4
  * K6Client
5
5
  * Service version: 1.0.0
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.2
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
@@ -62,8 +62,9 @@ export class ExampleAPIClient {
62
62
  ): {
63
63
  response: Response
64
64
  data: CreateExampleData201
65
+ operationId: string
65
66
  } {
66
- const url = new URL(
67
+ const k6url = new URL(
67
68
  this.cleanBaseUrl +
68
69
  `/example` +
69
70
  `?${new URLSearchParams(params).toString()}`
@@ -74,7 +75,7 @@ export class ExampleAPIClient {
74
75
  )
75
76
  const response = http.request(
76
77
  'POST',
77
- url.toString(),
78
+ k6url.toString(),
78
79
  JSON.stringify(createExampleDataBody),
79
80
  {
80
81
  ...mergedRequestParameters,
@@ -94,6 +95,7 @@ export class ExampleAPIClient {
94
95
  return {
95
96
  response,
96
97
  data,
98
+ operationId: 'createExampleData',
97
99
  }
98
100
  }
99
101
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.2
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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.2
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
@@ -41,8 +41,9 @@ export class ExampleAPIClient {
41
41
  ): {
42
42
  response: Response
43
43
  data: CreateExampleData201
44
+ operationId: string
44
45
  } {
45
- const url = new URL(
46
+ const k6url = new URL(
46
47
  this.cleanBaseUrl +
47
48
  `/example` +
48
49
  `?${new URLSearchParams(params).toString()}`
@@ -53,7 +54,7 @@ export class ExampleAPIClient {
53
54
  )
54
55
  const response = http.request(
55
56
  'POST',
56
- url.toString(),
57
+ k6url.toString(),
57
58
  JSON.stringify(createExampleDataBody),
58
59
  {
59
60
  ...mergedRequestParameters,
@@ -73,6 +74,7 @@ export class ExampleAPIClient {
73
74
  return {
74
75
  response,
75
76
  data,
77
+ operationId: 'createExampleData',
76
78
  }
77
79
  }
78
80
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.2
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
@@ -41,8 +41,9 @@ export class DefaultClient {
41
41
  ): {
42
42
  response: Response
43
43
  data: CreateExampleData201
44
+ operationId: string
44
45
  } {
45
- const url = new URL(
46
+ const k6url = new URL(
46
47
  this.cleanBaseUrl +
47
48
  `/example` +
48
49
  `?${new URLSearchParams(params).toString()}`
@@ -53,7 +54,7 @@ export class DefaultClient {
53
54
  )
54
55
  const response = http.request(
55
56
  'POST',
56
- url.toString(),
57
+ k6url.toString(),
57
58
  JSON.stringify(createExampleDataBody),
58
59
  {
59
60
  ...mergedRequestParameters,
@@ -73,6 +74,7 @@ export class DefaultClient {
73
74
  return {
74
75
  response,
75
76
  data,
77
+ operationId: 'createExampleData',
76
78
  }
77
79
  }
78
80
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.2
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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.2
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
@@ -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,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.2
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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.2
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.2
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,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.2
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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.2
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
@@ -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,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.2
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
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.2
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.2
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,5 +1,5 @@
1
1
  /**
2
- * Automatically generated by @grafana/openapi-to-k6: 0.3.2
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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/openapi-to-k6",
3
- "version": "0.3.2",
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,10 +22,10 @@
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
31
  "orval": "^7.5.0",
@@ -33,22 +33,22 @@
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
  }
@@ -121,7 +121,7 @@
121
121
  "fileName": "exampleAPI.ts",
122
122
  "expectedSubstrings": [
123
123
  "export class ExampleAPIClient {",
124
- "const url = new URL(this.cleanBaseUrl + `/example`);",
124
+ "const k6url = new URL(this.cleanBaseUrl + `/example`);",
125
125
  "JSON.stringify(createExampleDataBody),",
126
126
  "POST",
127
127
  "export type CreateExampleData201 = { /** The unique ID of the created resource */ id?: string; name?: string; age?: number; isActive?: boolean; tags?: string[]; date?: string; meta?: CreateExampleData201Meta; };"
@@ -28,7 +28,10 @@ const commonSubstringsForAllSDK = [
28
28
  'Service version',
29
29
  'const mergedRequestParameters = this._mergeRequestParameters( requestParameters || {}, this.commonRequestParameters, );',
30
30
  'try { data = response.json(); } catch { data = response.body; }',
31
- 'return { response, data, };',
31
+ ]
32
+
33
+ const commonMatchesForAllSDK = [
34
+ /return { response, data, operationId: "[^"]*", };/,
32
35
  ]
33
36
 
34
37
  const commonSubstringsForK6SampleScript = [`const baseUrl = "<BASE_URL>";`]
@@ -95,6 +98,11 @@ describe('generator', () => {
95
98
  replaceSpacesAndNewLineToSingleSpace(generatedContent)
96
99
  ).toContain(expectedString)
97
100
  }
101
+ for (const expectedToMatch of commonMatchesForAllSDK) {
102
+ expect(
103
+ replaceSpacesAndNewLineToSingleSpace(generatedContent)
104
+ ).toMatch(expectedToMatch)
105
+ }
98
106
  })
99
107
 
100
108
  it('should generate a sample K6 script', async () => {