-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add option to camelCase property names #226
Comments
Hi Adam You can actually already do this. FV has support for both Propertname resolvers and displayname resolvers which allow you to customise how the property names are generated. These are accessible on the global static ValidatorOptions class. |
Thanks @JeremySkinner - I was able to get this working as you described with the PropertyNameResolver. Would you be interested in a PR that introduces an IDisplayNameResolver and IPropertyNameResolver interfaces and your default implementation, as well as a camel case version? |
I'm not really keen to introduce such a large breaking change like that, so I'd rather stick with the existing delegate-based approach rather than introducing a new interface. Perhaps you'd like to include the code you wrote here though? I can then put it in the wiki as an example of how to write a custom resolver. Thanks! |
Sure thing! Here is my camel case property resolver. This was taken directly from the json.net code:
And then in startup.cs:
|
Snake case if someone want:
|
Due to the conventions mismatch of .NET and javascript, lots of JSON serializers provide the ability to serialize outbound property names in models in a camelCase format. It's great that FluentValidation gives us the ability to change the property name, but it would be even better if we had a way to extend the way property names are generated, and include a few common formats.
If you could point me in the right direction, I could submit a PR for this.
The text was updated successfully, but these errors were encountered: