[BUG][Typescript fetch] JSON-serialization does not obay timezone for date fields
Created by: stephanpelikan
Description
I'm located in Austria which is GMT+1 and in daylight-saving period it is GMT+2. When I have this API definition
openapi: 3.0.0
...
components:
schemas:
MemberApplicationForm:
type: object
properties:
birthdate:
type: string
format: date
and set a Javascript Date new Date('2022-06-05T00:00:00')
then the toISOString()
method returns 2022-06-04T22:00:00.000Z
which is used as a bases for date formatting in JSON. Therefore the date is '2022-06-04' instead of '2022-06-05'!
Files affected:
- modules/openapi-generator/src/main/resources/typescript-fetch/apis.mustache
- modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustache
openapi-generator version
6.0.0
OpenAPI declaration file content or url
Generation Details
Maven build:
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.0.0</version>
<executions>
<execution>
<id>generate-administration-api</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/src/main/resources/api/administration/v1.yaml</inputSpec>
<output>${project.build.directory}/generated-sources</output>
<generatorName>spring</generatorName>
<apiPackage>at.demo.administration.api.v1</apiPackage>
<modelPackage>at.demo.administration.api.v1</modelPackage>
<generateSupportingFiles>true</generateSupportingFiles>
<supportingFilesToGenerate>ApiUtil.java</supportingFilesToGenerate>
<configOptions>
<sourceFolder>openapi</sourceFolder>
<interfaceOnly>true</interfaceOnly>
<useSpringController>true</useSpringController>
<dateLibrary>java8</dateLibrary>
<useBeanValidation>true</useBeanValidation>
</configOptions>
<addCompileSourceRoot>true</addCompileSourceRoot>
</configuration>
</execution>
</executions>
</plugin>
Steps to reproduce
See description
Related issues/PRs
This PR also belongs to date/time in Typescript fetch but does not fix that issue: https://github.com/OpenAPITools/openapi-generator/pull/11685/commits/2cde020568701b92b3a347d26fc8e746c172bbb0#
Suggest a fix
const offset = yourDate.getTimezoneOffset()
yourDate = new Date(yourDate.getTime() - (offset*60*1000))
return yourDate.toISOString().substr(0,10);