swaggerhub-cli 0.13.0 → 0.15.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.
Files changed (72) hide show
  1. package/README.md +209 -122
  2. package/bin/run +5 -4
  3. package/oclif.manifest.json +283 -122
  4. package/package.json +14 -12
  5. package/src/check-node-version.js +3 -2
  6. package/src/commands/api/clone.js +66 -0
  7. package/src/commands/api/create.js +10 -10
  8. package/src/commands/api/delete.js +7 -7
  9. package/src/commands/api/get.js +9 -9
  10. package/src/commands/api/publish.js +7 -7
  11. package/src/commands/api/rename.js +8 -10
  12. package/src/commands/api/setdefault.js +6 -6
  13. package/src/commands/api/unpublish.js +5 -5
  14. package/src/commands/api/update.js +11 -11
  15. package/src/commands/api/validate/download-rules.js +11 -11
  16. package/src/commands/api/validate/index.js +10 -10
  17. package/src/commands/api/validate/local.js +11 -11
  18. package/src/commands/configure.js +8 -8
  19. package/src/commands/domain/clone.js +66 -0
  20. package/src/commands/domain/create.js +14 -14
  21. package/src/commands/domain/delete.js +7 -7
  22. package/src/commands/domain/get.js +8 -8
  23. package/src/commands/domain/publish.js +6 -6
  24. package/src/commands/domain/rename.js +78 -0
  25. package/src/commands/domain/setdefault.js +6 -6
  26. package/src/commands/domain/unpublish.js +6 -6
  27. package/src/commands/domain/update.js +11 -11
  28. package/src/commands/integration/create.js +7 -7
  29. package/src/commands/integration/delete.js +6 -6
  30. package/src/commands/integration/execute.js +6 -6
  31. package/src/commands/integration/get.js +9 -9
  32. package/src/commands/integration/list.js +7 -7
  33. package/src/commands/integration/update.js +6 -6
  34. package/src/commands/project/api/add.js +7 -9
  35. package/src/commands/project/api/remove.js +10 -13
  36. package/src/commands/project/create.js +9 -13
  37. package/src/commands/project/delete.js +7 -7
  38. package/src/commands/project/domain/add.js +7 -9
  39. package/src/commands/project/domain/remove.js +10 -13
  40. package/src/commands/project/get.js +8 -8
  41. package/src/commands/project/list.js +6 -6
  42. package/src/commands/project/member/list.js +8 -8
  43. package/src/commands/spectral/download.js +9 -9
  44. package/src/commands/spectral/upload.js +11 -11
  45. package/src/config/index.js +18 -4
  46. package/src/format-readme.js +3 -2
  47. package/src/help.js +2 -2
  48. package/src/hooks/setup-config.js +9 -5
  49. package/src/index.js +2 -2
  50. package/src/requests/api.js +3 -3
  51. package/src/requests/domain.js +3 -3
  52. package/src/requests/project.js +2 -2
  53. package/src/requests/spec.js +5 -5
  54. package/src/requests/spectral.js +3 -3
  55. package/src/requests/standardization.js +4 -4
  56. package/src/support/command/base-command.js +11 -12
  57. package/src/support/command/base-validate-command.js +3 -3
  58. package/src/support/command/handle-response.js +7 -5
  59. package/src/support/command/parse-input.js +8 -6
  60. package/src/support/command/update-command.js +5 -5
  61. package/src/support/http/default-headers.js +1 -1
  62. package/src/support/http/header-templates.js +2 -2
  63. package/src/support/http/index.js +7 -7
  64. package/src/support/http/proxy-agent.js +4 -4
  65. package/src/support/inquirer/index.js +4 -4
  66. package/src/support/inquirer/prompt-templates.js +3 -3
  67. package/src/support/isOnPrem.js +3 -3
  68. package/src/template-strings/errors.js +6 -6
  69. package/src/template-strings/index.js +3 -3
  70. package/src/template-strings/info.js +10 -4
  71. package/src/utils/definitions.js +8 -6
  72. package/src/utils/general.js +3 -3
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "swaggerhub-cli",
3
3
  "description": "SwaggerHub CLI",
4
- "version": "0.13.0",
4
+ "version": "0.15.0",
5
5
  "author": "SmartBear",
6
6
  "bin": {
7
7
  "swaggerhub": "./bin/run"
@@ -11,7 +11,7 @@
11
11
  "@oclif/core": "^3.26.3",
12
12
  "@oclif/plugin-help": "^6.0.21",
13
13
  "@oclif/plugin-plugins": "^5.0.21",
14
- "archiver": "^7.0.1",
14
+ "archiver": "^8.0.0",
15
15
  "deep-extend": "^0.6.0",
16
16
  "fs-extra": "^11.1.1",
17
17
  "http-proxy-agent": "^9.1.0",
@@ -27,27 +27,24 @@
27
27
  "devDependencies": {
28
28
  "@faker-js/faker": "^10.0.0",
29
29
  "@oclif/test": "^3.2.15",
30
+ "c8": "^12.0.0",
30
31
  "chai": "^6.3.0",
31
32
  "eslint": "^10.13.0",
32
33
  "eslint-plugin-chai-friendly": "^1.0.0",
33
34
  "eslint-plugin-immutable": "^1.0.0",
34
- "eslint-plugin-mocha": "^11.3.0",
35
+ "eslint-plugin-mocha": "^12.0.0",
35
36
  "eslint-plugin-n": "^18.3.0",
36
- "globby": "^16.2.0",
37
37
  "husky": "^9.0.1",
38
38
  "mocha": "^11.7.6",
39
39
  "nock": "^14.0.1",
40
- "nyc": "^18.0.0",
41
40
  "rewire": "^9.0.1",
42
- "sinon": "^22.0.0",
43
- "tmp": "^0.2.7"
41
+ "sinon": "^22.0.0"
44
42
  },
45
43
  "engines": {
46
- "node": ">=22.9.0",
44
+ "node": ">=22.12.0",
47
45
  "npm": ">=11.9.0"
48
46
  },
49
47
  "overrides": {
50
- "npm": "^11.9.0",
51
48
  "glob": "^10.5.0",
52
49
  "serialize-javascript": "^7.1.4"
53
50
  },
@@ -63,10 +60,15 @@
63
60
  ],
64
61
  "license": "Apache-2.0",
65
62
  "main": "src/index.js",
63
+ "type": "module",
64
+ "exports": {
65
+ ".": "./src/index.js",
66
+ "./package.json": "./package.json"
67
+ },
66
68
  "oclif": {
67
69
  "commands": "./src/commands",
68
70
  "hooks": {
69
- "init": "./src/hooks/setup-config"
71
+ "init": "./src/hooks/setup-config.js"
70
72
  },
71
73
  "bin": "swaggerhub",
72
74
  "plugins": [
@@ -93,14 +95,14 @@
93
95
  "description": "this topic supports the management of Spectral rulesets"
94
96
  }
95
97
  },
96
- "helpClass": "./src/help"
98
+ "helpClass": "./src/help.js"
97
99
  },
98
100
  "repository": "SmartBear/swaggerhub-cli",
99
101
  "scripts": {
100
102
  "postpack": "rm -f oclif.manifest.json",
101
103
  "prepack": "npx oclif manifest",
102
104
  "prepare": "husky",
103
- "test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
105
+ "test": "c8 mocha --forbid-only \"test/**/*.test.js\"",
104
106
  "lint": "eslint ./src ./test",
105
107
  "postinstall": "node ./src/check-node-version"
106
108
  }
@@ -1,5 +1,6 @@
1
- const semver = require('semver')
2
- const { engines } = require('../package.json')
1
+ import semver from 'semver'
2
+ import packageJson from '../package.json' with { type: 'json' }
3
+ const { engines } = packageJson
3
4
 
4
5
  const version = engines.node
5
6
 
