OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
21.24k stars 6.43k forks source link

[BUG] [multiplatform] unintentionally convert a datetime without a time zone to a datetime with UTC time zone. #10603

Open alumuko opened 2 years ago

alumuko commented 2 years ago
Description

The generator unintentionally convert a datetime without a time zone to a datetime with UTC time zone.

write in yaml

          dateTime2:
            type: string
            example: "2021-09-01 00:00:00"

but web ui shows: "dateTime2": "2021-09-01T00:00:00.000Z"

At least, there are the problem with "python-flask" and "nodejs-express-server" . but there aren't the problem with "html".

openapi-generator version

5.2.1.

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  title: test
  version: 1.0.0
paths:
  /test/{dateTime}/:
    get:
      parameters:
        - name: "dateTime"
          in: "path"
          required: true
          schema:
            type: string
            example: "2021-09-01 00:00:00"
      responses:
        "200":
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  dateTime2:
                    type: string
                    example: "2021-09-01 00:00:00"
Generation Details

java -jar openapi-generator-cli-5.2.1.jar generate -i test.yaml -g python-flask -o test-openapi-flask

java -jar openapi-generator-cli-5.2.1.jar generate -i test.yaml -g nodejs-express-server -o test-openapi-nodejs-express-server

java -jar openapi-generator-cli-5.2.1.jar generate -i test.yaml -g html -o test-openapi-html

Steps to reproduce

java -jar openapi-generator-cli-5.2.1.jar generate -i test.yaml -g python-flask -o test-openapi-flask cd test-openapi-flask python -m openapi_server

access http://localhost:8080/ui/#/default/test_date_time_get

Related issues/PRs

https://app.slack.com/client/TLQFRCNJZ/CLSB0U0R5

Suggest a fix
MargieMo commented 2 years ago

Hello, could you please clarify, would you like to change the "2021-09-01T00:00:00.000Z" to "2021-09-01 00:00:00" by deleting the T and .000Z? To me, it seems like there is no timezone difference, both are midnight of 9/01/21. Also the related issues cannot open.

alumuko commented 2 years ago

"both are midnight of 9/01/21" is not correct.

"2021-09-01T00:00:00Z" has UTC time zone. The same time is AM 9.00 in Japan local time. "2021-09-01T00:00:00Z" and "2021-09-01T09:00:00+09:00" are same time.

"2021-09-01 00:00:00" has no time zone. It means midnight at local time. If you write in "2021-09-01 00:00:00" in Greenwich in Great Britain, it means "2021-09-01T00:00:00Z". If you write in "2021-09-01 00:00:00" in Japan, it means midnight in Japan, and it means "2021-08-31T15:00:00Z".

People don't prefer to calculate to Greenwich time before to input date time, especially for using local only system. So I need datetime input without time zone.