Yaml:
dateAndTime:
format: date-time
type: string
is generated for typescript-angular as:
dateAndTime?: Date;
Yaml:
date:
format: date
type: string
is generated for typescript-angular as:
date?: sring;
Why is there difference?
Why is not date-time generated as string?
Thnx.
a date would be something like 2019-10-16, but since Date can also contain time information I think string is a good choice for date properties.
for date-time, it should be string, too, since Date is not serializable in json. We usually override the type to be string, too.
But this should be changed in the code.
@akehir what do you think?
I agree, it should be string.
However, that could lead to "breaking" changes in typescript being used today (which is admittedly better than the current case, where you could run into runtime bugs).
The main drawback I see, however, is that you loose the 'documentation' given by the "Date" type. Right now, if I get a Date in the generated typescript. I know that I can parse that string into a JS date, which can be helpful.
Hi, well I'm fine with both being string or date(I prefere strings though) but it should be consistent, which is not now :(
Right now, if I get a Date in the generated typescript. I know that I can parse that string into a JS date, which can be helpful.
I'm sorry, but I don't understand what you mean?
since there is still the possibility to supply the type-mapping option, I would change it to string for both, date and date-time.
@skorunka would you like to file a PR?
@macjohnny Might try to. But if you guys know its 5 mins job for ya, go for it. It might take hours for me. But yeah, will try..
@skorunka I can point you to the right files to change
I think the source is here:
https://github.com/OpenAPITools/openapi-generator/blob/c32fa5d0120c8d2ddbb9f810af8640f301060d39/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractTypeScriptClientCodegen.java#L124-L125
a custom type mapping should be added here:
https://github.com/OpenAPITools/openapi-generator/blob/c32fa5d0120c8d2ddbb9f810af8640f301060d39/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/TypeScriptAngularClientCodegen.java#L76
then simply run
mvn clean package
bin/typescript-angular-petstore-all.sh
and commit the changed samples in the /samples folder
@macjohnny I suggest putting this in the settings. I do not agree that the date should be just a string. In the project that I am developing, the date is transmitted in ISO format (ex 2019-12-26T14:46:56+00:00 - date or 2019-12-26T14:46:56Z - date time) and this standard is used a lot. The option that you offer will result in the parameter having the date format specified by the locale (this is never ISO in js / ts). I came here just because date is generated as a string ...
a
datewould be something like2019-10-16, but sinceDatecan also contain time information I thinkstringis a good choice fordateproperties.
fordate-time, it should bestring, too, sinceDateis not serializable in json. We usually override the type to bestring, too.
But this should be changed in the code.
@akehir what do you think?
Date is converted to json by JSON.stringify(...) function, when you convert a date from new Date("2020-04-13T00:00:00.000+08:00") to json you will get a 2020-04-12T16:00:00.000Z string, It is converted to UTC, in server side if you receive this string for instance in java spring boot app, LocalDateTIme will get a value of 2020-04-12T16:00:00. In server side it means 2020-04-12T16:00:00.000+08:00, not same as original 2020-04-13T00:00:00.000+08:00.
I think date-type need to be a string in client side to make is possible to skip the timezone conversion of the javascript date class.
this issue is fixed with https://github.com/OpenAPITools/openapi-generator/pull/5314 and https://github.com/OpenAPITools/openapi-generator/pull/5266
Most helpful comment
@macjohnny I suggest putting this in the settings. I do not agree that the date should be just a string. In the project that I am developing, the date is transmitted in ISO format (ex 2019-12-26T14:46:56+00:00 - date or 2019-12-26T14:46:56Z - date time) and this standard is used a lot. The option that you offer will result in the parameter having the date format specified by the locale (this is never ISO in js / ts). I came here just because date is generated as a string ...