@grafana/openapi-to-k6 0.2.6 → 0.3.0

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 (116) hide show
  1. package/README.md +5 -1
  2. package/dist/constants.js +7 -3
  3. package/dist/generator/k6Client.js +5 -55
  4. package/dist/generator/k6ScriptBuilder.js +256 -0
  5. package/examples/basic_schema/single/k6-script.sample.ts +3 -2
  6. package/examples/basic_schema/single/simpleAPI.ts +1 -1
  7. package/examples/basic_schema/split/k6-script.sample.ts +3 -2
  8. package/examples/basic_schema/split/simpleAPI.schemas.ts +1 -1
  9. package/examples/basic_schema/split/simpleAPI.ts +1 -1
  10. package/examples/basic_schema/tags/default.ts +1 -1
  11. package/examples/basic_schema/tags/k6-script.sample.ts +4 -3
  12. package/examples/basic_schema/tags/simpleAPI.schemas.ts +1 -1
  13. package/examples/form_data_schema/schema.json +6 -3
  14. package/examples/form_data_schema/single/formDataAPI.ts +1 -1
  15. package/examples/form_data_schema/single/k6-script.sample.ts +10 -2
  16. package/examples/form_data_schema/split/formDataAPI.schemas.ts +1 -1
  17. package/examples/form_data_schema/split/formDataAPI.ts +1 -1
  18. package/examples/form_data_schema/split/k6-script.sample.ts +10 -2
  19. package/examples/form_data_schema/tags/default.ts +1 -1
  20. package/examples/form_data_schema/tags/formDataAPI.schemas.ts +1 -1
  21. package/examples/form_data_schema/tags/k6-script.sample.ts +11 -3
  22. package/examples/form_url_encoded_data_schema/schema.json +6 -3
  23. package/examples/form_url_encoded_data_schema/single/formURLEncodedAPI.ts +1 -1
  24. package/examples/form_url_encoded_data_schema/single/k6-script.sample.ts +11 -2
  25. package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.schemas.ts +1 -1
  26. package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.ts +1 -1
  27. package/examples/form_url_encoded_data_schema/split/k6-script.sample.ts +11 -2
  28. package/examples/form_url_encoded_data_schema/tags/default.ts +1 -1
  29. package/examples/form_url_encoded_data_schema/tags/formURLEncodedAPI.schemas.ts +1 -1
  30. package/examples/form_url_encoded_data_schema/tags/k6-script.sample.ts +12 -3
  31. package/examples/form_url_encoded_data_with_query_params_schema/schema.json +8 -4
  32. package/examples/form_url_encoded_data_with_query_params_schema/single/formURLEncodedAPIWithQueryParameters.ts +1 -1
  33. package/examples/form_url_encoded_data_with_query_params_schema/single/k6-script.sample.ts +19 -6
  34. package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.schemas.ts +1 -1
  35. package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.ts +1 -1
  36. package/examples/form_url_encoded_data_with_query_params_schema/split/k6-script.sample.ts +19 -6
  37. package/examples/form_url_encoded_data_with_query_params_schema/tags/default.ts +1 -1
  38. package/examples/form_url_encoded_data_with_query_params_schema/tags/formURLEncodedAPIWithQueryParameters.schemas.ts +1 -1
  39. package/examples/form_url_encoded_data_with_query_params_schema/tags/k6-script.sample.ts +14 -3
  40. package/examples/get_request_with_path_parameters_schema/schema.json +2 -1
  41. package/examples/get_request_with_path_parameters_schema/single/k6-script.sample.ts +6 -2
  42. package/examples/get_request_with_path_parameters_schema/single/simpleAPI.ts +1 -1
  43. package/examples/get_request_with_path_parameters_schema/split/k6-script.sample.ts +6 -2
  44. package/examples/get_request_with_path_parameters_schema/split/simpleAPI.schemas.ts +1 -1
  45. package/examples/get_request_with_path_parameters_schema/split/simpleAPI.ts +1 -1
  46. package/examples/get_request_with_path_parameters_schema/tags/default.ts +1 -1
  47. package/examples/get_request_with_path_parameters_schema/tags/k6-script.sample.ts +7 -3
  48. package/examples/get_request_with_path_parameters_schema/tags/simpleAPI.schemas.ts +1 -1
  49. package/examples/headers_schema/schema.json +2 -1
  50. package/examples/headers_schema/single/headerDemoAPI.ts +1 -1
  51. package/examples/headers_schema/single/k6-script.sample.ts +15 -4
  52. package/examples/headers_schema/split/headerDemoAPI.schemas.ts +1 -1
  53. package/examples/headers_schema/split/headerDemoAPI.ts +1 -1
  54. package/examples/headers_schema/split/k6-script.sample.ts +15 -4
  55. package/examples/headers_schema/tags/default.ts +1 -1
  56. package/examples/headers_schema/tags/headerDemoAPI.schemas.ts +1 -1
  57. package/examples/headers_schema/tags/k6-script.sample.ts +16 -5
  58. package/examples/no_title_schema/single/k6-script.sample.ts +3 -2
  59. package/examples/no_title_schema/single/k6Client.ts +1 -1
  60. package/examples/no_title_schema/split/k6-script.sample.ts +3 -2
  61. package/examples/no_title_schema/split/k6Client.schemas.ts +1 -1
  62. package/examples/no_title_schema/split/k6Client.ts +1 -1
  63. package/examples/no_title_schema/tags/default.ts +1 -1
  64. package/examples/no_title_schema/tags/k6-script.sample.ts +4 -3
  65. package/examples/no_title_schema/tags/k6Client.schemas.ts +1 -1
  66. package/examples/post_request_with_query_params/schema.json +14 -7
  67. package/examples/post_request_with_query_params/single/exampleAPI.ts +1 -1
  68. package/examples/post_request_with_query_params/single/k6-script.sample.ts +11 -2
  69. package/examples/post_request_with_query_params/split/exampleAPI.schemas.ts +1 -1
  70. package/examples/post_request_with_query_params/split/exampleAPI.ts +1 -1
  71. package/examples/post_request_with_query_params/split/k6-script.sample.ts +11 -2
  72. package/examples/post_request_with_query_params/tags/default.ts +1 -1
  73. package/examples/post_request_with_query_params/tags/exampleAPI.schemas.ts +1 -1
  74. package/examples/post_request_with_query_params/tags/k6-script.sample.ts +12 -3
  75. package/examples/query_params_schema/schema.json +20 -10
  76. package/examples/query_params_schema/single/exampleAPI.ts +1 -1
  77. package/examples/query_params_schema/single/k6-script.sample.ts +8 -2
  78. package/examples/query_params_schema/split/exampleAPI.schemas.ts +1 -1
  79. package/examples/query_params_schema/split/exampleAPI.ts +1 -1
  80. package/examples/query_params_schema/split/k6-script.sample.ts +8 -2
  81. package/examples/query_params_schema/tags/default.ts +1 -1
  82. package/examples/query_params_schema/tags/exampleAPI.schemas.ts +1 -1
  83. package/examples/query_params_schema/tags/k6-script.sample.ts +9 -3
  84. package/examples/simple_post_request_schema/schema.json +30 -15
  85. package/examples/simple_post_request_schema/single/exampleAPI.ts +1 -1
  86. package/examples/simple_post_request_schema/single/k6-script.sample.ts +16 -2
  87. package/examples/simple_post_request_schema/split/exampleAPI.schemas.ts +1 -1
  88. package/examples/simple_post_request_schema/split/exampleAPI.ts +1 -1
  89. package/examples/simple_post_request_schema/split/k6-script.sample.ts +16 -2
  90. package/examples/simple_post_request_schema/tags/default.ts +1 -1
  91. package/examples/simple_post_request_schema/tags/exampleAPI.schemas.ts +1 -1
  92. package/examples/simple_post_request_schema/tags/k6-script.sample.ts +17 -3
  93. package/package.json +3 -1
  94. package/src/constants.ts +7 -3
  95. package/src/generator/k6Client.ts +3 -72
  96. package/src/generator/k6ScriptBuilder.ts +328 -0
  97. package/tests/e2e/schema.json +135 -18
  98. package/tests/functional-tests/helper.ts +16 -0
  99. package/tests/functional-tests/test-generator/generator.test.ts +154 -0
  100. package/tests/functional-tests/test-sample-k6-scripts/fixtures/schema_using_ref_models.json +394 -0
  101. package/tests/functional-tests/test-sample-k6-scripts/fixtures/schema_with_examples.json +416 -0
  102. package/tests/functional-tests/test-sample-k6-scripts/fixtures/schema_with_no_variables.json +32 -0
  103. package/tests/functional-tests/test-sample-k6-scripts/sampleK6Scripts.test.ts +248 -0
  104. package/tests/functional-tests/test-tags-filtering/tagsFiltering.test.ts +166 -0
  105. package/tests/functional-tests/generator.test.ts +0 -319
  106. /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/basic_schema.json +0 -0
  107. /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/form_data_schema.json +0 -0
  108. /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/form_url_encoded_data_schema.json +0 -0
  109. /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/form_url_encoded_data_with_query_params_schema.json +0 -0
  110. /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/get_request_with_path_parameters_schema.json +0 -0
  111. /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/headers_schema.json +0 -0
  112. /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/no_title_schema.json +0 -0
  113. /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/post_request_with_query_params.json +0 -0
  114. /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/query_params_schema.json +0 -0
  115. /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/simple_post_request_schema.json +0 -0
  116. /package/tests/functional-tests/{fixtures → test-tags-filtering/fixtures}/tags_filtering.json +0 -0
