swagger-api / swagger-api/swagger-codegen
[typescript][node] Date format is not serialized to ISO string format
@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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.