swaggerhub-cli 0.8.0 → 0.9.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 +89 -56
- package/oclif.manifest.json +1017 -626
- package/package.json +10 -10
- package/src/commands/api/validate/download-rules.js +58 -0
- package/src/commands/api/validate/index.js +8 -0
- package/src/requests/standardization.js +14 -1
package/package.json
CHANGED
|
@@ -1,38 +1,38 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swaggerhub-cli",
|
|
3
3
|
"description": "SwaggerHub CLI",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.0",
|
|
5
5
|
"author": "SmartBear",
|
|
6
6
|
"bin": {
|
|
7
7
|
"swaggerhub": "./bin/run"
|
|
8
8
|
},
|
|
9
9
|
"bugs": "https://github.com/SmartBear/swaggerhub-cli/issues",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@oclif/core": "^
|
|
12
|
-
"@oclif/plugin-help": "^
|
|
13
|
-
"@oclif/plugin-plugins": "^3.1.
|
|
11
|
+
"@oclif/core": "^3.3.1",
|
|
12
|
+
"@oclif/plugin-help": "^6.0.3",
|
|
13
|
+
"@oclif/plugin-plugins": "^3.1.8",
|
|
14
14
|
"deep-extend": "^0.6.0",
|
|
15
15
|
"fs-extra": "^11.1.1",
|
|
16
16
|
"inquirer": "^8.2.5",
|
|
17
17
|
"js-yaml": "^4.1.0",
|
|
18
18
|
"json-templates": "^5.0.0",
|
|
19
19
|
"node-fetch": "^2.6.12",
|
|
20
|
-
"semver": "^7.5.
|
|
20
|
+
"semver": "^7.5.4"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@oclif/test": "^2.
|
|
23
|
+
"@oclif/test": "^2.4.2",
|
|
24
24
|
"chai": "^4.3.7",
|
|
25
|
-
"eslint": "^8.
|
|
25
|
+
"eslint": "^8.46.0",
|
|
26
26
|
"eslint-plugin-chai-friendly": "^0.7.2",
|
|
27
27
|
"eslint-plugin-immutable": "^1.0.0",
|
|
28
28
|
"eslint-plugin-mocha": "^10.1.0",
|
|
29
29
|
"eslint-plugin-node": "^11.1.0",
|
|
30
|
-
"globby": "^
|
|
30
|
+
"globby": "^14.0.0",
|
|
31
31
|
"husky": "^8.0.3",
|
|
32
32
|
"mocha": "^10.2.0",
|
|
33
|
-
"nock": "^13.3.
|
|
33
|
+
"nock": "^13.3.2",
|
|
34
34
|
"nyc": "^15.1.0",
|
|
35
|
-
"rewire": "^
|
|
35
|
+
"rewire": "^7.0.0",
|
|
36
36
|
"tmp": "^0.2.1"
|
|
37
37
|
},
|
|
38
38
|
"engines": {
|
|
@@ -0,0 +1,58 @@
|
|
|
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')
|
|
6
|
+
|
|
7
|
+
class ValidateDownloadRulesCommand extends BaseCommand {
|
|
8
|
+
async run() {
|
|
9
|
+
const { args, flags } = await this.parse(ValidateDownloadRulesCommand)
|
|
10
|
+
|
|
11
|
+
const includeSystemRules = flags['include-system-rules'] ?? false
|
|
12
|
+
const includeDisabledRules = flags['include-disabled-rules'] ?? false
|
|
13
|
+
const organization = args['OWNER']
|
|
14
|
+
|
|
15
|
+
const organizationRuleset = await this.getExportedOrganizationRuleset(organization, {includeSystemRules, includeDisabledRules})
|
|
16
|
+
this.log(JSON.stringify(organizationRuleset, null, 2))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
getExportedOrganizationRuleset(orgName, queryParams) {
|
|
20
|
+
return this.executeHttp({
|
|
21
|
+
execute: () => getStandardization([orgName, 'spectral'], queryParams),
|
|
22
|
+
onResolve: pipeAsync(getResponseContent, JSON.parse),
|
|
23
|
+
options: {}
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
ValidateDownloadRulesCommand.description = `Get existing SwaggerHub's organization standardization ruleset.
|
|
29
|
+
Requires organization name argument. An error will occur if provided organization doesn't exist
|
|
30
|
+
or your account is not permitted to access that organization's settings.
|
|
31
|
+
If the flag \`-s\` or \`--include-system-rules\` is used, the returned ruleset will also include SwaggerHub system rules.
|
|
32
|
+
If the flag \`-d\` or \`--include-disabled-rules\` is used, the returned ruleset will also include disabled custom rules`
|
|
33
|
+
|
|
34
|
+
ValidateDownloadRulesCommand.examples = [
|
|
35
|
+
'swaggerhub api:validate:download-rules myOrg -s',
|
|
36
|
+
'swaggerhub api:validate:download-rules myOrg --include-disabled-rules -s',
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
ValidateDownloadRulesCommand.args = {
|
|
40
|
+
'OWNER': Args.string({
|
|
41
|
+
required: true,
|
|
42
|
+
description: 'Which organization standardization rules to fetch from SwaggerHub'
|
|
43
|
+
})
|
|
44
|
+
}
|
|
45
|
+
ValidateDownloadRulesCommand.flags = {
|
|
46
|
+
'include-system-rules': Flags.boolean({
|
|
47
|
+
char: 's',
|
|
48
|
+
description: 'Includes system rules in fetched organization\'s ruleset',
|
|
49
|
+
required: false
|
|
50
|
+
}),
|
|
51
|
+
'include-disabled-rules': Flags.boolean({
|
|
52
|
+
char: 'd',
|
|
53
|
+
description: 'Includes disabled rules in fetched organization\'s ruleset',
|
|
54
|
+
required: false
|
|
55
|
+
}),
|
|
56
|
+
...BaseCommand.flags
|
|
57
|
+
}
|
|
58
|
+
module.exports = ValidateDownloadRulesCommand
|
|
@@ -11,6 +11,7 @@ class ValidateCommand extends BaseValidateCommand {
|
|
|
11
11
|
const { args, flags } = await this.parse(ValidateCommand)
|
|
12
12
|
const apiPath = getApiIdentifierArg(args)
|
|
13
13
|
const validPath = await this.ensureVersion(apiPath)
|
|
14
|
+
await this.checkApiExists(validPath)
|
|
14
15
|
// eslint-disable-next-line immutable/no-let
|
|
15
16
|
let validationResult = await this.getValidationResult(validPath)
|
|
16
17
|
// Required to support On-Prem 2.4.1
|
|
@@ -21,6 +22,13 @@ class ValidateCommand extends BaseValidateCommand {
|
|
|
21
22
|
this.exitWithCode(flags, validationResult)
|
|
22
23
|
}
|
|
23
24
|
|
|
25
|
+
checkApiExists(apiPath) {
|
|
26
|
+
return this.executeHttp({
|
|
27
|
+
execute: () => getApi([apiPath]),
|
|
28
|
+
options: { resolveStatus: [200] }
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
24
32
|
getValidationResult(apiPath) {
|
|
25
33
|
return this.executeHttp({
|
|
26
34
|
execute: () => getApi([apiPath, 'standardization']),
|
|
@@ -15,6 +15,19 @@ const postStandardization = (pathParams, body) => {
|
|
|
15
15
|
})
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
+
const getStandardization = (pathParams, queryParams) => {
|
|
19
|
+
const { SWAGGERHUB_URL, SWAGGERHUB_API_KEY } = config.getConfig()
|
|
20
|
+
|
|
21
|
+
return http({
|
|
22
|
+
url: [SWAGGERHUB_URL, 'standardization', ...pathParams],
|
|
23
|
+
query: queryParams,
|
|
24
|
+
accept: 'json',
|
|
25
|
+
auth: SWAGGERHUB_API_KEY,
|
|
26
|
+
method: 'GET',
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
18
30
|
module.exports = {
|
|
19
|
-
postStandardization
|
|
31
|
+
postStandardization,
|
|
32
|
+
getStandardization
|
|
20
33
|
}
|