@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.
- package/.github/workflows/publish.yaml +2 -2
- package/.github/workflows/tests.yaml +14 -6
- package/README.md +54 -14
- package/dist/analytics.js +2 -1
- package/dist/cli.js +20 -6
- package/dist/constants.js +8 -2
- package/dist/{generator.js → generator/index.js} +7 -13
- package/dist/{k6SdkClient.js → generator/k6Client.js} +148 -161
- package/examples/basic_schema/single/k6-script.sample.ts +11 -0
- package/examples/basic_schema/single/simpleAPI.ts +87 -0
- package/examples/basic_schema/split/k6-script.sample.ts +11 -0
- package/examples/basic_schema/split/simpleAPI.schemas.ts +9 -0
- package/examples/basic_schema/split/simpleAPI.ts +85 -0
- package/examples/basic_schema/tags/default.ts +85 -0
- package/examples/basic_schema/tags/k6-script.sample.ts +11 -0
- package/examples/basic_schema/tags/simpleAPI.schemas.ts +9 -0
- package/examples/form_data_schema/single/formDataAPI.ts +115 -0
- package/examples/form_data_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/form_data_schema/split/formDataAPI.schemas.ts +24 -0
- package/examples/form_data_schema/split/formDataAPI.ts +98 -0
- package/examples/form_data_schema/split/k6-script.sample.ts +11 -0
- package/examples/form_data_schema/tags/default.ts +98 -0
- package/examples/form_data_schema/tags/formDataAPI.schemas.ts +24 -0
- package/examples/form_data_schema/tags/k6-script.sample.ts +11 -0
- package/examples/form_url_encoded_data_schema/single/formURLEncodedAPI.ts +112 -0
- package/examples/form_url_encoded_data_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.schemas.ts +24 -0
- package/examples/form_url_encoded_data_schema/split/formURLEncodedAPI.ts +98 -0
- package/examples/form_url_encoded_data_schema/split/k6-script.sample.ts +11 -0
- package/examples/form_url_encoded_data_schema/tags/default.ts +98 -0
- package/examples/form_url_encoded_data_schema/tags/formURLEncodedAPI.schemas.ts +24 -0
- package/examples/form_url_encoded_data_schema/tags/k6-script.sample.ts +11 -0
- package/examples/form_url_encoded_data_with_query_params_schema/single/formURLEncodedAPIWithQueryParameters.ts +128 -0
- package/examples/form_url_encoded_data_with_query_params_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.schemas.ts +35 -0
- package/examples/form_url_encoded_data_with_query_params_schema/split/formURLEncodedAPIWithQueryParameters.ts +104 -0
- package/examples/form_url_encoded_data_with_query_params_schema/split/k6-script.sample.ts +14 -0
- package/examples/form_url_encoded_data_with_query_params_schema/tags/default.ts +104 -0
- package/examples/form_url_encoded_data_with_query_params_schema/tags/formURLEncodedAPIWithQueryParameters.schemas.ts +35 -0
- package/examples/form_url_encoded_data_with_query_params_schema/tags/k6-script.sample.ts +14 -0
- package/examples/get_request_with_path_parameters_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/get_request_with_path_parameters_schema/single/simpleAPI.ts +94 -0
- package/examples/get_request_with_path_parameters_schema/split/k6-script.sample.ts +11 -0
- package/examples/get_request_with_path_parameters_schema/split/simpleAPI.schemas.ts +12 -0
- package/examples/get_request_with_path_parameters_schema/split/simpleAPI.ts +90 -0
- package/examples/get_request_with_path_parameters_schema/tags/default.ts +90 -0
- package/examples/get_request_with_path_parameters_schema/tags/k6-script.sample.ts +11 -0
- package/examples/get_request_with_path_parameters_schema/tags/simpleAPI.schemas.ts +12 -0
- package/examples/headers_schema/single/headerDemoAPI.ts +202 -0
- package/examples/headers_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/headers_schema/split/headerDemoAPI.schemas.ts +32 -0
- package/examples/headers_schema/split/headerDemoAPI.ts +184 -0
- package/examples/headers_schema/split/k6-script.sample.ts +25 -0
- package/examples/headers_schema/tags/default.ts +182 -0
- package/examples/headers_schema/tags/headerDemoAPI.schemas.ts +32 -0
- package/examples/headers_schema/tags/k6-script.sample.ts +25 -0
- package/examples/no_title_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/no_title_schema/single/k6Client.ts +87 -0
- package/examples/{basic_schema → no_title_schema/split}/k6-script.sample.ts +2 -2
- package/examples/no_title_schema/split/k6Client.schemas.ts +9 -0
- package/examples/no_title_schema/split/k6Client.ts +85 -0
- package/examples/no_title_schema/tags/default.ts +85 -0
- package/examples/no_title_schema/tags/k6-script.sample.ts +11 -0
- package/examples/no_title_schema/tags/k6Client.schemas.ts +9 -0
- package/examples/post_request_with_query_params/single/exampleAPI.ts +126 -0
- package/examples/post_request_with_query_params/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/post_request_with_query_params/split/exampleAPI.schemas.ts +33 -0
- package/examples/post_request_with_query_params/split/exampleAPI.ts +105 -0
- package/examples/post_request_with_query_params/split/k6-script.sample.ts +14 -0
- package/examples/post_request_with_query_params/tags/default.ts +105 -0
- package/examples/post_request_with_query_params/tags/exampleAPI.schemas.ts +33 -0
- package/examples/post_request_with_query_params/tags/k6-script.sample.ts +14 -0
- package/examples/query_params_schema/single/exampleAPI.ts +120 -0
- package/examples/query_params_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/query_params_schema/split/exampleAPI.schemas.ts +37 -0
- package/examples/query_params_schema/split/exampleAPI.ts +94 -0
- package/examples/query_params_schema/split/k6-script.sample.ts +11 -0
- package/examples/query_params_schema/tags/default.ts +94 -0
- package/examples/query_params_schema/tags/exampleAPI.schemas.ts +37 -0
- package/examples/query_params_schema/tags/k6-script.sample.ts +11 -0
- package/examples/simple_post_request_schema/{exampleAPI.ts → single/exampleAPI.ts} +49 -49
- package/examples/simple_post_request_schema/{k6-script.sample.ts → single/k6-script.sample.ts} +2 -2
- package/examples/simple_post_request_schema/split/exampleAPI.schemas.ts +47 -0
- package/examples/simple_post_request_schema/split/exampleAPI.ts +99 -0
- package/examples/simple_post_request_schema/split/k6-script.sample.ts +13 -0
- package/examples/simple_post_request_schema/tags/default.ts +99 -0
- package/examples/simple_post_request_schema/tags/exampleAPI.schemas.ts +47 -0
- package/examples/simple_post_request_schema/tags/k6-script.sample.ts +13 -0
- package/images/openapi-to-k6.png +0 -0
- package/package.json +2 -2
- package/src/analytics.ts +3 -1
- package/src/cli.ts +34 -8
- package/src/constants.ts +7 -1
- package/src/{generator.ts → generator/index.ts} +8 -21
- package/src/{k6SdkClient.ts → generator/k6Client.ts} +174 -222
- package/src/type.d.ts +4 -4
- package/tests/e2e/schema.json +8 -0
- package/tests/e2e/{k6Script.ts → single/k6Script.ts} +7 -2
- package/tests/e2e/split/k6Script.ts +82 -0
- package/tests/e2e/tags/k6Script.ts +106 -0
- package/tests/functional-tests/fixtures/schemas/basic_schema.json +1 -4
- package/tests/functional-tests/fixtures/schemas/form_data_schema.json +4 -4
- package/tests/functional-tests/fixtures/schemas/form_url_encoded_data_schema.json +3 -3
- package/tests/functional-tests/fixtures/schemas/form_url_encoded_data_with_query_params_schema.json +2 -2
- package/tests/functional-tests/fixtures/schemas/get_request_with_path_parameters_schema.json +2 -2
- package/tests/functional-tests/fixtures/schemas/headers_schema.json +7 -8
- package/tests/functional-tests/fixtures/schemas/no_title_schema.json +2 -5
- package/tests/functional-tests/fixtures/schemas/post_request_with_query_params.json +3 -4
- package/tests/functional-tests/fixtures/schemas/query_params_schema.json +3 -3
- package/tests/functional-tests/fixtures/schemas/simple_post_request_schema.json +3 -5
- package/tests/functional-tests/generator.test.ts +46 -5
- package/examples/basic_schema/simpleAPI.ts +0 -87
- package/examples/form_data_schema/formDataAPI.ts +0 -115
- package/examples/form_url_encoded_data_schema/formURLEncodedAPI.ts +0 -114
- package/examples/form_url_encoded_data_with_query_params_schema/formURLEncodedAPIWithQueryParameters.ts +0 -130
- package/examples/get_request_with_path_parameters_schema/simpleAPI.ts +0 -94
- package/examples/headers_schema/headerDemoAPI.ts +0 -196
- package/examples/no_title_schema/K6Client.ts +0 -86
- package/examples/post_request_with_query_params/exampleAPI.ts +0 -124
- package/examples/query_params_schema/exampleAPI.ts +0 -118
- package/examples/update_examples.sh +0 -21
|
@@ -19,13 +19,13 @@ jobs:
|
|
|
19
19
|
node-version: '21'
|
|
20
20
|
registry-url: 'https://registry.npmjs.org'
|
|
21
21
|
scope: '@grafana'
|
|
22
|
+
cache: 'npm'
|
|
23
|
+
cache-dependency-path: 'package-lock.json'
|
|
22
24
|
- run: npm ci
|
|
23
25
|
- name: Update version in package.json
|
|
24
26
|
run: |
|
|
25
27
|
NEW_VERSION=${{ github.event.release.tag_name }}
|
|
26
28
|
npm version $NEW_VERSION --no-git-tag-version
|
|
27
|
-
- name: Update generated examples
|
|
28
|
-
run: npm run update-examples
|
|
29
29
|
- name: Commit updated package.json
|
|
30
30
|
run: |
|
|
31
31
|
git config --global user.name 'github-actions[bot]'
|
|
@@ -12,7 +12,9 @@ jobs:
|
|
|
12
12
|
- uses: actions/checkout@v4
|
|
13
13
|
- uses: actions/setup-node@v4
|
|
14
14
|
with:
|
|
15
|
-
node-version: '21
|
|
15
|
+
node-version: '21'
|
|
16
|
+
cache: 'npm'
|
|
17
|
+
cache-dependency-path: 'package-lock.json'
|
|
16
18
|
- run: npm ci
|
|
17
19
|
- run: npm run lint
|
|
18
20
|
- run: npm test
|
|
@@ -22,10 +24,15 @@ jobs:
|
|
|
22
24
|
- uses: actions/checkout@v4
|
|
23
25
|
- uses: actions/setup-node@v4
|
|
24
26
|
with:
|
|
25
|
-
node-version: '21
|
|
27
|
+
node-version: '21'
|
|
28
|
+
cache: 'npm'
|
|
29
|
+
cache-dependency-path: 'package-lock.json'
|
|
26
30
|
- run: npm ci
|
|
27
31
|
- name: Generate SDK for E2E tests
|
|
28
|
-
run:
|
|
32
|
+
run: |
|
|
33
|
+
npm run dev -- ./tests/e2e/schema.json ./tests/e2e/single/sdk.ts --disable-analytics --mode single
|
|
34
|
+
npm run dev -- ./tests/e2e/schema.json ./tests/e2e/split/sdk.ts --disable-analytics --mode split
|
|
35
|
+
npm run dev -- ./tests/e2e/schema.json ./tests/e2e/tags/sdk.ts --disable-analytics --mode tags
|
|
29
36
|
- name: Start Mockoon CLI
|
|
30
37
|
uses: mockoon/cli-action@v2
|
|
31
38
|
with:
|
|
@@ -35,17 +42,18 @@ jobs:
|
|
|
35
42
|
- uses: grafana/setup-k6-action@v1
|
|
36
43
|
- uses: grafana/run-k6-action@v1
|
|
37
44
|
with:
|
|
38
|
-
path: './tests/e2e
|
|
45
|
+
path: './tests/e2e/*/k6Script.ts'
|
|
39
46
|
flags: '--compatibility-mode=experimental_enhanced'
|
|
40
47
|
inspect-flags: '--compatibility-mode=experimental_enhanced'
|
|
41
48
|
run-examples:
|
|
42
49
|
runs-on: ubuntu-latest
|
|
43
|
-
needs: [test, e2e-test]
|
|
44
50
|
steps:
|
|
45
51
|
- uses: actions/checkout@v4
|
|
46
52
|
- uses: actions/setup-node@v4
|
|
47
53
|
with:
|
|
48
|
-
node-version: '21
|
|
54
|
+
node-version: '21'
|
|
55
|
+
cache: 'npm'
|
|
56
|
+
cache-dependency-path: 'package-lock.json'
|
|
49
57
|
- run: npm ci
|
|
50
58
|
- name: Update examples
|
|
51
59
|
run: npm run update-examples
|
package/README.md
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
<
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
<img
|
|
4
|
+
src="./images/openapi-to-k6.png"
|
|
5
|
+
width="600"
|
|
6
|
+
style="pointer-events: none;" />
|
|
7
|
+
<br />
|
|
8
|
+
<hr/>
|
|
9
|
+
<p align="center">⚠️</p>
|
|
10
|
+
<b>This tool is currently in the experimental stage. Expect bugs, incomplete features, and breaking changes as development progresses. Use at your own risk, and please report any issues or feedback to help us improve.</b>
|
|
11
|
+
<hr/>
|
|
12
|
+
</div>
|
|
8
13
|
|
|
9
14
|
## Overview
|
|
10
15
|
|
|
@@ -17,16 +22,51 @@ OpenAPI documentation.
|
|
|
17
22
|
|
|
18
23
|
Along with the client, it also generates a sample k6 script as an example of how to use the client.
|
|
19
24
|
|
|
20
|
-
|
|
21
|
-
|
|
25
|
+
The generated client exports a class with methods for each endpoint in the OpenAPI specification. You can create
|
|
26
|
+
a instance of the class and use the methods to call the endpoints.
|
|
22
27
|
|
|
23
|
-
To take a look at a few examples of how the generated client and sample script looks, check out the [examples](./examples) directory.
|
|
28
|
+
To take a look at a few examples of how the generated client looks and sample script looks, check out the [examples](./examples) directory.
|
|
24
29
|
|
|
25
|
-
Note: Optional usage analytics are gathered to make the tool better. To disable this, use the option
|
|
26
|
-
`--disable-analytics` or set an environment variable `DISABLE_ANALYTICS=true`.
|
|
27
30
|
|
|
28
31
|
## Getting started
|
|
29
32
|
|
|
33
|
+
1. Install the tool globally via
|
|
34
|
+
|
|
35
|
+
```shell
|
|
36
|
+
npm install -g @grafana/openapi-to-k6
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
2. To start using the tool either give path to your OpenAPI schema file or provide a URL to your Open
|
|
40
|
+
API schema and the output path where you want to generate the client files.
|
|
41
|
+
|
|
42
|
+
```shell
|
|
43
|
+
openapi-to-k6 <path-to-openapi-schema | url-to-openapi-schema> <output path>
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
This will the generate a TypeScript client and a sample k6 script in the corresponding directory.
|
|
47
|
+
|
|
48
|
+
You can also supply the optional flag `--include-sample-script` to also generate a sample k6 script
|
|
49
|
+
along with the client.
|
|
50
|
+
|
|
51
|
+
💡 _Note_: The tool supports both JSON and YAML format for OpenAPI schema.
|
|
52
|
+
|
|
53
|
+
### Options
|
|
54
|
+
|
|
55
|
+
Following are some of the configuration options supported by the tool.
|
|
56
|
+
|
|
57
|
+
1. `--mode` or `-m`: Specify the mode to use for generating the client. Following are available options:
|
|
58
|
+
1. `single`: This is the default mode used is nothing is specified. It generated the TypeScript client as a single file with all the types and implementation in a single file.
|
|
59
|
+
2. `split`: This mode splits the types and implementation into separate files.
|
|
60
|
+
3. `tags`: This modes splits your OpenAPI schema based on the tags and generates a separate client for each tag. If a route has no tag set, it will be available in `default.ts` file.
|
|
61
|
+
|
|
62
|
+
To check how the output looks for each mode, check out the [examples](./examples) directory.
|
|
63
|
+
2. `--disable-analytics`: Disable anonymous usage analytics reporting which helping making the tool better. You can also set an environment variable `DISABLE_ANALYTICS=true` to disable the analytics.
|
|
64
|
+
3. `--include-sample-script`: Generate a sample k6 script.
|
|
65
|
+
4. `--verbose` or `-v` : Enable verbose logging to see more detailed logging output.
|
|
66
|
+
5. `--help` or `-h` : Show help message.
|
|
67
|
+
|
|
68
|
+
## Developing locally
|
|
69
|
+
|
|
30
70
|
1. Clone the repository
|
|
31
71
|
|
|
32
72
|
```shell
|
|
@@ -69,7 +109,7 @@ cd tests/e2e/
|
|
|
69
109
|
This will run the mock server in a docker container in background.
|
|
70
110
|
|
|
71
111
|
```shell
|
|
72
|
-
docker run -
|
|
112
|
+
docker run -v ./schema.json:/tmp/schema.json -p 3000:3000 mockoon/cli:latest -d /tmp/schema.json
|
|
73
113
|
```
|
|
74
114
|
|
|
75
115
|
3. Assuming you have already followed previous steps and have the environment set up, you can generate the SDK by using
|
|
@@ -90,4 +130,4 @@ k6 run --compatibility-mode=experimental_enhanced ./K6Script.ts
|
|
|
90
130
|
2. Install the compiled package locally by using `npm install .` or `npm install -g .`.
|
|
91
131
|
3. Use the CLI `k6-sdkgen <path-to-openapi-schema> <output path>`
|
|
92
132
|
|
|
93
|
-
Special
|
|
133
|
+
Special mention for the the open-source library [Orval](https://orval.dev/) which is used for the generation of the TypeScript client.
|
package/dist/analytics.js
CHANGED
|
@@ -37,7 +37,7 @@ function getAnonymousUserId() {
|
|
|
37
37
|
* @param packageDetails - Details of the openapi-to-k6 package.
|
|
38
38
|
* @returns
|
|
39
39
|
*/
|
|
40
|
-
function generateDefaultAnalyticsData(packageDetails) {
|
|
40
|
+
function generateDefaultAnalyticsData(packageDetails, isSampleK6ScriptGenerated) {
|
|
41
41
|
const defaultAnalyticsData = {
|
|
42
42
|
generatedRequestsCount: {
|
|
43
43
|
post: 0,
|
|
@@ -47,6 +47,7 @@ function generateDefaultAnalyticsData(packageDetails) {
|
|
|
47
47
|
delete: 0,
|
|
48
48
|
head: 0,
|
|
49
49
|
},
|
|
50
|
+
isSampleK6ScriptGenerated,
|
|
50
51
|
openApiSpecVersion: '',
|
|
51
52
|
toolVersion: packageDetails.version,
|
|
52
53
|
anonymousUserId: getAnonymousUserId(),
|
package/dist/cli.js
CHANGED
|
@@ -16,13 +16,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
16
16
|
const chalk_1 = __importDefault(require("chalk"));
|
|
17
17
|
const commander_1 = require("commander");
|
|
18
18
|
const analytics_1 = require("./analytics");
|
|
19
|
+
const constants_1 = require("./constants");
|
|
19
20
|
const generator_1 = __importDefault(require("./generator"));
|
|
20
21
|
const helper_1 = require("./helper");
|
|
21
22
|
const logger_1 = require("./logger");
|
|
22
23
|
const program = new commander_1.Command();
|
|
23
24
|
const packageDetails = (0, helper_1.getPackageDetails)();
|
|
25
|
+
/**
|
|
26
|
+
* Validate that the mode argument is one of the supported modes.
|
|
27
|
+
*
|
|
28
|
+
* @param {string} value - The mode value to validate
|
|
29
|
+
* @return {Mode} - The validated mode value
|
|
30
|
+
*/
|
|
31
|
+
function validateMode(value) {
|
|
32
|
+
if (!Object.values(constants_1.Mode).includes(value)) {
|
|
33
|
+
throw new commander_1.InvalidArgumentError(`Supported modes: ${Object.values(constants_1.Mode).join(', ')}`);
|
|
34
|
+
}
|
|
35
|
+
return value;
|
|
36
|
+
}
|
|
24
37
|
function generateSDK(_a) {
|
|
25
|
-
return __awaiter(this, arguments, void 0, function* ({ openApiPath, outputDir, shouldGenerateSampleK6Script, analyticsData, }) {
|
|
38
|
+
return __awaiter(this, arguments, void 0, function* ({ openApiPath, outputDir, shouldGenerateSampleK6Script, analyticsData, mode, }) {
|
|
26
39
|
logger_1.logger.logMessage('Generating TypeScript client for k6...\n');
|
|
27
40
|
logger_1.logger.logMessage(`OpenAPI schema: ${openApiPath}`);
|
|
28
41
|
logger_1.logger.logMessage(`Output: ${outputDir}\n`);
|
|
@@ -31,6 +44,7 @@ function generateSDK(_a) {
|
|
|
31
44
|
outputDir,
|
|
32
45
|
shouldGenerateSampleK6Script,
|
|
33
46
|
analyticsData,
|
|
47
|
+
mode,
|
|
34
48
|
});
|
|
35
49
|
if (shouldGenerateSampleK6Script) {
|
|
36
50
|
logger_1.logger.logMessage(`TypeScript client and sample k6 script generated successfully.`, chalk_1.default.green);
|
|
@@ -46,14 +60,13 @@ program
|
|
|
46
60
|
.version(packageDetails.version)
|
|
47
61
|
.argument('<openApiPath>', 'Path or URL for the OpenAPI schema file')
|
|
48
62
|
.argument('<outputDir>', 'Directory where the SDK should be generated')
|
|
63
|
+
.option('-m, --mode <string>', `mode to use for generating the client. Valid values - ${Object.values(constants_1.Mode).join(', ')}`, validateMode, constants_1.Mode.SINGLE)
|
|
49
64
|
.option('-v, --verbose', 'enable verbose mode to show debug logs')
|
|
50
|
-
.option('--
|
|
65
|
+
.option('--include-sample-script', 'generate a sample k6 script')
|
|
51
66
|
.option('--disable-analytics', 'disable anonymous usage data collection')
|
|
52
67
|
.action((openApiPath, outputDir, options) => __awaiter(void 0, void 0, void 0, function* () {
|
|
53
68
|
let analyticsData;
|
|
54
69
|
const shouldDisableAnalytics = options.disableAnalytics || process.env.DISABLE_ANALYTICS === 'true';
|
|
55
|
-
const shouldDisableSampleScript = options.disableSampleScript ||
|
|
56
|
-
process.env.DISABLE_SAMPLE_SCRIPT === 'true';
|
|
57
70
|
if (options.verbose) {
|
|
58
71
|
logger_1.logger.setVerbose(true);
|
|
59
72
|
logger_1.logger.debug('Verbose mode enabled, showing debug logs');
|
|
@@ -63,7 +76,7 @@ program
|
|
|
63
76
|
}
|
|
64
77
|
else {
|
|
65
78
|
logger_1.logger.debug('Anonymous usage data collection enabled');
|
|
66
|
-
analyticsData = (0, analytics_1.generateDefaultAnalyticsData)(packageDetails);
|
|
79
|
+
analyticsData = (0, analytics_1.generateDefaultAnalyticsData)(packageDetails, !!options.includeSampleScript);
|
|
67
80
|
}
|
|
68
81
|
logger_1.logger.debug(`
|
|
69
82
|
Supplied OpenAPI schema: ${openApiPath}
|
|
@@ -73,8 +86,9 @@ program
|
|
|
73
86
|
yield generateSDK({
|
|
74
87
|
openApiPath,
|
|
75
88
|
outputDir,
|
|
76
|
-
shouldGenerateSampleK6Script:
|
|
89
|
+
shouldGenerateSampleK6Script: !!options.includeSampleScript,
|
|
77
90
|
analyticsData,
|
|
91
|
+
mode: options.mode,
|
|
78
92
|
});
|
|
79
93
|
}
|
|
80
94
|
catch (error) {
|
package/dist/constants.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.K6_SCRIPT_TEMPLATE = exports.SAMPLE_K6_SCRIPT_FILE_NAME = exports.DEFAULT_SCHEMA_TITLE = void 0;
|
|
3
|
+
exports.Mode = exports.K6_SCRIPT_TEMPLATE = exports.SAMPLE_K6_SCRIPT_FILE_NAME = exports.DEFAULT_SCHEMA_TITLE = void 0;
|
|
4
4
|
exports.DEFAULT_SCHEMA_TITLE = 'K6Client';
|
|
5
5
|
exports.SAMPLE_K6_SCRIPT_FILE_NAME = 'k6-script.sample.ts';
|
|
6
6
|
exports.K6_SCRIPT_TEMPLATE = `
|
|
7
7
|
import { {{clientFunctionName}} } from '{{clientPath}}'
|
|
8
8
|
|
|
9
9
|
const baseUrl = '<BASE_URL>';
|
|
10
|
-
const client = {{clientFunctionName}}({ baseUrl })
|
|
10
|
+
const client = new {{clientFunctionName}}({ baseUrl })
|
|
11
11
|
|
|
12
12
|
export default function () {
|
|
13
13
|
{{#each clientFunctionsList}}
|
|
@@ -19,3 +19,9 @@ export default function () {
|
|
|
19
19
|
{{/each}}
|
|
20
20
|
}
|
|
21
21
|
`;
|
|
22
|
+
var Mode;
|
|
23
|
+
(function (Mode) {
|
|
24
|
+
Mode["SINGLE"] = "single";
|
|
25
|
+
Mode["SPLIT"] = "split";
|
|
26
|
+
Mode["TAGS"] = "tags";
|
|
27
|
+
})(Mode || (exports.Mode = Mode = {}));
|
|
@@ -15,10 +15,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
const fs_1 = __importDefault(require("fs"));
|
|
16
16
|
const orval_1 = __importDefault(require("orval"));
|
|
17
17
|
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const constants_1 = require("
|
|
19
|
-
const helper_1 = require("
|
|
20
|
-
const
|
|
21
|
-
const
|
|
18
|
+
const constants_1 = require("../constants");
|
|
19
|
+
const helper_1 = require("../helper");
|
|
20
|
+
const logger_1 = require("../logger");
|
|
21
|
+
const k6Client_1 = require("./k6Client");
|
|
22
22
|
const outputOverrider = helper_1.OutputOverrider.getInstance();
|
|
23
23
|
const packageDetails = (0, helper_1.getPackageDetails)();
|
|
24
24
|
const generatedFileHeaderGenerator = (info) => {
|
|
@@ -44,10 +44,7 @@ const afterAllFilesWriteHandler = (filePaths) => __awaiter(void 0, void 0, void
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
|
-
exports.default = (_a) => __awaiter(void 0, [_a], void 0, function* ({ openApiPath, outputDir, shouldGenerateSampleK6Script, analyticsData, }) {
|
|
48
|
-
const schemaDetails = {
|
|
49
|
-
title: '',
|
|
50
|
-
};
|
|
47
|
+
exports.default = (_a) => __awaiter(void 0, [_a], void 0, function* ({ openApiPath, outputDir, shouldGenerateSampleK6Script, analyticsData, mode, }) {
|
|
51
48
|
/**
|
|
52
49
|
* Note!
|
|
53
50
|
* 1. override.requestOptions is not supported for the custom K6 client
|
|
@@ -58,8 +55,8 @@ exports.default = (_a) => __awaiter(void 0, [_a], void 0, function* ({ openApiPa
|
|
|
58
55
|
input: openApiPath,
|
|
59
56
|
output: {
|
|
60
57
|
target: outputDir,
|
|
61
|
-
mode:
|
|
62
|
-
client: () => (0,
|
|
58
|
+
mode: mode,
|
|
59
|
+
client: () => (0, k6Client_1.getK6ClientBuilder)(shouldGenerateSampleK6Script, analyticsData),
|
|
63
60
|
override: {
|
|
64
61
|
header: generatedFileHeaderGenerator,
|
|
65
62
|
},
|
|
@@ -70,7 +67,4 @@ exports.default = (_a) => __awaiter(void 0, [_a], void 0, function* ({ openApiPa
|
|
|
70
67
|
},
|
|
71
68
|
});
|
|
72
69
|
}));
|
|
73
|
-
if (!schemaDetails.title) {
|
|
74
|
-
logger_1.logger.warning('Could not find schema title in the OpenAPI spec. Please provide a `title` in the schema in `info` block to generate proper file names');
|
|
75
|
-
}
|
|
76
70
|
});
|