Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (13)
✅ Files skipped from review due to trivial changes (5)
🚧 Files skipped from review as they are similar to previous changes (5)
WalkthroughAdds a new CLI flag Changes
Sequence Diagram(s)sequenceDiagram
participant User as "User (CLI)"
participant CLI as "fastapi_code_generator.cli"
participant Parser as "OpenAPIParser / Generator"
participant FS as "Filesystem (templates/output)"
User->>CLI: run generator with --enable-faux-immutability
CLI->>Parser: generate_code(enable_faux_immutability=True)
Parser->>Parser: select model templates with ConfigDict(frozen=True)
Parser->>FS: write generated modules (models.py, main.py, ...)
FS-->>User: generated files containing frozen models
Note over Parser,FS: tests load generated models and assert hash(instance) is int
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
|
📚 Docs Preview: https://pr-569.fastapi-code-generator.pages.dev |
Merging this PR will not alter performance
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #569 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 17 17
Lines 1271 1285 +14
Branches 131 131
=========================================
+ Hits 1271 1285 +14
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
a84256d to
382021d
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
fastapi_code_generator/prompt_data.py (1)
356-360: Align example wording with the CLI hashability caveat.The scenario description is slightly more absolute than the help text. Consider reusing the same “when fields are hashable” phrasing for consistency across generated docs.
✏️ Suggested wording tweak
- 'description': 'Generate frozen Pydantic models for hashable model ' - 'instances.', + 'description': 'Generate frozen Pydantic models so instances are ' + 'hashable when their fields are hashable.',🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@fastapi_code_generator/prompt_data.py` around lines 356 - 360, Update the 'description' string in the option dict (the entry with 'options': ['--enable-faux-immutability']) to mirror the CLI caveat wording by replacing the current absolute phrasing with the conditional phrasing "when fields are hashable" (e.g., "Generate frozen Pydantic models when fields are hashable.") so the prompt example and CLI help are consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@tests/main/test_main.py`:
- Line 787: The use of exec(models, namespace) triggers Ruff S102; add an inline
suppression and rationale directly on that line to acknowledge intentional use
of exec in the test (e.g., append a noqa comment like "# noqa: S102 -- executing
generated test models in a controlled test namespace" or similar), so the linter
is waived but the reason is recorded; ensure the comment references exec(models,
namespace) and explains that execution is limited to the test-controlled
namespace.
---
Nitpick comments:
In `@fastapi_code_generator/prompt_data.py`:
- Around line 356-360: Update the 'description' string in the option dict (the
entry with 'options': ['--enable-faux-immutability']) to mirror the CLI caveat
wording by replacing the current absolute phrasing with the conditional phrasing
"when fields are hashable" (e.g., "Generate frozen Pydantic models when fields
are hashable.") so the prompt example and CLI help are consistent.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 1a2b2f3d-e53d-4942-834e-8ecef104873d
📒 Files selected for processing (9)
README.mddocs/cli-reference.mddocs/index.mddocs/llms-full.txtfastapi_code_generator/_types/generate_config_dict.pyfastapi_code_generator/cli.pyfastapi_code_generator/config.pyfastapi_code_generator/prompt_data.pytests/main/test_main.py
382021d to
69a44cf
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
tests/main/test_main.py (1)
38-38:⚠️ Potential issue | 🟠 MajorAdd intentional Ruff waiver for
execon Line 38.
execis test-intentional here, but without an inline waiver this can fail lint (S102).🔧 Minimal fix
- exec(models_path.read_text(encoding="utf-8"), namespace) + exec( # noqa: S102 - executing generated fixture code in test-controlled namespace + models_path.read_text(encoding="utf-8"), namespace + )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/main/test_main.py` at line 38, Add an inline Ruff waiver for the intentional exec usage on the exec(models_path.read_text(encoding="utf-8"), namespace) line so the S102 lint rule is ignored; locate that exact exec call in tests/main/test_main.py and append an inline ruff/NOQA waiver for S102 (e.g., use the ruff-specific noqa for rule S102) to suppress the lint error while keeping the intent clear.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@tests/main/test_main.py`:
- Line 38: Add an inline Ruff waiver for the intentional exec usage on the
exec(models_path.read_text(encoding="utf-8"), namespace) line so the S102 lint
rule is ignored; locate that exact exec call in tests/main/test_main.py and
append an inline ruff/NOQA waiver for S102 (e.g., use the ruff-specific noqa for
rule S102) to suppress the lint error while keeping the intent clear.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 724271ba-4823-41c9-b0f2-5cce89856c33
📒 Files selected for processing (13)
README.mddocs/cli-reference.mddocs/index.mddocs/llms-full.txtdocs/supported_formats.mdfastapi_code_generator/_types/generate_config_dict.pyfastapi_code_generator/cli.pyfastapi_code_generator/config.pyfastapi_code_generator/prompt_data.pytests/data/expected/openapi/coverage/faux_immutability/main.pytests/data/expected/openapi/coverage/faux_immutability/models.pytests/data/openapi/coverage/faux_immutability.yamltests/main/test_main.py
✅ Files skipped from review due to trivial changes (7)
- fastapi_code_generator/_types/generate_config_dict.py
- docs/cli-reference.md
- docs/index.md
- tests/data/expected/openapi/coverage/faux_immutability/main.py
- README.md
- tests/data/expected/openapi/coverage/faux_immutability/models.py
- docs/supported_formats.md
🚧 Files skipped from review as they are similar to previous changes (1)
- fastapi_code_generator/config.py
69a44cf to
7654ba8
Compare
Breaking Change AnalysisResult: No breaking changes detected Reasoning: The This analysis was performed by repository automation using PR labels and the |
Fixes: #441
Summary
--enable-faux-immutabilityand pass it through to datamodel-code-generator.ConfigDict(frozen=True), making instances hashable when their fields are hashable.Tests
uv run pytest -quv run pytest --collect-cli-docs tests/main/test_main.py tests/cli_doc -quv run python scripts/build_cli_docs.py --checkuv run python scripts/build_prompt_data.py --output fastapi_code_generator/prompt_data.py --checkuv run python scripts/build_schema_docs.py --checkuv run python scripts/build_config_types.py --checkuv run python scripts/update_command_help_on_markdown.py --checkuv run python scripts/build_llms_txt.py --checkSummary by CodeRabbit
New Features
--enable-faux-immutabilityCLI option to generate frozen Pydantic models so instances are hashable when their fields are hashable.Documentation
Tests
Examples