Skip to content

Support datamodel-code-generator 0.59#589

Merged
koxudaxi merged 1 commit into
mainfrom
support-datamodel-code-generator-0.59
May 31, 2026
Merged

Support datamodel-code-generator 0.59#589
koxudaxi merged 1 commit into
mainfrom
support-datamodel-code-generator-0.59

Conversation

@koxudaxi

@koxudaxi koxudaxi commented May 31, 2026

Copy link
Copy Markdown
Owner

Summary

  • Update datamodel-code-generator to the latest 0.59 series.
  • Handle boolean JSON Schema variants in discriminator object-variant detection.
  • Refresh the shadowed-import expected output for the new generated import behavior.

Validation

  • uv run pytest
  • ./scripts/lint.sh

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced discriminator variant processing to correctly handle non-object and boolean schema representations.
    • Updated generated code templates to use direct type references instead of aliases.
  • Tests

    • Added test coverage for boolean variant discriminator handling.
  • Chores

    • Updated dependencies.

@github-actions

Copy link
Copy Markdown
Contributor

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

@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The PR updates the parser to handle boolean schemas in discriminator variants, bumps the datamodel-code-generator dependency from 0.56.1 to 0.59, and updates expected test templates to reflect the new behavior. The core change guards _is_object_discriminator_variant against non-object inputs and validates the logic with a new test.

Changes

Boolean Discriminator Variant Support

Layer / File(s) Summary
Parser boolean discriminator variant logic
fastapi_code_generator/parser.py
_is_object_discriminator_variant now accepts JsonSchemaObject | bool input, explicitly returns False for non-object types, and resolves $ref before checking object properties or recursing into allOf.
Parser test for boolean variant discriminator removal
tests/test_parser.py
New test verifies that get_field_extras removes the discriminator field when a oneOf variant contains a boolean schema value alongside object schemas.
Dependency update and expected template adjustment
pyproject.toml, tests/data/expected/openapi/default_template/shadowed_imports/main.py
datamodel-code-generator[http] updated from 0.56.1 to 0.59; expected test template imports datetime.date directly instead of aliased, and get_actions_ parameter type changes from Optional[date_aliased] to Optional[date].

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

Poem

🐰 Schemas once boolean now handled with care,
The parser checks type before object's declare,
Dependencies rise from 0.56 to beyond,
Templates refresh with the new magic wand,
✨ Discriminators dance where they belong.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.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 'Support datamodel-code-generator 0.59' directly aligns with the main objective of upgrading the project to support datamodel-code-generator 0.59 series, which is reflected in all four changed files.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch support-datamodel-code-generator-0.59

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

codspeed-hq Bot commented May 31, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 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 untouched benchmark


Comparing support-datamodel-code-generator-0.59 (f3405b5) with main (a1e6ae2)

Open in CodSpeed

@codecov

codecov Bot commented May 31, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (a1e6ae2) to head (f3405b5).

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #589   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           17        17           
  Lines         1351      1357    +6     
  Branches       139       140    +1     
=========================================
+ Hits          1351      1357    +6     
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.

@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

🤖 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 bump to datamodel-code-generator (>=0.59,<0.60)
introduces breaking codegen changes; regenerate all generated models (the code
produced by datamodel-code-generator), run snapshot/unit tests, and update any
custom templates to account for the new flags and attributes — specifically
update template logic that relied on field.required to use
field.use_default_with_required where appropriate, adapt templates/consumers of
RootModel/payload changes, remove usages/imports of internal classes
ValidatedDefault and WrappedDefault, handle TypedDict import deduplication, and
adjust dict key handling for patternProperties/propertyNames; after regen, fix
any typing/validation diffs and re-run tests to confirm all snapshots and type
checks pass.
🪄 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: d8ef0a02-875d-466b-b6f5-3d1af885691e

📥 Commits

Reviewing files that changed from the base of the PR and between a1e6ae2 and f3405b5.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (4)
  • fastapi_code_generator/parser.py
  • pyproject.toml
  • tests/data/expected/openapi/default_template/shadowed_imports/main.py
  • tests/test_parser.py

Comment thread pyproject.toml
@koxudaxi koxudaxi marked this pull request as ready for review May 31, 2026 13:23
@koxudaxi koxudaxi merged commit c633a56 into main May 31, 2026
44 checks passed
@koxudaxi koxudaxi deleted the support-datamodel-code-generator-0.59 branch May 31, 2026 13:26
@github-actions github-actions Bot added breaking-change-analyzed PR has been checked for release draft updates breaking-change PR contains breaking changes labels May 31, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Breaking Change Analysis

Result: Breaking changes detected

Reasoning: The PR contains two breaking changes: (1) Generated code output changed - the shadowed import aliasing behavior from datamodel-code-generator 0.59 now uses direct type references instead of _aliased suffixes, which changes the generated FastAPI code output. This is confirmed by the test expectation change from from datetime import date as date_aliased to from datetime import date. (2) The dependency floor for datamodel-code-generator jumped from 0.56.1 to 0.59, dropping compatibility with three minor versions that users may have been using.

Content for Release Notes

Code Generation Changes

  • Shadowed imports no longer use aliases - Generated code that previously aliased conflicting imports (e.g., from datetime import date as date_aliased) now uses the direct type reference (e.g., from datetime import date). Function signatures also change accordingly (e.g., date_aliaseddate). Users who regenerate code may see different output, and downstream code referencing aliased names will need updating. (Support datamodel-code-generator 0.59 #589)

Python or Dependency Support Changes

  • datamodel-code-generator minimum version raised from 0.56.1 to 0.59 - The required version of datamodel-code-generator[http] changed from >=0.56.1,<0.57 to >=0.59,<0.60, dropping support for versions 0.56.x through 0.58.x. Users pinned to older versions of datamodel-code-generator will need to upgrade. (Support datamodel-code-generator 0.59 #589)

This analysis was performed by Claude Code Action

@github-actions

Copy link
Copy Markdown
Contributor

🎉 Released in 0.7.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.

1 participant