@@ -622,7 +622,7 @@ function compileNumberSchema(
622622}
623623
624624function compileStringSchema ( compiler : Compiler , schema : OpenAPIStringSchema ) {
625- return compiler . declareValidationFunction ( schema , ( { value, error } ) => {
625+ return compiler . declareValidationFunction ( schema , ( { value, context , path , error } ) => {
626626 const enumCheck = compileEnumableCheck ( compiler , schema , value , error ) ;
627627 if ( enumCheck ) {
628628 return enumCheck ;
@@ -641,6 +641,44 @@ function compileStringSchema(compiler: Compiler, schema: OpenAPIStringSchema) {
641641 ) ,
642642 ) ;
643643
644+ // Validate the format using the potential `context?.formatString?.[schema.format]`
645+ if ( schema . format ) {
646+ const formatResult = builders . identifier ( 'formatResult' ) ;
647+
648+ nodes . push (
649+ builders . variableDeclaration ( 'const' , [
650+ builders . variableDeclarator (
651+ formatResult ,
652+ builders . callExpression . from ( {
653+ callee : builders . memberExpression . from ( {
654+ object : builders . memberExpression . from ( {
655+ object : context ,
656+ property : builders . identifier ( 'formatString' ) ,
657+ optional : true ,
658+ } ) ,
659+ property : builders . literal ( schema . format ) ,
660+ computed : true ,
661+ optional : true ,
662+ } ) ,
663+ optional : true ,
664+ arguments : [ value , path ] ,
665+ } ) ,
666+ ) ,
667+ ] ) ,
668+ ) ;
669+
670+ nodes . push (
671+ builders . ifStatement (
672+ builders . binaryExpression (
673+ 'instanceof' ,
674+ formatResult ,
675+ ValidationErrorIdentifier ,
676+ ) ,
677+ builders . blockStatement ( [ builders . returnStatement ( formatResult ) ] ) ,
678+ ) ,
679+ ) ;
680+ }
681+
644682 if ( schema . minLength ) {
645683 nodes . push (
646684 builders . ifStatement (
0 commit comments