Typescript generated client uses inconsistent casing for property names
See original GitHub issueFor this definition in JSON I have Username
and Password
properties.
"definitions": {
"TokenRequest": {
"type": "object",
"additionalProperties": false,
"properties": {
"Username": {
"type": "string"
},
"Password": {
"type": "string"
}
}
},
The angular client I’m generating contains the following interface for an ITokenRequest
and (as expected) makes the properties lowercase to conform to JS conventions.
export interface ITokenRequest {
username?: string | undefined;
password?: string | undefined;
}
However the init()
function does not change the casing and gives me this.username = data["Username"];
and you end up with undefined
for all the properties.
export class TokenRequest implements ITokenRequest {
username?: string | undefined;
password?: string | undefined;
constructor(data?: ITokenRequest) {
if (data) {
for (var property in data) {
if (data.hasOwnProperty(property))
(<any>this)[property] = (<any>data)[property];
}
}
}
init(data?: any) {
if (data) {
this.username = data["Username"];
this.password = data["Password"];
}
}
static fromJS(data: any): TokenRequest {
data = typeof data === 'object' ? data : {};
let result = new TokenRequest();
result.init(data);
return result;
}
toJSON(data?: any) {
data = typeof data === 'object' ? data : {};
data["Username"] = this.username;
data["Password"] = this.password;
return data;
}
}
This is with all the latest bits from today using msbuild targets to generate the code. I haven’t used nswag in a couple months, so can’t say exactly when this started.
// Generated using the NSwag toolchain v11.17.19.0 (NJsonSchema v9.10.58.0 (Newtonsoft.Json v9.0.0.0)) (http://NSwag.org)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:14 (7 by maintainers)
Top Results From Across the Web
Typescript generated client uses inconsistent casing for ...
I'm generating a Angular 6 Client with DTO Interfaces. The interface gets generated with uppercase property Name (first letter) instead of all ...
Read more >Inconsistent property name casing in generated JsonResult
I am using IIS and IE9 for testing. I feel like the response is somehow being cached. There are other places in the...
Read more >TypeScript's quirks: How inconsistencies make ...
The logic here is that because TypeScript is structurally typed, it only cares about the properties that objects contain (not how they were ......
Read more >TypeScript's quirks: How inconsistencies make ...
Excess property checks catch a common JavaScript bug (typoed property names), structural static typing matches the dynamic duck typing ...
Read more >Getting started with the TypeScript satisfies operator
The TypeScript satisfies operator is a new and better approach to type-safe configuration in TypeScript released in TypeScript v4.9.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I think this PR fixes that + makes using the same settings in the middleware and CLI easier: https://github.com/RSuter/NSwag/pull/1430
Not sure yet if the actual implementation has the best possible design
Ah, I think for that to work we need the same logic here
https://github.com/RSuter/NSwag/blob/master/src/NSwag.Commands/Commands/SwaggerGeneration/AspNetCore/AspNetCoreToSwaggerGeneratorCommandEntryPoint.cs#L35
and here
https://github.com/RSuter/NSwag/blob/master/src/NSwag.Commands/Commands/SwaggerGeneration/AspNetCore/AspNetCoreToSwaggerCommand.cs#L239