Task To Accomplish
I am creating a validation service which validates a user profile data for correctness. A user profile can have following information:
- Name
- Address
- Social Security Number(SSN)
- Other fields.
When user will submit the profile edit form, I will call the validation service to check if the user entered correct data or not.
Requirements
- Every field is having different method of validation. For eg., To check name, the rule could be to use a regex. To check if address is valid, I might have to call some third party api which will tell if address does actually exist. In general, there could be numerous ways to validate fields.
- The profile data has many attributes and is unstructured.
I want to come up with a validation registry component which will be called by validation service to check what is to be done with the field. This component should be generic enough so that it can take up many heterogenous ways to validate certain attributes. I don’t want to create if else blocks in my code to create the validation rules.
Things that have come to my mind
- Creating registry in yaml :
I can write the rules in a yaml file which will tell how to validate an attribute. PFB
attributes:
-name: email
desc: Email address
type: /entity/Profile/emailaddress
validation: false
-name: address
desc: Home address
validation: true
validators:
dns: www.xyz.com
port: 443
socketTimeout: 30000
endpoint: /user/{userId}/validateAddress
mode: sync
Objective
I want to explore different ways to implement such system which is generic enough. Please let me know your thoughts on this.