Skip to content

Commit 055aa9e

Browse files
micrycMiloszTarka
andauthored
Release/v0.10.0 (#591)
* SWG-15720 & SWG-15721 adjusting for non-versioning * SWG-15720 & SWG-15721 adjusting tests --------- Co-authored-by: Milosz Tarka <milosz.tarka.it@gmail.com>
1 parent 2fdc52b commit 055aa9e

7 files changed

Lines changed: 23 additions & 74 deletions

File tree

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ USAGE
146146
* [`swaggerhub project:get OWNER/PROJECT_NAME`](#swaggerhub-projectget)
147147
* [`swaggerhub project:list [OWNER]`](#swaggerhub-projectlist)
148148
* [`swaggerhub project:member:list OWNER/PROJECT_NAME`](#swaggerhub-projectmemberlist)
149-
* [`swaggerhub spectral:upload OWNER/RULESET_NAME/VERSION directory`](#swaggerhub-spectralupload)
150-
* [`swaggerhub spectral:download OWNER/RULESET_NAME/VERSION directory`](#swaggerhub-spectraldownload)
149+
* [`swaggerhub spectral:upload OWNER/RULESET_NAME directory`](#swaggerhub-spectralupload)
150+
* [`swaggerhub spectral:download OWNER/RULESET_NAME directory`](#swaggerhub-spectraldownload)
151151

152152
## `swaggerhub api:create`
153153

@@ -1381,10 +1381,10 @@ Create or update organization's Spectral ruleset
13811381

13821382
```
13831383
USAGE
1384-
$ swaggerhub spectral:upload OWNER/RULESET_NAME/VERSION directory [-h]
1384+
$ swaggerhub spectral:upload OWNER/RULESET_NAME directory [-h]
13851385
13861386
ARGUMENTS
1387-
OWNER/RULESET_NAME/[VERSION] The Spectral ruleset details for SwaggerHub organization
1387+
OWNER/RULESET_NAME The Spectral ruleset details for SwaggerHub organization
13881388
directory Relative path to directory with ruleset files
13891389
13901390
FLAGS
@@ -1394,7 +1394,7 @@ DESCRIPTION
13941394
Create or update organization's Spectral ruleset
13951395
13961396
EXAMPLES
1397-
$ swaggerhub spectral:upload my_organization/my_api_ruleset/1.0.0 rules
1397+
$ swaggerhub spectral:upload my_organization/my_api_ruleset rules
13981398
```
13991399

14001400
_See code: [src/commands/spectral/upload.js](https://github.com/SmartBear/swaggerhub-cli/blob/v0.9.1/src/commands/spectral/upload.js)_
@@ -1406,10 +1406,10 @@ Fetch organization's Spectral ruleset
14061406

14071407
```
14081408
USAGE
1409-
$ swaggerhub spectral:download OWNER/RULESET_NAME/VERSION directory [-h]
1409+
$ swaggerhub spectral:download OWNER/RULESET_NAME directory [-h]
14101410
14111411
ARGUMENTS
1412-
OWNER/RULESET_NAME/[VERSION] The Spectral ruleset details for SwaggerHub organization
1412+
OWNER/RULESET_NAME The Spectral ruleset details for SwaggerHub organization
14131413
directory Relative path to directory the ruleset files should be saved to
14141414
14151415
FLAGS
@@ -1419,7 +1419,7 @@ DESCRIPTION
14191419
Fetch organization's Spectral ruleset
14201420
14211421
EXAMPLES
1422-
$ swaggerhub spectral:download my_organization/my_api_ruleset/1.0.0 rules
1422+
$ swaggerhub spectral:download my_organization/my_api_ruleset rules
14231423
```
14241424

14251425
_See code: [src/commands/spectral/download.js](https://github.com/SmartBear/swaggerhub-cli/blob/v0.9.1/src/commands/spectral/download.js)_

src/commands/spectral/download.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ class DownloadSpectralRulesetCommand extends BaseCommand {
1010
async run() {
1111
const { args } = await this.parse(DownloadSpectralRulesetCommand)
1212
const rulesetPath = getSpectralIdentifierArg(args)
13-
const [owner, name, version = '1.0.0'] = splitPathParams(rulesetPath)
14-
const rulesetPathWithVersion = [owner, name, version].join('/')
1513

16-
await this.getSpectralRuleset(rulesetPathWithVersion, args['directory'])
14+
await this.getSpectralRuleset(rulesetPath, args['directory'])
1715
}
1816

1917
getSpectralRuleset(pathParams, outputDir) {
@@ -50,12 +48,11 @@ class DownloadSpectralRulesetCommand extends BaseCommand {
5048
DownloadSpectralRulesetCommand.description = `Fetch organization's Spectral ruleset`
5149

5250
DownloadSpectralRulesetCommand.examples = [
53-
'swaggerhub spectral:download my_organization/my_api_ruleset/1.0.0 rules/',
5451
'swaggerhub spectral:download my_organization/my_api_ruleset rules/',
5552
]
5653

5754
DownloadSpectralRulesetCommand.args = {
58-
'OWNER/RULESET_NAME/[VERSION]': Args.string({
55+
'OWNER/RULESET_NAME': Args.string({
5956
required: true,
6057
description: 'Organization\'s Spectral ruleset to create or update on SwaggerHub'
6158
}),

src/commands/spectral/upload.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ class UploadSpectralRulesetCommand extends BaseCommand {
1111
async run() {
1212
const { args } = await this.parse(UploadSpectralRulesetCommand)
1313
const rulesetPath = getSpectralIdentifierArg(args)
14-
const [owner, name, version = '1.0.0'] = splitPathParams(rulesetPath)
15-
const rulesetPathWithVersion = [owner, name, version].join('/')
1614

1715
const zippedDirectory = await this.zipTheDirectory(args.directory)
18-
await this.saveSpectralRuleset(rulesetPathWithVersion, zippedDirectory)
16+
await this.saveSpectralRuleset(rulesetPath, zippedDirectory)
1917
}
2018

2119
async zipTheDirectory(directoryPath) {
@@ -40,12 +38,11 @@ class UploadSpectralRulesetCommand extends BaseCommand {
4038
UploadSpectralRulesetCommand.description = `Create or update organization's Spectral ruleset`
4139

4240
UploadSpectralRulesetCommand.examples = [
43-
'swaggerhub spectral:upload my_organization/my_api_ruleset/1.0.0 rules/',
4441
'swaggerhub spectral:upload my_organization/my_api_ruleset rules/',
4542
]
4643

4744
UploadSpectralRulesetCommand.args = {
48-
'OWNER/RULESET_NAME/[VERSION]': Args.string({
45+
'OWNER/RULESET_NAME': Args.string({
4946
required: true,
5047
description: 'Organization\'s Spectral ruleset to create or update on SwaggerHub'
5148
}),

src/support/command/parse-input.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const optionalVersionRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+(\/[\w\-.]+)?(\/?
77
const requiredVersionRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+\/[\w\-.]+(\/?)$/)
88
const integrationIdentifierRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+\/[\w\-.]+\/[\w\-.]+(\/?)$/)
99
const projectIdentifierRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+$/)
10+
const spectralIdentifierRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+$/)
1011

1112
const isValidIdentifier = (id, isVersionRequired) => isVersionRequired
1213
? requiredVersionRegex.test(id)
@@ -53,10 +54,12 @@ const getProjectIdentifierArg = args => {
5354
}
5455

5556
const getSpectralIdentifierArg = args => {
56-
const isVersionRequired = !!args['OWNER/RULESET_NAME/VERSION']
57-
const format = isVersionRequired ? 'OWNER/RULESET_NAME/VERSION' : 'OWNER/RULESET_NAME/[VERSION]'
57+
const format = 'OWNER/RULESET_NAME'
5858
const identifier = args[format]
59-
return getIdentifierArg(isVersionRequired, format, identifier)
59+
if (!spectralIdentifierRegex.test(identifier)) {
60+
throw new CLIError(errorMsg.argsMustMatchFormat({ format }))
61+
}
62+
return identifier
6063
}
6164

6265
const readConfigFile = filename => {

test/commands/spectral/download.test.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ const unzipper = require('unzipper')
55

66
const org = 'org1'
77
const rulesetName = 'rulesetA'
8-
const version = '1.0.2'
9-
const rulesetPath = `${org}/${rulesetName}/${version}`
10-
const rulesetPathWithoutVersion = `${org}/${rulesetName}`
8+
const rulesetPath = `${org}/${rulesetName}`
119
const outputDir = 'rules'
1210

1311
describe('invalid spectral:download', () => {
@@ -52,19 +50,6 @@ describe('valid spectral:download', () => {
5250
expect(ctx.stdout).to.be.undefined
5351
})
5452

55-
56-
test
57-
.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' }))
58-
.nock('https://api.swaggerhub.com/standardization', api => api
59-
.get(`/spectral-rulesets/${rulesetPathWithoutVersion}/1.0.0/zip`)
60-
.reply(200, zipBuffer, { 'Content-Type': 'application/zip' })
61-
)
62-
.stub(fs.promises, 'mkdir', stub => stub.resolves())
63-
.stub(unzipper.Open, 'buffer', stub => stub.resolves({ extract: ({ path }) => Promise.resolve() }))
64-
.command(['spectral:download', rulesetPathWithoutVersion, outputDir])
65-
.it('runs spectral:download without version and extracts ruleset zip to directory', ctx => {
66-
expect(ctx.stdout).to.be.undefined
67-
})
6853

6954
test
7055
.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' }))

test/commands/spectral/upload.test.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ const fs = require('fs')
44

55
const org = 'org1'
66
const rulesetName = 'rulesetA'
7-
const version = '1.0.2'
8-
const rulesetPath = `${org}/${rulesetName}/${version}`
9-
const rulesetPathWithoutVersion = `${org}/${rulesetName}`
7+
const rulesetPath = `${org}/${rulesetName}`
108
const inputDir = 'rules'
119

1210
describe('invalid spectral:upload', () => {
@@ -50,18 +48,6 @@ describe('valid spectral:upload', () => {
5048
expect(ctx.stdout).to.be.undefined
5149
})
5250

53-
test
54-
.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' }))
55-
.nock('https://api.swaggerhub.com/standardization', api => api
56-
.put(`/spectral-rulesets/${rulesetPathWithoutVersion}/1.0.0/zip`)
57-
.reply(200, '{"success":true}', { 'Content-Type': 'application/json' })
58-
)
59-
.stub(fs, 'createReadStream', stub => stub.returns(zipBuffer))
60-
.command(['spectral:upload', rulesetPathWithoutVersion, inputDir])
61-
.it('runs spectral:upload without version and uploads zipped ruleset directory', ctx => {
62-
expect(ctx.stdout).to.be.undefined
63-
})
64-
6551
test
6652
.stub(config, 'getConfig', stub => stub.returns({ SWAGGERHUB_URL: 'https://api.swaggerhub.com' }))
6753
.nock('https://api.swaggerhub.com/standardization', api => api

test/support/parse-input.test.js

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -202,43 +202,24 @@ describe('getProjectIdentifierArg', () => {
202202

203203
describe('getSpectralIdentifierArg', () => {
204204

205-
context('valid version identifier', () =>
206-
it('should be returned', () =>
207-
expect(getSpectralIdentifierArg({ 'OWNER/RULESET_NAME/VERSION': 'owner/ruleset/1.2.3' })).to.equal('owner/ruleset/1.2.3')
208-
)
209-
)
210-
211205
context('valid identifier', () =>
212206
it('should be returned', () =>
213-
expect(getSpectralIdentifierArg({ 'OWNER/RULESET_NAME/[VERSION]': 'owner/ruleset' }, false)).to.equal('owner/ruleset')
207+
expect(getSpectralIdentifierArg({ 'OWNER/RULESET_NAME': 'owner/ruleset' })).to.equal('owner/ruleset')
214208
)
215209
)
216210

217211
context('invalid identifier', () =>
218212
it('should throw an exception', () =>
219-
expect(() => { getSpectralIdentifierArg({ 'OWNER/RULESET_NAME/VERSION': 'owner/ruleset/version/extra' })})
213+
expect(() => { getSpectralIdentifierArg({ 'OWNER/RULESET_NAME': 'owner/ruleset/1.2.3' })})
220214
.to.throw(CLIError)
221215
)
222216
)
223217

224218
context('invalid identifier with space', () =>
225219
it('should throw an exception', () =>
226-
expect(() => { getSpectralIdentifierArg({ 'OWNER/RULESET_NAME/VERSION': 'owner/ruleset name/version' })})
227-
.to.throw(CLIError)
228-
)
229-
)
230-
231-
context('invalid identifier with space and no version', () => {
232-
it('should throw an exception', () =>
233-
expect(() => { getSpectralIdentifierArg({ 'OWNER/RULESET_NAME/[VERSION]': 'owner/ruleset name' }, false)})
220+
expect(() => { getSpectralIdentifierArg({ 'OWNER/RULESET_NAME': 'owner/ruleset name' })})
234221
.to.throw(CLIError)
235222
)
236-
})
237-
238-
context('invalid identifier with version required', () =>
239-
it('should throw an exception', () =>
240-
expect(() => { getSpectralIdentifierArg({ 'OWNER/RULESET_NAME/VERSION': 'owner/ruleset' })}).to.throw(CLIError)
241-
)
242223
)
243224
})
244225

0 commit comments

Comments
 (0)