Skip to content

Commit dc1a8ef

Browse files
feat(formats): add arazzo format (stoplightio#2663)
1 parent 3797272 commit dc1a8ef

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { arazzo1_0 } from '../arazzo';
2+
3+
describe('Arazzo format', () => {
4+
describe('Arazzo 1.0.x', () => {
5+
it.each(['1.0.0', '1.0', '1.0.1', '1.0.2', '1.0.99'])('recognizes %s version correctly', version => {
6+
expect(arazzo1_0({ arazzo: version }, null)).toBe(true);
7+
});
8+
9+
const testCases = [
10+
{ arazzo: '0.1' },
11+
{ arazzo: '1.1.0' },
12+
{ arazzo: '2' },
13+
{ arazzo: '2.0' },
14+
{ arazzo: '2.0.' },
15+
{ arazzo: '2.0.01' },
16+
{ arazzo: 2 },
17+
{ arazzo: null },
18+
{ arazzo: '4.0' },
19+
{},
20+
null,
21+
];
22+
23+
it.each(testCases)('does not recognize invalid document %o', document => {
24+
expect(arazzo1_0(document, null)).toBe(false);
25+
});
26+
});
27+
});

packages/formats/src/arazzo.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import type { Format } from '@stoplight/spectral-core';
2+
import { isPlainObject } from '@stoplight/json';
3+
4+
type MaybeArazzo = { arazzo: unknown } & Record<string, unknown>;
5+
6+
const arazzo1_0Regex = /^1\.0(?:\.[0-9]*)?$/;
7+
8+
const isArazzo = (document: unknown): document is { arazzo: string } & Record<string, unknown> =>
9+
isPlainObject(document) && 'arazzo' in document && arazzo1_0Regex.test(String((document as MaybeArazzo).arazzo));
10+
11+
export const arazzo1_0: Format = isArazzo;
12+
arazzo1_0.displayName = 'Arazzo 1.0.x';

packages/formats/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
export * from './openapi';
22
export * from './asyncapi';
33
export * from './jsonSchema';
4+
export * from './arazzo';

0 commit comments

Comments
 (0)