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/README.md +85 -61
- package/bin/run +4 -0
- package/oclif.manifest.json +234 -191
- package/package.json +22 -19
- package/src/commands/api/rename.js +69 -0
- package/src/commands/api/validate/download-rules.js +3 -1
- package/src/commands/api/validate/index.js +1 -1
- package/src/commands/spectral/download.js +6 -6
- package/src/commands/spectral/upload.js +8 -8
- package/src/requests/spectral.js +1 -1
- package/src/support/command/handle-response.js +3 -3
- package/src/support/command/parse-input.js +4 -0
- package/src/template-strings/info.js +2 -0
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.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": "^
|
|
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
|
-
"@
|
|
26
|
-
"
|
|
27
|
-
"
|
|
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": "^
|
|
31
|
-
"eslint-plugin-
|
|
32
|
-
"globby": "^
|
|
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.
|
|
35
|
+
"mocha": "^11.7.6",
|
|
35
36
|
"nock": "^14.0.1",
|
|
36
|
-
"nyc": "^
|
|
37
|
-
"rewire": "^
|
|
38
|
-
"sinon": "^
|
|
39
|
-
"tmp": "^0.2.
|
|
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": "
|
|
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(
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
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/',
|
package/src/requests/spectral.js
CHANGED
|
@@ -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,
|