Fix OpenAPI schema for zero numeric bounds on ListField children#9977
Merged
Conversation
browniebroke
approved these changes
Jun 9, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes OpenAPI schema generation in AutoSchema so numeric bounds of 0/0.0 on fields are not dropped when mapping ListField child schemas, addressing cases where falsy checks previously omitted valid minimum/maximum values.
Changes:
- Update
AutoSchema._map_min_max()to treat onlyNoneas “unset”, preserving zero-valuedmin_value/max_value. - Add regression tests covering
FloatFieldandIntegerFieldchildren insideListFieldwithmin_value=0/max_value=0.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
rest_framework/schemas/openapi.py |
Fixes min/max mapping logic to include zero numeric bounds in generated schemas. |
tests/schemas/test_openapi.py |
Adds regression coverage ensuring minimum/maximum are emitted for zero-valued bounds on ListField children. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
auvipy
approved these changes
Jun 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses discussion #9976
Summary
This PR fixes OpenAPI schema generation for
ListFieldchild fields with zero-valued numeric bounds.AutoSchema._map_min_max()previously used truthiness checks formin_valueandmax_value, which caused valid bounds like0and0.0to be omitted from generated schemas.This updates the checks to only skip
None, preserving existing behavior for positive, negative, and absent bounds.Changes
minimumwhen a child field usesmin_value=0ormin_value=0.0maximumwhen a child field usesmax_value=0ormax_value=0.0IntegerFieldandFloatFieldchildren insideListFieldTesting
Ran:
Result:
Also ran:
Result:
The skipped tests are due to
uritemplatenot being installed locally.