-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[python] Fix date-time parsing #6458
[python] Fix date-time parsing #6458
Conversation
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
...python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
Show resolved
Hide resolved
...python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
Outdated
Show resolved
Hide resolved
...python-experimental/petstore-with-fake-endpoints-models-for-testing-with-http-signature.yaml
Outdated
Show resolved
Hide resolved
try { | ||
date = (OffsetDateTime) currentExample; | ||
} catch (ClassCastException e) { | ||
date = ((Date) currentExample).toInstant().atOffset(ZoneOffset.UTC); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain what this code is doing?
Is it assigning the UTC time zone if the date lacks a time zone?
If so I am concerned that we are adding information which is not present.
Is there a spec which directs us to do this?
What happens when invalid values are set as examples/defaults like "1-2" or "NotADateOrDateTime"?
How about adding a sample spec with invalid dates at:
https://github.com/OpenAPITools/openapi-generator/tree/master/modules/openapi-generator/src/test/resources/2_0/issue-xxx.yaml
And adding a pythonclientexperimentaltest.java test case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@spacether this is a common pattern. Whatever the date refers to (LocalDate without offset, UTC with offset), it'll represent a single instant since the epoch. Once you have that instant, the only way to accurately represent it is at UTC offset. That call gives you an OffsetDateTime which can accurately hold ISO8601 date-time as defined in the OpenAPI Specification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few recommendations.
...erator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java
Outdated
Show resolved
Hide resolved
...erator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java
Outdated
Show resolved
Hide resolved
...erator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java
Outdated
Show resolved
Hide resolved
...erator/src/main/java/org/openapitools/codegen/languages/PythonClientExperimentalCodegen.java
Show resolved
Hide resolved
…ate-time-parsing' into jirikuncar/python-experimental/date-time-parsing
…-experimental/date-time-parsing
All tests passed except for some outstanding samples. I merged master and regenerated those samples via #6533 |
* master: (345 commits) [kotlin][spring] Fix ApiUtil compilation (#6084) update python samples [Python] Fixed docstrings in api.mustache (#6391) [BUG][python] Support named arrays (#6493) [Go] whitelist AdditionalProperties in the field name (#6543) [kotlin][client] remove tabs usage (#6526) [PS] automatically derive discriminator mapping for oneOf/anyOf (#6542) [C++][Ue4] various bus fixes (#6539) Fix incorrect npx command (#6537) update pester to 5.x (#6536) comment out openapi3 java jersey2-java8 tests add additional properties support to powershell client generator (#6528) [Go][Experimental] Support additionalProperties (#6525) #5476 [kotlin] [spring] fix swagger and spring annotation for defaultValue (#6101) [samples] regenerate (#6533) [python] Fix date-time parsing (#6458) Register OAuth2ClientContext as bean (#6172) [Go][Experimental] Fix discriminator lookup (#6521) Typescript-rxjs: print param name (#6368) add oneof discrimistrator lookup to go experimental (#6517) ...
Fixes #6433
PR checklist
./bin/
(or Windows batch scripts under.\bin\windows
) to update Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit, and these must match the expectations made by your contribution. You only need to run./bin/{LANG}-petstore.sh
,./bin/openapi3/{LANG}-petstore.sh
if updating the code or mustache templates for a language ({LANG}
) (e.g. php, ruby, python, etc).master
,4.3.x
,5.0.x
. Default:master
.@taxpon (2017/07) @frol (2017/07) @mbohlool (2017/07) @cbornet (2017/09) @kenjones-cisco (2017/11) @tomplus (2018/10) @Jyhess (2019/01) @arun-nalla (2019/11) @spacether (2019/11)