@grafana/openapi-to-k6 0.3.0 → 0.3.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.
- package/dist/generator/index.js +13 -6
- package/dist/generator/k6Client.js +3 -1
- package/dist/helper.js +16 -0
- package/examples/basic_schema/schema.json +2 -1
- package/examples/basic_schema/single/simpleAPI.ts +4 -1
- package/examples/basic_schema/split/simpleAPI.schemas.ts +2 -1
- package/examples/basic_schema/split/simpleAPI.ts +3 -1
- package/examples/basic_schema/tags/default.ts +3 -1
- package/examples/basic_schema/tags/simpleAPI.schemas.ts +2 -1
- package/examples/form_data_schema/single/formDataAPI.ts +8 -6
- package/examples/form_data_schema/split/formDataAPI.schemas.ts +5 -5
- package/examples/form_data_schema/split/formDataAPI.ts +4 -2
- package/examples/form_data_schema/tags/default.ts +4 -2
- package/examples/form_data_schema/tags/formDataAPI.schemas.ts +5 -5
- package/examples/form_url_encoded_data_schema/single/formURLEncodedAPI.ts +8 -6
- package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.schemas.ts +5 -5
- package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.ts +4 -2
- package/examples/form_url_encoded_data_schema/tags/default.ts +4 -2
- package/examples/form_url_encoded_data_schema/tags/formURLEncodedAPI.schemas.ts +5 -5
- package/examples/form_url_encoded_data_with_query_params_schema/single/formURLEncodedAPIWithQueryParameters.ts +8 -6
- package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.schemas.ts +5 -5
- package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.ts +4 -2
- package/examples/form_url_encoded_data_with_query_params_schema/tags/default.ts +4 -2
- package/examples/form_url_encoded_data_with_query_params_schema/tags/formURLEncodedAPIWithQueryParameters.schemas.ts +5 -5
- package/examples/get_request_with_path_parameters_schema/single/simpleAPI.ts +4 -2
- package/examples/get_request_with_path_parameters_schema/split/simpleAPI.schemas.ts +2 -2
- package/examples/get_request_with_path_parameters_schema/split/simpleAPI.ts +3 -1
- package/examples/get_request_with_path_parameters_schema/tags/default.ts +3 -1
- package/examples/get_request_with_path_parameters_schema/tags/simpleAPI.schemas.ts +2 -2
- package/examples/headers_schema/single/headerDemoAPI.ts +5 -3
- package/examples/headers_schema/split/headerDemoAPI.schemas.ts +1 -1
- package/examples/headers_schema/split/headerDemoAPI.ts +5 -3
- package/examples/headers_schema/tags/default.ts +5 -3
- package/examples/headers_schema/tags/headerDemoAPI.schemas.ts +1 -1
- package/examples/no_title_schema/single/k6Client.ts +3 -1
- package/examples/no_title_schema/split/k6Client.schemas.ts +1 -1
- package/examples/no_title_schema/split/k6Client.ts +3 -1
- package/examples/no_title_schema/tags/default.ts +3 -1
- package/examples/no_title_schema/tags/k6Client.schemas.ts +1 -1
- package/examples/post_request_with_query_params/single/exampleAPI.ts +8 -6
- package/examples/post_request_with_query_params/split/exampleAPI.schemas.ts +5 -5
- package/examples/post_request_with_query_params/split/exampleAPI.ts +4 -2
- package/examples/post_request_with_query_params/tags/default.ts +4 -2
- package/examples/post_request_with_query_params/tags/exampleAPI.schemas.ts +5 -5
- package/examples/query_params_schema/single/exampleAPI.ts +5 -3
- package/examples/query_params_schema/split/exampleAPI.schemas.ts +3 -3
- package/examples/query_params_schema/split/exampleAPI.ts +3 -1
- package/examples/query_params_schema/tags/default.ts +3 -1
- package/examples/query_params_schema/tags/exampleAPI.schemas.ts +3 -3
- package/examples/simple_post_request_schema/single/exampleAPI.ts +14 -12
- package/examples/simple_post_request_schema/split/exampleAPI.schemas.ts +11 -11
- package/examples/simple_post_request_schema/split/exampleAPI.ts +4 -2
- package/examples/simple_post_request_schema/tags/default.ts +4 -2
- package/examples/simple_post_request_schema/tags/exampleAPI.schemas.ts +11 -11
- package/package.json +3 -2
- package/src/generator/index.ts +20 -7
- package/src/generator/k6Client.ts +3 -1
- package/src/helper.ts +17 -0
- package/tests/e2e/single/k6Script.ts +54 -1
- package/tests/functional-tests/test-generator/fixtures/basic_parameter_in_ref.json +59 -0
- package/tests/functional-tests/test-generator/fixtures/form_data_schema.json +1 -1
- package/tests/functional-tests/test-generator/fixtures/form_url_encoded_data_schema.json +1 -1
- package/tests/functional-tests/test-generator/fixtures/headers_schema.json +2 -2
- package/tests/functional-tests/test-generator/fixtures/simple_post_request_schema.json +1 -1
- package/{vite.config.js → vite.config.mjs} +4 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.1
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of data in the POST request body
|
|
@@ -11,14 +11,14 @@ export type CreateExampleData201Meta = {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export type CreateExampleData201 = {
|
|
14
|
-
age?: number
|
|
15
|
-
date?: string
|
|
16
14
|
/** The unique ID of the created resource */
|
|
17
15
|
id?: string
|
|
18
|
-
isActive?: boolean
|
|
19
|
-
meta?: CreateExampleData201Meta
|
|
20
16
|
name?: string
|
|
17
|
+
age?: number
|
|
18
|
+
isActive?: boolean
|
|
21
19
|
tags?: string[]
|
|
20
|
+
date?: string
|
|
21
|
+
meta?: CreateExampleData201Meta
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -32,16 +32,16 @@ export type CreateExampleDataBodyMeta = {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export type CreateExampleDataBody = {
|
|
35
|
+
/** A string parameter */
|
|
36
|
+
name: string
|
|
35
37
|
/** An integer parameter */
|
|
36
38
|
age: number
|
|
37
|
-
/** A date parameter in YYYY-MM-DD format */
|
|
38
|
-
date?: string
|
|
39
39
|
/** A boolean parameter */
|
|
40
40
|
isActive: boolean
|
|
41
|
-
/** An object parameter containing metadata */
|
|
42
|
-
meta?: CreateExampleDataBodyMeta
|
|
43
|
-
/** A string parameter */
|
|
44
|
-
name: string
|
|
45
41
|
/** An array of strings */
|
|
46
42
|
tags?: string[]
|
|
43
|
+
/** A date parameter in YYYY-MM-DD format */
|
|
44
|
+
date?: string
|
|
45
|
+
/** An object parameter containing metadata */
|
|
46
|
+
meta?: CreateExampleDataBodyMeta
|
|
47
47
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.1
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of data in the POST request body
|
|
@@ -25,6 +25,8 @@ export class ExampleAPIClient {
|
|
|
25
25
|
commonRequestParameters?: Params
|
|
26
26
|
}) {
|
|
27
27
|
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
28
|
+
|
|
29
|
+
this.commonRequestParameters = clientOptions.commonRequestParameters || {}
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
/**
|
|
@@ -50,8 +52,8 @@ export class ExampleAPIClient {
|
|
|
50
52
|
{
|
|
51
53
|
...mergedRequestParameters,
|
|
52
54
|
headers: {
|
|
53
|
-
'Content-Type': 'application/json',
|
|
54
55
|
...mergedRequestParameters?.headers,
|
|
56
|
+
'Content-Type': 'application/json',
|
|
55
57
|
},
|
|
56
58
|
}
|
|
57
59
|
)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.1
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of data in the POST request body
|
|
@@ -25,6 +25,8 @@ export class DefaultClient {
|
|
|
25
25
|
commonRequestParameters?: Params
|
|
26
26
|
}) {
|
|
27
27
|
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\/+$/, '')
|
|
28
|
+
|
|
29
|
+
this.commonRequestParameters = clientOptions.commonRequestParameters || {}
|
|
28
30
|
}
|
|
29
31
|
|
|
30
32
|
/**
|
|
@@ -50,8 +52,8 @@ export class DefaultClient {
|
|
|
50
52
|
{
|
|
51
53
|
...mergedRequestParameters,
|
|
52
54
|
headers: {
|
|
53
|
-
'Content-Type': 'application/json',
|
|
54
55
|
...mergedRequestParameters?.headers,
|
|
56
|
+
'Content-Type': 'application/json',
|
|
55
57
|
},
|
|
56
58
|
}
|
|
57
59
|
)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Automatically generated by @grafana/openapi-to-k6: 0.3.
|
|
2
|
+
* Automatically generated by @grafana/openapi-to-k6: 0.3.1
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
* Example API
|
|
5
5
|
* API with all formats of data in the POST request body
|
|
@@ -11,14 +11,14 @@ export type CreateExampleData201Meta = {
|
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export type CreateExampleData201 = {
|
|
14
|
-
age?: number
|
|
15
|
-
date?: string
|
|
16
14
|
/** The unique ID of the created resource */
|
|
17
15
|
id?: string
|
|
18
|
-
isActive?: boolean
|
|
19
|
-
meta?: CreateExampleData201Meta
|
|
20
16
|
name?: string
|
|
17
|
+
age?: number
|
|
18
|
+
isActive?: boolean
|
|
21
19
|
tags?: string[]
|
|
20
|
+
date?: string
|
|
21
|
+
meta?: CreateExampleData201Meta
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
@@ -32,16 +32,16 @@ export type CreateExampleDataBodyMeta = {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
export type CreateExampleDataBody = {
|
|
35
|
+
/** A string parameter */
|
|
36
|
+
name: string
|
|
35
37
|
/** An integer parameter */
|
|
36
38
|
age: number
|
|
37
|
-
/** A date parameter in YYYY-MM-DD format */
|
|
38
|
-
date?: string
|
|
39
39
|
/** A boolean parameter */
|
|
40
40
|
isActive: boolean
|
|
41
|
-
/** An object parameter containing metadata */
|
|
42
|
-
meta?: CreateExampleDataBodyMeta
|
|
43
|
-
/** A string parameter */
|
|
44
|
-
name: string
|
|
45
41
|
/** An array of strings */
|
|
46
42
|
tags?: string[]
|
|
43
|
+
/** A date parameter in YYYY-MM-DD format */
|
|
44
|
+
date?: string
|
|
45
|
+
/** An object parameter containing metadata */
|
|
46
|
+
meta?: CreateExampleDataBodyMeta
|
|
47
47
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grafana/openapi-to-k6",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.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": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"commander": "^12.1.0",
|
|
29
29
|
"handlebars": "^4.7.8",
|
|
30
30
|
"openapi-typescript": "^7.4.1",
|
|
31
|
-
"orval": "^7.
|
|
31
|
+
"orval": "^7.4.1",
|
|
32
32
|
"prettier": "^3.3.3",
|
|
33
33
|
"uuid": "^10.0.0"
|
|
34
34
|
},
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
"prettier": "^3.3.3",
|
|
48
48
|
"ts-node": "^10.9.2",
|
|
49
49
|
"typescript": "^5.6.2",
|
|
50
|
+
"vite-tsconfig-paths": "^5.1.4",
|
|
50
51
|
"vitest": "^2.1.3"
|
|
51
52
|
},
|
|
52
53
|
"lint-staged": {
|
package/src/generator/index.ts
CHANGED
|
@@ -27,7 +27,10 @@ const generatedFileHeaderGenerator = (info: InfoObject) => {
|
|
|
27
27
|
]
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
const afterAllFilesWriteHandler = async (
|
|
30
|
+
const afterAllFilesWriteHandler = async (
|
|
31
|
+
filePaths: string[],
|
|
32
|
+
outputOverrider: OutputOverrider
|
|
33
|
+
) => {
|
|
31
34
|
const removeSingleFile = (filePath: string) => {
|
|
32
35
|
try {
|
|
33
36
|
fs.unlinkSync(filePath)
|
|
@@ -53,8 +56,13 @@ const afterAllFilesWriteHandler = async (filePaths: string[]) => {
|
|
|
53
56
|
removeSingleFile(filePath)
|
|
54
57
|
continue
|
|
55
58
|
}
|
|
56
|
-
|
|
57
|
-
|
|
59
|
+
try {
|
|
60
|
+
await formatFileWithPrettier(filePath)
|
|
61
|
+
} catch (error) {
|
|
62
|
+
await outputOverrider.temporarilyWriteToStdoutAndStderr(async () => {
|
|
63
|
+
logger.error(`Error in formatting file ${filePath}: ${error}`)
|
|
64
|
+
})
|
|
65
|
+
}
|
|
58
66
|
|
|
59
67
|
const fileName = path.basename(filePath)
|
|
60
68
|
|
|
@@ -125,7 +133,10 @@ export default async ({
|
|
|
125
133
|
},
|
|
126
134
|
hooks: {
|
|
127
135
|
afterAllFilesWrite: async (filePaths: string[]) => {
|
|
128
|
-
const filteredFilePaths = await afterAllFilesWriteHandler(
|
|
136
|
+
const filteredFilePaths = await afterAllFilesWriteHandler(
|
|
137
|
+
filePaths,
|
|
138
|
+
outputOverrider
|
|
139
|
+
)
|
|
129
140
|
generatedFilePaths.push(...filteredFilePaths)
|
|
130
141
|
},
|
|
131
142
|
},
|
|
@@ -135,8 +146,10 @@ export default async ({
|
|
|
135
146
|
if (generatedFilePaths.length === 0) {
|
|
136
147
|
const tagsMessage =
|
|
137
148
|
tags?.length && tags.length > 0
|
|
138
|
-
? ` Applied tag filter(s): ${tags.join(', ')}`
|
|
139
|
-
: ''
|
|
140
|
-
throw new NoFilesGeneratedError(
|
|
149
|
+
? ` Applied tag filter(s): ${tags.join(', ')}. `
|
|
150
|
+
: ' '
|
|
151
|
+
throw new NoFilesGeneratedError(
|
|
152
|
+
`No files were generated.${tagsMessage}Try running with --verbose flag to get more details.`
|
|
153
|
+
)
|
|
141
154
|
}
|
|
142
155
|
}
|
|
@@ -102,6 +102,7 @@ const _getRequestParamsValue = ({
|
|
|
102
102
|
// Expand the headers
|
|
103
103
|
if (body.contentType || headers) {
|
|
104
104
|
let headersValue = `\n headers: {`
|
|
105
|
+
headersValue += '\n...mergedRequestParameters?.headers,'
|
|
105
106
|
if (body.contentType) {
|
|
106
107
|
if (body.formData) {
|
|
107
108
|
headersValue += `\n'Content-Type': '${body.contentType}; boundary=' + formData.boundary,`
|
|
@@ -115,7 +116,7 @@ const _getRequestParamsValue = ({
|
|
|
115
116
|
headersValue += `\n...Object.fromEntries(Object.entries(headers || {}).map(([key, value]) => [key, String(value)])),`
|
|
116
117
|
}
|
|
117
118
|
|
|
118
|
-
headersValue += `\n
|
|
119
|
+
headersValue += `\n},`
|
|
119
120
|
value += headersValue
|
|
120
121
|
}
|
|
121
122
|
|
|
@@ -270,6 +271,7 @@ const generateK6Header: ClientHeaderBuilder = ({ title }) => {
|
|
|
270
271
|
commonRequestParameters?: Params
|
|
271
272
|
}) {
|
|
272
273
|
this.cleanBaseUrl = clientOptions.baseUrl.replace(/\\/+$/, '');\n
|
|
274
|
+
this.commonRequestParameters = clientOptions.commonRequestParameters || {};
|
|
273
275
|
}\n
|
|
274
276
|
`
|
|
275
277
|
}
|
package/src/helper.ts
CHANGED
|
@@ -123,6 +123,23 @@ export class OutputOverrider {
|
|
|
123
123
|
process.stdout.write = this.originalStdoutWrite
|
|
124
124
|
process.stderr.write = this.originalStderrWrite
|
|
125
125
|
}
|
|
126
|
+
|
|
127
|
+
// Method to temporarily write to stdout and stderr
|
|
128
|
+
public async temporarilyWriteToStdoutAndStderr(
|
|
129
|
+
callback: () => Promise<void>
|
|
130
|
+
) {
|
|
131
|
+
const currentStdoutWrite = process.stdout.write
|
|
132
|
+
const currentStderrWrite = process.stderr.write
|
|
133
|
+
|
|
134
|
+
process.stdout.write = this.originalStdoutWrite
|
|
135
|
+
process.stderr.write = this.originalStderrWrite
|
|
136
|
+
try {
|
|
137
|
+
await callback()
|
|
138
|
+
} finally {
|
|
139
|
+
process.stdout.write = currentStdoutWrite
|
|
140
|
+
process.stderr.write = currentStderrWrite
|
|
141
|
+
}
|
|
142
|
+
}
|
|
126
143
|
}
|
|
127
144
|
|
|
128
145
|
/**
|
|
@@ -3,8 +3,15 @@ import { check } from 'k6'
|
|
|
3
3
|
import { ComprehensiveAPIClient } from './sdk.ts'
|
|
4
4
|
/* eslint-enable import/no-unresolved */
|
|
5
5
|
|
|
6
|
+
const commonRequestParameters = {
|
|
7
|
+
headers: {
|
|
8
|
+
'Only-Common-Header': 'test',
|
|
9
|
+
'Only-Common-Header-2': 'test-2',
|
|
10
|
+
'X-Correlation-ID': 'only-common-header-value',
|
|
11
|
+
},
|
|
12
|
+
}
|
|
6
13
|
const baseUrl = 'http://localhost:3000'
|
|
7
|
-
const client = new ComprehensiveAPIClient({ baseUrl })
|
|
14
|
+
const client = new ComprehensiveAPIClient({ baseUrl, commonRequestParameters })
|
|
8
15
|
|
|
9
16
|
export const options = {
|
|
10
17
|
thresholds: {
|
|
@@ -79,4 +86,50 @@ export default function () {
|
|
|
79
86
|
id: 'test',
|
|
80
87
|
})
|
|
81
88
|
checkResponseStatus(getItemsHeaderResponseData.response, 200)
|
|
89
|
+
|
|
90
|
+
const requestParameters = {
|
|
91
|
+
headers: {
|
|
92
|
+
'Only-Common-Header-2': 'test-common-header-2-parameter',
|
|
93
|
+
'X-Correlation-ID': 'test-request-parameter',
|
|
94
|
+
},
|
|
95
|
+
}
|
|
96
|
+
const getItemsNewMandatoryHeadersResponseData =
|
|
97
|
+
client.getItemsNewMandatoryHeaders(
|
|
98
|
+
{
|
|
99
|
+
itemId: 'test',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
'X-Auth-Token': 'test',
|
|
103
|
+
'X-Correlation-ID': 'test-function-argument',
|
|
104
|
+
},
|
|
105
|
+
requestParameters
|
|
106
|
+
)
|
|
107
|
+
checkResponseStatus(getItemsNewMandatoryHeadersResponseData.response, 200)
|
|
108
|
+
|
|
109
|
+
const requestHeaders =
|
|
110
|
+
getItemsNewMandatoryHeadersResponseData.response.request.headers
|
|
111
|
+
console.log('requestHeaders')
|
|
112
|
+
console.log(requestHeaders)
|
|
113
|
+
|
|
114
|
+
// Validate that the header present only in common request parameters is present in the request
|
|
115
|
+
check(requestHeaders, {
|
|
116
|
+
'has only-common-header': (r) => r['Only-Common-Header'][0] === 'test',
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
// Validate that the header present only in the request parameters is present in the request
|
|
120
|
+
check(requestHeaders, {
|
|
121
|
+
'has X-Auth-Token': (r) => r['X-Auth-Token'][0] === 'test',
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
// Validate that the header present in the requestParameters takes precedence over the value in common request parameters
|
|
125
|
+
check(requestHeaders, {
|
|
126
|
+
'has correct value of Only-Common-Header-2 from request parameters': (r) =>
|
|
127
|
+
r['Only-Common-Header-2'][0] === 'test-common-header-2-parameter',
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
// Validate that the value of the header present in function arguments takes precedence over the value in common request parameters and request parameters
|
|
131
|
+
check(requestHeaders, {
|
|
132
|
+
'has correct value X-Correlation-ID from function arguments': (r) =>
|
|
133
|
+
r['X-Correlation-Id'][0] === 'test-function-argument',
|
|
134
|
+
})
|
|
82
135
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"openapi_schema": {
|
|
3
|
+
"openapi": "3.0.0",
|
|
4
|
+
"info": {
|
|
5
|
+
"title": "Simple API",
|
|
6
|
+
"version": "1.0.0"
|
|
7
|
+
},
|
|
8
|
+
"paths": {
|
|
9
|
+
"/example": {
|
|
10
|
+
"get": {
|
|
11
|
+
"summary": "Retrieve example data",
|
|
12
|
+
"parameters": [
|
|
13
|
+
{
|
|
14
|
+
"$ref": "#/components/parameters/stackId"
|
|
15
|
+
}
|
|
16
|
+
],
|
|
17
|
+
"responses": {
|
|
18
|
+
"200": {
|
|
19
|
+
"description": "Successful response",
|
|
20
|
+
"content": {
|
|
21
|
+
"application/json": {
|
|
22
|
+
"schema": {
|
|
23
|
+
"type": "object",
|
|
24
|
+
"properties": {
|
|
25
|
+
"message": {
|
|
26
|
+
"type": "string",
|
|
27
|
+
"example": "Hello, World!"
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"components": {
|
|
39
|
+
"parameters": {
|
|
40
|
+
"stackId": {
|
|
41
|
+
"in": "header",
|
|
42
|
+
"name": "X-Stack-Id",
|
|
43
|
+
"schema": {
|
|
44
|
+
"type": "integer"
|
|
45
|
+
},
|
|
46
|
+
"required": true
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
"expected_sdk": {
|
|
52
|
+
"fileName": "simpleAPI.ts",
|
|
53
|
+
"expectedSubstrings": [
|
|
54
|
+
"export class SimpleAPIClient",
|
|
55
|
+
"export type StackIdParameter = number;",
|
|
56
|
+
"export type GetExampleHeaders = { \"X-Stack-Id\": StackIdParameter; };"
|
|
57
|
+
]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -88,7 +88,7 @@
|
|
|
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
90
|
"const url = new URL(this.cleanBaseUrl + `/upload`);",
|
|
91
|
-
"const response = http.request(\"POST\", url.toString(), formData.body(), { ...mergedRequestParameters, headers: { \"Content-Type\": \"multipart/form-data; boundary=\" + formData.boundary,
|
|
91
|
+
"const response = http.request(\"POST\", url.toString(), formData.body(), { ...mergedRequestParameters, headers: { ...mergedRequestParameters?.headers, \"Content-Type\": \"multipart/form-data; boundary=\" + formData.boundary, }, });"
|
|
92
92
|
]
|
|
93
93
|
}
|
|
94
94
|
}
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"expectedSubstrings": [
|
|
88
88
|
"export class FormURLEncodedAPIClient",
|
|
89
89
|
"const url = new URL(this.cleanBaseUrl + `/submit-form`);",
|
|
90
|
-
"const response = http.request( \"POST\", url.toString(), JSON.stringify(postSubmitFormBody), { ...mergedRequestParameters, headers: { \"Content-Type\": \"application/x-www-form-urlencoded\",
|
|
90
|
+
"const response = http.request( \"POST\", url.toString(), JSON.stringify(postSubmitFormBody), { ...mergedRequestParameters, headers: { ...mergedRequestParameters?.headers, \"Content-Type\": \"application/x-www-form-urlencoded\", }, }, );"
|
|
91
91
|
]
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -152,9 +152,9 @@
|
|
|
152
152
|
"expectedSubstrings": [
|
|
153
153
|
"export class HeaderDemoAPIClient",
|
|
154
154
|
"getExampleGet( headers?: GetExampleGetHeaders, requestParameters?: Params, ): { response: Response; data: GetExampleGet200; }",
|
|
155
|
-
"response = http.request(\"GET\", url.toString(), undefined, { ...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), ]), ),
|
|
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
156
|
"postExamplePost( postExamplePostBody: PostExamplePostBody, headers: PostExamplePostHeaders, requestParameters?: Params, ): { response: Response; data: void; }",
|
|
157
|
-
"response = http.request( \"POST\", url.toString(), JSON.stringify(postExamplePostBody), { ...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), ]), ),
|
|
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
158
|
"getExampleResponseHeaders(requestParameters?: Params): { response: Response; data: GetExampleResponseHeaders200; }",
|
|
159
159
|
"response = http.request( \"GET\", url.toString(), undefined, mergedRequestParameters, );"
|
|
160
160
|
]
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
"const url = new URL(this.cleanBaseUrl + `/example`);",
|
|
125
125
|
"JSON.stringify(createExampleDataBody),",
|
|
126
126
|
"POST",
|
|
127
|
-
"export type CreateExampleData201 = {
|
|
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; };"
|
|
128
128
|
]
|
|
129
129
|
}
|
|
130
130
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { defineConfig } from 'vite'
|
|
2
|
+
import tsconfigPaths from 'vite-tsconfig-paths'
|
|
2
3
|
|
|
3
4
|
export default defineConfig({
|
|
5
|
+
plugins: [tsconfigPaths()],
|
|
4
6
|
test: {
|
|
5
7
|
environment: 'node',
|
|
8
|
+
globals: true,
|
|
9
|
+
include: ['tests/**/*.test.ts'],
|
|
6
10
|
coverage: {
|
|
7
11
|
reporter: ['json', 'text', 'lcov'],
|
|
8
12
|
reportsDirectory: 'coverage',
|