-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: register rules against specific formats (#432)
* feat: register formats in ruleset and rule schemas * feat: handle formats in merger * test(reader): cover formats * feat: implement registerFormat * feat: register OAS formats for CLI * test: oas spec is logged properly now when ruleset with rules is given * feat: improve naming and lookups * chore: tweak naming
- Loading branch information
Showing
22 changed files
with
514 additions
and
25 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
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
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
12 changes: 12 additions & 0 deletions
12
src/rulesets/__tests__/__fixtures__/my-open-api-ruleset.json
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,12 @@ | ||
{ | ||
"extends": ["spectral:oas2", "spectral:oas3"], | ||
"rules": { | ||
"valid-rule": { | ||
"message": "should be OK", | ||
"given": "$.info", | ||
"then": { | ||
"function": "truthy" | ||
} | ||
} | ||
} | ||
} |
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,56 @@ | ||
import { isOpenApiv2, isOpenApiv3, isOpenApiv3_1 } from '../lookups'; | ||
|
||
// @oclif/test packages requires @types/mocha, therefore we have 2 packages coming up with similar typings | ||
// TS is confused and prefers the mocha ones, so we need to instrument it to pick up the Jest ones | ||
declare var it: jest.It; | ||
|
||
describe('Format lookups', () => { | ||
describe('OpenAPI 2.0 aka Swagger', () => { | ||
it.each(['2.0.0', '2', '2.0'])('recognizes %s version correctly', version => { | ||
expect(isOpenApiv2({ swagger: version })).toBe(true); | ||
}); | ||
|
||
it('does not recognize invalid document', () => { | ||
expect(isOpenApiv2({ openapi: '2.0' })).toBe(false); | ||
expect(isOpenApiv2({ openapi: null })).toBe(false); | ||
expect(isOpenApiv2({ swagger: null })).toBe(false); | ||
expect(isOpenApiv2({ swagger: '3.0' })).toBe(false); | ||
expect(isOpenApiv2({ swagger: '1.0' })).toBe(false); | ||
expect(isOpenApiv2({})).toBe(false); | ||
expect(isOpenApiv2(null)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('OpenAPI 3.0', () => { | ||
it.each(['3.0.0', '3', '3.0'])('recognizes %s version correctly', version => { | ||
expect(isOpenApiv3({ openapi: version })).toBe(true); | ||
}); | ||
|
||
it('does not recognize invalid document', () => { | ||
expect(isOpenApiv3({ openapi: '4.0' })).toBe(false); | ||
expect(isOpenApiv3({ openapi: '2.0' })).toBe(false); | ||
expect(isOpenApiv3({ openapi: null })).toBe(false); | ||
expect(isOpenApiv3({ swagger: null })).toBe(false); | ||
expect(isOpenApiv3({ swagger: '3.0' })).toBe(false); | ||
expect(isOpenApiv3({})).toBe(false); | ||
expect(isOpenApiv3(null)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('OpenAPI 3.1', () => { | ||
it.each(['3.1.0', '3.1'])('recognizes %s version correctly', version => { | ||
expect(isOpenApiv3_1({ openapi: version })).toBe(true); | ||
}); | ||
|
||
it('does not recognize invalid document', () => { | ||
expect(isOpenApiv3_1({ openapi: '4.0' })).toBe(false); | ||
expect(isOpenApiv3_1({ openapi: 3.0 })).toBe(false); | ||
expect(isOpenApiv3_1({ openapi: '2.0' })).toBe(false); | ||
expect(isOpenApiv3_1({ openapi: null })).toBe(false); | ||
expect(isOpenApiv3_1({ swagger: null })).toBe(false); | ||
expect(isOpenApiv3_1({ swagger: '3.0' })).toBe(false); | ||
expect(isOpenApiv3_1({})).toBe(false); | ||
expect(isOpenApiv3_1(null)).toBe(false); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.