diff --git a/src/compileValueSchema.ts b/src/compileValueSchema.ts index 188a23b..f5193c3 100644 --- a/src/compileValueSchema.ts +++ b/src/compileValueSchema.ts @@ -660,19 +660,31 @@ function compileNumberSchema( if (schema.maximum !== undefined) { nodes.push( builders.ifStatement( - builders.binaryExpression(schema.exclusiveMaximum ? '>=' : '>', value, builders.literal(schema.maximum)), - builders.blockStatement([builders.returnStatement(error('value greater than maximum'))]), - ) - ) + builders.binaryExpression( + schema.exclusiveMaximum ? '>=' : '>', + value, + builders.literal(schema.maximum), + ), + builders.blockStatement([ + builders.returnStatement(error('value greater than maximum')), + ]), + ), + ); } if (schema.minimum !== undefined) { nodes.push( builders.ifStatement( - builders.binaryExpression(schema.exclusiveMinimum ? '<=' : '<', value, builders.literal(schema.minimum)), - builders.blockStatement([builders.returnStatement(error('value less than minimum'))]), - ) - ) + builders.binaryExpression( + schema.exclusiveMinimum ? '<=' : '<', + value, + builders.literal(schema.minimum), + ), + builders.blockStatement([ + builders.returnStatement(error('value less than minimum')), + ]), + ), + ); } nodes.push(builders.returnStatement(value)); diff --git a/src/tests/compileValueSchema.test.ts b/src/tests/compileValueSchema.test.ts index 888d387..07b4a13 100644 --- a/src/tests/compileValueSchema.test.ts +++ b/src/tests/compileValueSchema.test.ts @@ -18,7 +18,7 @@ describe('Number', () => { maximum: 10, }); expect(compiler.compile()).toMatchSnapshot(); - }) + }); test('maximum exclusiveMaximum', () => { const compiler = new Compiler(); @@ -28,7 +28,7 @@ describe('Number', () => { exclusiveMaximum: true, }); expect(compiler.compile()).toMatchSnapshot(); - }) + }); test('minimum', () => { const compiler = new Compiler(); @@ -37,7 +37,7 @@ describe('Number', () => { minimum: 10, }); expect(compiler.compile()).toMatchSnapshot(); - }) + }); test('minimim exclusiveMinimum', () => { const compiler = new Compiler(); @@ -47,7 +47,7 @@ describe('Number', () => { exclusiveMinimum: true, }); expect(compiler.compile()).toMatchSnapshot(); - }) + }); }); describe('Integer', () => { diff --git a/src/types.ts b/src/types.ts index 1aff336..6f69c80 100644 --- a/src/types.ts +++ b/src/types.ts @@ -76,15 +76,19 @@ interface CommonNumberSchema { exclusiveMinimum?: boolean; exclusiveMaximum?: boolean; } -export interface OpenAPINumberSchema extends CommonNumberSchema, OpenAPINullableSchema, OpenAPIEnumableSchema { +export interface OpenAPINumberSchema + extends CommonNumberSchema, + OpenAPINullableSchema, + OpenAPIEnumableSchema { type: 'number'; maximum?: number; minimum?: number; } - - -export interface OpenAPIIntegerSchema extends CommonNumberSchema, OpenAPINullableSchema, OpenAPIEnumableSchema { +export interface OpenAPIIntegerSchema + extends CommonNumberSchema, + OpenAPINullableSchema, + OpenAPIEnumableSchema { type: 'integer'; format?: 'int32'; } diff --git a/tests/gitbook.test.ts b/tests/gitbook.test.ts index dea88f4..361289e 100644 --- a/tests/gitbook.test.ts +++ b/tests/gitbook.test.ts @@ -327,7 +327,7 @@ test('GET spaces/space_iphone-doc/revisions/somerevision/files?limit=1000 (inval 'content-type': 'application/json', }, query: { - limit: '1000' + limit: '1000', }, }); expect(result instanceof ValidationError ? result.path : null).toEqual(['query', 'limit']); @@ -341,8 +341,8 @@ test('GET spaces/space_iphone-doc/revisions/somerevision/files?limit=-1 (invalid 'content-type': 'application/json', }, query: { - limit: '-1' + limit: '-1', }, }); expect(result instanceof ValidationError ? result.path : null).toEqual(['query', 'limit']); -}); \ No newline at end of file +});