@@ -0,0 +1,394 @@
1
+ {
2
+ "openapi": "3.0.3",
3
+ "info": {
4
+ "title": "Comprehensive API",
5
+ "version": "1.0.0",
6
+ "description": "API supporting various HTTP methods with query, path parameters, and headers"
7
+ },
8
+ "components": {
9
+ "schemas": {
10
+ "ItemBase": {
11
+ "type": "object",
12
+ "properties": {
13
+ "name": {
14
+ "type": "string",
15
+ "example": "Sample Item"
16
+ },
17
+ "description": {
18
+ "type": "string",
19
+ "example": "This is a sample description for the item."
20
+ }
21
+ }
22
+ },
23
+ "ItemId": {
24
+ "type": "string",
25
+ "example": "12345-getItemById"
26
+ },
27
+ "UpdatedItem": {
28
+ "type": "object",
29
+ "properties": {
30
+ "name": {
31
+ "type": "string",
32
+ "example": "Updated Item Name"
33
+ },
34
+ "description": {
35
+ "type": "string",
36
+ "example": "Updated description for the item."
37
+ }
38
+ }
39
+ },
40
+ "PatchItem": {
41
+ "type": "object",
42
+ "properties": {
43
+ "name": {
44
+ "type": "string",
45
+ "example": "Partially Updated Item Name"
46
+ }
47
+ }
48
+ },
49
+ "FormUrlEncodedItem": {
50
+ "type": "object",
51
+ "properties": {
52
+ "name": {
53
+ "type": "string",
54
+ "example": "Form Encoded Item"
55
+ },
56
+ "description": {
57
+ "type": "string",
58
+ "example": "Description for form-urlencoded item."
59
+ }
60
+ },
61
+ "required": ["name"]
62
+ },
63
+ "FormDataItem": {
64
+ "type": "object",
65
+ "properties": {
66
+ "name": {
67
+ "type": "string",
68
+ "example": "Form Data Item"
69
+ }
70
+ },
71
+ "required": ["file", "name"]
72
+ },
73
+ "UserPost": {
74
+ "type": "object",
75
+ "properties": {
76
+ "title": {
77
+ "type": "string"
78
+ },
79
+ "content": {
80
+ "type": "string"
81
+ }
82
+ }
83
+ }
84
+ },
85
+ "parameters": {
86
+ "itemIdPath": {
87
+ "name": "id",
88
+ "in": "path",
89
+ "required": true,
90
+ "description": "ID of the item to retrieve",
91
+ "schema": {
92
+ "$ref": "#/components/schemas/ItemId"
93
+ }
94
+ },
95
+ "detailQuery": {
96
+ "name": "detail",
97
+ "in": "query",
98
+ "required": false,
99
+ "description": "Whether to return detailed information",
100
+ "schema": {
101
+ "type": "boolean",
102
+ "default": false,
103
+ "example": true
104
+ }
105
+ },
106
+ "userId": {
107
+ "name": "userId",
108
+ "in": "path",
109
+ "required": true,
110
+ "schema": {
111
+ "type": "string"
112
+ }
113
+ },
114
+ "postId": {
115
+ "name": "postId",
116
+ "in": "path",
117
+ "required": true,
118
+ "schema": {
119
+ "type": "string"
120
+ }
121
+ },
122
+ "clientIdHeader": {
123
+ "name": "X-Client-ID",
124
+ "in": "header",
125
+ "description": "Client ID for the request",
126
+ "required": true,
127
+ "schema": {
128
+ "type": "string",
129
+ "example": "client-123"
130
+ }
131
+ },
132
+ "requestIdHeader": {
133
+ "name": "X-Request-ID",
134
+ "in": "header",
135
+ "description": "Unique request identifier",
136
+ "required": false,
137
+ "schema": {
138
+ "type": "string",
139
+ "example": "req-56789"
140
+ }
141
+ },
142
+ "authTokenHeader": {
143
+ "name": "X-Auth-Token",
144
+ "in": "header",
145
+ "description": "Authentication token",
146
+ "required": true,
147
+ "schema": {
148
+ "type": "string",
149
+ "example": "Bearer abcdef12345"
150
+ }
151
+ },
152
+ "correlationIdHeader": {
153
+ "name": "X-Correlation-ID",
154
+ "in": "header",
155
+ "description": "Correlation ID for tracking requests",
156
+ "required": true,
157
+ "schema": {
158
+ "type": "string",
159
+ "example": "correlation-12345"
160
+ }
161
+ },
162
+ "optionalHeader": {
163
+ "name": "X-Optional-Header",
164
+ "in": "header",
165
+ "description": "Optional header",
166
+ "required": false,
167
+ "schema": {
168
+ "type": "string",
169
+ "example": "optional-header-value"
170
+ }
171
+ }
172
+ }
173
+ },
174
+ "paths": {
175
+ "/items/{id}": {
176
+ "get": {
177
+ "tags": ["Items"],
178
+ "summary": "Get an item by ID",
179
+ "parameters": [
180
+ { "$ref": "#/components/parameters/itemIdPath" },
181
+ { "$ref": "#/components/parameters/detailQuery" }
182
+ ],
183
+ "responses": {
184
+ "200": {
185
+ "description": "Successful response"
186
+ }
187
+ }
188
+ },
189
+ "post": {
190
+ "tags": ["Items"],
191
+ "summary": "Create an item by ID",
192
+ "parameters": [{ "$ref": "#/components/parameters/itemIdPath" }],
193
+ "requestBody": {
194
+ "required": true,
195
+ "content": {
196
+ "application/json": {
197
+ "schema": {
198
+ "$ref": "#/components/schemas/ItemBase"
199
+ }
200
+ }
201
+ }
202
+ },
203
+ "responses": {
204
+ "201": {
205
+ "description": "Item created successfully"
206
+ }
207
+ }
208
+ },
209
+ "put": {
210
+ "tags": ["Items"],
211
+ "summary": "Update an item by ID",
212
+ "parameters": [{ "$ref": "#/components/parameters/itemIdPath" }],
213
+ "requestBody": {
214
+ "required": true,
215
+ "content": {
216
+ "application/json": {
217
+ "schema": {
218
+ "$ref": "#/components/schemas/UpdatedItem"
219
+ }
220
+ }
221
+ }
222
+ },
223
+ "responses": {
224
+ "200": {
225
+ "description": "Item updated successfully"
226
+ }
227
+ }
228
+ },
229
+ "patch": {
230
+ "tags": ["Items"],
231
+ "summary": "Partially update an item by ID",
232
+ "parameters": [{ "$ref": "#/components/parameters/itemIdPath" }],
233
+ "requestBody": {
234
+ "required": true,
235
+ "content": {
236
+ "application/json": {
237
+ "schema": {
238
+ "$ref": "#/components/schemas/PatchItem"
239
+ }
240
+ }
241
+ }
242
+ },
243
+ "responses": {
244
+ "200": {
245
+ "description": "Item partially updated"
246
+ }
247
+ }
248
+ },
249
+ "delete": {
250
+ "tags": ["Items"],
251
+ "summary": "Delete an item by ID",
252
+ "parameters": [{ "$ref": "#/components/parameters/itemIdPath" }],
253
+ "responses": {
254
+ "204": {
255
+ "description": "Item deleted successfully"
256
+ }
257
+ }
258
+ },
259
+ "head": {
260
+ "tags": ["Items"],
261
+ "summary": "Check if item exists",
262
+ "parameters": [{ "$ref": "#/components/parameters/itemIdPath" }],
263
+ "responses": {
264
+ "200": {
265
+ "description": "Item exists"
266
+ },
267
+ "404": {
268
+ "description": "Item not found"
269
+ }
270
+ }
271
+ }
272
+ },
273
+ "/items-form-url-encoded": {
274
+ "post": {
275
+ "tags": ["ItemsForm", "Items"],
276
+ "summary": "Create an item using form-urlencoded data",
277
+ "requestBody": {
278
+ "required": true,
279
+ "content": {
280
+ "application/x-www-form-urlencoded": {
281
+ "schema": {
282
+ "$ref": "#/components/schemas/FormUrlEncodedItem"
283
+ }
284
+ }
285
+ }
286
+ },
287
+ "responses": {
288
+ "201": {
289
+ "description": "Item created successfully"
290
+ }
291
+ }
292
+ }
293
+ },
294
+ "/items-form-data": {
295
+ "post": {
296
+ "tags": ["ItemsForm", "Items"],
297
+ "summary": "Create an item using form-data",
298
+ "requestBody": {
299
+ "required": true,
300
+ "content": {
301
+ "multipart/form-data": {
302
+ "schema": {
303
+ "$ref": "#/components/schemas/FormDataItem"
304
+ }
305
+ }
306
+ }
307
+ },
308
+ "responses": {
309
+ "201": {
310
+ "description": "Item created with file upload"
311
+ }
312
+ }
313
+ }
314
+ },
315
+ "/items-header": {
316
+ "get": {
317
+ "tags": ["ItemsHeader"],
318
+ "summary": "Get an item with custom headers",
319
+ "parameters": [
320
+ {
321
+ "name": "id",
322
+ "in": "query",
323
+ "required": true,
324
+ "description": "ID of the item to retrieve",
325
+ "schema": {
326
+ "type": "string",
327
+ "example": "123450-getItemByIdWithHeader"
328
+ }
329
+ },
330
+ { "$ref": "#/components/parameters/clientIdHeader" },
331
+ { "$ref": "#/components/parameters/requestIdHeader" }
332
+ ],
333
+ "responses": {
334
+ "200": {
335
+ "description": "Item retrieved successfully"
336
+ }
337
+ },
338
+ "requestBody": {
339
+ "required": false
340
+ }
341
+ }
342
+ },
343
+ "/users/{userId}/posts/{postId}": {
344
+ "get": {
345
+ "operationId": "getUserPost",
346
+ "parameters": [
347
+ { "$ref": "#/components/parameters/userId" },
348
+ { "$ref": "#/components/parameters/postId" }
349
+ ],
350
+ "responses": {
351
+ "200": {
352
+ "description": "Success",
353
+ "content": {
354
+ "application/json": {
355
+ "schema": {
356
+ "$ref": "#/components/schemas/UserPost"
357
+ }
358
+ }
359
+ }
360
+ }
361
+ }
362
+ }
363
+ },
364
+ "/items-new-mandatory-headers": {
365
+ "get": {
366
+ "tags": ["ItemsHeader"],
367
+ "summary": "Retrieve a new item with mandatory headers",
368
+ "parameters": [
369
+ {
370
+ "name": "itemId",
371
+ "in": "query",
372
+ "required": true,
373
+ "description": "ID of the item to retrieve",
374
+ "schema": {
375
+ "type": "string",
376
+ "example": "67890"
377
+ }
378
+ },
379
+ { "$ref": "#/components/parameters/authTokenHeader" },
380
+ { "$ref": "#/components/parameters/correlationIdHeader" },
381
+ { "$ref": "#/components/parameters/optionalHeader" }
382
+ ],
383
+ "responses": {
384
+ "200": {
385
+ "description": "New item retrieved successfully"
386
+ },
387
+ "400": {
388
+ "description": "Invalid request"
389
+ }
390
+ }
391
+ }
392
+ }
393
+ }
394
+ }