diff --git a/src/compileComponentSchemas.ts b/src/compileComponentSchemas.ts index c50713a..1762e1d 100644 --- a/src/compileComponentSchemas.ts +++ b/src/compileComponentSchemas.ts @@ -1,8 +1,8 @@ -import { builders } from "ast-types"; -import { Compiler } from "./compiler"; -import { compileValueSchema } from "./compileValueSchema"; -import { OpenAPIValueSchema } from "./types"; -import { annotateWithJSDocComment } from "./comments"; +import { builders } from 'ast-types'; +import { Compiler } from './compiler'; +import { compileValueSchema } from './compileValueSchema'; +import { OpenAPIValueSchema } from './types'; +import { annotateWithJSDocComment } from './comments'; const COMMENT = ` Map of all components defined in the spec to their validation functions. @@ -11,9 +11,12 @@ Map of all components defined in the spec to their validation functions. /** * Compile all component schemas to be expoerted as `components['Name']`. */ -export function compileComponentSchemas(compiler: Compiler, schemas: { - [key: string]: OpenAPIValueSchema; -}) { +export function compileComponentSchemas( + compiler: Compiler, + schemas: { + [key: string]: OpenAPIValueSchema; + }, +) { const properties = Object.entries(schemas).map(([name]) => { return builders.property( 'init', @@ -28,13 +31,11 @@ export function compileComponentSchemas(compiler: Compiler, schemas: { builders.variableDeclaration('const', [ builders.variableDeclarator( builders.identifier('componentSchemas'), - builders.objectExpression( - properties, - ), - ) + builders.objectExpression(properties), + ), ]), ), COMMENT, ), ]; -} \ No newline at end of file +} diff --git a/tests/gitbook.test.ts b/tests/gitbook.test.ts index a875a5c..76b6f4c 100644 --- a/tests/gitbook.test.ts +++ b/tests/gitbook.test.ts @@ -292,10 +292,12 @@ describe('componentSchemas', () => { test('should export a function to validate a component', () => { const validate = componentSchemas['ApiInformation']; expect(validate).toBeInstanceOf(Function); - expect(validate([], { - version: '1.0.0', - build: '123', - })).toEqual({ + expect( + validate([], { + version: '1.0.0', + build: '123', + }), + ).toEqual({ version: '1.0.0', build: '123', }); @@ -303,8 +305,10 @@ describe('componentSchemas', () => { const error = validate([], { version: '1.0.0', // Missing property - }) + }); expect(error instanceof ValidationError ? error.path : null).toEqual([]); - expect(error instanceof ValidationError ? error.message : null).toEqual('expected "build" to be defined'); + expect(error instanceof ValidationError ? error.message : null).toEqual( + 'expected "build" to be defined', + ); }); });