@grafana/openapi-to-k6 0.1.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/.github/workflows/publish.yaml +2 -2
  2. package/.github/workflows/tests.yaml +14 -6
  3. package/README.md +54 -14
  4. package/dist/analytics.js +2 -1
  5. package/dist/cli.js +20 -6
  6. package/dist/constants.js +8 -2
  7. package/dist/{generator.js → generator/index.js} +7 -13
  8. package/dist/{k6SdkClient.js → generator/k6Client.js} +148 -161
  9. package/examples/basic_schema/single/k6-script.sample.ts +11 -0
  10. package/examples/basic_schema/single/simpleAPI.ts +87 -0
  11. package/examples/basic_schema/split/k6-script.sample.ts +11 -0
  12. package/examples/basic_schema/split/simpleAPI.schemas.ts +9 -0
  13. package/examples/basic_schema/split/simpleAPI.ts +85 -0
  14. package/examples/basic_schema/tags/default.ts +85 -0
  15. package/examples/basic_schema/tags/k6-script.sample.ts +11 -0
  16. package/examples/basic_schema/tags/simpleAPI.schemas.ts +9 -0
  17. package/examples/form_data_schema/single/formDataAPI.ts +115 -0
  18. package/examples/form_data_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
  19. package/examples/form_data_schema/split/formDataAPI.schemas.ts +24 -0
  20. package/examples/form_data_schema/split/formDataAPI.ts +98 -0
  21. package/examples/form_data_schema/split/k6-script.sample.ts +11 -0
  22. package/examples/form_data_schema/tags/default.ts +98 -0
  23. package/examples/form_data_schema/tags/formDataAPI.schemas.ts +24 -0
  24. package/examples/form_data_schema/tags/k6-script.sample.ts +11 -0
  25. package/examples/form_url_encoded_data_schema/single/formURLEncodedAPI.ts +112 -0
  26. package/examples/form_url_encoded_data_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
  27. package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.schemas.ts +24 -0
  28. package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.ts +98 -0
  29. package/examples/form_url_encoded_data_schema/split/k6-script.sample.ts +11 -0
  30. package/examples/form_url_encoded_data_schema/tags/default.ts +98 -0
  31. package/examples/form_url_encoded_data_schema/tags/formURLEncodedAPI.schemas.ts +24 -0
  32. package/examples/form_url_encoded_data_schema/tags/k6-script.sample.ts +11 -0
  33. package/examples/form_url_encoded_data_with_query_params_schema/single/formURLEncodedAPIWithQueryParameters.ts +128 -0
  34. package/examples/form_url_encoded_data_with_query_params_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
  35. package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.schemas.ts +35 -0
  36. package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.ts +104 -0
  37. package/examples/form_url_encoded_data_with_query_params_schema/split/k6-script.sample.ts +14 -0
  38. package/examples/form_url_encoded_data_with_query_params_schema/tags/default.ts +104 -0
  39. package/examples/form_url_encoded_data_with_query_params_schema/tags/formURLEncodedAPIWithQueryParameters.schemas.ts +35 -0
  40. package/examples/form_url_encoded_data_with_query_params_schema/tags/k6-script.sample.ts +14 -0
  41. package/examples/get_request_with_path_parameters_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
  42. package/examples/get_request_with_path_parameters_schema/single/simpleAPI.ts +94 -0
  43. package/examples/get_request_with_path_parameters_schema/split/k6-script.sample.ts +11 -0
  44. package/examples/get_request_with_path_parameters_schema/split/simpleAPI.schemas.ts +12 -0
  45. package/examples/get_request_with_path_parameters_schema/split/simpleAPI.ts +90 -0
  46. package/examples/get_request_with_path_parameters_schema/tags/default.ts +90 -0
  47. package/examples/get_request_with_path_parameters_schema/tags/k6-script.sample.ts +11 -0
  48. package/examples/get_request_with_path_parameters_schema/tags/simpleAPI.schemas.ts +12 -0
  49. package/examples/headers_schema/single/headerDemoAPI.ts +202 -0
  50. package/examples/headers_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
  51. package/examples/headers_schema/split/headerDemoAPI.schemas.ts +32 -0
  52. package/examples/headers_schema/split/headerDemoAPI.ts +184 -0
  53. package/examples/headers_schema/split/k6-script.sample.ts +25 -0
  54. package/examples/headers_schema/tags/default.ts +182 -0
  55. package/examples/headers_schema/tags/headerDemoAPI.schemas.ts +32 -0
  56. package/examples/headers_schema/tags/k6-script.sample.ts +25 -0
  57. package/examples/no_title_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
  58. package/examples/no_title_schema/single/k6Client.ts +87 -0
  59. package/examples/{basic_schema → no_title_schema/split}/k6-script.sample.ts +2 -2
  60. package/examples/no_title_schema/split/k6Client.schemas.ts +9 -0
  61. package/examples/no_title_schema/split/k6Client.ts +85 -0
  62. package/examples/no_title_schema/tags/default.ts +85 -0
  63. package/examples/no_title_schema/tags/k6-script.sample.ts +11 -0
  64. package/examples/no_title_schema/tags/k6Client.schemas.ts +9 -0
  65. package/examples/post_request_with_query_params/single/exampleAPI.ts +126 -0
  66. package/examples/post_request_with_query_params/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
  67. package/examples/post_request_with_query_params/split/exampleAPI.schemas.ts +33 -0
  68. package/examples/post_request_with_query_params/split/exampleAPI.ts +105 -0
  69. package/examples/post_request_with_query_params/split/k6-script.sample.ts +14 -0
  70. package/examples/post_request_with_query_params/tags/default.ts +105 -0
  71. package/examples/post_request_with_query_params/tags/exampleAPI.schemas.ts +33 -0
  72. package/examples/post_request_with_query_params/tags/k6-script.sample.ts +14 -0
  73. package/examples/query_params_schema/single/exampleAPI.ts +120 -0
  74. package/examples/query_params_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
  75. package/examples/query_params_schema/split/exampleAPI.schemas.ts +37 -0
  76. package/examples/query_params_schema/split/exampleAPI.ts +94 -0
  77. package/examples/query_params_schema/split/k6-script.sample.ts +11 -0
  78. package/examples/query_params_schema/tags/default.ts +94 -0
  79. package/examples/query_params_schema/tags/exampleAPI.schemas.ts +37 -0
  80. package/examples/query_params_schema/tags/k6-script.sample.ts +11 -0
  81. package/examples/simple_post_request_schema/{exampleAPI.ts → single/exampleAPI.ts} +49 -49
  82. package/examples/simple_post_request_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
  83. package/examples/simple_post_request_schema/split/exampleAPI.schemas.ts +47 -0
  84. package/examples/simple_post_request_schema/split/exampleAPI.ts +99 -0
  85. package/examples/simple_post_request_schema/split/k6-script.sample.ts +13 -0
  86. package/examples/simple_post_request_schema/tags/default.ts +99 -0
  87. package/examples/simple_post_request_schema/tags/exampleAPI.schemas.ts +47 -0
  88. package/examples/simple_post_request_schema/tags/k6-script.sample.ts +13 -0
  89. package/images/openapi-to-k6.png +0 -0
  90. package/package.json +2 -2
  91. package/src/analytics.ts +3 -1
  92. package/src/cli.ts +34 -8
  93. package/src/constants.ts +7 -1
  94. package/src/{generator.ts → generator/index.ts} +8 -21
  95. package/src/{k6SdkClient.ts → generator/k6Client.ts} +174 -222
  96. package/src/type.d.ts +4 -4
  97. package/tests/e2e/schema.json +8 -0
  98. package/tests/e2e/{k6Script.ts → single/k6Script.ts} +7 -2
  99. package/tests/e2e/split/k6Script.ts +82 -0
  100. package/tests/e2e/tags/k6Script.ts +106 -0
  101. package/tests/functional-tests/fixtures/schemas/basic_schema.json +1 -4
  102. package/tests/functional-tests/fixtures/schemas/form_data_schema.json +4 -4
  103. package/tests/functional-tests/fixtures/schemas/form_url_encoded_data_schema.json +3 -3
  104. package/tests/functional-tests/fixtures/schemas/form_url_encoded_data_with_query_params_schema.json +2 -2
  105. package/tests/functional-tests/fixtures/schemas/get_request_with_path_parameters_schema.json +2 -2
  106. package/tests/functional-tests/fixtures/schemas/headers_schema.json +7 -8
  107. package/tests/functional-tests/fixtures/schemas/no_title_schema.json +2 -5
  108. package/tests/functional-tests/fixtures/schemas/post_request_with_query_params.json +3 -4
  109. package/tests/functional-tests/fixtures/schemas/query_params_schema.json +3 -3
  110. package/tests/functional-tests/fixtures/schemas/simple_post_request_schema.json +3 -5
  111. package/tests/functional-tests/generator.test.ts +46 -5
  112. package/examples/basic_schema/simpleAPI.ts +0 -87
  113. package/examples/form_data_schema/formDataAPI.ts +0 -115
  114. package/examples/form_url_encoded_data_schema/formURLEncodedAPI.ts +0 -114
  115. package/examples/form_url_encoded_data_with_query_params_schema/formURLEncodedAPIWithQueryParameters.ts +0 -130
  116. package/examples/get_request_with_path_parameters_schema/simpleAPI.ts +0 -94
  117. package/examples/headers_schema/headerDemoAPI.ts +0 -196
  118. package/examples/no_title_schema/K6Client.ts +0 -86
  119. package/examples/post_request_with_query_params/exampleAPI.ts +0 -124
  120. package/examples/query_params_schema/exampleAPI.ts +0 -118
  121. package/examples/update_examples.sh +0 -21
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.2.0
3
+ * Do not edit manually.
4
+ * Form URL Encoded API
5
+ * OpenAPI spec version: 1.0.0
6
+ */
7
+ import { URL } from 'https://jslib.k6.io/url/1.0.0/index.js'
8
+ import http from 'k6/http'
9
+ import type { Params, Response } from 'k6/http'
10
+ import type {
11
+ PostSubmitForm200,
12
+ PostSubmitFormBody,
13
+ } from './formURLEncodedAPI.schemas'
14
+
15
+ /**
16
+ * This is the base client to use for interacting with the API.
17
+ */
18
+ export class DefaultClient {
19
+ private cleanBaseUrl: string
20
+ private commonRequestParameters: Params
21
+
22
+ constructor(clientOptions: {
23
+ baseUrl: string
24
+ commonRequestParameters?: Params
25
+ }) {
26
+ this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
27
+ }
28
+
29
+ /**
30
+ * This endpoint accepts form URL-encoded data.
31
+ * @summary Submit form data
32
+ */
33
+ postSubmitForm(
34
+ postSubmitFormBody: PostSubmitFormBody,
35
+ requestParameters?: Params
36
+ ): {
37
+ response: Response
38
+ data: PostSubmitForm200
39
+ } {
40
+ const url = new URL(this.cleanBaseUrl + `/submit-form`)
41
+ const mergedRequestParameters = this._mergeRequestParameters(
42
+ requestParameters || {},
43
+ this.commonRequestParameters
44
+ )
45
+ const response = http.request(
46
+ 'POST',
47
+ url.toString(),
48
+ JSON.stringify(postSubmitFormBody),
49
+ {
50
+ ...mergedRequestParameters,
51
+ headers: {
52
+ 'Content-Type': 'application/x-www-form-urlencoded',
53
+ ...mergedRequestParameters?.headers,
54
+ },
55
+ }
56
+ )
57
+ let data
58
+
59
+ try {
60
+ data = response.json()
61
+ } catch {
62
+ data = response.body
63
+ }
64
+ return {
65
+ response,
66
+ data,
67
+ }
68
+ }
69
+
70
+ /**
71
+ * Merges the provided request parameters with default parameters for the client.
72
+ *
73
+ * @param {Params} requestParameters - The parameters provided specifically for the request
74
+ * @param {Params} commonRequestParameters - Common parameters for all requests
75
+ * @returns {Params} - The merged parameters
76
+ */
77
+ private _mergeRequestParameters(
78
+ requestParameters?: Params,
79
+ commonRequestParameters?: Params
80
+ ): Params {
81
+ return {
82
+ ...commonRequestParameters, // Default to common parameters
83
+ ...requestParameters, // Override with request-specific parameters
84
+ headers: {
85
+ ...(commonRequestParameters?.headers || {}), // Ensure headers are defined
86
+ ...(requestParameters?.headers || {}),
87
+ },
88
+ cookies: {
89
+ ...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
90
+ ...(requestParameters?.cookies || {}),
91
+ },
92
+ tags: {
93
+ ...(commonRequestParameters?.tags || {}), // Ensure tags are defined
94
+ ...(requestParameters?.tags || {}),
95
+ },
96
+ }
97
+ }
98
+ }
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.2.0
3
+ * Do not edit manually.
4
+ * Form URL Encoded API
5
+ * OpenAPI spec version: 1.0.0
6
+ */
7
+ export type PostSubmitForm400 = {
8
+ error?: string
9
+ success?: boolean
10
+ }
11
+
12
+ export type PostSubmitForm200 = {
13
+ message?: string
14
+ success?: boolean
15
+ }
16
+
17
+ export type PostSubmitFormBody = {
18
+ /** Age of the user */
19
+ age?: number
20
+ /** Email address of the user */
21
+ email: string
22
+ /** Name of the user */
23
+ name: string
24
+ }
@@ -0,0 +1,11 @@
1
+ import { FormURLEncodedAPIClient } from './formURLEncodedAPI.ts'
2
+
3
+ const baseUrl = '<BASE_URL>'
4
+ const client = new FormURLEncodedAPIClient({ baseUrl })
5
+
6
+ export default function () {
7
+ /**
8
+ * Submit form data
9
+ */
10
+ const postSubmitFormResponseData = client.postSubmitForm(postSubmitFormBody)
11
+ }
@@ -0,0 +1,128 @@
1
+ /**
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.2.0
3
+ * Do not edit manually.
4
+ * Form URL Encoded API with Query Parameters
5
+ * OpenAPI spec version: 1.0.0
6
+ */
7
+ import { URL, URLSearchParams } from 'https://jslib.k6.io/url/1.0.0/index.js'
8
+ import http from 'k6/http'
9
+ import type { Params, Response } from 'k6/http'
10
+ export type PostSubmitForm400 = {
11
+ error?: string
12
+ success?: boolean
13
+ }
14
+
15
+ export type PostSubmitForm200 = {
16
+ message?: string
17
+ success?: boolean
18
+ }
19
+
20
+ export type PostSubmitFormBody = {
21
+ /** Age of the user */
22
+ age?: number
23
+ /** Email address of the user */
24
+ email: string
25
+ /** Name of the user */
26
+ name: string
27
+ }
28
+
29
+ export type PostSubmitFormParams = {
30
+ /**
31
+ * Authentication token
32
+ */
33
+ token: string
34
+ /**
35
+ * Locale of the user
36
+ */
37
+ locale?: string
38
+ }
39
+
40
+ /**
41
+ * This is the base client to use for interacting with the API.
42
+ */
43
+ export class FormURLEncodedAPIWithQueryParametersClient {
44
+ private cleanBaseUrl: string
45
+ private commonRequestParameters: Params
46
+
47
+ constructor(clientOptions: {
48
+ baseUrl: string
49
+ commonRequestParameters?: Params
50
+ }) {
51
+ this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
52
+ }
53
+
54
+ /**
55
+ * This endpoint accepts form URL-encoded data and query parameters.
56
+ * @summary Submit form data with query parameters
57
+ */
58
+ postSubmitForm(
59
+ postSubmitFormBody: PostSubmitFormBody,
60
+ params: PostSubmitFormParams,
61
+ requestParameters?: Params
62
+ ): {
63
+ response: Response
64
+ data: PostSubmitForm200
65
+ } {
66
+ const url = new URL(
67
+ this.cleanBaseUrl +
68
+ `/submit-form` +
69
+ `?${new URLSearchParams(params).toString()}`
70
+ )
71
+ const mergedRequestParameters = this._mergeRequestParameters(
72
+ requestParameters || {},
73
+ this.commonRequestParameters
74
+ )
75
+ const response = http.request(
76
+ 'POST',
77
+ url.toString(),
78
+ JSON.stringify(postSubmitFormBody),
79
+ {
80
+ ...mergedRequestParameters,
81
+ headers: {
82
+ 'Content-Type': 'application/x-www-form-urlencoded',
83
+ ...mergedRequestParameters?.headers,
84
+ },
85
+ }
86
+ )
87
+ let data
88
+
89
+ try {
90
+ data = response.json()
91
+ } catch {
92
+ data = response.body
93
+ }
94
+ return {
95
+ response,
96
+ data,
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Merges the provided request parameters with default parameters for the client.
102
+ *
103
+ * @param {Params} requestParameters - The parameters provided specifically for the request
104
+ * @param {Params} commonRequestParameters - Common parameters for all requests
105
+ * @returns {Params} - The merged parameters
106
+ */
107
+ private _mergeRequestParameters(
108
+ requestParameters?: Params,
109
+ commonRequestParameters?: Params
110
+ ): Params {
111
+ return {
112
+ ...commonRequestParameters, // Default to common parameters
113
+ ...requestParameters, // Override with request-specific parameters
114
+ headers: {
115
+ ...(commonRequestParameters?.headers || {}), // Ensure headers are defined
116
+ ...(requestParameters?.headers || {}),
117
+ },
118
+ cookies: {
119
+ ...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
120
+ ...(requestParameters?.cookies || {}),
121
+ },
122
+ tags: {
123
+ ...(commonRequestParameters?.tags || {}), // Ensure tags are defined
124
+ ...(requestParameters?.tags || {}),
125
+ },
126
+ }
127
+ }
128
+ }
@@ -1,7 +1,7 @@
1
- import { createFormURLEncodedAPIwithQueryParameters } from './formURLEncodedAPIWithQueryParameters.ts'
1
+ import { FormURLEncodedAPIwithQueryParametersClient } from './formURLEncodedAPIWithQueryParameters.ts'
2
2
 
3
3
  const baseUrl = '<BASE_URL>'
4
- const client = createFormURLEncodedAPIwithQueryParameters({ baseUrl })
4
+ const client = new FormURLEncodedAPIwithQueryParametersClient({ baseUrl })
5
5
 
6
6
  export default function () {
7
7
  /**
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.2.0
3
+ * Do not edit manually.
4
+ * Form URL Encoded API with Query Parameters
5
+ * OpenAPI spec version: 1.0.0
6
+ */
7
+ export type PostSubmitForm400 = {
8
+ error?: string
9
+ success?: boolean
10
+ }
11
+
12
+ export type PostSubmitForm200 = {
13
+ message?: string
14
+ success?: boolean
15
+ }
16
+
17
+ export type PostSubmitFormBody = {
18
+ /** Age of the user */
19
+ age?: number
20
+ /** Email address of the user */
21
+ email: string
22
+ /** Name of the user */
23
+ name: string
24
+ }
25
+
26
+ export type PostSubmitFormParams = {
27
+ /**
28
+ * Authentication token
29
+ */
30
+ token: string
31
+ /**
32
+ * Locale of the user
33
+ */
34
+ locale?: string
35
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.2.0
3
+ * Do not edit manually.
4
+ * Form URL Encoded API with Query Parameters
5
+ * OpenAPI spec version: 1.0.0
6
+ */
7
+ import { URL, URLSearchParams } from 'https://jslib.k6.io/url/1.0.0/index.js'
8
+ import http from 'k6/http'
9
+ import type { Params, Response } from 'k6/http'
10
+ import type {
11
+ PostSubmitForm200,
12
+ PostSubmitFormBody,
13
+ PostSubmitFormParams,
14
+ } from './formURLEncodedAPIWithQueryParameters.schemas'
15
+
16
+ /**
17
+ * This is the base client to use for interacting with the API.
18
+ */
19
+ export class FormURLEncodedAPIWithQueryParametersClient {
20
+ private cleanBaseUrl: string
21
+ private commonRequestParameters: Params
22
+
23
+ constructor(clientOptions: {
24
+ baseUrl: string
25
+ commonRequestParameters?: Params
26
+ }) {
27
+ this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
28
+ }
29
+
30
+ /**
31
+ * This endpoint accepts form URL-encoded data and query parameters.
32
+ * @summary Submit form data with query parameters
33
+ */
34
+ postSubmitForm(
35
+ postSubmitFormBody: PostSubmitFormBody,
36
+ params: PostSubmitFormParams,
37
+ requestParameters?: Params
38
+ ): {
39
+ response: Response
40
+ data: PostSubmitForm200
41
+ } {
42
+ const url = new URL(
43
+ this.cleanBaseUrl +
44
+ `/submit-form` +
45
+ `?${new URLSearchParams(params).toString()}`
46
+ )
47
+ const mergedRequestParameters = this._mergeRequestParameters(
48
+ requestParameters || {},
49
+ this.commonRequestParameters
50
+ )
51
+ const response = http.request(
52
+ 'POST',
53
+ url.toString(),
54
+ JSON.stringify(postSubmitFormBody),
55
+ {
56
+ ...mergedRequestParameters,
57
+ headers: {
58
+ 'Content-Type': 'application/x-www-form-urlencoded',
59
+ ...mergedRequestParameters?.headers,
60
+ },
61
+ }
62
+ )
63
+ let data
64
+
65
+ try {
66
+ data = response.json()
67
+ } catch {
68
+ data = response.body
69
+ }
70
+ return {
71
+ response,
72
+ data,
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Merges the provided request parameters with default parameters for the client.
78
+ *
79
+ * @param {Params} requestParameters - The parameters provided specifically for the request
80
+ * @param {Params} commonRequestParameters - Common parameters for all requests
81
+ * @returns {Params} - The merged parameters
82
+ */
83
+ private _mergeRequestParameters(
84
+ requestParameters?: Params,
85
+ commonRequestParameters?: Params
86
+ ): Params {
87
+ return {
88
+ ...commonRequestParameters, // Default to common parameters
89
+ ...requestParameters, // Override with request-specific parameters
90
+ headers: {
91
+ ...(commonRequestParameters?.headers || {}), // Ensure headers are defined
92
+ ...(requestParameters?.headers || {}),
93
+ },
94
+ cookies: {
95
+ ...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
96
+ ...(requestParameters?.cookies || {}),
97
+ },
98
+ tags: {
99
+ ...(commonRequestParameters?.tags || {}), // Ensure tags are defined
100
+ ...(requestParameters?.tags || {}),
101
+ },
102
+ }
103
+ }
104
+ }
@@ -0,0 +1,14 @@
1
+ import { FormURLEncodedAPIwithQueryParametersClient } from './formURLEncodedAPIWithQueryParameters.ts'
2
+
3
+ const baseUrl = '<BASE_URL>'
4
+ const client = new FormURLEncodedAPIwithQueryParametersClient({ baseUrl })
5
+
6
+ export default function () {
7
+ /**
8
+ * Submit form data with query parameters
9
+ */
10
+ const postSubmitFormResponseData = client.postSubmitForm(
11
+ postSubmitFormBody,
12
+ params
13
+ )
14
+ }
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.2.0
3
+ * Do not edit manually.
4
+ * Form URL Encoded API with Query Parameters
5
+ * OpenAPI spec version: 1.0.0
6
+ */
7
+ import { URL, URLSearchParams } from 'https://jslib.k6.io/url/1.0.0/index.js'
8
+ import http from 'k6/http'
9
+ import type { Params, Response } from 'k6/http'
10
+ import type {
11
+ PostSubmitForm200,
12
+ PostSubmitFormBody,
13
+ PostSubmitFormParams,
14
+ } from './formURLEncodedAPIWithQueryParameters.schemas'
15
+
16
+ /**
17
+ * This is the base client to use for interacting with the API.
18
+ */
19
+ export class DefaultClient {
20
+ private cleanBaseUrl: string
21
+ private commonRequestParameters: Params
22
+
23
+ constructor(clientOptions: {
24
+ baseUrl: string
25
+ commonRequestParameters?: Params
26
+ }) {
27
+ this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
28
+ }
29
+
30
+ /**
31
+ * This endpoint accepts form URL-encoded data and query parameters.
32
+ * @summary Submit form data with query parameters
33
+ */
34
+ postSubmitForm(
35
+ postSubmitFormBody: PostSubmitFormBody,
36
+ params: PostSubmitFormParams,
37
+ requestParameters?: Params
38
+ ): {
39
+ response: Response
40
+ data: PostSubmitForm200
41
+ } {
42
+ const url = new URL(
43
+ this.cleanBaseUrl +
44
+ `/submit-form` +
45
+ `?${new URLSearchParams(params).toString()}`
46
+ )
47
+ const mergedRequestParameters = this._mergeRequestParameters(
48
+ requestParameters || {},
49
+ this.commonRequestParameters
50
+ )
51
+ const response = http.request(
52
+ 'POST',
53
+ url.toString(),
54
+ JSON.stringify(postSubmitFormBody),
55
+ {
56
+ ...mergedRequestParameters,
57
+ headers: {
58
+ 'Content-Type': 'application/x-www-form-urlencoded',
59
+ ...mergedRequestParameters?.headers,
60
+ },
61
+ }
62
+ )
63
+ let data
64
+
65
+ try {
66
+ data = response.json()
67
+ } catch {
68
+ data = response.body
69
+ }
70
+ return {
71
+ response,
72
+ data,
73
+ }
74
+ }
75
+
76
+ /**
77
+ * Merges the provided request parameters with default parameters for the client.
78
+ *
79
+ * @param {Params} requestParameters - The parameters provided specifically for the request
80
+ * @param {Params} commonRequestParameters - Common parameters for all requests
81
+ * @returns {Params} - The merged parameters
82
+ */
83
+ private _mergeRequestParameters(
84
+ requestParameters?: Params,
85
+ commonRequestParameters?: Params
86
+ ): Params {
87
+ return {
88
+ ...commonRequestParameters, // Default to common parameters
89
+ ...requestParameters, // Override with request-specific parameters
90
+ headers: {
91
+ ...(commonRequestParameters?.headers || {}), // Ensure headers are defined
92
+ ...(requestParameters?.headers || {}),
93
+ },
94
+ cookies: {
95
+ ...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
96
+ ...(requestParameters?.cookies || {}),
97
+ },
98
+ tags: {
99
+ ...(commonRequestParameters?.tags || {}), // Ensure tags are defined
100
+ ...(requestParameters?.tags || {}),
101
+ },
102
+ }
103
+ }
104
+ }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.2.0
3
+ * Do not edit manually.
4
+ * Form URL Encoded API with Query Parameters
5
+ * OpenAPI spec version: 1.0.0
6
+ */
7
+ export type PostSubmitForm400 = {
8
+ error?: string
9
+ success?: boolean
10
+ }
11
+
12
+ export type PostSubmitForm200 = {
13
+ message?: string
14
+ success?: boolean
15
+ }
16
+
17
+ export type PostSubmitFormBody = {
18
+ /** Age of the user */
19
+ age?: number
20
+ /** Email address of the user */
21
+ email: string
22
+ /** Name of the user */
23
+ name: string
24
+ }
25
+
26
+ export type PostSubmitFormParams = {
27
+ /**
28
+ * Authentication token
29
+ */
30
+ token: string
31
+ /**
32
+ * Locale of the user
33
+ */
34
+ locale?: string
35
+ }
@@ -0,0 +1,14 @@
1
+ import { FormURLEncodedAPIwithQueryParametersClient } from './formURLEncodedAPIWithQueryParameters.ts'
2
+
3
+ const baseUrl = '<BASE_URL>'
4
+ const client = new FormURLEncodedAPIwithQueryParametersClient({ baseUrl })
5
+
6
+ export default function () {
7
+ /**
8
+ * Submit form data with query parameters
9
+ */
10
+ const postSubmitFormResponseData = client.postSubmitForm(
11
+ postSubmitFormBody,
12
+ params
13
+ )
14
+ }
@@ -1,7 +1,7 @@
1
- import { createSimpleAPI } from './simpleAPI.ts'
1
+ import { SimpleAPIClient } from './simpleAPI.ts'
2
2
 
3
3
  const baseUrl = '<BASE_URL>'
4
- const client = createSimpleAPI({ baseUrl })
4
+ const client = new SimpleAPIClient({ baseUrl })
5
5
 
6
6
  export default function () {
7
7
  /**
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Automatically generated by @grafana/openapi-to-k6: 0.2.0
3
+ * Do not edit manually.
4
+ * Simple API
5
+ * An API with a single GET request that takes a path parameter
6
+ * OpenAPI spec version: 1.0.0
7
+ */
8
+ import { URL } from 'https://jslib.k6.io/url/1.0.0/index.js'
9
+ import http from 'k6/http'
10
+ import type { Params, Response } from 'k6/http'
11
+ export type GetItemById200 = {
12
+ description?: string
13
+ id?: string
14
+ name?: string
15
+ }
16
+
17
+ /**
18
+ * This is the base client to use for interacting with the API.
19
+ */
20
+ export class SimpleAPIClient {
21
+ private cleanBaseUrl: string
22
+ private commonRequestParameters: Params
23
+
24
+ constructor(clientOptions: {
25
+ baseUrl: string
26
+ commonRequestParameters?: Params
27
+ }) {
28
+ this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
29
+ }
30
+
31
+ /**
32
+ * Returns a single item based on the provided ID
33
+ * @summary Get an item by its ID
34
+ */
35
+ getItemById(
36
+ id: string,
37
+ requestParameters?: Params
38
+ ): {
39
+ response: Response
40
+ data: GetItemById200
41
+ } {
42
+ const url = new URL(this.cleanBaseUrl + `/items/${id}`)
43
+ const mergedRequestParameters = this._mergeRequestParameters(
44
+ requestParameters || {},
45
+ this.commonRequestParameters
46
+ )
47
+ const response = http.request(
48
+ 'GET',
49
+ url.toString(),
50
+ undefined,
51
+ mergedRequestParameters
52
+ )
53
+ let data
54
+
55
+ try {
56
+ data = response.json()
57
+ } catch {
58
+ data = response.body
59
+ }
60
+ return {
61
+ response,
62
+ data,
63
+ }
64
+ }
65
+
66
+ /**
67
+ * Merges the provided request parameters with default parameters for the client.
68
+ *
69
+ * @param {Params} requestParameters - The parameters provided specifically for the request
70
+ * @param {Params} commonRequestParameters - Common parameters for all requests
71
+ * @returns {Params} - The merged parameters
72
+ */
73
+ private _mergeRequestParameters(
74
+ requestParameters?: Params,
75
+ commonRequestParameters?: Params
76
+ ): Params {
77
+ return {
78
+ ...commonRequestParameters, // Default to common parameters
79
+ ...requestParameters, // Override with request-specific parameters
80
+ headers: {
81
+ ...(commonRequestParameters?.headers || {}), // Ensure headers are defined
82
+ ...(requestParameters?.headers || {}),
83
+ },
84
+ cookies: {
85
+ ...(commonRequestParameters?.cookies || {}), // Ensure cookies are defined
86
+ ...(requestParameters?.cookies || {}),
87
+ },
88
+ tags: {
89
+ ...(commonRequestParameters?.tags || {}), // Ensure tags are defined
90
+ ...(requestParameters?.tags || {}),
91
+ },
92
+ }
93
+ }
94
+ }
@@ -0,0 +1,11 @@
1
+ import { SimpleAPIClient } from './simpleAPI.ts'
2
+
3
+ const baseUrl = '<BASE_URL>'
4
+ const client = new SimpleAPIClient({ baseUrl })
5
+
6
+ export default function () {
7
+ /**
8
+ * Get an item by its ID
9
+ */
10
+ const getItemByIdResponseData = client.getItemById(id)
11
+ }