swaggerhub-cli 0.8.1 → 0.9.1
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 +214 -137
- package/oclif.manifest.json +1017 -626
- package/package.json +15 -14
- package/src/commands/api/validate/download-rules.js +58 -0
- package/src/config/index.js +3 -2
- package/src/requests/standardization.js +14 -1
package/package.json
CHANGED
|
@@ -1,42 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swaggerhub-cli",
|
|
3
3
|
"description": "SwaggerHub CLI",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.1",
|
|
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": "^
|
|
11
|
+
"@oclif/core": "^3.26.3",
|
|
12
|
+
"@oclif/plugin-help": "^6.0.21",
|
|
13
|
+
"@oclif/plugin-plugins": "^5.0.21",
|
|
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.
|
|
20
|
+
"semver": "^7.6.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@oclif/test": "^2.
|
|
24
|
-
"chai": "^4.3.
|
|
25
|
-
"
|
|
26
|
-
"eslint
|
|
23
|
+
"@oclif/test": "^3.2.10",
|
|
24
|
+
"chai": "^4.3.10",
|
|
25
|
+
"sinon": "^18.0.0",
|
|
26
|
+
"eslint": "^9.0.0",
|
|
27
|
+
"eslint-plugin-chai-friendly": "^1.0.0",
|
|
27
28
|
"eslint-plugin-immutable": "^1.0.0",
|
|
28
29
|
"eslint-plugin-mocha": "^10.1.0",
|
|
29
30
|
"eslint-plugin-node": "^11.1.0",
|
|
30
|
-
"globby": "^
|
|
31
|
-
"husky": "^
|
|
31
|
+
"globby": "^14.0.0",
|
|
32
|
+
"husky": "^9.0.1",
|
|
32
33
|
"mocha": "^10.2.0",
|
|
33
34
|
"nock": "^13.3.2",
|
|
34
|
-
"nyc": "^
|
|
35
|
-
"rewire": "^
|
|
35
|
+
"nyc": "^17.0.0",
|
|
36
|
+
"rewire": "^7.0.0",
|
|
36
37
|
"tmp": "^0.2.1"
|
|
37
38
|
},
|
|
38
39
|
"engines": {
|
|
39
|
-
"node": ">=
|
|
40
|
+
"node": ">=18.0.0"
|
|
40
41
|
},
|
|
41
42
|
"files": [
|
|
42
43
|
"/bin",
|
|
@@ -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
|
package/src/config/index.js
CHANGED
|
@@ -21,9 +21,10 @@ const setConfig = update => {
|
|
|
21
21
|
|
|
22
22
|
const isURLValid = () => {
|
|
23
23
|
const { SWAGGERHUB_URL } = getConfig()
|
|
24
|
+
const url = new URL(SWAGGERHUB_URL)
|
|
24
25
|
return swaggerhubUrlRegex.test(SWAGGERHUB_URL) ||
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
(!url.hostname.endsWith('api.swaggerhub.com') && url.pathname.endsWith('/v1')) ||
|
|
27
|
+
url.hostname === 'localhost'
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
module.exports = {
|
|
@@ -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
|
}
|