@grafana/openapi-to-k6 0.2.0 → 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.
@@ -26,8 +26,6 @@ jobs:
26
26
  run: |
27
27
  NEW_VERSION=${{ github.event.release.tag_name }}
28
28
  npm version $NEW_VERSION --no-git-tag-version
29
- - name: Update generated examples
30
- run: npm run update-examples
31
29
  - name: Commit updated package.json
32
30
  run: |
33
31
  git config --global user.name 'github-actions[bot]'
package/README.md CHANGED
@@ -45,20 +45,25 @@ To take a look at a few examples of how the generated client looks and sample sc
45
45
 
46
46
  This will the generate a TypeScript client and a sample k6 script in the corresponding directory.
47
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
+
48
53
  ### Options
49
54
 
50
55
  Following are some of the configuration options supported by the tool.
51
56
 
52
- 1. `--mode` or ` -m`: Specify the mode to use for generating the client. Following are available options:
57
+ 1. `--mode` or `-m`: Specify the mode to use for generating the client. Following are available options:
53
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.
54
59
  2. `split`: This mode splits the types and implementation into separate files.
55
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.
56
61
 
57
62
  To check how the output looks for each mode, check out the [examples](./examples) directory.
58
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.
59
- 3. `--disable-sample-script`: Disable the generation of sample k6 script.
60
- 4. `--verbose` or ` -v` : Enable verbose logging to see more detailed logging output.
61
- 5. `--help` or ` -h` : Show help message.
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.
62
67
 
63
68
  ## Developing locally
64
69
 
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
@@ -62,13 +62,11 @@ program
62
62
  .argument('<outputDir>', 'Directory where the SDK should be generated')
63
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)
64
64
  .option('-v, --verbose', 'enable verbose mode to show debug logs')
65
- .option('--disable-sample-script', 'disable generating sample k6 script')
65
+ .option('--include-sample-script', 'generate a sample k6 script')
66
66
  .option('--disable-analytics', 'disable anonymous usage data collection')
