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

fix(ModuleImports): This PR fixes the module import resolver for module of type BaseClassDataType #1862

Merged

Conversation

rshah-evertz
Copy link
Contributor

@rshah-evertz rshah-evertz commented Feb 20, 2024

Description

Currently, there is a bug in datamodel-codegenerator's import resolver. While parsing and resolving the imports for a module, if the data model is of data type BaseClassDataType and the length of split reference_path is greater than the length of split current_module, the final output_path resolved is incorrect.

Example

current_module: "api.schemas"
reference: "api.this.that.ClassToImport"
relative(current_module, reference) returns: ('.this', 'that')
resulting from_ value for model of instance BaseClassDataType: .thisthat

This PR fixes this error by ensuring that when joining the tuple returned by the relative method it is checked that the first item in the tuple ends with a .

Is this acceptable, @koxudaxi?

rshah-evertz and others added 2 commits February 20, 2024 14:35
…pe BaseClassDataType, it needs to be ensured that the from_ value is joined appropriately.
Copy link

codecov bot commented Feb 20, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (main@76fc354). Click here to learn what that means.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1862   +/-   ##
=======================================
  Coverage        ?   98.89%           
=======================================
  Files           ?       37           
  Lines           ?     4163           
  Branches        ?      969           
=======================================
  Hits            ?     4117           
  Misses          ?       29           
  Partials        ?       17           
Flag Coverage Δ
unittests 98.55% <100.00%> (?)

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

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

Copy link

codspeed-hq bot commented Feb 20, 2024

CodSpeed Performance Report

Merging #1862 will not alter performance

Comparing rshah-evertz:fix-imports-for-base-class-data-type (5968f9b) with main (76fc354)

Summary

✅ 29 untouched benchmarks

@koxudaxi
Copy link
Owner

@rshah-evertz
I'm sorry for late reply.
Looks good.
Could you please add a unit test for your changes?

Thank you!!

@nwicht
Copy link
Contributor

nwicht commented Apr 8, 2024

@rshah-evertz I have the same issue, and your fix would be great.

Do you need help to write the unit test?

@rshah-evertz
Copy link
Contributor Author

I actually do need help with the unit test. How do I regenerate the expected files with the default timestamp of 2019-07-26T00:00:00+00:00? @koxudaxi

@rshah-evertz
Copy link
Contributor Author

I've changed the existing nested directory structure to test the change I've made. Also, manually fixed the timestamps of newly generated expected files because I couldn't figure out how to run the codegen with the default timestamp.

@rshah-evertz
Copy link
Contributor Author

Unsure about why codecov is failing. Any ideas? @koxudaxi

@koxudaxi koxudaxi merged commit 95260f5 into koxudaxi:main Apr 12, 2024
92 checks passed
@rshah-evertz rshah-evertz deleted the fix-imports-for-base-class-data-type branch April 12, 2024 18:47
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.

None yet

3 participants