swaggerhub-cli 0.9.1 → 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 +52 -1
- package/oclif.manifest.json +130 -1
- package/package.json +19 -8
- package/src/commands/api/rename.js +69 -0
- package/src/commands/spectral/download.js +69 -0
- package/src/commands/spectral/upload.js +59 -0
- package/src/requests/spectral.js +30 -0
- package/src/support/command/handle-response.js +13 -4
- package/src/support/command/parse-input.js +15 -0
- package/src/template-strings/errors.js +2 -0
- package/src/template-strings/info.js +2 -0
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
|
|
19
|
+
Node.js 20.17 or later.
|
|
20
20
|
|
|
21
21
|
# Installation
|
|
22
22
|
```sh-session
|
|
@@ -146,6 +146,8 @@ USAGE
|
|
|
146
146
|
* [`swaggerhub project:get OWNER/PROJECT_NAME`](#swaggerhub-projectget)
|
|
147
147
|
* [`swaggerhub project:list [OWNER]`](#swaggerhub-projectlist)
|
|
148
148
|
* [`swaggerhub project:member:list OWNER/PROJECT_NAME`](#swaggerhub-projectmemberlist)
|
|
149
|
+
* [`swaggerhub spectral:upload OWNER/RULESET_NAME directory`](#swaggerhub-spectralupload)
|
|
150
|
+
* [`swaggerhub spectral:download OWNER/RULESET_NAME directory`](#swaggerhub-spectraldownload)
|
|
149
151
|
|
|
150
152
|
## `swaggerhub api:create`
|
|
151
153
|
|
|
@@ -1372,6 +1374,55 @@ EXAMPLES
|
|
|
1372
1374
|
```
|
|
1373
1375
|
|
|
1374
1376
|
_See code: [src/commands/project/member/list.js](https://github.com/SmartBear/swaggerhub-cli/blob/v0.9.1/src/commands/project/member/list.js)_
|
|
1377
|
+
|
|
1378
|
+
## `swaggerhub spectral:upload`
|
|
1379
|
+
|
|
1380
|
+
Create or update organization's Spectral ruleset
|
|
1381
|
+
|
|
1382
|
+
```
|
|
1383
|
+
USAGE
|
|
1384
|
+
$ swaggerhub spectral:upload OWNER/RULESET_NAME directory [-h]
|
|
1385
|
+
|
|
1386
|
+
ARGUMENTS
|
|
1387
|
+
OWNER/RULESET_NAME The Spectral ruleset details for SwaggerHub organization
|
|
1388
|
+
directory Relative path to directory with ruleset files
|
|
1389
|
+
|
|
1390
|
+
FLAGS
|
|
1391
|
+
-h, --help Show CLI help.
|
|
1392
|
+
|
|
1393
|
+
DESCRIPTION
|
|
1394
|
+
Create or update organization's Spectral ruleset
|
|
1395
|
+
|
|
1396
|
+
EXAMPLES
|
|
1397
|
+
$ swaggerhub spectral:upload my_organization/my_api_ruleset rules
|
|
1398
|
+
```
|
|
1399
|
+
|
|
1400
|
+
_See code: [src/commands/spectral/upload.js](https://github.com/SmartBear/swaggerhub-cli/blob/v0.9.1/src/commands/spectral/upload.js)_
|
|
1401
|
+
|
|
1402
|
+
|
|
1403
|
+
## `swaggerhub spectral:download`
|
|
1404
|
+
|
|
1405
|
+
Fetch organization's Spectral ruleset
|
|
1406
|
+
|
|
1407
|
+
```
|
|
1408
|
+
USAGE
|
|
1409
|
+
$ swaggerhub spectral:download OWNER/RULESET_NAME directory [-h]
|
|
1410
|
+
|
|
1411
|
+
ARGUMENTS
|
|
1412
|
+
OWNER/RULESET_NAME The Spectral ruleset details for SwaggerHub organization
|
|
1413
|
+
directory Relative path to directory the ruleset files should be saved to
|
|
1414
|
+
|
|
1415
|
+
FLAGS
|
|
1416
|
+
-h, --help Show CLI help.
|
|
1417
|
+
|
|
1418
|
+
DESCRIPTION
|
|
1419
|
+
Fetch organization's Spectral ruleset
|
|
1420
|
+
|
|
1421
|
+
EXAMPLES
|
|
1422
|
+
$ swaggerhub spectral:download my_organization/my_api_ruleset rules
|
|
1423
|
+
```
|
|
1424
|
+
|
|
1425
|
+
_See code: [src/commands/spectral/download.js](https://github.com/SmartBear/swaggerhub-cli/blob/v0.9.1/src/commands/spectral/download.js)_
|
|
1375
1426
|
<!-- commandsstop -->
|
|
1376
1427
|
|
|
1377
1428
|
# Plugins
|
package/oclif.manifest.json
CHANGED
|
@@ -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": {
|
|
@@ -1219,6 +1262,92 @@
|
|
|
1219
1262
|
"list.js"
|
|
1220
1263
|
]
|
|
1221
1264
|
},
|
|
1265
|
+
"spectral:download": {
|
|
1266
|
+
"aliases": [],
|
|
1267
|
+
"args": {
|
|
1268
|
+
"OWNER/RULESET_NAME": {
|
|
1269
|
+
"description": "Organization's Spectral ruleset to create or update on SwaggerHub",
|
|
1270
|
+
"name": "OWNER/RULESET_NAME",
|
|
1271
|
+
"required": true
|
|
1272
|
+
},
|
|
1273
|
+
"directory": {
|
|
1274
|
+
"description": "Relative path to directory the ruleset files should be saved to",
|
|
1275
|
+
"name": "directory",
|
|
1276
|
+
"required": true
|
|
1277
|
+
}
|
|
1278
|
+
},
|
|
1279
|
+
"description": "Fetch organization's Spectral ruleset",
|
|
1280
|
+
"examples": [
|
|
1281
|
+
"swaggerhub spectral:download my_organization/my_api_ruleset rules/"
|
|
1282
|
+
],
|
|
1283
|
+
"flags": {
|
|
1284
|
+
"help": {
|
|
1285
|
+
"char": "h",
|
|
1286
|
+
"description": "Show CLI help.",
|
|
1287
|
+
"name": "help",
|
|
1288
|
+
"allowNo": false,
|
|
1289
|
+
"type": "boolean"
|
|
1290
|
+
}
|
|
1291
|
+
},
|
|
1292
|
+
"hasDynamicHelp": false,
|
|
1293
|
+
"hiddenAliases": [],
|
|
1294
|
+
"id": "spectral:download",
|
|
1295
|
+
"pluginAlias": "swaggerhub-cli",
|
|
1296
|
+
"pluginName": "swaggerhub-cli",
|
|
1297
|
+
"pluginType": "core",
|
|
1298
|
+
"strict": true,
|
|
1299
|
+
"enableJsonFlag": false,
|
|
1300
|
+
"isESM": false,
|
|
1301
|
+
"relativePath": [
|
|
1302
|
+
"src",
|
|
1303
|
+
"commands",
|
|
1304
|
+
"spectral",
|
|
1305
|
+
"download.js"
|
|
1306
|
+
]
|
|
1307
|
+
},
|
|
1308
|
+
"spectral:upload": {
|
|
1309
|
+
"aliases": [],
|
|
1310
|
+
"args": {
|
|
1311
|
+
"OWNER/RULESET_NAME": {
|
|
1312
|
+
"description": "Organization's Spectral ruleset to create or update on SwaggerHub",
|
|
1313
|
+
"name": "OWNER/RULESET_NAME",
|
|
1314
|
+
"required": true
|
|
1315
|
+
},
|
|
1316
|
+
"directory": {
|
|
1317
|
+
"description": "Relative path to directory with ruleset files",
|
|
1318
|
+
"name": "directory",
|
|
1319
|
+
"required": true
|
|
1320
|
+
}
|
|
1321
|
+
},
|
|
1322
|
+
"description": "Create or update organization's Spectral ruleset",
|
|
1323
|
+
"examples": [
|
|
1324
|
+
"swaggerhub spectral:upload my_organization/my_api_ruleset rules/"
|
|
1325
|
+
],
|
|
1326
|
+
"flags": {
|
|
1327
|
+
"help": {
|
|
1328
|
+
"char": "h",
|
|
1329
|
+
"description": "Show CLI help.",
|
|
1330
|
+
"name": "help",
|
|
1331
|
+
"allowNo": false,
|
|
1332
|
+
"type": "boolean"
|
|
1333
|
+
}
|
|
1334
|
+
},
|
|
1335
|
+
"hasDynamicHelp": false,
|
|
1336
|
+
"hiddenAliases": [],
|
|
1337
|
+
"id": "spectral:upload",
|
|
1338
|
+
"pluginAlias": "swaggerhub-cli",
|
|
1339
|
+
"pluginName": "swaggerhub-cli",
|
|
1340
|
+
"pluginType": "core",
|
|
1341
|
+
"strict": true,
|
|
1342
|
+
"enableJsonFlag": false,
|
|
1343
|
+
"isESM": false,
|
|
1344
|
+
"relativePath": [
|
|
1345
|
+
"src",
|
|
1346
|
+
"commands",
|
|
1347
|
+
"spectral",
|
|
1348
|
+
"upload.js"
|
|
1349
|
+
]
|
|
1350
|
+
},
|
|
1222
1351
|
"api:validate:download-rules": {
|
|
1223
1352
|
"aliases": [],
|
|
1224
1353
|
"args": {
|
|
@@ -1612,5 +1741,5 @@
|
|
|
1612
1741
|
]
|
|
1613
1742
|
}
|
|
1614
1743
|
},
|
|
1615
|
-
"version": "0.
|
|
1744
|
+
"version": "0.11.0"
|
|
1616
1745
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swaggerhub-cli",
|
|
3
3
|
"description": "SwaggerHub CLI",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.11.0",
|
|
5
5
|
"author": "SmartBear",
|
|
6
6
|
"bin": {
|
|
7
7
|
"swaggerhub": "./bin/run"
|
|
@@ -11,18 +11,20 @@
|
|
|
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
15
|
"deep-extend": "^0.6.0",
|
|
15
16
|
"fs-extra": "^11.1.1",
|
|
16
17
|
"inquirer": "^8.2.5",
|
|
17
18
|
"js-yaml": "^4.1.0",
|
|
18
19
|
"json-templates": "^5.0.0",
|
|
19
20
|
"node-fetch": "^2.6.12",
|
|
20
|
-
"semver": "^7.6.0"
|
|
21
|
+
"semver": "^7.6.0",
|
|
22
|
+
"unzipper": "^0.12.3"
|
|
21
23
|
},
|
|
22
24
|
"devDependencies": {
|
|
25
|
+
"@faker-js/faker": "^10.0.0",
|
|
23
26
|
"@oclif/test": "^3.2.10",
|
|
24
27
|
"chai": "^4.3.10",
|
|
25
|
-
"sinon": "^18.0.0",
|
|
26
28
|
"eslint": "^9.0.0",
|
|
27
29
|
"eslint-plugin-chai-friendly": "^1.0.0",
|
|
28
30
|
"eslint-plugin-immutable": "^1.0.0",
|
|
@@ -30,14 +32,20 @@
|
|
|
30
32
|
"eslint-plugin-node": "^11.1.0",
|
|
31
33
|
"globby": "^14.0.0",
|
|
32
34
|
"husky": "^9.0.1",
|
|
33
|
-
"mocha": "^
|
|
34
|
-
"nock": "^
|
|
35
|
-
"nyc": "^
|
|
35
|
+
"mocha": "^11.7.5",
|
|
36
|
+
"nock": "^14.0.1",
|
|
37
|
+
"nyc": "^18.0.0",
|
|
36
38
|
"rewire": "^7.0.0",
|
|
37
|
-
"
|
|
39
|
+
"sinon": "^19.0.2",
|
|
40
|
+
"tmp": "^0.2.5"
|
|
38
41
|
},
|
|
39
42
|
"engines": {
|
|
40
|
-
"node": "
|
|
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"
|
|
41
49
|
},
|
|
42
50
|
"files": [
|
|
43
51
|
"/bin",
|
|
@@ -76,6 +84,9 @@
|
|
|
76
84
|
},
|
|
77
85
|
"projects": {
|
|
78
86
|
"description": "this topic supports the management of Projects"
|
|
87
|
+
},
|
|
88
|
+
"spectral": {
|
|
89
|
+
"description": "this topic supports the management of Spectral rulesets"
|
|
79
90
|
}
|
|
80
91
|
},
|
|
81
92
|
"helpClass": "./src/help"
|
|
@@ -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
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
const { Args , Errors } = require('@oclif/core')
|
|
2
|
+
const { getSpectralRuleset } = require('../../requests/spectral')
|
|
3
|
+
const { getSpectralIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
|
|
4
|
+
const { errorMsg } = require('../../template-strings')
|
|
5
|
+
const BaseCommand = require('../../support/command/base-command')
|
|
6
|
+
const unzipper = require('unzipper');
|
|
7
|
+
const fs = require('fs');
|
|
8
|
+
|
|
9
|
+
class DownloadSpectralRulesetCommand extends BaseCommand {
|
|
10
|
+
async run() {
|
|
11
|
+
const { args } = await this.parse(DownloadSpectralRulesetCommand)
|
|
12
|
+
const rulesetPath = getSpectralIdentifierArg(args)
|
|
13
|
+
|
|
14
|
+
await this.getSpectralRuleset(rulesetPath, args['directory'])
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
getSpectralRuleset(pathParams, outputDir) {
|
|
18
|
+
return this.executeHttp({
|
|
19
|
+
execute: () => getSpectralRuleset(pathParams),
|
|
20
|
+
onResolve: response => this.extractZipResponse(response, outputDir),
|
|
21
|
+
options: {}
|
|
22
|
+
})
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
async extractZipResponse(response, outputDir) {
|
|
26
|
+
const buffer = Buffer.from(response.content, 'binary');
|
|
27
|
+
await this.createDirectory(outputDir)
|
|
28
|
+
const directory = await unzipper.Open.buffer(buffer);
|
|
29
|
+
await directory.extract({ path: outputDir });
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async createDirectory(outputDir) {
|
|
33
|
+
try {
|
|
34
|
+
await fs.promises.mkdir(outputDir)
|
|
35
|
+
} catch (err) {
|
|
36
|
+
if (err.code === 'EEXIST') {
|
|
37
|
+
throw new Errors.CLIError(errorMsg.directoryExists({ directory: outputDir }))
|
|
38
|
+
}
|
|
39
|
+
if (err.message) {
|
|
40
|
+
throw new Errors.CLIError(err.message)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
throw new Errors.CLIError(errorMsg.unknown())
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
DownloadSpectralRulesetCommand.description = `Fetch organization's Spectral ruleset`
|
|
49
|
+
|
|
50
|
+
DownloadSpectralRulesetCommand.examples = [
|
|
51
|
+
'swaggerhub spectral:download my_organization/my_api_ruleset rules/',
|
|
52
|
+
]
|
|
53
|
+
|
|
54
|
+
DownloadSpectralRulesetCommand.args = {
|
|
55
|
+
'OWNER/RULESET_NAME': Args.string({
|
|
56
|
+
required: true,
|
|
57
|
+
description: 'Organization\'s Spectral ruleset to create or update on SwaggerHub'
|
|
58
|
+
}),
|
|
59
|
+
'directory': Args.string({
|
|
60
|
+
required: true,
|
|
61
|
+
description: 'Relative path to directory the ruleset files should be saved to'
|
|
62
|
+
})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
DownloadSpectralRulesetCommand.flags = {
|
|
66
|
+
...BaseCommand.flags
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
module.exports = DownloadSpectralRulesetCommand
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const { Args } = require('@oclif/core')
|
|
2
|
+
const {saveSpectralRuleset} = require('../../requests/spectral')
|
|
3
|
+
const { getSpectralIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
|
|
4
|
+
const BaseCommand = require('../../support/command/base-command')
|
|
5
|
+
const { PassThrough } = require('stream')
|
|
6
|
+
const { pipeAsync } = require('../../utils/general')
|
|
7
|
+
const archiver = require('archiver')
|
|
8
|
+
const { getResponseContent } = require('../../support/command/handle-response')
|
|
9
|
+
|
|
10
|
+
class UploadSpectralRulesetCommand extends BaseCommand {
|
|
11
|
+
async run() {
|
|
12
|
+
const { args } = await this.parse(UploadSpectralRulesetCommand)
|
|
13
|
+
const rulesetPath = getSpectralIdentifierArg(args)
|
|
14
|
+
|
|
15
|
+
const zippedDirectory = await this.zipTheDirectory(args.directory)
|
|
16
|
+
await this.saveSpectralRuleset(rulesetPath, zippedDirectory)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async zipTheDirectory(directoryPath) {
|
|
20
|
+
const archive = archiver('zip', { zlib: { level: 9 } });
|
|
21
|
+
const passthrough = new PassThrough();
|
|
22
|
+
|
|
23
|
+
archive.directory(directoryPath, false);
|
|
24
|
+
archive.finalize();
|
|
25
|
+
archive.pipe(passthrough);
|
|
26
|
+
return passthrough;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
saveSpectralRuleset(pathParams, zippedDirectory) {
|
|
30
|
+
return this.executeHttp({
|
|
31
|
+
execute: () => saveSpectralRuleset(pathParams, zippedDirectory),
|
|
32
|
+
onResolve: pipeAsync(getResponseContent, JSON.parse),
|
|
33
|
+
options: {}
|
|
34
|
+
})
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
UploadSpectralRulesetCommand.description = `Create or update organization's Spectral ruleset`
|
|
39
|
+
|
|
40
|
+
UploadSpectralRulesetCommand.examples = [
|
|
41
|
+
'swaggerhub spectral:upload my_organization/my_api_ruleset rules/',
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
UploadSpectralRulesetCommand.args = {
|
|
45
|
+
'OWNER/RULESET_NAME': Args.string({
|
|
46
|
+
required: true,
|
|
47
|
+
description: 'Organization\'s Spectral ruleset to create or update on SwaggerHub'
|
|
48
|
+
}),
|
|
49
|
+
'directory': Args.string({
|
|
50
|
+
required: true,
|
|
51
|
+
description: 'Relative path to directory with ruleset files'
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
UploadSpectralRulesetCommand.flags = {
|
|
56
|
+
...BaseCommand.flags
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = UploadSpectralRulesetCommand
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const config = require('../config')
|
|
2
|
+
const http = require('../support/http')
|
|
3
|
+
|
|
4
|
+
const saveSpectralRuleset = (pathParams, body) => {
|
|
5
|
+
const { SWAGGERHUB_URL, SWAGGERHUB_API_KEY } = config.getConfig()
|
|
6
|
+
|
|
7
|
+
return http({
|
|
8
|
+
url: [SWAGGERHUB_URL, 'standardization', 'spectral-rulesets', pathParams, 'zip'],
|
|
9
|
+
auth: SWAGGERHUB_API_KEY,
|
|
10
|
+
contentType: 'zip',
|
|
11
|
+
method: 'PUT',
|
|
12
|
+
body
|
|
13
|
+
})
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const getSpectralRuleset = (pathParams) => {
|
|
17
|
+
const { SWAGGERHUB_URL, SWAGGERHUB_API_KEY } = config.getConfig()
|
|
18
|
+
|
|
19
|
+
return http({
|
|
20
|
+
url: [SWAGGERHUB_URL, 'standardization', 'spectral-rulesets', pathParams, 'zip'],
|
|
21
|
+
auth: SWAGGERHUB_API_KEY,
|
|
22
|
+
contentType: 'zip',
|
|
23
|
+
method: 'GET'
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
saveSpectralRuleset,
|
|
29
|
+
getSpectralRuleset
|
|
30
|
+
}
|
|
@@ -2,12 +2,21 @@ const { CLIError } = require('@oclif/core').Errors
|
|
|
2
2
|
const { hasJsonStructure, isError } = require('../../utils/general')
|
|
3
3
|
const { errorMsg } = require('../../template-strings')
|
|
4
4
|
|
|
5
|
-
const parseResponse = response => new Promise(resolve =>
|
|
6
|
-
|
|
5
|
+
const parseResponse = response => new Promise(resolve => {
|
|
6
|
+
|
|
7
|
+
const resolveContent = content => resolve({
|
|
7
8
|
status: response.status,
|
|
8
9
|
ok: response.ok,
|
|
9
|
-
content
|
|
10
|
-
})
|
|
10
|
+
content,
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const contentType = response.headers?.get('content-type') || '';
|
|
14
|
+
if (contentType.includes('application/zip')) {
|
|
15
|
+
response.buffer().then(resolveContent)
|
|
16
|
+
} else {
|
|
17
|
+
response.text().then(resolveContent)
|
|
18
|
+
}
|
|
19
|
+
});
|
|
11
20
|
|
|
12
21
|
const checkForErrors = ({ resolveStatus = [] } = {}) => response => {
|
|
13
22
|
if (resolveStatus.includes(response.status) || response.ok) {
|
|
@@ -3,10 +3,13 @@ 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\-.]+(\/?)$/)
|
|
9
11
|
const projectIdentifierRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+$/)
|
|
12
|
+
const spectralIdentifierRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+$/)
|
|
10
13
|
|
|
11
14
|
const isValidIdentifier = (id, isVersionRequired) => isVersionRequired
|
|
12
15
|
? requiredVersionRegex.test(id)
|
|
@@ -52,6 +55,15 @@ const getProjectIdentifierArg = args => {
|
|
|
52
55
|
return identifier
|
|
53
56
|
}
|
|
54
57
|
|
|
58
|
+
const getSpectralIdentifierArg = args => {
|
|
59
|
+
const format = 'OWNER/RULESET_NAME'
|
|
60
|
+
const identifier = args[format]
|
|
61
|
+
if (!spectralIdentifierRegex.test(identifier)) {
|
|
62
|
+
throw new CLIError(errorMsg.argsMustMatchFormat({ format }))
|
|
63
|
+
}
|
|
64
|
+
return identifier
|
|
65
|
+
}
|
|
66
|
+
|
|
55
67
|
const readConfigFile = filename => {
|
|
56
68
|
if (!existsSync(filename)) {
|
|
57
69
|
throw new CLIError(errorMsg.fileNotFound({ filename }))
|
|
@@ -78,9 +90,12 @@ const resolvedParam = ({ resolved }) => resolved ? { resolved: true } : null
|
|
|
78
90
|
|
|
79
91
|
module.exports = {
|
|
80
92
|
getApiIdentifierArg,
|
|
93
|
+
apiNameRegex,
|
|
94
|
+
noVersionRegex,
|
|
81
95
|
getDomainIdentifierArg,
|
|
82
96
|
getIntegrationIdentifierArg,
|
|
83
97
|
getProjectIdentifierArg,
|
|
98
|
+
getSpectralIdentifierArg,
|
|
84
99
|
readConfigFile,
|
|
85
100
|
splitPathParams,
|
|
86
101
|
splitFlagParams,
|