-
-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(formats): add arazzo format (#2663)
- Loading branch information
1 parent
3797272
commit dc1a8ef
Showing
3 changed files
with
40 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { arazzo1_0 } from '../arazzo'; | ||
|
||
describe('Arazzo format', () => { | ||
describe('Arazzo 1.0.x', () => { | ||
it.each(['1.0.0', '1.0', '1.0.1', '1.0.2', '1.0.99'])('recognizes %s version correctly', version => { | ||
expect(arazzo1_0({ arazzo: version }, null)).toBe(true); | ||
}); | ||
|
||
const testCases = [ | ||
{ arazzo: '0.1' }, | ||
{ arazzo: '1.1.0' }, | ||
{ arazzo: '2' }, | ||
{ arazzo: '2.0' }, | ||
{ arazzo: '2.0.' }, | ||
{ arazzo: '2.0.01' }, | ||
{ arazzo: 2 }, | ||
{ arazzo: null }, | ||
{ arazzo: '4.0' }, | ||
{}, | ||
null, | ||
]; | ||
|
||
it.each(testCases)('does not recognize invalid document %o', document => { | ||
expect(arazzo1_0(document, null)).toBe(false); | ||
}); | ||
}); | ||
}); |
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 @@ | ||
import type { Format } from '@stoplight/spectral-core'; | ||
import { isPlainObject } from '@stoplight/json'; | ||
|
||
type MaybeArazzo = { arazzo: unknown } & Record<string, unknown>; | ||
|
||
const arazzo1_0Regex = /^1\.0(?:\.[0-9]*)?$/; | ||
|
||
const isArazzo = (document: unknown): document is { arazzo: string } & Record<string, unknown> => | ||
isPlainObject(document) && 'arazzo' in document && arazzo1_0Regex.test(String((document as MaybeArazzo).arazzo)); | ||
|
||
export const arazzo1_0: Format = isArazzo; | ||
arazzo1_0.displayName = 'Arazzo 1.0.x'; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './openapi'; | ||
export * from './asyncapi'; | ||
export * from './jsonSchema'; | ||
export * from './arazzo'; |