Skip to content

Update datamodel-code-generator requirement - #611

Merged
koxudaxi merged 2 commits into
mainfrom
update-datamodel-code-generator
Jun 26, 2026
Merged

Update datamodel-code-generator requirement#611
koxudaxi merged 2 commits into
mainfrom
update-datamodel-code-generator

Conversation

@koxudaxi

@koxudaxi koxudaxi commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Summary by CodeRabbit

  • New Features

    • Added CLI options to control remote $ref handling, including allowing remote HTTP/HTTPS references and trusted private-network references.
    • Expanded command help and CLI reference docs with usage examples for the new options.
  • Bug Fixes

    • Improved option handling so related flags are recognized consistently.
    • Refined tag parsing to better handle comma-separated values and extra whitespace.

@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@koxudaxi, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 22 minutes and 30 seconds. Learn how PR review limits work.

Your organization has run out of usage credits. Purchase more credits in the billing tab to continue.

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: a8e0271e-e710-4a5a-9267-4f19bb9ce9da

📥 Commits

Reviewing files that changed from the base of the PR and between b76b7b2 and fd73150.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • fastapi_code_generator/cli.py
  • pyproject.toml
  • tests/test_parser.py

Walkthrough

The PR adds two remote $ref CLI options, threads them through config, parser, and prompt metadata, updates generated CLI docs, and adjusts parser schema handling and related tests.

Changes

Remote $ref CLI controls

Layer / File(s) Summary
Option surface and snapshots
README.md, docs/cli-reference.md, docs/index.md, docs/llms-full.txt, fastapi_code_generator/_types/generate_config_dict.py, fastapi_code_generator/config.py, fastapi_code_generator/prompt_data.py, pyproject.toml
The new remote-ref options are added to config metadata, prompt metadata, generated help/reference snapshots, and the dependency bounds.
CLI wiring
fastapi_code_generator/cli.py, fastapi_code_generator/parser.py, tests/test_parser.py
The CLI adds --allow-remote-refs and --allow-private-network, normalizes them before code generation, and forwards them into OpenAPIParser; the helper test covers remote-ref normalization and tag parsing.
Parameter schema matching
fastapi_code_generator/parser.py, tests/test_parser.py
get_parameter_type now matches ReferenceObject and JsonSchemaObject content schemas explicitly, and the parser test covers the boolean content.schema_ path.
Validation updates
tests/cli_doc/test_cli_doc_coverage.py, tests/cli_doc/test_cli_options_sync.py, tests/main/test_main.py, tests/test_config.py
CLI doc marker collection, option sync checks, remote-ref CLI examples, and config drift tests are updated for the new flags.

Sequence Diagram(s)

sequenceDiagram
  participant main
  participant generate_code
  participant OpenAPIParser
  participant OpenAPIModelParser
  main->>generate_code: remote-ref options and specify_tags
  generate_code->>generate_code: _resolve_remote_reference_options(...)
  generate_code->>OpenAPIParser: normalized allow_remote_refs and allow_private_network
  OpenAPIParser->>OpenAPIModelParser: allow_remote_refs and allow_private_network
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

I twitched my nose and hopped in place,
New flags now brighten CLI space.
Remote refs hum, the docs agree,
Safe little burrows for you and me.
Thump-thump—this carrot code sings 🐰

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.35% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is related to a real part of the change set, but it only highlights the dependency bump and not the broader CLI and parser updates.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch update-datamodel-code-generator

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

📚 Docs Preview: https://pr-611.fastapi-code-generator.pages.dev

@codspeed-hq

codspeed-hq Bot commented Jun 26, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 44.7%

⚠️ Unknown Walltime execution environment detected

Using the Walltime instrument on standard Hosted Runners will lead to inconsistent data.

For the most accurate results, we recommend using CodSpeed Macro Runners: bare-metal machines fine-tuned for performance measurement consistency.

⚡ 1 improved benchmark

Performance Changes

Benchmark BASE HEAD Efficiency
test_generate_default_template_benchmark 57.1 ms 39.4 ms +44.7%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing update-datamodel-code-generator (fd73150) with main (a253d2a)

Open in CodSpeed

Comment thread fastapi_code_generator/cli.py Fixed
@codecov

codecov Bot commented Jun 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a253d2a) to head (fd73150).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #611   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines         1461      1500   +39     
  Branches       153       158    +5     
=========================================
+ Hits          1461      1500   +39     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

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

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
fastapi_code_generator/cli.py (1)

79-83: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Optional: surface the contradictory --no-allow-remote-refs --allow-private-network combination.

When allow_remote_refs=False and allow_private_network=True, the function returns (False, True), i.e. private-network access is enabled while remote $ref fetching is fully disabled — a no-op/contradictory state. Consider warning (or ignoring --allow-private-network) when remote refs are explicitly disabled, so users get feedback instead of a silently meaningless flag.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@fastapi_code_generator/cli.py` around lines 79 - 83, The allow-remote-refs
resolution in the CLI currently returns a contradictory `(False, True)` state
when `--no-allow-remote-refs` is combined with `--allow-private-network`. Update
the option-handling logic in the function that processes `allow_remote_refs` and
`allow_private_network` to either warn the user or ignore
`allow_private_network` whenever remote refs are explicitly disabled. Keep the
behavior consistent with the existing `match` handling so the result is not a
silently meaningless flag combination.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@pyproject.toml`:
- Line 31: The dependency constraint for datamodel-code-generator is too low and
still allows versions that do not support the allow_private_network argument
used by the parser. Update the requirement in pyproject.toml for
datamodel-code-generator[http] to start at 0.61 while keeping the existing upper
bound, so the package manager will avoid installing incompatible 0.59.x and
0.60.x releases.

