-
Notifications
You must be signed in to change notification settings - Fork 38
camelCasing or PascalCasing
Prior to version 1.7, property names and function names of TypeScript codes generated are the exact matches to the respective C# codes of Web API. If the C# codes follow the naming conventions of .NET class libraries, you will have pascal casing for property names and function names. This is somehow at odd against the camel casing convention in javascript and JSON.
If the Web front end developers are from C# background, this is not a problem, since they are getting used to pascal casing. And by default Web API scaffolding codes generated JSON objects with property names exactly matching to the property names of POCO.
However, front-end developers from the other backgrounds might prefer the camel casing convention, and it is better to let the team decide what casing to use. Since version 1.7, WebApiClientGen optionally supports camelCasing when generating TypeScript codes.
In the CodeGen config:
{
"ClientLibraryProjectFolderName": "DemoWebApi.ClientApi",
"ExcludedControllerNames": [
"DemoWebApi.Controllers.Account"
],
"GenerateBothAsyncAndSync": true,
"TypeScriptFolder": "ClientApi",
"DataModelAssemblyNames": [
"DemoWebApi.DemoData", "DemoWebApi"
],
"CherryPickingMethods": 1,
"CamelCase" : true
}
If CamelCase=true, the TypeScript codes generated will conform to the camelCasing convention of javascript.
If CamelCase=false, no camelCasing will be carried out upon property names and function names.
If CamelCase is not defined, WebApiClientGen will check whether
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ContractResolver is Newtonsoft.Json.Serialization.CamelCasePropertyNamesContractResolver
If CamelCasePropertyNamesContractResolver is in the pipeline, camelCasing will be used. If not, no camelCasing transformation to TypeScript codes will be carried out.
Hint:
The data binding of Web API through JSON objects and JSON.NET is case insensitive during deserialization. In other words, ASP.NET Web API accepts properties of JSON object in case insensitive manner.
Remarks:
If you have been using WebApiClientGen prior to version 1.7, your existing applications won't be broken, and you may continue to use PascalCasing in your TypeScript codes. However, if you decide to use camelCasing from now on, you will have to modify your TypeScript client codes, because the design time validation and compile time validation are case sensitive.
References: WebAPI camelCasing JSON