@@ -23,6 +23,9 @@ import { z, type ZodErrorMap } from 'zod';
2323import { valibot } from '$lib/adapters/valibot.js' ;
2424import * as v from 'valibot' ;
2525
26+ import { classValidator } from '$lib/adapters/class-validator.js' ;
27+ import { ArrayMinSize , IsOptional , IsString , IsEmail , IsArray , MinLength , IsInt , Min , IsDate , Matches } from 'class-validator' ;
28+
2629//import { ajv } from '$lib/adapters/ajv.js';
2730//import type { JSONSchema } from '$lib/jsonSchema/index.js';
2831
@@ -70,7 +73,7 @@ import { SchemaError, type JSONSchema } from '$lib/index.js';
7073
7174///// Test data /////////////////////////////////////////////////////
7275
73- /*
76+ /*
7477TEST SCHEMA TEMPLATE:
7578
7679| field | type | opt/null | constraints | default |
@@ -467,6 +470,40 @@ describe('Valibot', () => {
467470 */
468471} ) ;
469472
473+ describe ( 'class-validator' , ( ) => {
474+ class ClassValidatorSchema {
475+ @IsString ( )
476+ name : string = 'Unknown' ;
477+
478+ @IsString ( )
479+ @IsEmail ( )
480+ email : string | undefined ;
481+
482+ @IsArray ( )
483+ @MinLength ( 2 , { each : true } )
484+ @ArrayMinSize ( 3 )
485+ tags : string [ ] | undefined ;
486+
487+ @IsInt ( )
488+ @Min ( 0 )
489+ score : number | undefined ;
490+
491+ @IsDate ( )
492+ date : Date | undefined ;
493+
494+ @IsOptional ( )
495+ @Matches ( / ^ \S * $ / , { message : 'No spaces allowed' } )
496+ nospace : string | undefined ;
497+
498+ @IsOptional ( )
499+ @IsString ( )
500+ extra : string | null = null ;
501+ }
502+
503+ const adapter = classValidator ( ClassValidatorSchema , { defaults } ) ;
504+ schemaTest ( adapter , [ 'email' , 'date' , 'nospace' , 'tags' ] , 'simple' ) ;
505+ } ) ;
506+
470507/////////////////////////////////////////////////////////////////////
471508
472509// ajv is disabled due to no ESM compatibility.
0 commit comments