---

Nitpick comments:
In `@fastapi_code_generator/cli.py`:
- Around line 79-83: The allow-remote-refs resolution in the CLI currently
returns a contradictory `(False, True)` state when `--no-allow-remote-refs` is
combined with `--allow-private-network`. Update the option-handling logic in the
function that processes `allow_remote_refs` and `allow_private_network` to
either warn the user or ignore `allow_private_network` whenever remote refs are
explicitly disabled. Keep the behavior consistent with the existing `match`
handling so the result is not a silently meaningless flag combination.
🪄 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: 3216d5dd-5206-45b6-813d-82863ac3e6a9

📥 Commits

Reviewing files that changed from the base of the PR and between a253d2a and b76b7b2.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (15)
  • README.md
  • docs/cli-reference.md
  • docs/index.md
  • docs/llms-full.txt
  • fastapi_code_generator/_types/generate_config_dict.py
  • fastapi_code_generator/cli.py
  • fastapi_code_generator/config.py
  • fastapi_code_generator/parser.py
  • fastapi_code_generator/prompt_data.py
  • pyproject.toml
  • tests/cli_doc/test_cli_doc_coverage.py
  • tests/cli_doc/test_cli_options_sync.py
  • tests/main/test_main.py
  • tests/test_config.py
  • tests/test_parser.py

Comment thread pyproject.toml Outdated
@koxudaxi
koxudaxi merged commit ec5b615 into main Jun 26, 2026
44 checks passed
@koxudaxi
koxudaxi deleted the update-datamodel-code-generator branch June 26, 2026 15:18
@github-actions github-actions Bot added breaking-change-analyzed PR has been checked for release draft updates breaking-change PR contains breaking changes labels Jun 26, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: Breaking changes detected

Reasoning: This PR contains multiple breaking changes: (1) The parse_responses rewrite fundamentally changes how non-200 success status codes are rendered in generated FastAPI code - changing response_model values, adding explicit status_code parameters, and altering return type annotations. This directly changes the HTTP behavior of regenerated applications (status codes shift from 200 to the correct code like 201). (2) The operation.status_code field is now populated for many more operations, which affects custom Jinja2 templates. (3) The minimum datamodel-code-generator version was bumped from 0.59 to 0.61, dropping support for two minor versions of that dependency.

Content for Release Notes

Code Generation Changes

  • Non-200 success responses now use response_model and status_code instead of responses dict - Previously, endpoints with non-200 success status codes (e.g., 201) generated response_model=None with the model placed in the responses={'201': {'model': Model}} dict. Now, the primary success response is promoted to response_model=Model with an explicit status_code=201. This changes the actual HTTP status codes returned by generated FastAPI applications (previously defaulted to 200, now returns the correct status code). Return type annotations also change from Optional[Model] to Model. Existing generated code that relies on the old responses dict structure or 200 status codes will behave differently after regeneration. (Update datamodel-code-generator requirement #611)

    Before:

    @app.post('/subscriptions', response_model=None, responses={'201': {'model': Subscription}})
    def create_subscription(body: SubscriptionRequest) -> Optional[Subscription]:

    After:

    @app.post('/subscriptions', response_model=Subscription, status_code=201)
    def create_subscription(body: SubscriptionRequest) -> Subscription:
  • Endpoints with non-200 success codes now emit explicit status_code in decorators - Operations that define only a 201 (or other non-200) success response without a response body now generate status_code=201 in the route decorator. Previously, no status_code was emitted and FastAPI would default to 200. This affects POST, PUT, and other write endpoints across all templates (default and router). (Update datamodel-code-generator requirement #611)

    Before:

    @app.post('/pets', response_model=None, tags=['pets'])

    After:

    @app.post('/pets', response_model=None, status_code=201, tags=['pets'])

Custom Template Update Required

  • operation.status_code is now set for all non-200 success status codes - Previously, operation.status_code was only populated for 204 no-content responses. It is now set for any non-200 success status code (201, 202, etc.). Custom Jinja2 templates that use {% if operation.status_code %} will now render status_code= for many more routes than before. Additionally, operation.response now contains the actual model name (e.g., 'Subscription') instead of 'None' for non-200 success responses, and operation.additional_responses no longer includes the primary success response entry. (Update datamodel-code-generator requirement #611)

Python or Dependency Support Changes

  • Minimum datamodel-code-generator version raised from 0.59 to 0.61 - The dependency constraint changed from >=0.59,<0.60 to >=0.61,<0.66. Users pinned to datamodel-code-generator 0.59 or 0.60 must upgrade to at least 0.61. (Update datamodel-code-generator requirement #611)

This analysis was performed by Claude Code Action

@github-actions

Copy link
Copy Markdown
Contributor

🎉 Released in 0.8.0

This PR is now available in the latest release. See the release notes for details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking-change PR contains breaking changes breaking-change-analyzed PR has been checked for release draft updates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants