package pl.openrest.dto.validation.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.validation.Validator;

import pl.openrest.dto.mapper.BeforeCreateMappingHandler;
import pl.openrest.dto.mapper.BeforeUpdateMappingHandler;
import pl.openrest.dto.mapper.MappingManager;
import pl.openrest.dto.validation.handler.ValidationContextHandler;
import pl.openrest.dto.validation.handler.ValidatorInvoker;

@Configuration
public class OpenRestDtoValidationConfiguration {

    @Autowired
    private Validator validator;

    @Bean
    public ValidatorInvoker validatorInvoker() {
        return new ValidatorInvoker();
    }

    @Autowired
    public void addDtoValidatorInvokerHandler(MappingManager mappingManager) {
        ValidatorInvoker validatorInvoker = validatorInvoker();
        ValidationContextHandler contextHandler = new ValidationContextHandler();
        mappingManager.addHandler((BeforeCreateMappingHandler) contextHandler);
        mappingManager.addHandler((BeforeUpdateMappingHandler) contextHandler);
        mappingManager.addHandler((BeforeCreateMappingHandler) validatorInvoker);
        mappingManager.addHandler((BeforeUpdateMappingHandler) validatorInvoker);
    }

    @Autowired
    private void addValidators(ValidatorInvoker invoker) {
        invoker.addValidator(validator);
    }

}

@@ -421,24 +421,87 @@
 ingManager;%0A
+import pl.openrest.dto.validation.DtoFieldExpressionValidator;%0A
 import pl.op
@@ -732,16 +732,119 @@
 dator;%0A%0A
+    @Autowired(required = false)%0A    private DtoFieldExpressionValidator dtoFieldExpressionValidator;%0A%0A
     @Bea
@@ -1622,21 +1622,145 @@
 validator);%0A
+        if (dtoFieldExpressionValidator != null) %7B%0A            invoker.addValidator(dtoFieldExpressionValidator);%0A        %7D%0A
     %7D%0A%0A%7D%0A

Add DtoFieldExpressionValidator to ValidatorInvoker