swaggerhub-cli 0.10.0 → 0.11.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/README.md CHANGED
@@ -16,7 +16,7 @@ The SwaggerHub CLI enables teams to build automation and workflows around Swagge
16
16
  * [Contributing](#contributing)
17
17
  <!-- tocstop -->
18
18
  # Requirements
19
- Node.js 20.x or later.
19
+ Node.js 20.17 or later.
20
20
 
21
21
  # Installation
22
22
  ```sh-session
@@ -261,6 +261,49 @@
261
261
  "publish.js"
262
262
  ]
263
263
  },
264
+ "api:rename": {
265
+ "aliases": [],
266
+ "args": {
267
+ "OWNER/API_NAME": {
268
+ "description": "API to be renamed",
269
+ "name": "OWNER/API_NAME",
270
+ "required": true
271
+ },
272
+ "API_NEW_NAME": {
273
+ "description": "New name for the API",
274
+ "name": "API_NEW_NAME",
275
+ "required": true
276
+ }
277
+ },
278
+ "description": "rename an API",
279
+ "examples": [
280
+ "swaggerhub api:rename organization/apiOldName apiNewName"
281
+ ],
282
+ "flags": {
283
+ "help": {
284
+ "char": "h",
285
+ "description": "Show CLI help.",
286
+ "name": "help",
287
+ "allowNo": false,
288
+ "type": "boolean"
289
+ }
290
+ },
291
+ "hasDynamicHelp": false,
292
+ "hiddenAliases": [],
293
+ "id": "api:rename",
294
+ "pluginAlias": "swaggerhub-cli",
295
+ "pluginName": "swaggerhub-cli",
296
+ "pluginType": "core",
297
+ "strict": true,
298
+ "enableJsonFlag": false,
299
+ "isESM": false,
300
+ "relativePath": [
301
+ "src",
302
+ "commands",
303
+ "api",
304
+ "rename.js"
305
+ ]
306
+ },
264
307
  "api:setdefault": {
265
308
  "aliases": [],
266
309
  "args": {
@@ -1698,5 +1741,5 @@
1698
1741
  ]
1699
1742
  }
1700
1743
  },
1701
- "version": "0.10.0"
1744
+ "version": "0.11.0"
1702
1745
  }
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.11.0",
5
5
  "author": "SmartBear",
6
6
  "bin": {
7
7
  "swaggerhub": "./bin/run"
@@ -22,6 +22,7 @@
22
22
  "unzipper": "^0.12.3"
23
23
  },
24
24
  "devDependencies": {
25
+ "@faker-js/faker": "^10.0.0",
25
26
  "@oclif/test": "^3.2.10",
26
27
  "chai": "^4.3.10",
27
28
  "eslint": "^9.0.0",
@@ -31,15 +32,20 @@
31
32
  "eslint-plugin-node": "^11.1.0",
32
33
  "globby": "^14.0.0",
33
34
  "husky": "^9.0.1",
34
- "mocha": "^11.1.0",
35
+ "mocha": "^11.7.5",
35
36
  "nock": "^14.0.1",
36
- "nyc": "^17.0.0",
37
+ "nyc": "^18.0.0",
37
38
  "rewire": "^7.0.0",
38
39
  "sinon": "^19.0.2",
39
- "tmp": "^0.2.1"
40
+ "tmp": "^0.2.5"
40
41
  },
41
42
  "engines": {
42
- "node": ">=20.0.0"
43
+ "node": "^20.17.0 || >=22.9.0",
44
+ "npm": ">=11.0.0"
45
+ },
46
+ "overrides": {
47
+ "npm": "^11.9.0",
48
+ "glob": "^10.5.0"
43
49
  },
44
50
  "files": [
45
51
  "/bin",
@@ -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
+ class RenameApiCommand extends BaseCommand {
12
+
13
+ async run() {
14
+ const { args } = await this.parse(RenameApiCommand)
15
+
16
+ const apiPath = getApiToRename(args)
17
+ const newName = getApiNewName(args)
18
+
19
+ this.log(`Renaming API: '${apiPath}' to '${newName}'`)
20
+
21
+ await this.executeHttp({
22
+ execute: () => postApi(
23
+ {
24
+ pathParams: [apiPath, 'rename'],
25
+ queryParams: { 'newName': newName },
26
+ body: '{}'
27
+ }),
28
+ onResolve: this.logCommandSuccess({apiPath, newName}),
29
+ options: {}
30
+ })
31
+ }
32
+ }
33
+
34
+ const getApiToRename = args => {
35
+ const newName = args['OWNER/API_NAME']
36
+ if (!noVersionRegex.test(newName)) {
37
+ throw new CLIError(errorMsg.argsMustMatchFormat({format: 'OWNER/API_NAME'}))
38
+ }
39
+ return newName
40
+ }
41
+
42
+ const getApiNewName = args => {
43
+ const newName = args['API_NEW_NAME']
44
+ if (!apiNameRegex.test(newName)) {
45
+ throw new CLIError(errorMsg.argsMustMatchFormat({format: 'API_NEW_NAME'}))
46
+ }
47
+ return newName
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
@@ -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}}\'',