Fix missing | None for nullable enum literals in TypedDict#2991
Fix missing | None for nullable enum literals in TypedDict#2991
Conversation
|
Note Reviews pausedIt 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 Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughparse_enum_as_literal now excludes literal None from Literal members and marks the resulting DataType as optional when None/null is present in the JSON Schema enum, causing generated Literal types to be emitted as Changes
Sequence Diagram(s)(skip — changes are parser-only and do not introduce multi-component sequential flows) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 6✅ Passed checks (6 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 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-2991.datamodel-code-generator.pages.dev |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/datamodel_code_generator/parser/jsonschema.py`:
- Around line 3529-3534: In parse_enum_as_literal, guard against enums that are
all-None by first building literals = [i for i in obj.enum if i is not None] and
is_optional = None in obj.enum, then if literals is empty and is_optional is
True return a None-only DataType (i.e., construct and return self.data_type that
represents a None-only enum — for example with empty literals and
is_optional=True) instead of returning a potentially invalid empty Literal;
otherwise return the normal self.data_type(literals=literals,
is_optional=is_optional).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2991 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 94 94
Lines 18065 18068 +3
Branches 2090 2090
=========================================
+ Hits 18065 18068 +3
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:
|
Breaking Change AnalysisResult: No breaking changes detected Reasoning: This PR is a bug fix that corrects generated code to include This analysis was performed by Claude Code Action |
|
🎉 Released in 0.54.0 This PR is now available in the latest release. See the release notes for details. |
Fixes: #2986
Summary by CodeRabbit
Bug Fixes
Tests