-
-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(rules): further separate oas3 and oas2 rules
- Loading branch information
Showing
12 changed files
with
300 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/rulesets/oas/__tests__/api-host.ts → src/rulesets/oas2/__tests__/api-host.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
src/rulesets/oas/__tests__/api-schemes.ts → src/rulesets/oas2/__tests__/api-schemes.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Spectral } from '../../../spectral'; | ||
import { oas2Rules } from '../index'; | ||
|
||
const ruleset = { rules: oas2Rules() }; | ||
|
||
describe('host-not-example', () => { | ||
const s = new Spectral(); | ||
s.addRules({ | ||
'host-not-example': Object.assign(ruleset.rules['host-not-example'], { | ||
enabled: true, | ||
}), | ||
}); | ||
|
||
test('validate a correct object', () => { | ||
const results = s.run({ | ||
swagger: '2.0', | ||
paths: {}, | ||
host: 'stoplight.io', | ||
}); | ||
expect(results.results.length).toEqual(0); | ||
}); | ||
|
||
test('return errors if server is example.com', () => { | ||
const results = s.run({ | ||
swagger: '2.0', | ||
paths: {}, | ||
host: 'https://example.com', | ||
}); | ||
expect(results.results.length).toEqual(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Spectral } from '../../../spectral'; | ||
import { oas2Rules } from '../index'; | ||
|
||
const ruleset = { rules: oas2Rules() }; | ||
|
||
describe('host-trailing-slash', () => { | ||
const s = new Spectral(); | ||
s.addRules({ | ||
'host-trailing-slash': Object.assign(ruleset.rules['host-trailing-slash'], { | ||
enabled: true, | ||
}), | ||
}); | ||
|
||
test('validate a correct object', () => { | ||
const results = s.run({ | ||
swagger: '2.0', | ||
paths: {}, | ||
host: 'stoplight.io', | ||
}); | ||
expect(results.results.length).toEqual(0); | ||
}); | ||
|
||
test('return errors if host url ends with a slash', () => { | ||
const results = s.run({ | ||
swagger: '2.0', | ||
paths: {}, | ||
host: 'stoplight.io/', | ||
}); | ||
expect(results.results.length).toEqual(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Spectral } from '../../../spectral'; | ||
import { oas3Rules } from '../index'; | ||
|
||
const ruleset = { rules: oas3Rules() }; | ||
|
||
describe('api-servers', () => { | ||
const s = new Spectral(); | ||
s.addRules({ | ||
'api-servers': Object.assign(ruleset.rules['api-servers'], { | ||
enabled: true, | ||
}), | ||
}); | ||
|
||
test('validate a correct object', () => { | ||
const results = s.run({ | ||
openapi: '3.0.0', | ||
paths: {}, | ||
servers: [{ url: 'https://stoplight.io' }], | ||
}); | ||
expect(results.results.length).toEqual(0); | ||
}); | ||
|
||
test('return errors if servers is missing ', () => { | ||
const results = s.run({ | ||
openapi: '3.0.0', | ||
paths: {}, | ||
}); | ||
expect(results.results.length).toEqual(1); | ||
}); | ||
|
||
test('return errors if servers is an empty array ', () => { | ||
const results = s.run({ | ||
openapi: '3.0.0', | ||
paths: {}, | ||
servers: [], | ||
}); | ||
expect(results.results.length).toEqual(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Spectral } from '../../../spectral'; | ||
import { oas3Rules } from '../index'; | ||
|
||
const ruleset = { rules: oas3Rules() }; | ||
|
||
describe('model-description', () => { | ||
const s = new Spectral(); | ||
s.addRules({ | ||
'model-description': Object.assign(ruleset.rules['model-description'], { | ||
enabled: true, | ||
}), | ||
}); | ||
|
||
test('validate a correct object', () => { | ||
const results = s.run({ | ||
openapi: '3.0.0', | ||
paths: {}, | ||
components: { | ||
schemas: { | ||
user: { | ||
description: 'this describes the user model', | ||
}, | ||
}, | ||
}, | ||
}); | ||
expect(results.results.length).toEqual(0); | ||
}); | ||
|
||
test('return errors if a definition is missing description', () => { | ||
const results = s.run({ | ||
openapi: '3.0.0', | ||
paths: {}, | ||
components: { | ||
schemas: { | ||
user: {}, | ||
}, | ||
}, | ||
}); | ||
expect(results.results.length).toEqual(1); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.