You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
typeDatePathObject="date"|{[path: string]: DatePathObject}/** the idea for the datePathObject is that its an object that has all the date formats that are in the response spec to we only transform those that are listed */privatemapResponseRecursive(response,datePathObject: DatePathObject): any {if(response==null){returnresponse;}if(typeofresponse==="object"&&typeofdatePathObject==="object"){if(Array.isArray(response)){// instead of [number] there should probably something more unique - maybe even a symbolreturnresponse.map(subEntry=>this.mapResponseRecursive(subEntry,datePathObject[`[number]`]))}for(constkeyofObject.keys(response)){if(keyindatePathObject){response[key]=this.mapResponseRecursive(response[key],datePathObject[key])}}}if(typeofresponse=="string"&&datePathObject=="date"){returnnewDate(response)}returnresponse}returnthis.httpClient.request{{^isResponseFile}}<{{#returnType}}{{{returnType}}}{{#isResponseTypeFile}}|undefined{{/isResponseTypeFile}}{{/returnType}}{{^returnType}}any{{/returnType}}>{{/isResponseFile}}('{{httpMethod}}',`${this.configuration.basePath}${localVarPath}`,{
....}).pipe(map(response=>this.mapResponseRecursive(response,/**get path data from spec*/)))
for the example spec above the datePathObject would be this:
{"time": "date"}
The text was updated successfully, but these errors were encountered:
an alternative would be to make the models each a class , then the class that is handling the response model can do the Date transformation in the constructor
jonnytest1
changed the title
[BUG] [typescript-angular] no convertion for Date format in response
[BUG] [typescript-angular] no conversion for Date format in response
Jan 29, 2025
Bug Report Checklist
Description
using typescipt-angular doesn transform date-time string formats to Date , even though its typed as Date
openapi-generator version
OpenAPI declaration file content or url
Generation Details
typescript-angular
Steps to reproduce
openapi-generator-cli generate
Related issues/PRs
Suggest a fix
in https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/resources/typescript-angular/api.service.mustache
pipe the response into a map() and convert all the date-time formated fields to a Date
for the example spec above the datePathObject would be this:
The text was updated successfully, but these errors were encountered: