swaggerhub-cli 0.10.0 → 0.12.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "swaggerhub-cli",
3
3
  "description": "SwaggerHub CLI",
4
- "version": "0.10.0",
4
+ "version": "0.12.0",
5
5
  "author": "SmartBear",
6
6
  "bin": {
7
7
  "swaggerhub": "./bin/run"
@@ -15,31 +15,38 @@
15
15
  "deep-extend": "^0.6.0",
16
16
  "fs-extra": "^11.1.1",
17
17
  "inquirer": "^8.2.5",
18
- "js-yaml": "^4.1.0",
18
+ "js-yaml": "^5.2.2",
19
19
  "json-templates": "^5.0.0",
20
20
  "node-fetch": "^2.6.12",
21
21
  "semver": "^7.6.0",
22
22
  "unzipper": "^0.12.3"
23
23
  },
24
24
  "devDependencies": {
25
- "@oclif/test": "^3.2.10",
26
- "chai": "^4.3.10",
27
- "eslint": "^9.0.0",
25
+ "@faker-js/faker": "^10.0.0",
26
+ "@oclif/test": "^3.2.15",
27
+ "chai": "^6.3.0",
28
+ "eslint": "^10.10.0",
28
29
  "eslint-plugin-chai-friendly": "^1.0.0",
29
30
  "eslint-plugin-immutable": "^1.0.0",
30
- "eslint-plugin-mocha": "^10.1.0",
31
- "eslint-plugin-node": "^11.1.0",
32
- "globby": "^14.0.0",
31
+ "eslint-plugin-mocha": "^11.3.0",
32
+ "eslint-plugin-n": "^18.3.0",
33
+ "globby": "^16.2.0",
33
34
  "husky": "^9.0.1",
34
- "mocha": "^11.1.0",
35
+ "mocha": "^11.7.6",
35
36
  "nock": "^14.0.1",
36
- "nyc": "^17.0.0",
37
- "rewire": "^7.0.0",
38
- "sinon": "^19.0.2",
39
- "tmp": "^0.2.1"
37
+ "nyc": "^18.0.0",
38
+ "rewire": "^9.0.1",
39
+ "sinon": "^22.0.0",
40
+ "tmp": "^0.2.7"
40
41
  },
41
42
  "engines": {
42
- "node": ">=20.0.0"
43
+ "node": "^20.17.0 || >=22.9.0",
44
+ "npm": ">=11.9.0"
45
+ },
46
+ "overrides": {
47
+ "npm": "^11.9.0",
48
+ "glob": "^10.5.0",
49
+ "serialize-javascript": "^7.0.5"
43
50
  },
44
51
  "files": [
45
52
  "/bin",
@@ -89,13 +96,9 @@
89
96
  "scripts": {
90
97
  "postpack": "rm -f oclif.manifest.json",
91
98
  "prepack": "npx oclif manifest",
99
+ "prepare": "husky",
92
100
  "test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
93
101
  "lint": "eslint ./src ./test",
94
102
  "postinstall": "node ./src/check-node-version"
95
- },
96
- "husky": {
97
- "hooks": {
98
- "pre-push": "npm run lint && npm run test"
99
- }
100
103
  }
101
104
  }
