You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Write the dots of a directory of the input as _ in a model's module path without --treat-dot-as-module - #6000
Improved handling of dotted directory and filename components when generating model module paths. Dots are now processed consistently with the selected dot-handling setting, while file extensions remain intact.
Added coverage for generated models that reference schemas in dotted directories.
… path without `--treat-dot-as-module`
A directory of the input named with a dot (`api.v2/`) was written as it was named, while the import of a model in it read
the dot as a package separator (`from .api.v2 import b`), a module that does not exist. The module path of a model
writes the dots of its directories as `_`, as it does those of its file's name, unless `--treat-dot-as-module` splits
them into packages, so the written directory (`api_v2/`), the keys of the parser's result and every import name the
same package.
Only output that failed to import changes; the stored output of `complex.directory` is written at `complex_directory`.
Fixes: #5710
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
Walkthrough
The change updates generated module-path handling for dotted directory names. It adds regression cases for multiple dot-handling settings, expected generated models, and payload validation.
Regression cases cover default behavior, explicit dot handling, and collapsed root models. Expected output includes generated models for each configuration, and payload validation references include the fixture.
The change aligns dotted-directory output paths with generated imports. The suspected model-loss regression was not substantiated; mergeable after normal checks.
Pre-merge checks: 5
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly describes the main change: replacing dots in directory names with underscores in model module paths when --treat-dot-as-module is not enabled. It is specific and related to the pull …
Linked Issues check
[#5710] Requirement: without --treat-dot-as-module, the generated import must point to a module that exists when a schema references a file in a dotted directory (for example api.v2/b.json). The impor…
Out of Scope Changes check
All changes connect to the dotted-directory import fix for #5710. The core change is in get_module_path (src/datamodel_code_generator/model/base.py). The docs/architecture.md edit clarifies the writte…
Docstring Coverage
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Full details: Title check
Explanation
The title clearly describes the main change: replacing dots in directory names with underscores in model module paths when --treat-dot-as-module is not enabled. It is specific and related to the pull request.
Full details: Linked Issues check
Explanation
[#5710] Requirement: without --treat-dot-as-module, the generated import must point to a module that exists when a schema references a file in a dotted directory (for example api.v2/b.json). The import and the written path must agree. The PR changes get_module_path in src/datamodel_code_generator/model/base.py. When treat_dot_as_module is not True, directory components and the file stem have their dots replaced with underscores. The expected outputs under tests/data/expected/main/jsonschema/main_jsonschema/dotted_directory_reference[default]/ show the module written as api_v2/b.py and the import in a.py as .api_v2 (for example b_1.B from api_v2). Both the write path and the import now use api_v2, so import out.a resolves. The new parameterized test in tests/main/jsonschema/test_main_jsonschema.py covers default, --no-treat-dot-as-module, --treat-dot-as-module, and --collapse-root-models. The --treat-dot-as-module expected output keeps the api/v2 layout, as the issue describes. The assessment relies on the PR summary and the expected-output summaries. The ignored fixture files under tests/data/jsonschema/dotted_directory_reference/ were not inspected, per the exclusion rules. No requirement remains unmet from the summary evidence.
Full details: Out of Scope Changes check
Explanation
All changes connect to the dotted-directory import fix for #5710. The core change is in get_module_path (src/datamodel_code_generator/model/base.py). The docs/architecture.md edit clarifies the written_name and module-path behavior that this change alters. The new test, its .refs matrix entry, and the test_payload_validation.refs entry for the dotted_directory_reference/a_leaf.json fixture exercise the new behavior. The generated expected-output files cover the fixture's default, collapse-root-models, and treat-dot-as-module variants. The added generator and filename header comments in those files are produced by the generator for this fixture. No unrelated behavior change appears in the summary. The summary does not list changes to other existing expected outputs, so regressions elsewhere cannot be ruled out from this evidence alone. That uncertainty does not show an out-of-scope change.
Full details: Docstring Coverage
Explanation
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 26 files. (4 skipped: 3 unsupported, 1 too large.)
Finishing Touches
Generate docstrings
Commit to this branch
Create a new PR
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
LanguageTool
docs/architecture.md
LanguageTool checks are incomplete because the per-file request limit of 5 was reached. Remaining text was skipped; findings from completed checks are retained.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
⚠️52 benchmarks with a significant change ran on different hardware
Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.
No successful run was found on fix1-7 (c7766f7) during the generation of this report, so 86978a3 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
Reasoning: The only source change is in model/base.py get_module_path. Before, the directory parts of a file path were kept as they were. Now their dots become underscores unless treat_dot_as_module is True, in which case they are kept and the dotted names split into nested packages. This renames the generated directories for any input directory with a dot in its name, in the default mode and with --no-treat-dot-as-module. Evidence: the existing treat_dot_not_as_module expected output moved from complex.directory to complex_directory with identical file contents, and the new dotted_directory_reference expectations show api.v2 written as api_v2 and imported as .api_v2. The behaviour diff gate marks the default cell for the new dotted_directory_reference input as a crash-fix, because the old generated imports pointed at a missing module. Even so, the output file tree changes for existing users, so anyone who references the old directory paths or commits the generated code is affected. I list it under Code Generation Changes. The accepted cells in the gate about integer constraints past 2 to the 53 come from unrelated changes, not this diff. No CLI options, Python API, templates, Python version support or error handling changed.
Content for Release Notes
Code Generation Changes
Input directories with dots in their names are now written with underscores - Unless --treat-dot-as-module is set (so in the default mode and with --no-treat-dot-as-module), every dot in an input directory's name now becomes _ in the written package, as already happened for file names. For example, api.v2/ is now written as api_v2/ and complex.directory/ as complex_directory/, and imports of their modules use the new name, such as from .api_v2 import b. Before, the output directory kept its dots, so in the default mode the generated imports pointed at .api.v2, a package that did not exist, and failed. Anyone who commits generated code, or whose scripts, sys.path entries or tooling point at the old dotted directory paths, must update them and remove the stale dotted directories. With --treat-dot-as-module, each dot still becomes a nested package as before. (Write the dots of a directory of the input as _ in a model's module path without --treat-dot-as-module #6000)
This analysis was produced by the release draft workflow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #5710
Summary by CodeRabbit