Skip to content

Update datamodel-code-generator to 0.56.1#534

Merged
koxudaxi merged 11 commits intomainfrom
chore/update-datamodel-code-generator-0-56-1
Apr 27, 2026
Merged

Update datamodel-code-generator to 0.56.1#534
koxudaxi merged 11 commits intomainfrom
chore/update-datamodel-code-generator-0-56-1

Conversation

@koxudaxi
Copy link
Copy Markdown
Owner

@koxudaxi koxudaxi commented Apr 21, 2026

Summary by CodeRabbit

  • New Features

    • --enum-field-as-literal gains a none choice
    • Added pydantic_v2.dataclass as an output model option; default output model now pydantic_v2.BaseModel
  • Chores

    • Dropped Python 3.9 from supported/target versions (minimum 3.10)
    • Updated dependency constraint for the code-generator package
  • Behavioral/Generated Output

    • Generated FastAPI code uses explicit Query(...) for some optional query params and moves Pydantic v1 patterns to v2-style models/config
  • Documentation

    • CLI help and output-type docs updated to reflect the above
  • Tests

    • Added test validating alias escaping and Query/Header generation

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

Docs, types, CLI, and parser updated to prefer Pydantic v2: default output model set to pydantic_v2.BaseModel (and pydantic_v2.dataclass added), pydantic.BaseModel removed, Python 3.9 removed from allowed versions, enum_field_as_literal gains none, parser emits Query(...) for optional list query params and adopts Pydantic v2 constructs.

Changes

Cohort / File(s) Summary
Documentation Updates
README.md, docs/cli-reference.md, docs/index.md, docs/llms-full.txt, docs/supported_formats.md
CLI help/docs updated: --enum-field-as-literal adds none; --output-model-type docs switched to pydantic_v2.* and default to pydantic_v2.BaseModel (removed pydantic.BaseModel); --python-version no longer lists 3.9.
Type & Config Schemas
fastapi_code_generator/_types/generate_config_dict.py, fastapi_code_generator/config.py, fastapi_code_generator/prompt_data.py
Typing and config adjusted: TypedDict optionals use `T
CLI & Entry Point
fastapi_code_generator/cli.py
CLI defaults changed: output_model_type default set to DataModelType.PydanticV2BaseModel in main() and generate_code(); imports adjusted to use datamodel_code_generator.enums/format.
Parser & Runtime Model Changes
fastapi_code_generator/parser.py
Migrated runtime models to Pydantic v2: default root type → RootModel, CachedPropertyModel uses model_config = ConfigDict(...), runtime root checks updated, and get_parameter_type() now wraps optional list query defaults with fastapi.Query(...) and tightens alias error logic.
Prompt Data Generation Script
scripts/build_prompt_data.py, fastapi_code_generator/prompt_data.py
Script refactored to produce structured prompt payload (PROMPT_DATA) instead of simple option descriptions; new rendering helpers and CLI --output support; replaces previous build/update behavior.
Dependency
pyproject.toml
Bumped datamodel-code-generator[http] constraint from >=0.45,<0.46 to >=0.56.1,<0.57.
Generated Test Fixtures — Models
tests/data/expected/.../models.py (multiple files)
Fixtures updated for Pydantic v2: use RootModel[...] for root lists, replace datetime with pydantic.AwareDatetime for timestamps, convert inner class Configmodel_config = ConfigDict(...), change example=examples=[...], and add Field(..., examples=[...]) where applicable.
Generated Test Fixtures — Endpoints
tests/data/expected/.../main.py (multiple files)
Endpoint signatures updated: response/request wrapper classes replaced with direct List[...] types; optional list query params use Query(None); imports and typing updated accordingly.
Tests
tests/test_config.py, tests/main/test_main.py
Tests updated/added: expected defaults and CLI choices updated to reflect pydantic_v2 changes; new test validates escaped-alias preservation in generated Query/Header alias arguments.
Test Fixture Removals
tests/data/expected/openapi/coverage/model_options/custom_models.py
Removed several exported root-model wrapper classes that previously exposed root: List[...], replaced by direct list types elsewhere.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰
Hopped through configs, v2 lights the trail,
Root fields now root, and queries wear a veil,
Three point nine waved, a gentle goodbye,
Options grew none — a small happy sigh,
A carrot for clarity, nibble and prevail! 🥕

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 32.00% 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 accurately describes the primary change: updating the datamodel-code-generator dependency from 0.45.x to 0.56.1, which triggers cascading updates across CLI options, configuration types, and test fixtures.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/update-datamodel-code-generator-0-56-1

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 and usage tips.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 21, 2026

Merging this PR will degrade performance by 18.48%

⚠️ 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.

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
test_generate_default_template_benchmark 37.2 ms 45.7 ms -18.48%

Comparing chore/update-datamodel-code-generator-0-56-1 (13aaf10) with main (342dc40)

Open in CodSpeed

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (342dc40) to head (13aaf10).
⚠️ Report is 12 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #534   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           16        16           
  Lines         1012      1049   +37     
  Branches       110       110           
=========================================
+ Hits          1012      1049   +37     
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 Sentry.
📢 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 21, 2026

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 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/data/expected/openapi/coverage/model_options/main.py`:
- Around line 64-67: The GET endpoint show_food_by_id currently declares the
list query parameter as message_texts: Optional[List[str]] = None which FastAPI
treats as a request body; change the signature to message_texts:
Optional[List[str]] = Query(None) and add the Query import from fastapi so
FastAPI recognizes it as an optional list query parameter (update the function
show_food_by_id and imports accordingly).
🪄 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: 73644768-ca9c-4f7d-b0c6-1b8d893b3fe5

