Skip to content

Commit

Permalink
Merge pull request #3 from ballerine-io/bal-2444
Browse files Browse the repository at this point in the history
Set Typebox version to be constant
  • Loading branch information
tomer-shvadron authored Jul 17, 2024
2 parents 505f70e + a3f969a commit 74de761
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ballerine-nestjs-typebox",
"version": "3.0.2-next.8",
"version": "3.0.2-next.9",
"description": "",
"author": "Andrew Smiley <[email protected]>",
"license": "MIT",
Expand All @@ -27,6 +27,7 @@
"@nestjs/swagger": "^6.1.1 || ^7.0.11",
"@sinclair/typebox": "^0.32.4",
"ajv": "^8.14.0",
"ajv-formats": "^2.1.1",
"rxjs": "^7.5.6"
},
"dependencies": {
Expand All @@ -37,7 +38,7 @@
"@nestjs/common": "^10.0.5",
"@nestjs/core": "^10.0.5",
"@nestjs/swagger": "^7.1.1",
"@sinclair/typebox": "^0.32.4",
"@sinclair/typebox": "0.32.15",
"@types/node": "^20.4.1",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
Expand Down
22 changes: 18 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { DECORATORS } from '@nestjs/swagger/dist/constants.js';
import { Static, TSchema, Type, TypeGuard } from '@sinclair/typebox';
import Ajv from 'ajv';
import fastUri from 'fast-uri';

import { AjvValidationException } from './exceptions.js';
import { TypeboxTransformInterceptor } from './interceptors.js';
import type {
Expand All @@ -23,6 +22,8 @@ import type {
} from './types.js';
import { capitalize, coerceType, isObj } from './util.js';

import AjvFormats from 'ajv-formats';

const ajv = new Ajv({
coerceTypes: 'array',
useDefaults: true,
Expand All @@ -32,8 +33,13 @@ const ajv = new Ajv({
// Explicitly set allErrors to `false`.
// When set to `true`, a DoS attack is possible.
allErrors: false,

// Our custom options:
keywords: ['transform'],
});

AjvFormats.default(ajv);

export function isSchemaValidator<TRequestSchema extends TSchema, TResponseSchema extends TSchema>(
// eslint-disable-next-line @typescript-eslint/no-explicit-any
type: any
Expand Down

0 comments on commit 74de761

Please sign in to comment.