diff --git a/README.md b/README.md index 4101d3c6..03c053d1 100644 --- a/README.md +++ b/README.md @@ -110,6 +110,7 @@ USAGE * [`swaggerhub api:unpublish OWNER/API_NAME/VERSION`](#swaggerhub-apiunpublish) * [`swaggerhub api:update OWNER/API_NAME/[VERSION]`](#swaggerhub-apiupdate) * [`swaggerhub api:validate OWNER/API_NAME/[VERSION]`](#swaggerhub-apivalidate) +* [`swaggerhub api:validate:download-rules OWNER`](#swaggerhub-apivalidatedownload-rules) * [`swaggerhub api:validate:local`](#swaggerhub-apivalidatelocal) * [`swaggerhub configure`](#swaggerhub-configure) * [`swaggerhub domain:create OWNER/DOMAIN_NAME/[VERSION]`](#swaggerhub-domaincreate) @@ -425,6 +426,37 @@ EXAMPLES _See code: [src/commands/api/validate/local.js](https://github.com/SmartBear/swaggerhub-cli/blob/v0.8.1/src/commands/api/validate/local.js)_ +## `swaggerhub api:validate:download-rules` + +Get existing SwaggerHub's organization standardization ruleset. + +``` +USAGE + $ swaggerhub api:validate:download-rules OWNER [-s] [-d] [-h] + +ARGUMENTS + OWNER Which organization standardization rules to fetch from SwaggerHub + +FLAGS + -d, --include-disabled-rules Includes disabled rules in fetched organization's ruleset + -h, --help Show CLI help. + -s, --include-system-rules Includes system rules in fetched organization's ruleset + +DESCRIPTION + Get existing SwaggerHub's organization standardization ruleset. + Requires organization name argument. An error will occur if provided organization is non existing + or your account is not permitted to access that organization settings. + If the flag `-s` or `--include-system-rules` is used, the returned ruleset will also include SwaggerHub system rules. + If the flag `-d` or `--include-disabled-rules` is used, the returned ruleset will also include disabled custom rules + +EXAMPLES + $ swaggerhub api:validate:download-rules myOrg -s + + $ swaggerhub api:validate:download-rules myOrg --include-disabled-rules -s +``` + +_See code: [src/commands/api/validate/download-rules.js](https://github.com/SmartBear/swaggerhub-cli/blob/v0.8.1/src/commands/api/validate/download-rules.js)_ + ## `swaggerhub configure` configure application settings diff --git a/src/commands/api/validate/download-rules.js b/src/commands/api/validate/download-rules.js index 5490702b..be632e46 100644 --- a/src/commands/api/validate/download-rules.js +++ b/src/commands/api/validate/download-rules.js @@ -1,10 +1,10 @@ const { Flags, Args } = require('@oclif/core') -const BaseValidateCommand = require('../../../support/command/base-validate-command') +const BaseCommand = require('../../../support/command/base-command') const { pipeAsync } = require('../../../utils/general') const { getResponseContent } = require('../../../support/command/handle-response') const { getStandardization } = require('../../../requests/standardization') -class ValidateDownloadRulesCommand extends BaseValidateCommand { +class ValidateDownloadRulesCommand extends BaseCommand { async run() { const { args, flags } = await this.parse(ValidateDownloadRulesCommand) @@ -25,7 +25,11 @@ class ValidateDownloadRulesCommand extends BaseValidateCommand { } } -ValidateDownloadRulesCommand.description = `TODO` +ValidateDownloadRulesCommand.description = `Get existing SwaggerHub's organization standardization ruleset. +Requires organization name argument. An error will occur if provided organization is non existing +or your account is not permitted to access that organization settings. +If the flag \`-s\` or \`--include-system-rules\` is used, the returned ruleset will also include SwaggerHub system rules. +If the flag \`-d\` or \`--include-disabled-rules\` is used, the returned ruleset will also include disabled custom rules` ValidateDownloadRulesCommand.examples = [ 'swaggerhub api:validate:download-rules myOrg -s', @@ -49,6 +53,6 @@ ValidateDownloadRulesCommand.flags = { description: 'Includes disabled rules in fetched organization\'s ruleset', required: false }), - ...BaseValidateCommand.flags + ...BaseCommand.flags } module.exports = ValidateDownloadRulesCommand \ No newline at end of file diff --git a/test/commands/api/validate/download-rules.test.js b/test/commands/api/validate/download-rules.test.js index 84404313..14cc4e40 100644 --- a/test/commands/api/validate/download-rules.test.js +++ b/test/commands/api/validate/download-rules.test.js @@ -4,7 +4,7 @@ const { ruleset, rulesetWithDisabledRule, rulesetWithSystemRule, - rulesetWithDisabledAndSystemRule, basicRules + rulesetWithDisabledAndSystemRule } = require('../../../resources/rulesets') const orgName = 'org1' @@ -15,7 +15,6 @@ describe('invalid api:validate:download-rules', () => { .exit(2) .it('runs api:validate:download-rules with no organization name provided') - test .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/standardization',{ reqheaders: { Accept: 'application/json' }}, api => api @@ -25,18 +24,15 @@ describe('invalid api:validate:download-rules', () => { ) .command(['api:validate:download-rules', 'org2']) .exit(2) - .it('Access Denied returned when trying to fetch ruleset of not existing organization') + .it('Access Denied returned when trying to fetch ruleset of not existing or not available organization') test - .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) - .nock('https://api.swaggerhub.com/standardization',{ reqheaders: { Accept: 'application/json' }}, api => api - .get(`/org2/spectral`) - .query({ includeSystemRules : false, includeDisabledRules : false}) - .reply(404, 'Access Denied') + .stub(config, 'isURLValid', () => false) + .command(['api:validate:download-rules', 'org1']) + .catch(ctx => + expect(ctx.message).to.equal('Please verify that the configured SwaggerHub URL is correct.') ) - .command(['api:validate:download-rules', 'org2']) - .exit(2) - .it('Access Denied returned when trying to fetch ruleset of not existing organization') + .it('invalid SwaggerHub URL provided in the config') }) describe('valid api:validate:download-rules', () => { @@ -66,7 +62,6 @@ describe('valid api:validate:download-rules', () => { expect(ctx.stdout).to.contains(JSON.stringify(rulesetWithSystemRule, null, 2)) }) - test .stub(config, 'getConfig', () => ({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' })) .nock('https://api.swaggerhub.com/standardization',{ reqheaders: { Accept: 'application/json' }}, api => api