File tree Expand file tree Collapse file tree
src/code_scanners/routes_scanner Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -79,7 +79,11 @@ export async function extractValidators(
7979 * Inspect validators via "request.validateUsing" and "vine.validate"
8080 * method calls.
8181 */
82- const validationCalls = inspectMethodArguments ( method , [ 'request.validateUsing' , 'vine.validate' ] )
82+ const validationCalls = inspectMethodArguments ( method , [
83+ 'request.validateUsing' ,
84+ '$CTX.request.validateUsing' ,
85+ 'vine.validate' ,
86+ ] )
8387 . map ( ( node ) => {
8488 const firstArg = node . find ( {
8589 rule : { any : [ { kind : 'identifier' } , { kind : 'member_expression' } ] } ,
Original file line number Diff line number Diff line change @@ -408,6 +408,44 @@ test.group('Validator extractor', () => {
408408 )
409409 } )
410410
411+ test ( 'extract validator when using ctx.request.validateUsing' , async ( { assert, fs } ) => {
412+ await fs . create (
413+ 'app/controllers/users_controller.ts' ,
414+ `
415+ import { createUserValidator } from '#validators/user'
416+
417+ export default class UsersController {
418+ async store(ctx: HttpContext) {
419+ await ctx.request.validateUsing(createUserValidator)
420+ }
421+ }
422+ `
423+ )
424+
425+ assert . deepEqual (
426+ await extractValidators ( fs . basePath , new VirtualFileSystem ( fs . basePath ) , {
427+ path : join ( fs . basePath , 'app/controllers/users_controller.ts' ) ,
428+ method : 'store' ,
429+ name : 'UsersController' ,
430+ import : {
431+ type : 'default' ,
432+ value : 'UsersController' ,
433+ specifier : '#controllers/users_controller' ,
434+ } ,
435+ } ) ,
436+ [
437+ {
438+ import : {
439+ specifier : '#validators/user' ,
440+ type : 'named' ,
441+ value : 'createUserValidator' ,
442+ } ,
443+ name : 'createUserValidator' ,
444+ } ,
445+ ]
446+ )
447+ } )
448+
411449 test ( 'do not match method name when it appear in body of another method' , async ( {
412450 assert,
413451 fs,
You can’t perform that action at this time.
0 commit comments