@@ -0,0 +1,69 @@
1
+ const BaseCommand = require('../../support/command/base-command')
2
+ const { Args } = require('@oclif/core')
3
+ const {
4
+ noVersionRegex,
5
+ apiNameRegex
6
+ } = require('../../support/command/parse-input')
7
+ const { errorMsg } = require('../../template-strings')
8
+ const { CLIError } = require('@oclif/core/lib/errors')
9
+ const { postApi } = require('../../requests/api')
10
+
11
+ const getApiToRename = args => {
12
+ const newName = args['OWNER/API_NAME']
13
+ if (!noVersionRegex.test(newName)) {
14
+ throw new CLIError(errorMsg.argsMustMatchFormat({ format: 'OWNER/API_NAME' }))
15
+ }
16
+ return newName
17
+ }
18
+
19
+ const getApiNewName = args => {
20
+ const newName = args['API_NEW_NAME']
21
+ if (!apiNameRegex.test(newName)) {
22
+ throw new CLIError(errorMsg.argsMustMatchFormat({ format: 'API_NEW_NAME' }))
23
+ }
24
+ return newName
25
+ }
26
+
27
+ class RenameApiCommand extends BaseCommand {
28
+
29
+ async run() {
30
+ const { args } = await this.parse(RenameApiCommand)
31
+
32
+ const apiPath = getApiToRename(args)
33
+ const newName = getApiNewName(args)
34
+
35
+ this.log(`Renaming API: '${apiPath}' to '${newName}'`)
36
+
37
+ await this.executeHttp({
38
+ execute: () => postApi(
39
+ {
40
+ pathParams: [apiPath, 'rename'],
41
+ queryParams: { 'newName': newName },
42
+ body: '{}'
43
+ }),
44
+ onResolve: this.logCommandSuccess({ apiPath, newName }),
45
+ options: {}
46
+ })
47
+ }
48
+ }
49
+
50
+ RenameApiCommand.description = 'rename an API'
51
+
52
+ RenameApiCommand.examples = [
53
+ 'swaggerhub api:rename organization/apiOldName apiNewName'
54
+ ]
55
+
56
+ RenameApiCommand.args = {
57
+ 'OWNER/API_NAME': Args.string({
58
+ required: true,
59
+ description: 'API to be renamed'
60
+ }),
61
+ 'API_NEW_NAME': Args.string({
62
+ required: true,
63
+ description: 'New name for the API'
64
+ })
65
+ }
66
+
67
+ RenameApiCommand.flags = BaseCommand.flags
68
+
69
+ module.exports = RenameApiCommand
@@ -12,7 +12,9 @@ class ValidateDownloadRulesCommand extends BaseCommand {
12
12
  const includeDisabledRules = flags['include-disabled-rules'] ?? false
13
13
  const organization = args['OWNER']
14
14
 
15
- const organizationRuleset = await this.getExportedOrganizationRuleset(organization, {includeSystemRules, includeDisabledRules})
15
+ const organizationRuleset = await this.getExportedOrganizationRuleset(
16
+ organization, { includeSystemRules, includeDisabledRules }
17
+ )
16
18
  this.log(JSON.stringify(organizationRuleset, null, 2))
17
19
  }
18
20
 
