@grafana/openapi-to-k6 0.2.5 → 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.
- package/.github/workflows/tests.yaml +1 -0
- package/README.md +10 -4
- package/dist/cli.js +27 -12
- package/dist/constants.js +7 -3
- package/dist/errors.js +10 -0
- package/dist/generator/index.js +50 -3
- package/dist/generator/k6Client.js +5 -55
- package/dist/generator/k6ScriptBuilder.js +256 -0
- package/dist/helper.js +32 -0
- package/examples/basic_schema/single/k6-script.sample.ts +3 -2
- package/examples/basic_schema/single/simpleAPI.ts +1 -1
- package/examples/basic_schema/split/k6-script.sample.ts +3 -2
- package/examples/basic_schema/split/simpleAPI.schemas.ts +1 -1
- package/examples/basic_schema/split/simpleAPI.ts +1 -1
- package/examples/basic_schema/tags/default.ts +1 -1
- package/examples/basic_schema/tags/k6-script.sample.ts +4 -3
- package/examples/basic_schema/tags/simpleAPI.schemas.ts +1 -1
- package/examples/form_data_schema/schema.json +6 -3
- package/examples/form_data_schema/single/formDataAPI.ts +1 -1
- package/examples/form_data_schema/single/k6-script.sample.ts +10 -2
- package/examples/form_data_schema/split/formDataAPI.schemas.ts +1 -1
- package/examples/form_data_schema/split/formDataAPI.ts +1 -1
- package/examples/form_data_schema/split/k6-script.sample.ts +10 -2
- package/examples/form_data_schema/tags/default.ts +1 -1
- package/examples/form_data_schema/tags/formDataAPI.schemas.ts +1 -1
- package/examples/form_data_schema/tags/k6-script.sample.ts +11 -3
- package/examples/form_url_encoded_data_schema/schema.json +6 -3
- package/examples/form_url_encoded_data_schema/single/formURLEncodedAPI.ts +1 -1
- package/examples/form_url_encoded_data_schema/single/k6-script.sample.ts +11 -2
- package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.schemas.ts +1 -1
- package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.ts +1 -1
- package/examples/form_url_encoded_data_schema/split/k6-script.sample.ts +11 -2
- package/examples/form_url_encoded_data_schema/tags/default.ts +1 -1
- package/examples/form_url_encoded_data_schema/tags/formURLEncodedAPI.schemas.ts +1 -1
- package/examples/form_url_encoded_data_schema/tags/k6-script.sample.ts +12 -3
- package/examples/form_url_encoded_data_with_query_params_schema/schema.json +8 -4
- package/examples/form_url_encoded_data_with_query_params_schema/single/formURLEncodedAPIWithQueryParameters.ts +1 -1
- package/examples/form_url_encoded_data_with_query_params_schema/single/k6-script.sample.ts +19 -6
- package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.schemas.ts +1 -1
- package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.ts +1 -1
- package/examples/form_url_encoded_data_with_query_params_schema/split/k6-script.sample.ts +19 -6
- package/examples/form_url_encoded_data_with_query_params_schema/tags/default.ts +1 -1
- package/examples/form_url_encoded_data_with_query_params_schema/tags/formURLEncodedAPIWithQueryParameters.schemas.ts +1 -1
- package/examples/form_url_encoded_data_with_query_params_schema/tags/k6-script.sample.ts +14 -3
- package/examples/get_request_with_path_parameters_schema/schema.json +2 -1
- package/examples/get_request_with_path_parameters_schema/single/k6-script.sample.ts +6 -2
- package/examples/get_request_with_path_parameters_schema/single/simpleAPI.ts +1 -1
- package/examples/get_request_with_path_parameters_schema/split/k6-script.sample.ts +6 -2
- package/examples/get_request_with_path_parameters_schema/split/simpleAPI.schemas.ts +1 -1
- package/examples/get_request_with_path_parameters_schema/split/simpleAPI.ts +1 -1
- package/examples/get_request_with_path_parameters_schema/tags/default.ts +1 -1
- package/examples/get_request_with_path_parameters_schema/tags/k6-script.sample.ts +7 -3
- package/examples/get_request_with_path_parameters_schema/tags/simpleAPI.schemas.ts +1 -1
- package/examples/headers_schema/schema.json +2 -1
- package/examples/headers_schema/single/headerDemoAPI.ts +1 -1
- package/examples/headers_schema/single/k6-script.sample.ts +15 -4
- package/examples/headers_schema/split/headerDemoAPI.schemas.ts +1 -1
- package/examples/headers_schema/split/headerDemoAPI.ts +1 -1
- package/examples/headers_schema/split/k6-script.sample.ts +15 -4
- package/examples/headers_schema/tags/default.ts +1 -1
- package/examples/headers_schema/tags/headerDemoAPI.schemas.ts +1 -1
- package/examples/headers_schema/tags/k6-script.sample.ts +16 -5
- package/examples/no_title_schema/single/k6-script.sample.ts +3 -2
- package/examples/no_title_schema/single/k6Client.ts +1 -1
- package/examples/no_title_schema/split/k6-script.sample.ts +3 -2
- package/examples/no_title_schema/split/k6Client.schemas.ts +1 -1
- package/examples/no_title_schema/split/k6Client.ts +1 -1
- package/examples/no_title_schema/tags/default.ts +1 -1
- package/examples/no_title_schema/tags/k6-script.sample.ts +4 -3
- package/examples/no_title_schema/tags/k6Client.schemas.ts +1 -1
- package/examples/post_request_with_query_params/schema.json +14 -7
- package/examples/post_request_with_query_params/single/exampleAPI.ts +1 -1
- package/examples/post_request_with_query_params/single/k6-script.sample.ts +11 -2
- package/examples/post_request_with_query_params/split/exampleAPI.schemas.ts +1 -1
- package/examples/post_request_with_query_params/split/exampleAPI.ts +1 -1
- package/examples/post_request_with_query_params/split/k6-script.sample.ts +11 -2
- package/examples/post_request_with_query_params/tags/default.ts +1 -1
- package/examples/post_request_with_query_params/tags/exampleAPI.schemas.ts +1 -1
- package/examples/post_request_with_query_params/tags/k6-script.sample.ts +12 -3
- package/examples/query_params_schema/schema.json +20 -10
- package/examples/query_params_schema/single/exampleAPI.ts +1 -1
- package/examples/query_params_schema/single/k6-script.sample.ts +8 -2
- package/examples/query_params_schema/split/exampleAPI.schemas.ts +1 -1
- package/examples/query_params_schema/split/exampleAPI.ts +1 -1
- package/examples/query_params_schema/split/k6-script.sample.ts +8 -2
- package/examples/query_params_schema/tags/default.ts +1 -1
- package/examples/query_params_schema/tags/exampleAPI.schemas.ts +1 -1
- package/examples/query_params_schema/tags/k6-script.sample.ts +9 -3
- package/examples/simple_post_request_schema/schema.json +30 -15
- package/examples/simple_post_request_schema/single/exampleAPI.ts +1 -1
- package/examples/simple_post_request_schema/single/k6-script.sample.ts +16 -2
- package/examples/simple_post_request_schema/split/exampleAPI.schemas.ts +1 -1
- package/examples/simple_post_request_schema/split/exampleAPI.ts +1 -1
- package/examples/simple_post_request_schema/split/k6-script.sample.ts +16 -2
- package/examples/simple_post_request_schema/tags/default.ts +1 -1
- package/examples/simple_post_request_schema/tags/exampleAPI.schemas.ts +1 -1
- package/examples/simple_post_request_schema/tags/k6-script.sample.ts +17 -3
- package/package.json +3 -1
- package/src/cli.ts +32 -14
- package/src/constants.ts +7 -3
- package/src/errors.ts +6 -0
- package/src/generator/index.ts +67 -2
- package/src/generator/k6Client.ts +3 -72
- package/src/generator/k6ScriptBuilder.ts +328 -0
- package/src/helper.ts +40 -0
- package/src/type.d.ts +1 -0
- package/tests/e2e/schema.json +136 -18
- package/tests/e2e/single-tag-filter/k6Script.ts +50 -0
- package/tests/e2e/tags/k6Script.ts +3 -3
- package/tests/functional-tests/helper.ts +16 -0
- package/tests/functional-tests/{generator.test.ts → test-generator/generator.test.ts} +12 -21
- package/tests/functional-tests/test-sample-k6-scripts/fixtures/schema_using_ref_models.json +394 -0
- package/tests/functional-tests/test-sample-k6-scripts/fixtures/schema_with_examples.json +416 -0
- package/tests/functional-tests/test-sample-k6-scripts/fixtures/schema_with_no_variables.json +32 -0
- package/tests/functional-tests/test-sample-k6-scripts/sampleK6Scripts.test.ts +248 -0
- package/tests/functional-tests/test-tags-filtering/fixtures/tags_filtering.json +141 -0
- package/tests/functional-tests/test-tags-filtering/tagsFiltering.test.ts +166 -0
- package/tests/helper.test.ts +59 -0
- /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/basic_schema.json +0 -0
- /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/form_data_schema.json +0 -0
- /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/form_url_encoded_data_schema.json +0 -0
- /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/form_url_encoded_data_with_query_params_schema.json +0 -0
- /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/get_request_with_path_parameters_schema.json +0 -0
- /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/headers_schema.json +0 -0
- /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/no_title_schema.json +0 -0
- /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/post_request_with_query_params.json +0 -0
- /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/query_params_schema.json +0 -0
- /package/tests/functional-tests/{fixtures/schemas → test-generator/fixtures}/simple_post_request_schema.json +0 -0
|
@@ -0,0 +1,416 @@
|
|
|
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
|
+
"paths": {
|
|
9
|
+
"/items/{id}": {
|
|
10
|
+
"get": {
|
|
11
|
+
"tags": ["Items"],
|
|
12
|
+
"summary": "Get an item by ID",
|
|
13
|
+
"parameters": [
|
|
14
|
+
{
|
|
15
|
+
"name": "id",
|
|
16
|
+
"in": "path",
|
|
17
|
+
"required": true,
|
|
18
|
+
"description": "ID of the item to retrieve",
|
|
19
|
+
"schema": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"example": "12345-getItemById"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"name": "detail",
|
|
26
|
+
"in": "query",
|
|
27
|
+
"required": false,
|
|
28
|
+
"description": "Whether to return detailed information",
|
|
29
|
+
"schema": {
|
|
30
|
+
"type": "boolean",
|
|
31
|
+
"default": false,
|
|
32
|
+
"example": true
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"responses": {
|
|
37
|
+
"200": {
|
|
38
|
+
"description": "Successful response"
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"post": {
|
|
43
|
+
"tags": ["Items"],
|
|
44
|
+
"summary": "Create an item by ID",
|
|
45
|
+
"parameters": [
|
|
46
|
+
{
|
|
47
|
+
"name": "id",
|
|
48
|
+
"in": "path",
|
|
49
|
+
"required": true,
|
|
50
|
+
"description": "ID of the item to create",
|
|
51
|
+
"schema": {
|
|
52
|
+
"type": "string",
|
|
53
|
+
"example": "123450-createItemById"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
"requestBody": {
|
|
58
|
+
"required": true,
|
|
59
|
+
"content": {
|
|
60
|
+
"application/json": {
|
|
61
|
+
"schema": {
|
|
62
|
+
"type": "object",
|
|
63
|
+
"properties": {
|
|
64
|
+
"name": {
|
|
65
|
+
"type": "string",
|
|
66
|
+
"example": "Sample Item"
|
|
67
|
+
},
|
|
68
|
+
"description": {
|
|
69
|
+
"type": "string",
|
|
70
|
+
"example": "This is a sample description for the item."
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
"responses": {
|
|
78
|
+
"201": {
|
|
79
|
+
"description": "Item created successfully"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"put": {
|
|
84
|
+
"tags": ["Items"],
|
|
85
|
+
"summary": "Update an item by ID",
|
|
86
|
+
"parameters": [
|
|
87
|
+
{
|
|
88
|
+
"name": "id",
|
|
89
|
+
"in": "path",
|
|
90
|
+
"required": true,
|
|
91
|
+
"description": "ID of the item to update",
|
|
92
|
+
"schema": {
|
|
93
|
+
"type": "string",
|
|
94
|
+
"example": "123450-updateItemById"
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
"requestBody": {
|
|
99
|
+
"required": true,
|
|
100
|
+
"content": {
|
|
101
|
+
"application/json": {
|
|
102
|
+
"schema": {
|
|
103
|
+
"type": "object",
|
|
104
|
+
"properties": {
|
|
105
|
+
"name": {
|
|
106
|
+
"type": "string",
|
|
107
|
+
"example": "Updated Item Name"
|
|
108
|
+
},
|
|
109
|
+
"description": {
|
|
110
|
+
"type": "string",
|
|
111
|
+
"example": "Updated description for the item."
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
"responses": {
|
|
119
|
+
"200": {
|
|
120
|
+
"description": "Item updated successfully"
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
"patch": {
|
|
125
|
+
"tags": ["Items"],
|
|
126
|
+
"summary": "Partially update an item by ID",
|
|
127
|
+
"parameters": [
|
|
128
|
+
{
|
|
129
|
+
"name": "id",
|
|
130
|
+
"in": "path",
|
|
131
|
+
"required": true,
|
|
132
|
+
"description": "ID of the item to partially update",
|
|
133
|
+
"schema": {
|
|
134
|
+
"type": "string",
|
|
135
|
+
"example": "123450-patchItemById"
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
],
|
|
139
|
+
"requestBody": {
|
|
140
|
+
"required": true,
|
|
141
|
+
"content": {
|
|
142
|
+
"application/json": {
|
|
143
|
+
"schema": {
|
|
144
|
+
"type": "object",
|
|
145
|
+
"properties": {
|
|
146
|
+
"name": {
|
|
147
|
+
"type": "string",
|
|
148
|
+
"example": "Partially Updated Item Name"
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
"responses": {
|
|
156
|
+
"200": {
|
|
157
|
+
"description": "Item partially updated"
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
"delete": {
|
|
162
|
+
"tags": ["Items"],
|
|
163
|
+
"summary": "Delete an item by ID",
|
|
164
|
+
"parameters": [
|
|
165
|
+
{
|
|
166
|
+
"name": "id",
|
|
167
|
+
"in": "path",
|
|
168
|
+
"required": true,
|
|
169
|
+
"description": "ID of the item to delete",
|
|
170
|
+
"schema": {
|
|
171
|
+
"type": "string",
|
|
172
|
+
"example": "123450-deleteItemById"
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
],
|
|
176
|
+
"responses": {
|
|
177
|
+
"204": {
|
|
178
|
+
"description": "Item deleted successfully"
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
"head": {
|
|
183
|
+
"tags": ["Items"],
|
|
184
|
+
"summary": "Check if item exists",
|
|
185
|
+
"parameters": [
|
|
186
|
+
{
|
|
187
|
+
"name": "id",
|
|
188
|
+
"in": "path",
|
|
189
|
+
"required": true,
|
|
190
|
+
"description": "ID of the item to check",
|
|
191
|
+
"schema": {
|
|
192
|
+
"type": "string",
|
|
193
|
+
"example": "123450-checkItemById"
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
],
|
|
197
|
+
"responses": {
|
|
198
|
+
"200": {
|
|
199
|
+
"description": "Item exists"
|
|
200
|
+
},
|
|
201
|
+
"404": {
|
|
202
|
+
"description": "Item not found"
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
"/items-form-url-encoded": {
|
|
208
|
+
"post": {
|
|
209
|
+
"tags": ["ItemsForm", "Items"],
|
|
210
|
+
"summary": "Create an item using form-urlencoded data",
|
|
211
|
+
"requestBody": {
|
|
212
|
+
"required": true,
|
|
213
|
+
"content": {
|
|
214
|
+
"application/x-www-form-urlencoded": {
|
|
215
|
+
"schema": {
|
|
216
|
+
"type": "object",
|
|
217
|
+
"properties": {
|
|
218
|
+
"name": {
|
|
219
|
+
"type": "string",
|
|
220
|
+
"example": "Form Encoded Item"
|
|
221
|
+
},
|
|
222
|
+
"description": {
|
|
223
|
+
"type": "string",
|
|
224
|
+
"example": "Description for form-urlencoded item."
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
"required": ["name"]
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
},
|
|
232
|
+
"responses": {
|
|
233
|
+
"201": {
|
|
234
|
+
"description": "Item created successfully"
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
},
|
|
239
|
+
"/items-form-data": {
|
|
240
|
+
"post": {
|
|
241
|
+
"tags": ["ItemsForm", "Items"],
|
|
242
|
+
"summary": "Create an item using form-data",
|
|
243
|
+
"requestBody": {
|
|
244
|
+
"required": true,
|
|
245
|
+
"content": {
|
|
246
|
+
"multipart/form-data": {
|
|
247
|
+
"schema": {
|
|
248
|
+
"type": "object",
|
|
249
|
+
"properties": {
|
|
250
|
+
"name": {
|
|
251
|
+
"type": "string",
|
|
252
|
+
"example": "Form Data Item"
|
|
253
|
+
}
|
|
254
|
+
},
|
|
255
|
+
"required": ["file", "name"]
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
"responses": {
|
|
261
|
+
"201": {
|
|
262
|
+
"description": "Item created with file upload"
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
"/items-header": {
|
|
268
|
+
"get": {
|
|
269
|
+
"tags": ["ItemsHeader"],
|
|
270
|
+
"summary": "Get an item with custom headers",
|
|
271
|
+
"parameters": [
|
|
272
|
+
{
|
|
273
|
+
"name": "id",
|
|
274
|
+
"in": "query",
|
|
275
|
+
"required": true,
|
|
276
|
+
"description": "ID of the item to retrieve",
|
|
277
|
+
"schema": {
|
|
278
|
+
"type": "string",
|
|
279
|
+
"example": "123450-getItemByIdWithHeader"
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
],
|
|
283
|
+
"responses": {
|
|
284
|
+
"200": {
|
|
285
|
+
"description": "Item retrieved successfully"
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
"requestBody": {
|
|
289
|
+
"required": false
|
|
290
|
+
},
|
|
291
|
+
"headers": [
|
|
292
|
+
{
|
|
293
|
+
"name": "X-Client-ID",
|
|
294
|
+
"in": "header",
|
|
295
|
+
"description": "Client ID for the request",
|
|
296
|
+
"required": true,
|
|
297
|
+
"schema": {
|
|
298
|
+
"type": "string",
|
|
299
|
+
"example": "client-123"
|
|
300
|
+
}
|
|
301
|
+
},
|
|
302
|
+
{
|
|
303
|
+
"name": "X-Request-ID",
|
|
304
|
+
"in": "header",
|
|
305
|
+
"description": "Unique request identifier",
|
|
306
|
+
"required": false,
|
|
307
|
+
"schema": {
|
|
308
|
+
"type": "string",
|
|
309
|
+
"example": "req-56789"
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
]
|
|
313
|
+
}
|
|
314
|
+
},
|
|
315
|
+
"/users/{userId}/posts/{postId}": {
|
|
316
|
+
"get": {
|
|
317
|
+
"operationId": "getUserPost",
|
|
318
|
+
"tags": ["UsersPosts"],
|
|
319
|
+
"parameters": [
|
|
320
|
+
{
|
|
321
|
+
"name": "userId",
|
|
322
|
+
"in": "path",
|
|
323
|
+
"required": true,
|
|
324
|
+
"schema": {
|
|
325
|
+
"type": "string"
|
|
326
|
+
}
|
|
327
|
+
},
|
|
328
|
+
{
|
|
329
|
+
"name": "postId",
|
|
330
|
+
"in": "path",
|
|
331
|
+
"required": true,
|
|
332
|
+
"schema": {
|
|
333
|
+
"type": "string"
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
],
|
|
337
|
+
"responses": {
|
|
338
|
+
"200": {
|
|
339
|
+
"description": "Success",
|
|
340
|
+
"content": {
|
|
341
|
+
"application/json": {
|
|
342
|
+
"schema": {
|
|
343
|
+
"type": "object",
|
|
344
|
+
"properties": {
|
|
345
|
+
"title": {
|
|
346
|
+
"type": "string"
|
|
347
|
+
},
|
|
348
|
+
"content": {
|
|
349
|
+
"type": "string"
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
},
|
|
359
|
+
"/items-new-mandatory-headers": {
|
|
360
|
+
"get": {
|
|
361
|
+
"tags": ["ItemsHeader"],
|
|
362
|
+
"summary": "Retrieve a new item with mandatory headers",
|
|
363
|
+
"parameters": [
|
|
364
|
+
{
|
|
365
|
+
"name": "itemId",
|
|
366
|
+
"in": "query",
|
|
367
|
+
"required": true,
|
|
368
|
+
"description": "ID of the item to retrieve",
|
|
369
|
+
"schema": {
|
|
370
|
+
"type": "string",
|
|
371
|
+
"example": "67890"
|
|
372
|
+
}
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
"name": "X-Auth-Token",
|
|
376
|
+
"in": "header",
|
|
377
|
+
"description": "Authentication token",
|
|
378
|
+
"required": true,
|
|
379
|
+
"schema": {
|
|
380
|
+
"type": "string",
|
|
381
|
+
"example": "Bearer abcdef12345"
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
{
|
|
385
|
+
"name": "X-Correlation-ID",
|
|
386
|
+
"in": "header",
|
|
387
|
+
"description": "Correlation ID for tracking requests",
|
|
388
|
+
"required": true,
|
|
389
|
+
"schema": {
|
|
390
|
+
"type": "string",
|
|
391
|
+
"example": "correlation-12345"
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
"name": "X-Optional-Header",
|
|
396
|
+
"in": "header",
|
|
397
|
+
"description": "Optional header",
|
|
398
|
+
"required": false,
|
|
399
|
+
"schema": {
|
|
400
|
+
"type": "string",
|
|
401
|
+
"example": "optional-header-value"
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
],
|
|
405
|
+
"responses": {
|
|
406
|
+
"200": {
|
|
407
|
+
"description": "New item retrieved successfully"
|
|
408
|
+
},
|
|
409
|
+
"400": {
|
|
410
|
+
"description": "Invalid request"
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"openapi": "3.0.0",
|
|
3
|
+
"info": {
|
|
4
|
+
"title": "Simple API",
|
|
5
|
+
"version": "1.0.0"
|
|
6
|
+
},
|
|
7
|
+
"paths": {
|
|
8
|
+
"/example": {
|
|
9
|
+
"get": {
|
|
10
|
+
"summary": "Retrieve example data",
|
|
11
|
+
"responses": {
|
|
12
|
+
"200": {
|
|
13
|
+
"description": "Successful response",
|
|
14
|
+
"content": {
|
|
15
|
+
"application/json": {
|
|
16
|
+
"schema": {
|
|
17
|
+
"type": "object",
|
|
18
|
+
"properties": {
|
|
19
|
+
"message": {
|
|
20
|
+
"type": "string",
|
|
21
|
+
"example": "Hello, World!"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import fs from 'fs'
|
|
2
|
+
import os from 'os'
|
|
3
|
+
import path from 'path'
|
|
4
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
|
5
|
+
import { Mode } from '../../../src/constants'
|
|
6
|
+
import generator from '../../../src/generator'
|
|
7
|
+
import {
|
|
8
|
+
loadFixture,
|
|
9
|
+
mkdtemp,
|
|
10
|
+
readFile,
|
|
11
|
+
replaceSpacesAndNewLineToSingleSpace,
|
|
12
|
+
rmdir,
|
|
13
|
+
writeFile,
|
|
14
|
+
} from '../helper'
|
|
15
|
+
|
|
16
|
+
describe('validate sample k6 script', async () => {
|
|
17
|
+
const schemaNameToAssertionsMap = {
|
|
18
|
+
'schema_with_no_variables.json': {
|
|
19
|
+
common: {
|
|
20
|
+
expected_string: [],
|
|
21
|
+
unexpected_string: [],
|
|
22
|
+
},
|
|
23
|
+
[Mode.TAGS]: {
|
|
24
|
+
expected_number_of_files: 3,
|
|
25
|
+
expected_string: [],
|
|
26
|
+
unexpected_string: [],
|
|
27
|
+
},
|
|
28
|
+
[Mode.SINGLE]: {
|
|
29
|
+
expected_number_of_files: 2,
|
|
30
|
+
expected_string: [],
|
|
31
|
+
unexpected_string: [],
|
|
32
|
+
},
|
|
33
|
+
[Mode.SPLIT]: {
|
|
34
|
+
expected_number_of_files: 3,
|
|
35
|
+
expected_string: [],
|
|
36
|
+
unexpected_string: [],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
'schema_with_examples.json': {
|
|
40
|
+
common: {
|
|
41
|
+
expected_string: [
|
|
42
|
+
`let id, postItemsIdBody, putItemsIdBody, patchItemsIdBody, postItemsFormUrlEncodedBody, postItemsFormDataBody, params, userId, postId, headers;`,
|
|
43
|
+
`id = "12345-getItemById";`,
|
|
44
|
+
`id = "123450-createItemById";`,
|
|
45
|
+
`id = "123450-updateItemById";`,
|
|
46
|
+
`id = "123450-patchItemById";`,
|
|
47
|
+
`id = "123450-deleteItemById";`,
|
|
48
|
+
`id = "123450-checkItemById";`,
|
|
49
|
+
`userId = "`, // This is generated as random word using faker hence to validating the value
|
|
50
|
+
`postId = "`, // This is generated as random word using faker hence to validating the value
|
|
51
|
+
`postItemsIdBody = { name: "Sample Item", description: "This is a sample description for the item.", };`,
|
|
52
|
+
`putItemsIdBody = { name: "Updated Item Name", description: "Updated description for the item.", };`,
|
|
53
|
+
`patchItemsIdBody = { name: "Partially Updated Item Name", };`,
|
|
54
|
+
`postItemsFormUrlEncodedBody = { name: "Form Encoded Item", description: "Description for form-urlencoded item.", };`,
|
|
55
|
+
`postItemsFormDataBody = { name: "Form Data Item", };`,
|
|
56
|
+
`params = { id: "123450-getItemByIdWithHeader", };`,
|
|
57
|
+
`params = { itemId: "67890", };`,
|
|
58
|
+
`headers = { "X-Auth-Token": "Bearer abcdef12345", "X-Correlation-ID": "correlation-12345", };`,
|
|
59
|
+
],
|
|
60
|
+
unexpected_string: [],
|
|
61
|
+
},
|
|
62
|
+
[Mode.TAGS]: {
|
|
63
|
+
expected_number_of_files: 6,
|
|
64
|
+
expected_string: [
|
|
65
|
+
`import { ItemsClient } from "./items.ts";`,
|
|
66
|
+
`import { ItemsFormClient } from "./items-form.ts";`,
|
|
67
|
+
`import { ItemsHeaderClient } from "./items-header.ts";`,
|
|
68
|
+
`import { UsersPostsClient } from "./users-posts.ts";`,
|
|
69
|
+
`const itemsClient = new ItemsClient({ baseUrl });`,
|
|
70
|
+
`const itemsFormClient = new ItemsFormClient({ baseUrl });`,
|
|
71
|
+
`const itemsHeaderClient = new ItemsHeaderClient({ baseUrl });`,
|
|
72
|
+
`const usersPostsClient = new UsersPostsClient({ baseUrl });`,
|
|
73
|
+
],
|
|
74
|
+
unexpected_string: [
|
|
75
|
+
`import { DefaultClient } from "./default.ts";`,
|
|
76
|
+
`const defaultClient = new DefaultClient({ baseUrl });`,
|
|
77
|
+
],
|
|
78
|
+
},
|
|
79
|
+
[Mode.SINGLE]: {
|
|
80
|
+
expected_number_of_files: 2,
|
|
81
|
+
expected_string: [
|
|
82
|
+
`const comprehensiveAPIClient = new ComprehensiveAPIClient({ baseUrl });`,
|
|
83
|
+
],
|
|
84
|
+
unexpected_string: [
|
|
85
|
+
`import { ItemsClient } from "./items.ts";`,
|
|
86
|
+
`import { ItemsFormClient } from "./items-form.ts";`,
|
|
87
|
+
`import { ItemsHeaderClient } from "./items-header.ts";`,
|
|
88
|
+
`import { UsersPostsClient } from "./users-posts.ts";`,
|
|
89
|
+
`const itemsClient = new ItemsClient({ baseUrl });`,
|
|
90
|
+
`const itemsFormClient = new ItemsFormClient({ baseUrl });`,
|
|
91
|
+
`const itemsHeaderClient = new ItemsHeaderClient({ baseUrl });`,
|
|
92
|
+
`const usersPostsClient = new UsersPostsClient({ baseUrl });`,
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
[Mode.SPLIT]: {
|
|
96
|
+
expected_number_of_files: 3,
|
|
97
|
+
expected_string: [
|
|
98
|
+
`const comprehensiveAPIClient = new ComprehensiveAPIClient({ baseUrl });`,
|
|
99
|
+
],
|
|
100
|
+
unexpected_string: [
|
|
101
|
+
`import { ItemsClient } from "./items.ts";`,
|
|
102
|
+
`import { ItemsFormClient } from "./items-form.ts";`,
|
|
103
|
+
`import { ItemsHeaderClient } from "./items-header.ts";`,
|
|
104
|
+
`import { UsersPostsClient } from "./users-posts.ts";`,
|
|
105
|
+
`const itemsClient = new ItemsClient({ baseUrl });`,
|
|
106
|
+
`const itemsFormClient = new ItemsFormClient({ baseUrl });`,
|
|
107
|
+
`const itemsHeaderClient = new ItemsHeaderClient({ baseUrl });`,
|
|
108
|
+
`const usersPostsClient = new UsersPostsClient({ baseUrl });`,
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
'schema_using_ref_models.json': {
|
|
113
|
+
expected_number_of_files: 3,
|
|
114
|
+
common: {
|
|
115
|
+
expected_string: [
|
|
116
|
+
`let id, itemBase, updatedItem, patchItem, formUrlEncodedItem, formDataItem, params, headers, userId, postId;`,
|
|
117
|
+
`id = "12345-getItemById";`,
|
|
118
|
+
`userId = "`, // This is generated as random word using faker hence to validating the value
|
|
119
|
+
`postId = "`, // This is generated as random word using faker hence to validating the value
|
|
120
|
+
`itemBase = { name: "Sample Item", description: "This is a sample description for the item.", };`,
|
|
121
|
+
`updatedItem = { name: "Updated Item Name", description: "Updated description for the item.", };`,
|
|
122
|
+
`patchItem = { name: "Partially Updated Item Name", };`,
|
|
123
|
+
`formUrlEncodedItem = { name: "Form Encoded Item", description: "Description for form-urlencoded item.", };`,
|
|
124
|
+
`formDataItem = { name: "Form Data Item", };`,
|
|
125
|
+
`params = { id: "123450-getItemByIdWithHeader", };`,
|
|
126
|
+
`headers = { "X-Client-ID": "client-123", };`,
|
|
127
|
+
`params = { itemId: "67890", };`,
|
|
128
|
+
`headers = { "X-Auth-Token": "Bearer abcdef12345", "X-Correlation-ID": "correlation-12345", };`,
|
|
129
|
+
],
|
|
130
|
+
unexpected_string: [],
|
|
131
|
+
},
|
|
132
|
+
[Mode.TAGS]: {
|
|
133
|
+
expected_number_of_files: 6,
|
|
134
|
+
expected_string: [
|
|
135
|
+
`import { ItemsClient } from "./items.ts";`,
|
|
136
|
+
`import { ItemsFormClient } from "./items-form.ts";`,
|
|
137
|
+
`import { ItemsHeaderClient } from "./items-header.ts";`,
|
|
138
|
+
`import { DefaultClient } from "./default.ts";`,
|
|
139
|
+
`const itemsClient = new ItemsClient({ baseUrl });`,
|
|
140
|
+
`const itemsFormClient = new ItemsFormClient({ baseUrl });`,
|
|
141
|
+
`const itemsHeaderClient = new ItemsHeaderClient({ baseUrl });`,
|
|
142
|
+
`const defaultClient = new DefaultClient({ baseUrl });`,
|
|
143
|
+
],
|
|
144
|
+
unexpected_string: [
|
|
145
|
+
`import { UsersPostsClient } from "./users-posts.ts";`,
|
|
146
|
+
`const usersPostsClient = new UsersPostsClient({ baseUrl });`,
|
|
147
|
+
],
|
|
148
|
+
},
|
|
149
|
+
[Mode.SINGLE]: {
|
|
150
|
+
expected_number_of_files: 2,
|
|
151
|
+
expected_string: [],
|
|
152
|
+
unexpected_string: [
|
|
153
|
+
`import { ItemsClient } from "./items.ts";`,
|
|
154
|
+
`import { ItemsFormClient } from "./items-form.ts";`,
|
|
155
|
+
`import { ItemsHeaderClient } from "./items-header.ts";`,
|
|
156
|
+
`import { DefaultClient } from "./default.ts";`,
|
|
157
|
+
`const itemsClient = new ItemsClient({ baseUrl });`,
|
|
158
|
+
`const itemsFormClient = new ItemsFormClient({ baseUrl });`,
|
|
159
|
+
`const itemsHeaderClient = new ItemsHeaderClient({ baseUrl });`,
|
|
160
|
+
`const defaultClient = new DefaultClient({ baseUrl });`,
|
|
161
|
+
],
|
|
162
|
+
},
|
|
163
|
+
[Mode.SPLIT]: {
|
|
164
|
+
expected_number_of_files: 3,
|
|
165
|
+
expected_string: [],
|
|
166
|
+
unexpected_string: [],
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
for (const [schemaName, assertions] of Object.entries(
|
|
172
|
+
schemaNameToAssertionsMap
|
|
173
|
+
)) {
|
|
174
|
+
describe(`test ${schemaName} schema`, () => {
|
|
175
|
+
let tempDir: string, openapiSchemaPath: string
|
|
176
|
+
|
|
177
|
+
beforeAll(async () => {
|
|
178
|
+
tempDir = await mkdtemp(
|
|
179
|
+
path.join(os.tmpdir(), `example-k6-script-test-${schemaName}`)
|
|
180
|
+
)
|
|
181
|
+
openapiSchemaPath = path.join(tempDir, 'openapi-schema.json')
|
|
182
|
+
await writeFile(
|
|
183
|
+
openapiSchemaPath,
|
|
184
|
+
JSON.stringify(
|
|
185
|
+
loadFixture(path.join(__dirname, 'fixtures', schemaName))
|
|
186
|
+
)
|
|
187
|
+
)
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
afterAll(async () => {
|
|
191
|
+
await rmdir(tempDir, { recursive: true })
|
|
192
|
+
})
|
|
193
|
+
|
|
194
|
+
for (const mode of Object.values(Mode)) {
|
|
195
|
+
it(`should generate sample k6 script with correct example values in ${mode} mode for ${schemaName}`, async () => {
|
|
196
|
+
const generatedClientPath = path.join(
|
|
197
|
+
tempDir,
|
|
198
|
+
mode,
|
|
199
|
+
`generated-client`
|
|
200
|
+
)
|
|
201
|
+
|
|
202
|
+
await generator({
|
|
203
|
+
openApiPath: openapiSchemaPath,
|
|
204
|
+
outputDir: generatedClientPath,
|
|
205
|
+
mode,
|
|
206
|
+
shouldGenerateSampleK6Script: true,
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
const generatedFiles = fs.readdirSync(generatedClientPath)
|
|
210
|
+
expect(generatedFiles.length).toBe(
|
|
211
|
+
assertions[mode].expected_number_of_files
|
|
212
|
+
)
|
|
213
|
+
|
|
214
|
+
// Get the k6 script file
|
|
215
|
+
const k6ScriptFile = generatedFiles.find((file) =>
|
|
216
|
+
file.includes('k6-script.sample.ts')
|
|
217
|
+
)
|
|
218
|
+
expect(k6ScriptFile).toBeDefined()
|
|
219
|
+
|
|
220
|
+
const k6ScriptFilePath = path.join(generatedClientPath, k6ScriptFile!)
|
|
221
|
+
const k6ScriptContent = await readFile(k6ScriptFilePath, 'utf-8')
|
|
222
|
+
|
|
223
|
+
const allExpectedStrings = [
|
|
224
|
+
...assertions.common.expected_string,
|
|
225
|
+
...assertions[mode].expected_string,
|
|
226
|
+
]
|
|
227
|
+
|
|
228
|
+
for (const expectedString of allExpectedStrings) {
|
|
229
|
+
expect(
|
|
230
|
+
replaceSpacesAndNewLineToSingleSpace(k6ScriptContent)
|
|
231
|
+
).toContain(expectedString)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const allUnexpectedStrings = [
|
|
235
|
+
...assertions.common.unexpected_string,
|
|
236
|
+
...assertions[mode].unexpected_string,
|
|
237
|
+
]
|
|
238
|
+
|
|
239
|
+
for (const unexpectedString of allUnexpectedStrings) {
|
|
240
|
+
expect(
|
|
241
|
+
replaceSpacesAndNewLineToSingleSpace(k6ScriptContent)
|
|
242
|
+
).not.toContain(unexpectedString)
|
|
243
|
+
}
|
|
244
|
+
})
|
|
245
|
+
}
|
|
246
|
+
})
|
|
247
|
+
}
|
|
248
|
+
})
|