Skip to content
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

Use date/time/datetime Python types #1618

Closed
wants to merge 2 commits into from
Closed

Use date/time/datetime Python types #1618

wants to merge 2 commits into from

Conversation

twwd
Copy link

@twwd twwd commented Oct 13, 2023

according to the OpenAPI property type for all output model types

Fixes #1615

@codecov
Copy link

codecov bot commented Oct 13, 2023

Codecov Report

All modified lines are covered by tests ✅

Comparison is base (e9b6edf) 100.00% compared to head (52c2bd1) 100.00%.
Report is 740 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##            master     #1618     +/-   ##
===========================================
  Coverage   100.00%   100.00%             
===========================================
  Files           11        34     +23     
  Lines         1020      3755   +2735     
  Branches       201       879    +678     
===========================================
+ Hits          1020      3755   +2735     
Flag Coverage Δ
unittests 99.65% <99.60%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
datamodel_code_generator/__init__.py 100.00% <100.00%> (ø)
datamodel_code_generator/__main__.py 100.00% <100.00%> (ø)
datamodel_code_generator/arguments.py 100.00% <100.00%> (ø)
datamodel_code_generator/format.py 100.00% <100.00%> (ø)
datamodel_code_generator/http.py 100.00% <100.00%> (ø)
datamodel_code_generator/imports.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/__init__.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/base.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/dataclass.py 100.00% <100.00%> (ø)
datamodel_code_generator/model/enum.py 100.00% <100.00%> (ø)
... and 24 more

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@twwd twwd marked this pull request as draft October 13, 2023 10:15
@twwd
Copy link
Author

twwd commented Oct 13, 2023

It might be better to set the type to datetime.time etc. instead of just time etc. to prevent naming clashes.

@koxudaxi koxudaxi marked this pull request as ready for review October 19, 2023 17:41
@koxudaxi
Copy link
Owner

@twwd
Thank you for creating this PR.
In pydantic, parsing allows normal strings to be cast to datetime.datetime, but this is not done in dataclass or typedDict. Considering that OpenAPI is used as an interface definition with outside Python, wouldn't this change no longer match the use cases for dataclass or TypedDict? There will probably be a need to cast from string to datetime.datetime before assigning it to a dataclass.

@twwd
Copy link
Author

twwd commented Oct 20, 2023

I parse the server JSON response into a dataclass and handle the type conversion but I see that this is not the general use-case.
I patch the method as a workaround (if somebody else has a similar use-case)

with mock.patch('datamodel_code_generator.model.types.type_map_factory') as type_map_factory_mock:
   type_map_factory_mock.side_effect = adjusted_type_map_factory

@twwd twwd closed this Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Format is ignored for output model type dataclass
2 participants