Skip to content

Commit

Permalink
Set Typebox version to be constant
Browse files Browse the repository at this point in the history
  • Loading branch information
tomer-shvadron committed Jul 17, 2024
1 parent 505f70e commit 61c2f91
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.

5 changes: 5 additions & 0 deletions src/ajv-options.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import type { Options } from 'ajv';

export const ajvOptions = {
keywords: ['transform'],
} satisfies Options;
9 changes: 8 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,9 @@ import type {
} from './types.js';
import { capitalize, coerceType, isObj } from './util.js';

import AjvFormats from 'ajv-formats';
import { ajvOptions } from './ajv-options.js';

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

// Our custom options:
...ajvOptions,
});

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 61c2f91

Please sign in to comment.