📥 Commits

Reviewing files that changed from the base of the PR and between bde5216 and 6e45cd5.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (18)
  • README.md
  • docs/cli-reference.md
  • docs/index.md
  • docs/llms-full.txt
  • docs/supported_formats.md
  • 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/data/expected/openapi/coverage/model_options/custom_models.py
  • tests/data/expected/openapi/coverage/model_options/main.py
  • tests/data/expected/openapi/default_template/body_and_parameters/models.py
  • tests/data/expected/openapi/default_template/discriminator_in_root_with_properties/models.py
  • tests/data/expected/openapi/default_template/recursion/models.py
  • tests/data/expected/openapi/default_template/shadowed_imports/models.py
  • tests/test_config.py
💤 Files with no reviewable changes (1)
  • tests/data/expected/openapi/coverage/model_options/custom_models.py

Comment thread tests/data/expected/openapi/coverage/model_options/main.py
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 22, 2026

Caution

Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted.

Error details
{}

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@fastapi_code_generator/parser.py`:
- Around line 389-397: Replace raw single-quoted orig_name usages with a
repr-wrapped value to safely escape quotes/backslashes; specifically update the
alias construction in the Query branch (replace alias = f", alias='{orig_name}'"
with alias = f", alias={repr(orig_name)}") and the inline alias in the non-query
branch (replace alias='orig_name' inside the f-string for param_is with
alias={repr(orig_name)}), keeping the existing logic for required/default and
imports_for_fastapi, Query, param_is, default_value, alias and default
variables.
🪄 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: 52e688a7-e03e-4f92-ac88-94b7c086aee1

📥 Commits

Reviewing files that changed from the base of the PR and between f516dc8 and 07a85b1.

📒 Files selected for processing (4)
  • fastapi_code_generator/parser.py
  • tests/data/expected/openapi/coverage/model_options/main.py
  • tests/data/expected/openapi/default_template/body_and_parameters/main.py
  • tests/data/expected/openapi/remote_ref/body_and_parameters/main.py

Comment thread fastapi_code_generator/parser.py Outdated
@koxudaxi koxudaxi marked this pull request as ready for review April 22, 2026 22:45
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/build_prompt_data.py`:
- Around line 128-131: The help text for the "--output" argument is stale
because _render_output can emit Python when the path ends with .py, so update
the parser.add_argument help string (the "--output" argument in
build_prompt_data.py) to describe that the file may be JSON or a Python module
depending on the extension (e.g., ".json" for JSON payload, ".py" for Python),
and optionally mention that format selection is done by _render_output based on
the output filename extension.
🪄 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: 0c216db6-be6d-4043-886a-09e70e28e875

📥 Commits

Reviewing files that changed from the base of the PR and between 46c2185 and 7e1b82a.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (6)
  • docs/cli-reference.md
  • docs/llms-full.txt
  • fastapi_code_generator/prompt_data.py
  • pyproject.toml
  • scripts/build_prompt_data.py
  • tests/main/test_main.py
✅ Files skipped from review due to trivial changes (1)
  • pyproject.toml
🚧 Files skipped from review as they are similar to previous changes (2)
  • fastapi_code_generator/prompt_data.py
  • docs/llms-full.txt

Comment thread scripts/build_prompt_data.py
@koxudaxi koxudaxi merged commit c6c1558 into main Apr 27, 2026
44 of 45 checks passed
@koxudaxi koxudaxi deleted the chore/update-datamodel-code-generator-0-56-1 branch April 27, 2026 08:04
@coderabbitai coderabbitai Bot mentioned this pull request Apr 28, 2026
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.

1 participant