67
67
  .action((openApiPath, outputDir, options) => __awaiter(void 0, void 0, void 0, function* () {
68
68
  let analyticsData;
69
69
  const shouldDisableAnalytics = options.disableAnalytics || process.env.DISABLE_ANALYTICS === 'true';
70
- const shouldDisableSampleScript = options.disableSampleScript ||
71
- process.env.DISABLE_SAMPLE_SCRIPT === 'true';
72
70
  if (options.verbose) {
73
71
  logger_1.logger.setVerbose(true);
74
72
  logger_1.logger.debug('Verbose mode enabled, showing debug logs');
@@ -78,7 +76,7 @@ program
78
76
  }
79
77
  else {
80
78
  logger_1.logger.debug('Anonymous usage data collection enabled');
81
- analyticsData = (0, analytics_1.generateDefaultAnalyticsData)(packageDetails);
79
+ analyticsData = (0, analytics_1.generateDefaultAnalyticsData)(packageDetails, !!options.includeSampleScript);
82
80
  }
83
81
  logger_1.logger.debug(`
84
82
  Supplied OpenAPI schema: ${openApiPath}
@@ -88,7 +86,7 @@ program
88
86
  yield generateSDK({
89
87
  openApiPath,
90
88
  outputDir,
91
- shouldGenerateSampleK6Script: !shouldDisableSampleScript,
89
+ shouldGenerateSampleK6Script: !!options.includeSampleScript,
92
90
  analyticsData,
93
91
  mode: options.mode,
94
92
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@grafana/openapi-to-k6",
3
- "version": "0.2.0",
3
+ "version": "0.2.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": {
@@ -13,7 +13,7 @@
13
13
  "lint": "eslint --ext .ts,.tsx .",
14
14
  "lint:fix": "eslint --ext .ts,.tsx . --fix",
15
15
  "format": "prettier --ignore-unknown --write \"./**/*\"",
16
- "update-examples": "for dir in ./examples/*/; do (npm run dev -- \"$dir/schema.json\" \"$dir/single/\" -m single && npm run dev -- \"$dir/schema.json\" \"$dir/split/\" -m split && npm run dev -- \"$dir/schema.json\" \"$dir/tags/\" -m tags); done",
16
+ "update-examples": "for dir in ./examples/*/; do (npm run dev -- \"$dir/schema.json\" \"$dir/single/\" -m single --include-sample-script && npm run dev -- \"$dir/schema.json\" \"$dir/split/\" -m split --include-sample-script && npm run dev -- \"$dir/schema.json\" \"$dir/tags/\" -m tags --include-sample-script); done",
17
17
  "prepare": "husky"
18
18
  },
19
19
  "author": "",
package/src/analytics.ts CHANGED
@@ -26,7 +26,8 @@ function getAnonymousUserId(): string {
26
26
  * @returns
27
27
  */
28
28
  export function generateDefaultAnalyticsData(
29
- packageDetails: PackageDetails
29
+ packageDetails: PackageDetails,
30
+ isSampleK6ScriptGenerated: boolean
30
31
  ): AnalyticsData {
31
32
  const defaultAnalyticsData: AnalyticsData = {
32
33
  generatedRequestsCount: {
@@ -37,6 +38,7 @@ export function generateDefaultAnalyticsData(
37
38
  delete: 0,
38
39
  head: 0,
39
40
  },
41
+ isSampleK6ScriptGenerated,
40
42
  openApiSpecVersion: '',
41
43
  toolVersion: packageDetails.version,
42
44
  anonymousUserId: getAnonymousUserId(),
package/src/cli.ts CHANGED
@@ -69,7 +69,7 @@ program
69
69
  Mode.SINGLE
70
70
  )
71
71
  .option('-v, --verbose', 'enable verbose mode to show debug logs')
72
- .option('--disable-sample-script', 'disable generating sample k6 script')
72
+ .option('--include-sample-script', 'generate a sample k6 script')
73
73
  .option('--disable-analytics', 'disable anonymous usage data collection')
74
74
  .action(
75
75
  async (
@@ -79,15 +79,12 @@ program
79
79
  verbose?: boolean
80
80
  mode: Mode
81
81
  disableAnalytics?: boolean
82
- disableSampleScript?: boolean
82
+ includeSampleScript?: boolean
83
83
  }
84
84
  ) => {
85
85
  let analyticsData: AnalyticsData | undefined
86
86
  const shouldDisableAnalytics =
87
87
  options.disableAnalytics || process.env.DISABLE_ANALYTICS === 'true'
88
- const shouldDisableSampleScript =
89
- options.disableSampleScript ||
90
- process.env.DISABLE_SAMPLE_SCRIPT === 'true'
91
88
 
92
89
  if (options.verbose) {
93
90
  logger.setVerbose(true)
@@ -98,7 +95,10 @@ program
98
95
  logger.debug('Anonymous usage data collection disabled')
99
96
  } else {
100
97
  logger.debug('Anonymous usage data collection enabled')
101
- analyticsData = generateDefaultAnalyticsData(packageDetails)
98
+ analyticsData = generateDefaultAnalyticsData(
99
+ packageDetails,
100
+ !!options.includeSampleScript
101
+ )
102
102
  }
103
103
 
104
104
  logger.debug(`
@@ -109,7 +109,7 @@ program
109
109
  await generateSDK({
110
110
  openApiPath,
111
111
  outputDir,
112
- shouldGenerateSampleK6Script: !shouldDisableSampleScript,
112
+ shouldGenerateSampleK6Script: !!options.includeSampleScript,
113
113
  analyticsData,
114
114
  mode: options.mode,
115
115
  })
package/src/type.d.ts CHANGED
@@ -16,6 +16,7 @@ export interface AnalyticsData {
16
16
  patch: number
17
17
  head: number
18
18
  }
19
+ isSampleK6ScriptGenerated: boolean
19
20
  openApiSpecVersion: string
20
21
  toolVersion: string
21
22
  anonymousUserId: string