Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
emmerich committed Mar 14, 2024
1 parent 21b58ff commit 35c98d5
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
28 changes: 20 additions & 8 deletions src/compileValueSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
8 changes: 4 additions & 4 deletions src/tests/compileValueSchema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('Number', () => {
maximum: 10,
});
expect(compiler.compile()).toMatchSnapshot();
})
});

test('maximum exclusiveMaximum', () => {
const compiler = new Compiler();
Expand All @@ -28,7 +28,7 @@ describe('Number', () => {
exclusiveMaximum: true,
});
expect(compiler.compile()).toMatchSnapshot();
})
});

test('minimum', () => {
const compiler = new Compiler();
Expand All @@ -37,7 +37,7 @@ describe('Number', () => {
minimum: 10,
});
expect(compiler.compile()).toMatchSnapshot();
})
});

test('minimim exclusiveMinimum', () => {
const compiler = new Compiler();
Expand All @@ -47,7 +47,7 @@ describe('Number', () => {
exclusiveMinimum: true,
});
expect(compiler.compile()).toMatchSnapshot();
})
});
});

describe('Integer', () => {
Expand Down
12 changes: 8 additions & 4 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand Down
6 changes: 3 additions & 3 deletions tests/gitbook.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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']);
});
});

0 comments on commit 35c98d5

Please sign in to comment.