@@ -12,7 +12,7 @@ class ValidateCommand extends BaseValidateCommand {
12
12
  const apiPath = getApiIdentifierArg(args)
13
13
  const validPath = await this.ensureVersion(apiPath)
14
14
  await this.checkApiExists(validPath)
15
- // eslint-disable-next-line immutable/no-let
15
+
16
16
  let validationResult = await this.getValidationResult(validPath)
17
17
  // Required to support On-Prem 2.4.1
18
18
  if (validationResult.validation.length === 0 && isOnPrem()) {
@@ -3,8 +3,8 @@ const { getSpectralRuleset } = require('../../requests/spectral')
3
3
  const { getSpectralIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
4
4
  const { errorMsg } = require('../../template-strings')
5
5
  const BaseCommand = require('../../support/command/base-command')
6
- const unzipper = require('unzipper');
7
- const fs = require('fs');
6
+ const unzipper = require('unzipper')
7
+ const fs = require('fs')
8
8
 
9
9
  class DownloadSpectralRulesetCommand extends BaseCommand {
10
10
  async run() {
@@ -23,10 +23,10 @@ class DownloadSpectralRulesetCommand extends BaseCommand {
23
23
  }
24
24
 
25
25
  async extractZipResponse(response, outputDir) {
26
- const buffer = Buffer.from(response.content, 'binary');
26
+ const buffer = Buffer.from(response.content, 'binary')
27
27
  await this.createDirectory(outputDir)
28
- const directory = await unzipper.Open.buffer(buffer);
29
- await directory.extract({ path: outputDir });
28
+ const directory = await unzipper.Open.buffer(buffer)
29
+ await directory.extract({ path: outputDir })
30
30
  }
31
31
 
32
32
  async createDirectory(outputDir) {
@@ -45,7 +45,7 @@ class DownloadSpectralRulesetCommand extends BaseCommand {
45
45
  }
46
46
  }
47
47
 
48
- DownloadSpectralRulesetCommand.description = `Fetch organization's Spectral ruleset`
48
+ DownloadSpectralRulesetCommand.description = 'Fetch organization\'s Spectral ruleset'
49
49
 
50
50
  DownloadSpectralRulesetCommand.examples = [
51
51
  'swaggerhub spectral:download my_organization/my_api_ruleset rules/',
@@ -1,5 +1,5 @@
1
1
  const { Args } = require('@oclif/core')
2
- const {saveSpectralRuleset} = require('../../requests/spectral')
2
+ const { saveSpectralRuleset } = require('../../requests/spectral')
3
3
  const { getSpectralIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
4
4
  const BaseCommand = require('../../support/command/base-command')
5
5
  const { PassThrough } = require('stream')
@@ -17,13 +17,13 @@ class UploadSpectralRulesetCommand extends BaseCommand {
17
17
  }
18
18
 
19
19
  async zipTheDirectory(directoryPath) {
20
- const archive = archiver('zip', { zlib: { level: 9 } });
21
- const passthrough = new PassThrough();
20
+ const archive = archiver('zip', { zlib: { level: 9 } })
21
+ const passthrough = new PassThrough()
22
22
 
23
- archive.directory(directoryPath, false);
24
- archive.finalize();
25
- archive.pipe(passthrough);
26
- return passthrough;
23
+ archive.directory(directoryPath, false)
24
+ await archive.finalize()
25
+ archive.pipe(passthrough)
26
+ return passthrough
27
27
  }
28
28
 
29
29
  saveSpectralRuleset(pathParams, zippedDirectory) {
@@ -35,7 +35,7 @@ class UploadSpectralRulesetCommand extends BaseCommand {
35
35
  }
36
36
  }
37
37
 
38
- UploadSpectralRulesetCommand.description = `Create or update organization's Spectral ruleset`
38
+ UploadSpectralRulesetCommand.description = 'Create or update organization\'s Spectral ruleset'
39
39
 
40
40
  UploadSpectralRulesetCommand.examples = [
41
41
  'swaggerhub spectral:upload my_organization/my_api_ruleset rules/',
@@ -13,7 +13,7 @@ const saveSpectralRuleset = (pathParams, body) => {
13
13
  })
14
14
  }
15
15
 
16
- const getSpectralRuleset = (pathParams) => {
16
+ const getSpectralRuleset = pathParams => {
17
17
  const { SWAGGERHUB_URL, SWAGGERHUB_API_KEY } = config.getConfig()
18
18
 
19
19
  return http({
@@ -8,15 +8,15 @@ const parseResponse = response => new Promise(resolve => {
8
8
  status: response.status,
9
9
  ok: response.ok,
10
10
  content,
11
- });
11
+ })
12
12
 
13
- const contentType = response.headers?.get('content-type') || '';
13
+ const contentType = response.headers?.get('content-type') || ''
14
14
  if (contentType.includes('application/zip')) {
15
15
  response.buffer().then(resolveContent)
16
16
  } else {
17
17
  response.text().then(resolveContent)
18
18
  }
19
- });
19
+ })
20
20
 
21
21
  const checkForErrors = ({ resolveStatus = [] } = {}) => response => {
22
22
  if (resolveStatus.includes(response.status) || response.ok) {
@@ -3,6 +3,8 @@ const { hasJsonStructure } = require('../../utils/general')
3
3
  const { CLIError } = require('@oclif/core').Errors
4
4
  const { errorMsg } = require('../../template-strings')
5
5
 
6
+ const noVersionRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+$/)
7
+ const apiNameRegex = new RegExp(/^[\w\-.]+$/)
6
8
  const optionalVersionRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+(\/[\w\-.]+)?(\/?)$/)
7
9
  const requiredVersionRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+\/[\w\-.]+(\/?)$/)
8
10
  const integrationIdentifierRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+\/[\w\-.]+\/[\w\-.]+(\/?)$/)
@@ -88,6 +90,8 @@ const resolvedParam = ({ resolved }) => resolved ? { resolved: true } : null
88
90
 
89
91
  module.exports = {
90
92
  getApiIdentifierArg,
93
+ apiNameRegex,
94
+ noVersionRegex,
91
95
  getDomainIdentifierArg,
92
96
  getIntegrationIdentifierArg,
93
97
  getProjectIdentifierArg,
@@ -5,6 +5,8 @@ const infoMsg = {
5
5
 
6
6
  ApiDelete: 'Deleted API \'{{owner}}/{{name}}\'',
7
7
 
8
+ ApiRename: 'Renamed API \'{{apiPath}}\' to \'{{newName}}\'',
9
+
8
10
  DomainCreate: 'Created domain \'{{owner}}/{{name}}\'',
9
11
 
10
12
  DomainDelete: 'Deleted domain \'{{owner}}/{{name}}\'',