Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
TypeScript generation forces lower case first character #1926
To give some background, we use a C# WebAPI service, so we use Pascal casing in our objects. We have both C# cleints and TypeScript Clients that access the API.
When using the codegen to generate a TypeScript client for angularJS, the TypeScript code appears to be forcing the property names to camel case using the second variable in the camelize function on this line: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractTypeScriptClientCodegen.java#L86
This causing issue for us because our we service returns an object like this:
And the object in TypeScript looks like this:
So the object name is fine, its the properties that are wrong.
I think this second parameter in the camelize function should be added as a config option for those that need it compatible with C# services.
I understand that MS recommend camel casing for TypeScript properties (here https://github.com/Microsoft/TypeScript/wiki/Coding-guidelines), but this makes it incompatible with services written in C#, so I think the config option for the language is the best option.
Thanks for the prompt response!
After looking at it some further we found this article:
Then looked at our swagger codegen and autorest output for c# using camel casing in the Json objects from WebAPI.
Both apps in C# output like this for camel casing:
So they adjust for the API being in camel casing back to pascal casing in the API, where as the other languages don't seem to do it the other way round out of the box, i think the best approach for language compatibility is to:
Though we could force TypeScript into pascal casing, using the work around you proposed, it feels like swimming upstream after I've seen this alternative :)
Thanks for you help @wing328
That's one way to do it but as you've pointed out the C# API client needs some modification to translate the JSON property name (which means the solution will impact other existing API clients)
I think it's just a matter of time we encounter a case in which we must use the attribute mapping in TypeScript client to resolve the issue.
(btw, I was confused earlier as my comment aims to address another issue with JSON property name with special characters)
Also you may find some hardcore people out their that are using snake case or something lol. we still have some legacy apps that use(d) snake case.