Map OpenAPI Discriminator mapping's values to their real value in enums #3074
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (4)
💤 Files with no reviewable changes (1)
✅ Files skipped from review due to trivial changes (1)
📝 WalkthroughWalkthroughRefactors Parser discriminator resolution to support enum-member default values vs enum field names based on ChangesDiscriminator handling and test fixtures
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Possibly related PRs
Suggested labels
Suggested reviewers
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 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 |
Merging this PR will improve performance by 14.76%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ⚡ | WallTime | test_perf_large_models_pydantic_v2 |
3.8 s | 3.3 s | +17.61% |
| ⚡ | WallTime | test_perf_duplicate_names |
1,087.4 ms | 941.6 ms | +15.48% |
| ⚡ | WallTime | test_perf_complex_refs |
2.2 s | 1.9 s | +15.19% |
| ⚡ | WallTime | test_perf_deep_nested |
5.5 s | 4.8 s | +15.8% |
| ⚡ | WallTime | test_perf_multiple_files_input |
3.8 s | 3.3 s | +15.51% |
| ⚡ | WallTime | test_perf_openapi_large |
3 s | 2.6 s | +14.98% |
| ⚡ | WallTime | test_perf_all_options_enabled |
5.9 s | 5.2 s | +14.19% |
| ⚡ | WallTime | test_perf_kubernetes_style_pydantic_v2 |
2.7 s | 2.4 s | +12.74% |
| ⚡ | WallTime | test_perf_graphql_style_pydantic_v2 |
847.4 ms | 736.9 ms | +15% |
| ⚡ | WallTime | test_perf_stripe_style_pydantic_v2 |
2 s | 1.8 s | +10.86% |
| ⚡ | WallTime | test_perf_aws_style_openapi_pydantic_v2 |
2 s | 1.7 s | +15.16% |
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 ilovelinux:fix/ilovelinux-3073-enum-literal-values (3a53bf3) with main (35f7156)
Footnotes
-
98 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3074 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 89 92 +3
Lines 18650 19363 +713
Branches 2156 2206 +50
==========================================
+ Hits 18650 19363 +713
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:
|
|
This PR is draft because of the following tasks:
|
|
Hi, right now I don't have enough time to complete this PR. Feel free to adopt it, otherwise I should have more free time in june to complete steps described in #3074 (comment) 🤞 @kkinugasa since it's related to your issue, would you mind testing this PR and give us a feedback? Does it fix your issue? Thanks! |
c9e9459 to
ee22e3d
Compare
ee22e3d to
3a53bf3
Compare
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
Breaking Change AnalysisResult: No breaking changes detected Reasoning: The PR's core behavioral change — resolving discriminator mapping keys to actual enum values — only affects the specific case of multiple discriminator mapping entries pointing to the same model with integer enum types. In that case, the old code generated string literals (e.g., Literal['2', '3']) which were non-functional and would fail Pydantic validation. The new code generates correct integer literals (Literal[2, 3]). Since the old output was already broken, no working user code is affected. For the common case (single mapping entry per model), the output is unchanged because get_discriminator_field_value() already resolved enum values before reaching _create_discriminator_data_type. The GenerationStore refactoring maintains backward compatibility: self.results is still a list (via subclass), and public function signatures (sort_data_models, sort_base_classes_for_mro) only add optional parameters with None defaults. Performance optimizations (_RenderedDataModelField caching, _has_field_statement, _get_unique_name) are behavior-preserving internal changes. This analysis was performed by Claude Code Action |
|
🎉 Released in 0.58.0 This PR is now available in the latest release. See the release notes for details. |
Context
mappingfield is a key-value dictionary.Ref: https://swagger.io/specification/#options-for-mapping-values-to-schemas
What's changed
mapping's keys are mapped to their real enum values, if availableNotes
Summary by CodeRabbit