swaggerhub-cli 0.11.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 +84 -60
- package/bin/run +4 -0
- package/oclif.manifest.json +191 -191
- package/package.json +16 -19
- package/src/commands/api/rename.js +22 -22
- 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/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,7 +15,7 @@
|
|
|
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",
|
|
@@ -23,29 +23,30 @@
|
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@faker-js/faker": "^10.0.0",
|
|
26
|
-
"@oclif/test": "^3.2.
|
|
27
|
-
"chai": "^
|
|
28
|
-
"eslint": "^
|
|
26
|
+
"@oclif/test": "^3.2.15",
|
|
27
|
+
"chai": "^6.3.0",
|
|
28
|
+
"eslint": "^10.10.0",
|
|
29
29
|
"eslint-plugin-chai-friendly": "^1.0.0",
|
|
30
30
|
"eslint-plugin-immutable": "^1.0.0",
|
|
31
|
-
"eslint-plugin-mocha": "^
|
|
32
|
-
"eslint-plugin-
|
|
33
|
-
"globby": "^
|
|
31
|
+
"eslint-plugin-mocha": "^11.3.0",
|
|
32
|
+
"eslint-plugin-n": "^18.3.0",
|
|
33
|
+
"globby": "^16.2.0",
|
|
34
34
|
"husky": "^9.0.1",
|
|
35
|
-
"mocha": "^11.7.
|
|
35
|
+
"mocha": "^11.7.6",
|
|
36
36
|
"nock": "^14.0.1",
|
|
37
37
|
"nyc": "^18.0.0",
|
|
38
|
-
"rewire": "^
|
|
39
|
-
"sinon": "^
|
|
40
|
-
"tmp": "^0.2.
|
|
38
|
+
"rewire": "^9.0.1",
|
|
39
|
+
"sinon": "^22.0.0",
|
|
40
|
+
"tmp": "^0.2.7"
|
|
41
41
|
},
|
|
42
42
|
"engines": {
|
|
43
43
|
"node": "^20.17.0 || >=22.9.0",
|
|
44
|
-
"npm": ">=11.
|
|
44
|
+
"npm": ">=11.9.0"
|
|
45
45
|
},
|
|
46
46
|
"overrides": {
|
|
47
47
|
"npm": "^11.9.0",
|
|
48
|
-
"glob": "^10.5.0"
|
|
48
|
+
"glob": "^10.5.0",
|
|
49
|
+
"serialize-javascript": "^7.0.5"
|
|
49
50
|
},
|
|
50
51
|
"files": [
|
|
51
52
|
"/bin",
|
|
@@ -95,13 +96,9 @@
|
|
|
95
96
|
"scripts": {
|
|
96
97
|
"postpack": "rm -f oclif.manifest.json",
|
|
97
98
|
"prepack": "npx oclif manifest",
|
|
99
|
+
"prepare": "husky",
|
|
98
100
|
"test": "nyc mocha --forbid-only \"test/**/*.test.js\"",
|
|
99
101
|
"lint": "eslint ./src ./test",
|
|
100
102
|
"postinstall": "node ./src/check-node-version"
|
|
101
|
-
},
|
|
102
|
-
"husky": {
|
|
103
|
-
"hooks": {
|
|
104
|
-
"pre-push": "npm run lint && npm run test"
|
|
105
|
-
}
|
|
106
103
|
}
|
|
107
104
|
}
|
|
@@ -3,10 +3,26 @@ const { Args } = require('@oclif/core')
|
|
|
3
3
|
const {
|
|
4
4
|
noVersionRegex,
|
|
5
5
|
apiNameRegex
|
|
6
|
-
} = require(
|
|
6
|
+
} = require('../../support/command/parse-input')
|
|
7
7
|
const { errorMsg } = require('../../template-strings')
|
|
8
|
-
const { CLIError } = require(
|
|
9
|
-
const { postApi } = require(
|
|
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
|
+
}
|
|
10
26
|
|
|
11
27
|
class RenameApiCommand extends BaseCommand {
|
|
12
28
|
|
|
@@ -25,32 +41,16 @@ class RenameApiCommand extends BaseCommand {
|
|
|
25
41
|
queryParams: { 'newName': newName },
|
|
26
42
|
body: '{}'
|
|
27
43
|
}),
|
|
28
|
-
onResolve: this.logCommandSuccess({apiPath, newName}),
|
|
44
|
+
onResolve: this.logCommandSuccess({ apiPath, newName }),
|
|
29
45
|
options: {}
|
|
30
46
|
})
|
|
31
47
|
}
|
|
32
48
|
}
|
|
33
49
|
|
|
34
|
-
|
|
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"
|
|
50
|
+
RenameApiCommand.description = 'rename an API'
|
|
51
51
|
|
|
52
52
|
RenameApiCommand.examples = [
|
|
53
|
-
|
|
53
|
+
'swaggerhub api:rename organization/apiOldName apiNewName'
|
|
54
54
|
]
|
|
55
55
|
|
|
56
56
|
RenameApiCommand.args = {
|
|
@@ -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) {
|