koxudaxi / datamodel-code-generator

Pydantic model and dataclasses.dataclass generator for easy conversion of JSON, OpenAPI, JSON Schema, and YAML data sources.
https://koxudaxi.github.io/datamodel-code-generator/
MIT License
2.65k stars 296 forks source link

feature: dots in paths #2008

Closed luca-knaack-webcom closed 3 months ago

luca-knaack-webcom commented 3 months ago

This PR introduces the --treat-dot-as-module flag, allowing users to specify whether a filename like file.name.of.schema.json should generate a model at file_name_of_schema.py or file/name/of/schema.py. This is particularly beneficial for schemas defined as api.route.path.input.py and api.route.path.output.py, ensuring that the resulting Pydantic models are neatly organized into their respective packages.

Additionally, this PR addresses an issue where filenames containing dots would result in Python model files with the same dots, making them non-importable and non-compliant with PEP naming guidelines.

Merging this PR is likely to resolve issues such as #1638 and #1600.

The PR maintains backward compatibility by introducing new features that are accessible through an optional flag. It only modifies the interpretation of filenames with additional dots and does not affect folders containing dots (e.g., test_external_relative_ref).

codecov[bot] commented 3 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Please upload report for BASE (main@c197b8f). Learn more about missing BASE report.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #2008 +/- ## ======================================= Coverage ? 98.77% ======================================= Files ? 38 Lines ? 4243 Branches ? 991 ======================================= Hits ? 4191 Misses ? 32 Partials ? 20 ``` | [Flag](https://app.codecov.io/gh/koxudaxi/datamodel-code-generator/pull/2008/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Koudai+Aono) | Coverage Δ | | |---|---|---| | [unittests](https://app.codecov.io/gh/koxudaxi/datamodel-code-generator/pull/2008/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Koudai+Aono) | `98.46% <100.00%> (?)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=Koudai+Aono#carryforward-flags-in-the-pull-request-comment) to find out more.

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codspeed-hq[bot] commented 3 months ago

CodSpeed Performance Report

Merging #2008 will not alter performance

Comparing luca-knaack-webcom:feat/dots-in-path (05fe464) with main (c197b8f)

Summary

✅ 29 untouched benchmarks

luca-knaack-webcom commented 3 months ago

@koxudaxi, is there anything I can add to this PR to get it merged and resolve the issues?

koxudaxi commented 3 months ago

@luca-knaack-webcom Thank you for the excellent PR.

This may not be your problem, but it seems that covarage is not meeting 100%. Could you please confirm this? 🤔 https://github.com/koxudaxi/datamodel-code-generator/pull/2008/checks?check_run_id=26407631809 https://github.com/koxudaxi/datamodel-code-generator/pull/2008/checks?check_run_id=26407425938

The PR should not be in mergeable status if it does not meet 100%. :(

luca-knaack-webcom commented 3 months ago

I see. Thanks for pointing that out :)

While adding tests for the missing lines I encountered strange errors in the python-version 3.12 matrix branches of the test.yml workflow. Errors were mostly regarding TypeError: ForwardRef._evaluate() missing 1 required keyword-only argument: 'recursive_guard' or complaints that pytest wasn't found in the Unit Test step. For example: error-type 1 and error-type 2 Those test-errors did not seem to be related to my code, however, as they still occur now, although I reverted the changes made since last all tests ran.

Did you encounter this before @koxudaxi ?