Hello,
I have been using FluentValidation w/ Web API 2.0 and things work very well for me. Recently, we wanted to start exposing our Validation rules to consumers via an API call. Consumers would simply call a known path to obtain the validation rules. This also helps a front-end interface dynamically query the API to obtain validation rules thereby preventing them from being duplicated on the API.
So for e.g. say I have a Site class with properties Name and Abbreviation. Say I have a Required validation for both the properties and a WithMessage() as well.
It would be awesome if I could get all validations that are applied to the Site object so that I could convert them into a string representation and eventually into a JSON object similar to the one shown below:
{
"entity" : "site",
"validations" : [
}
The above is just an example. Essentially, I think I would create an extension that splits out a string representation of the messages for each property and eventually I would use that to build the JSON.
Does FluentValidation have any way I could get this data?
Any guidance would help!
I have been using FluentValidation w/ Web API 2.0 and things work very well for me. Recently, we wanted to start exposing our Validation rules to consumers via an API call. Consumers would simply call a known path to obtain the validation rules. This also helps a front-end interface dynamically query the API to obtain validation rules thereby preventing them from being duplicated on the API.
So for e.g. say I have a Site class with properties Name and Abbreviation. Say I have a Required validation for both the properties and a WithMessage() as well.
It would be awesome if I could get all validations that are applied to the Site object so that I could convert them into a string representation and eventually into a JSON object similar to the one shown below:
{
"entity" : "site",
"validations" : [
{
"element" : "name",
"required" : "true",
"message" : "Name is required"
},
{
"element" : "abbreviation",
"required": "true",
"message" : "Abbreviation is required"
}
]}
The above is just an example. Essentially, I think I would create an extension that splits out a string representation of the messages for each property and eventually I would use that to build the JSON.
Does FluentValidation have any way I could get this data?
Any guidance would help!