@@ -0,0 +1,66 @@
1
+ import BaseCommand from '../../support/command/base-command.js'
2
+ import { Args, Flags, Errors } from '@oclif/core'
3
+ import { getApiIdentifierArg, apiNameRegex } from '../../support/command/parse-input.js'
4
+ import { errorMsg } from '../../template-strings/index.js'
5
+ import { postApi } from '../../requests/api.js'
6
+
7
+ const { CLIError } = Errors
8
+
9
+ const getNewVersion = args => {
10
+ const newVersion = args['NEW_VERSION']
11
+ if (!apiNameRegex.test(newVersion)) {
12
+ throw new CLIError(errorMsg.argsMustMatchFormat({ format: 'NEW_VERSION' }))
13
+ }
14
+ return newVersion
15
+ }
16
+
17
+ class CloneApiCommand extends BaseCommand {
18
+
19
+ async run() {
20
+ const { args, flags } = await this.parse(CloneApiCommand)
21
+
22
+ const apiPath = getApiIdentifierArg(args)
23
+ const newVersion = getNewVersion(args)
24
+ const body = { version: newVersion }
25
+ if (flags.visibility) body.private = flags.visibility === 'private'
26
+
27
+ this.log(`Cloning API: '${apiPath}' as version '${newVersion}'`)
28
+
29
+ await this.executeHttp({
30
+ execute: () => postApi({
31
+ pathParams: [apiPath, 'clone'],
32
+ body: JSON.stringify(body)
33
+ }),
34
+ onResolve: this.logCommandSuccess({ apiPath, newVersion }),
35
+ options: {}
36
+ })
37
+ }
38
+ }
39
+
40
+ CloneApiCommand.description = 'clone an API version as a new version'
41
+
42
+ CloneApiCommand.examples = [
43
+ 'swaggerhub api:clone organization/api/1.0.0 1.0.1',
44
+ 'swaggerhub api:clone organization/api/1.0.0 1.0.1 --visibility public'
45
+ ]
46
+
47
+ CloneApiCommand.args = {
48
+ 'OWNER/API_NAME/VERSION': Args.string({
49
+ required: true,
50
+ description: 'API version to clone'
51
+ }),
52
+ 'NEW_VERSION': Args.string({
53
+ required: true,
54
+ description: 'Version identifier of the new API version'
55
+ })
56
+ }
57
+
58
+ CloneApiCommand.flags = {
59
+ visibility: Flags.string({
60
+ description: 'visibility of the new version (defaults to the server setting)',
61
+ options: ['public', 'private']
62
+ }),
63
+ ...BaseCommand.flags
64
+ }
65
+
66
+ export default CloneApiCommand
@@ -1,10 +1,10 @@
1
- const { Flags, Args } = require('@oclif/core')
2
- const { readFileSync } = require('fs-extra')
3
- const { getApi, postApi } = require('../../requests/api')
4
- const { getApiIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
5
- const { getVersion, parseDefinition, getSpecification } = require('../../utils/definitions')
6
- const BaseCommand = require('../../support/command/base-command')
7
- const UpdateCommand = require('../../support/command/update-command')
1
+ import { Flags, Args } from '@oclif/core'
2
+ import { readFileSync } from 'node:fs'
3
+ import { getApi, postApi } from '../../requests/api.js'
4
+ import { getApiIdentifierArg, splitPathParams } from '../../support/command/parse-input.js'
5
+ import { getVersion, parseDefinition, getSpecification } from '../../utils/definitions.js'
6
+ import BaseCommand from '../../support/command/base-command.js'
7
+ import UpdateCommand from '../../support/command/update-command.js'
8
8
 
9
9
  const isApiNameAvailable = response => response.status === 404
10
10
 
@@ -106,7 +106,7 @@ CreateAPICommand.examples = [
106
106
  CreateAPICommand.args = {
107
107
  'OWNER/API_NAME/[VERSION]': Args.string({
108
108
  required: true,
109
- description: 'API to create on SwaggerHub'
109
+ description: 'API to create on Swagger'
110
110
  })
111
111
  }
112
112
 
@@ -117,7 +117,7 @@ CreateAPICommand.flags = {
117
117
  required: true
118
118
  }),
119
119
  visibility: Flags.string({
120
- description: 'visibility of API in SwaggerHub',
120
+ description: 'visibility of API in Swagger',
121
121
  options: ['public', 'private'],
122
122
  default: 'private'
123
123
  }),
@@ -137,4 +137,4 @@ CreateAPICommand.flags = {
137
137
  ...BaseCommand.flags
138
138
  }
139
139
 
140
- module.exports = CreateAPICommand
140
+ export default CreateAPICommand
@@ -1,8 +1,8 @@
1
- const { Flags, Args } = require('@oclif/core')
2
- const { deleteApi } = require('../../requests/api')
3
- const { getApiIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
4
- const BaseCommand = require('../../support/command/base-command')
5
- const inquirer = require('inquirer')
1
+ import { Flags, Args } from '@oclif/core'
2
+ import { deleteApi } from '../../requests/api.js'
3
+ import { getApiIdentifierArg, splitPathParams } from '../../support/command/parse-input.js'
4
+ import BaseCommand from '../../support/command/base-command.js'
5
+ import inquirer from 'inquirer'
6
6
 
7
7
  class DeleteAPICommand extends BaseCommand {
8
8
 
@@ -49,7 +49,7 @@ DeleteAPICommand.examples = [
49
49
  DeleteAPICommand.args = {
50
50
  'OWNER/API_NAME/[VERSION]': Args.string({
51
51
  required: true,
52
- description: 'API to delete on SwaggerHub'
52
+ description: 'API to delete on Swagger'
53
53
  })
54
54
  }
55
55
 
@@ -61,4 +61,4 @@ DeleteAPICommand.flags = {
61
61
  ...BaseCommand.flags
62
62
  }
63
63
 
64
- module.exports = DeleteAPICommand
64
+ export default DeleteAPICommand
@@ -1,9 +1,9 @@
1
- const { Flags, Args } = require('@oclif/core')
2
- const { getApiIdentifierArg, reqType, resolvedParam } = require('../../support/command/parse-input')
3
- const { hasJsonStructure, prettyPrintJSON } = require('../../utils/general')
4
- const { getApi } = require('../../requests/api')
5
- const { getResponseContent } = require('../../support/command/handle-response')
6
- const BaseCommand = require('../../support/command/base-command')
1
+ import { Flags, Args } from '@oclif/core'
2
+ import { getApiIdentifierArg, reqType, resolvedParam } from '../../support/command/parse-input.js'
3
+ import { hasJsonStructure, prettyPrintJSON } from '../../utils/general.js'
4
+ import { getApi } from '../../requests/api.js'
5
+ import { getResponseContent } from '../../support/command/handle-response.js'
6
+ import BaseCommand from '../../support/command/base-command.js'
7
7
 
8
8
  class GetAPICommand extends BaseCommand {
9
9
  constructor(...props) {
@@ -48,7 +48,7 @@ GetAPICommand.examples = [
48
48
  GetAPICommand.args = {
49
49
  'OWNER/API_NAME/[VERSION]': Args.string({
50
50
  required: true,
51
- description: 'API to fetch from Swaggerhub'
51
+ description: 'API to fetch from Swagger'
52
52
  })
53
53
  }
54
54
 
@@ -59,9 +59,9 @@ GetAPICommand.flags = {
59
59
  }),
60
60
  resolved: Flags.boolean({
61
61
  char: 'r',
62
- description: 'gets the resolved API definition (supported in v1.25+). '
62
+ description: 'gets the resolved API definition'
63
63
  }),
64
64
  ...BaseCommand.flags
65
65
  }
66
66
 
67
- module.exports = GetAPICommand
67
+ export default GetAPICommand
@@ -1,8 +1,8 @@
1
- const { Flags, Args } = require('@oclif/core')
2
- const { getApiIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
3
- const BaseCommand = require('../../support/command/base-command')
4
- const UpdateCommand = require('../../support/command/update-command')
5
- const inquirer = require('inquirer')
1
+ import { Flags, Args } from '@oclif/core'
2
+ import { getApiIdentifierArg, splitPathParams } from '../../support/command/parse-input.js'
3
+ import BaseCommand from '../../support/command/base-command.js'
4
+ import UpdateCommand from '../../support/command/update-command.js'
5
+ import inquirer from 'inquirer'
6
6
 
7
7
  class PublishCommand extends UpdateCommand {
8
8
  async run() {
@@ -38,7 +38,7 @@ PublishCommand.examples = [
38
38
  PublishCommand.args = {
39
39
  'OWNER/API_NAME/VERSION': Args.string({
40
40
  required: true,
41
- description: 'API to publish on Swaggerhub'
41
+ description: 'API to publish on Swagger'
42
42
  })
43
43
  }
44
44
 
@@ -50,4 +50,4 @@ PublishCommand.flags = {
50
50
  ...BaseCommand.flags
51
51
  }
52
52
 
53
- module.exports = PublishCommand
53
+ export default PublishCommand
@@ -1,12 +1,10 @@
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')
1
+ import BaseCommand from '../../support/command/base-command.js'
2
+ import { Args, Errors } from '@oclif/core'
3
+ import { noVersionRegex, apiNameRegex } from '../../support/command/parse-input.js'
4
+ import { errorMsg } from '../../template-strings/index.js'
5
+ import { postApi } from '../../requests/api.js'
6
+
7
+ const { CLIError } = Errors
10
8
 
11
9
  const getApiToRename = args => {
12
10
  const newName = args['OWNER/API_NAME']
@@ -66,4 +64,4 @@ RenameApiCommand.args = {
66
64
 
67
65
  RenameApiCommand.flags = BaseCommand.flags
68
66
 
69
- module.exports = RenameApiCommand
67
+ export default RenameApiCommand
@@ -1,7 +1,7 @@
1
- const { Args } = require('@oclif/core')
2
- const { getApiIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
3
- const BaseCommand = require('../../support/command/base-command')
4
- const UpdateCommand = require('../../support/command/update-command')
1
+ import { Args } from '@oclif/core'
2
+ import { getApiIdentifierArg, splitPathParams } from '../../support/command/parse-input.js'
3
+ import BaseCommand from '../../support/command/base-command.js'
4
+ import UpdateCommand from '../../support/command/update-command.js'
5
5
 
6
6
  class SetDefaultCommand extends UpdateCommand {
7
7
 
@@ -23,10 +23,10 @@ SetDefaultCommand.examples = [
23
23
  SetDefaultCommand.args = {
24
24
  'OWNER/API_NAME/VERSION': Args.string({
25
25
  required: true,
26
- description: 'API to set as default on Swaggerhub'
26
+ description: 'API to set as default on Swagger'
27
27
  })
28
28
  }
29
29
 
30
30
  SetDefaultCommand.flags = BaseCommand.flags
31
31
 
32
- module.exports = SetDefaultCommand
32
+ export default SetDefaultCommand
@@ -1,7 +1,7 @@
1
- const { Args } = require('@oclif/core')
2
- const { getApiIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
3
- const BaseCommand = require('../../support/command/base-command')
4
- const UpdateCommand = require('../../support/command/update-command')
1
+ import { Args } from '@oclif/core'
2
+ import { getApiIdentifierArg, splitPathParams } from '../../support/command/parse-input.js'
3
+ import BaseCommand from '../../support/command/base-command.js'
4
+ import UpdateCommand from '../../support/command/update-command.js'
5
5
 
6
6
  class UnpublishCommand extends UpdateCommand {
7
7
 
@@ -29,4 +29,4 @@ UnpublishCommand.args = {
29
29
 
30
30
  UnpublishCommand.flags = BaseCommand.flags
31
31
 
32
- module.exports = UnpublishCommand
32
+ export default UnpublishCommand
@@ -1,10 +1,10 @@
1
- const { Flags, Args } = require('@oclif/core')
2
- const { readFileSync } = require('fs-extra')
3
- const { getApi, postApi } = require('../../requests/api')
4
- const { getApiIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
5
- const { getVersion, parseDefinition } = require('../../utils/definitions')
6
- const BaseCommand = require('../../support/command/base-command')
7
- const UpdateCommand = require('../../support/command/update-command')
1
+ import { Flags, Args } from '@oclif/core'
2
+ import { readFileSync } from 'node:fs'
3
+ import { getApi, postApi } from '../../requests/api.js'
4
+ import { getApiIdentifierArg, splitPathParams } from '../../support/command/parse-input.js'
5
+ import { getVersion, parseDefinition } from '../../utils/definitions.js'
6
+ import BaseCommand from '../../support/command/base-command.js'
7
+ import UpdateCommand from '../../support/command/update-command.js'
8
8
 
9
9
  class UpdateAPICommand extends UpdateCommand {
10
10
 
@@ -65,7 +65,7 @@ class UpdateAPICommand extends UpdateCommand {
65
65
  UpdateAPICommand.description = `update an API
66
66
  The API version from the file will be used unless the version is specified in the command argument.
67
67
  When no file is specified then the default API version will be updated.
68
- The API visibility can be changed by using visibility flag.
68
+ The API visibility can be changed by using the --visibility flag.
69
69
  `
70
70
 
71
71
  UpdateAPICommand.examples = [
@@ -80,7 +80,7 @@ UpdateAPICommand.examples = [
80
80
  UpdateAPICommand.args = {
81
81
  'OWNER/API_NAME/[VERSION]': Args.string({
82
82
  required: true,
83
- description: 'API to update on SwaggerHub'
83
+ description: 'API to update on Swagger'
84
84
  })
85
85
  }
86
86
 
@@ -92,7 +92,7 @@ UpdateAPICommand.flags = {
92
92
  multiple: false
93
93
  }),
94
94
  visibility: Flags.string({
95
- description: 'visibility of API in SwaggerHub',
95
+ description: 'visibility of API in Swagger',
96
96
  options: ['public', 'private']
97
97
  }),
98
98
  published: Flags.string({
@@ -107,4 +107,4 @@ UpdateAPICommand.flags = {
107
107
  ...BaseCommand.flags
108
108
  }
109
109
 
110
- module.exports = UpdateAPICommand
110
+ export default UpdateAPICommand
@@ -1,8 +1,8 @@
1
- const { Flags, Args } = require('@oclif/core')
2
- const BaseCommand = require('../../../support/command/base-command')
3
- const { pipeAsync } = require('../../../utils/general')
4
- const { getResponseContent } = require('../../../support/command/handle-response')
5
- const { getStandardization } = require('../../../requests/standardization')
1
+ import { Flags, Args } from '@oclif/core'
2
+ import BaseCommand from '../../../support/command/base-command.js'
3
+ import { pipeAsync } from '../../../utils/general.js'
4
+ import { getResponseContent } from '../../../support/command/handle-response.js'
5
+ import { getStandardization } from '../../../requests/standardization.js'
6
6
 
7
7
  class ValidateDownloadRulesCommand extends BaseCommand {
8
8
  async run() {
@@ -27,11 +27,11 @@ class ValidateDownloadRulesCommand extends BaseCommand {
27
27
  }
28
28
  }
29
29
 
30
- ValidateDownloadRulesCommand.description = `Get existing SwaggerHub's organization standardization ruleset.
31
- Requires organization name argument. An error will occur if provided organization doesn't exist
30
+ ValidateDownloadRulesCommand.description = `Get an organization's existing standardization ruleset from Swagger.
31
+ Requires organization name argument. An error will occur if the provided organization doesn't exist
32
32
  or your account is not permitted to access that organization's settings.
33
- If the flag \`-s\` or \`--include-system-rules\` is used, the returned ruleset will also include SwaggerHub system rules.
34
- If the flag \`-d\` or \`--include-disabled-rules\` is used, the returned ruleset will also include disabled custom rules`
33
+ If the flag \`-s\` or \`--include-system-rules\` is used, the returned ruleset will also include Swagger system rules.
34
+ If the flag \`-d\` or \`--include-disabled-rules\` is used, the returned ruleset will also include disabled custom rules.`
35
35
 
36
36
  ValidateDownloadRulesCommand.examples = [
37
37
  'swaggerhub api:validate:download-rules myOrg -s',
@@ -41,7 +41,7 @@ ValidateDownloadRulesCommand.examples = [
41
41
  ValidateDownloadRulesCommand.args = {
42
42
  'OWNER': Args.string({
43
43
  required: true,
44
- description: 'Which organization standardization rules to fetch from SwaggerHub'
44
+ description: 'Which organization standardization rules to fetch from Swagger'
45
45
  })
46
46
  }
47
47
  ValidateDownloadRulesCommand.flags = {
@@ -57,4 +57,4 @@ ValidateDownloadRulesCommand.flags = {
57
57
  }),
58
58
  ...BaseCommand.flags
59
59
  }
60
- module.exports = ValidateDownloadRulesCommand
60
+ export default ValidateDownloadRulesCommand
@@ -1,10 +1,10 @@
1
- const { Args } = require('@oclif/core')
2
- const BaseValidateCommand = require('../../../support/command/base-validate-command')
3
- const { getApiIdentifierArg } = require('../../../support/command/parse-input')
4
- const { getApi } = require('../../../requests/api')
5
- const { pipeAsync } = require('../../../utils/general')
6
- const { getResponseContent } = require('../../../support/command/handle-response')
7
- const { isOnPrem } = require('../../../support/isOnPrem')
1
+ import { Args } from '@oclif/core'
2
+ import BaseValidateCommand from '../../../support/command/base-validate-command.js'
3
+ import { getApiIdentifierArg } from '../../../support/command/parse-input.js'
4
+ import { getApi } from '../../../requests/api.js'
5
+ import { pipeAsync } from '../../../utils/general.js'
6
+ import { getResponseContent } from '../../../support/command/handle-response.js'
7
+ import { isOnPrem } from '../../../support/isOnPrem.js'
8
8
 
9
9
  class ValidateCommand extends BaseValidateCommand {
10
10
  async run() {
@@ -52,7 +52,7 @@ class ValidateCommand extends BaseValidateCommand {
52
52
  ValidateCommand.description = `Get validation result for an API version
53
53
  When VERSION is not included in the argument, the default version will be validated.
54
54
  An error will occur if the API version does not exist.
55
- If the flag \`-c\` or \`--failOnCritical\` is used and there are standardization
55
+ If the flag \`-c\` or \`--fail-on-critical\` is used and there are standardization
56
56
  errors with \`Critical\` severity present, the command will exit with error code \`1\`.
57
57
  `
58
58
 
@@ -65,11 +65,11 @@ ValidateCommand.examples = [
65
65
  ValidateCommand.args = {
66
66
  'OWNER/API_NAME/[VERSION]': Args.string({
67
67
  required: true,
68
- description: 'API to fetch validation errors for from Swaggerhub'
68
+ description: 'API to fetch validation errors for'
69
69
  })
70
70
  }
71
71
 
72
72
  ValidateCommand.flags = {
73
73
  ...BaseValidateCommand.flags
74
74
  }
75
- module.exports = ValidateCommand
75
+ export default ValidateCommand
@@ -1,10 +1,10 @@
1
- const { Flags } = require('@oclif/core')
2
- const BaseValidateCommand = require('../../../support/command/base-validate-command')
3
- const { pipeAsync } = require('../../../utils/general')
4
- const { getResponseContent } = require('../../../support/command/handle-response')
5
- const { postStandardization } = require('../../../requests/standardization')
6
- const { parseDefinition, getSpecification, getVersion } = require('../../../utils/definitions')
7
- const { readFileSync } = require('fs-extra')
1
+ import { Flags } from '@oclif/core'
2
+ import BaseValidateCommand from '../../../support/command/base-validate-command.js'
3
+ import { pipeAsync } from '../../../utils/general.js'
4
+ import { getResponseContent } from '../../../support/command/handle-response.js'
5
+ import { postStandardization } from '../../../requests/standardization.js'
6
+ import { parseDefinition, getSpecification, getVersion } from '../../../utils/definitions.js'
7
+ import { readFileSync } from 'node:fs'
8
8
 
9
9
  class ValidateLocalCommand extends BaseValidateCommand {
10
10
  async run() {
@@ -34,14 +34,14 @@ class ValidateLocalCommand extends BaseValidateCommand {
34
34
  }
35
35
  }
36
36
 
37
- ValidateLocalCommand.description = `Runs a scan against a local API definition using the organization's standardization configuration on SwaggerHub.
38
- If the flag \`-c\` or \`--failOnCritical\` is used and there are standardization
37
+ ValidateLocalCommand.description = `Runs a scan against a local API definition using the organization's standardization configuration on Swagger.
38
+ If the flag \`-c\` or \`--fail-on-critical\` is used and there are standardization
39
39
  errors with \`Critical\` severity present, the command will exit with error code \`1\`.
40
40
  `
41
41
 
42
42
  ValidateLocalCommand.examples = [
43
43
  'swaggerhub api:validate:local -o myOrg -f ./my-api.yaml -c -j ',
44
- 'swaggerhub api:validate:local --organization myOrg --file ./my-api/json --fail-on-critical --json',
44
+ 'swaggerhub api:validate:local --organization myOrg --file ./my-api.json --fail-on-critical --json',
45
45
  ]
46
46
 
47
47
  ValidateLocalCommand.flags = {
@@ -57,4 +57,4 @@ ValidateLocalCommand.flags = {
57
57
  }),
58
58
  ...BaseValidateCommand.flags
59
59
  }
60
- module.exports = ValidateLocalCommand
60
+ export default ValidateLocalCommand
@@ -1,8 +1,8 @@
1
- const path = require('path')
2
- const BaseCommand = require('../support/command/base-command')
3
- const inquirer = require('inquirer')
4
- const { getPrompts } = require('../support/inquirer')
5
- const { setConfig, getConfig } = require('../config')
1
+ import path from 'path'
2
+ import BaseCommand from '../support/command/base-command.js'
3
+ import inquirer from 'inquirer'
4
+ import { getPrompts } from '../support/inquirer/index.js'
5
+ import { setConfig, getConfig } from '../config/index.js'
6
6
 
7
7
  class ConfigureCommand extends BaseCommand {
8
8
  async run() {
@@ -18,10 +18,10 @@ class ConfigureCommand extends BaseCommand {
18
18
  }
19
19
 
20
20
  ConfigureCommand.description = `configure application settings
21
- Enter the SwaggerHub URL - default is https://api.swaggerhub.com
22
- Customers with on-premise installations need to point this to their on-premise API, which is http(s)://{swaggerhub-host}/v1
21
+ Enter the Swagger URL - default is https://api.swaggerhub.com
22
+ Customers with on-premise installations (version 2.x) need to point this to their on-premise API, which is http(s)://{swaggerhub-host}/v1
23
23
  Enter the API Key - this can be retrieved from https://app.swaggerhub.com/settings/apiKey
24
24
  You can set these as environment variables: SWAGGERHUB_URL, SWAGGERHUB_API_KEY. These take priority over config settings.
25
25
  `
26
- module.exports = ConfigureCommand
26
+ export default ConfigureCommand
27
27
 
@@ -0,0 +1,66 @@
1
+ import BaseCommand from '../../support/command/base-command.js'
2
+ import { Args, Flags, Errors } from '@oclif/core'
3
+ import { getDomainIdentifierArg, apiNameRegex } from '../../support/command/parse-input.js'
4
+ import { errorMsg } from '../../template-strings/index.js'
5
+ import { postDomain } from '../../requests/domain.js'
6
+
7
+ const { CLIError } = Errors
8
+
9
+ const getNewVersion = args => {
10
+ const newVersion = args['NEW_VERSION']
11
+ if (!apiNameRegex.test(newVersion)) {
12
+ throw new CLIError(errorMsg.argsMustMatchFormat({ format: 'NEW_VERSION' }))
13
+ }
14
+ return newVersion
15
+ }
16
+
17
+ class CloneDomainCommand extends BaseCommand {
18
+
19
+ async run() {
20
+ const { args, flags } = await this.parse(CloneDomainCommand)
21
+
22
+ const domainPath = getDomainIdentifierArg(args)
23
+ const newVersion = getNewVersion(args)
24
+ const body = { version: newVersion }
25
+ if (flags.visibility) body.private = flags.visibility === 'private'
26
+
27
+ this.log(`Cloning domain: '${domainPath}' as version '${newVersion}'`)
28
+
29
+ await this.executeHttp({
30
+ execute: () => postDomain({
31
+ pathParams: [domainPath, 'clone'],
32
+ body: JSON.stringify(body)
33
+ }),
34
+ onResolve: this.logCommandSuccess({ domainPath, newVersion }),
35
+ options: {}
36
+ })
37
+ }
38
+ }
39
+
40
+ CloneDomainCommand.description = 'clone a domain version as a new version'
41
+
42
+ CloneDomainCommand.examples = [
43
+ 'swaggerhub domain:clone organization/domain/1.0.0 1.0.1',
44
+ 'swaggerhub domain:clone organization/domain/1.0.0 1.0.1 --visibility public'
45
+ ]
46
+
47
+ CloneDomainCommand.args = {
48
+ 'OWNER/DOMAIN_NAME/VERSION': Args.string({
49
+ required: true,
50
+ description: 'Domain version to clone'
51
+ }),
52
+ 'NEW_VERSION': Args.string({
53
+ required: true,
54
+ description: 'Version identifier of the new domain version'
55
+ })
56
+ }
57
+
58
+ CloneDomainCommand.flags = {
59
+ visibility: Flags.string({
60
+ description: 'visibility of the new version (defaults to the server setting)',
61
+ options: ['public', 'private']
62
+ }),
63
+ ...BaseCommand.flags
64
+ }
65
+
66
+ export default CloneDomainCommand