Skip to content

Commit

Permalink
feat(formats): add arazzo format (#2663)
Browse files Browse the repository at this point in the history
  • Loading branch information
frankkilcommins authored Aug 14, 2024
1 parent 3797272 commit dc1a8ef
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/formats/src/__tests__/arazzo.test.ts
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);
});
});
});
12 changes: 12 additions & 0 deletions packages/formats/src/arazzo.ts
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';
1 change: 1 addition & 0 deletions packages/formats/src/index.ts
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';

0 comments on commit dc1a8ef

Please sign in to comment.