swagger-api / swagger-api/swagger-codegen

[typescript][node] Date format is not serialized to ISO string format

Open
#9,571 1 comment 1 reaction 1 assignee View on GitHub

@HugoMario is already working on this.

Since May 8, 2020.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

When I generate client classes for language typescript-node (-l typescript-node ) the Date is serialized using toString() method and resulting in incorrect format. How can I change the generated client to use ISO format - toISOString()?

Swagger-codegen version

2.4.3

Swagger declaration file content or url

https://api-uat.codat.io/swagger/docs/v1

Command line used for generation

java -jar swagger-codegen-cli.jar generate -i https://api-uat.codat.io/swagger/docs/v1 -l typescript-node -o d:\swagger --additional-properties supportsES6=true

Line 82 in the client with toString()

public static serialize(data: any, type: string) {
if (data == undefined) {
return data;
} else if (primitives.indexOf(type.toLowerCase()) !== -1) {
return data;
} else if (type.lastIndexOf("Array<", 0) === 0) { // string.startsWith pre es6
let subType: string = type.replace("Array<", ""); // Array => Type>
subType = subType.substring(0, subType.length - 1); // Type> => Type
let transformedData: any[] = [];
for (let index in data) {
let date = data[index];
transformedData.push(ObjectSerializer.serialize(date, subType));
}
return transformedData;
} else if (type === "Date") {
return data.toString();

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.