Skip to content

Fix OpenAPI schema for zero numeric bounds on ListField children#9977

Merged
auvipy merged 2 commits into
encode:mainfrom
zainnadeem786:fix-openapi-zero-bounds
Jun 10, 2026
Merged

Fix OpenAPI schema for zero numeric bounds on ListField children#9977
auvipy merged 2 commits into
encode:mainfrom
zainnadeem786:fix-openapi-zero-bounds

Conversation

@zainnadeem786

Copy link
Copy Markdown
Contributor

Addresses discussion #9976

Summary

This PR fixes OpenAPI schema generation for ListField child fields with zero-valued numeric bounds.

AutoSchema._map_min_max() previously used truthiness checks for min_value and max_value, which caused valid bounds like 0 and 0.0 to be omitted from generated schemas.

This updates the checks to only skip None, preserving existing behavior for positive, negative, and absent bounds.

Changes

  • Preserve minimum when a child field uses min_value=0 or min_value=0.0
  • Preserve maximum when a child field uses max_value=0 or max_value=0.0
  • Add regression coverage for IntegerField and FloatField children inside ListField

Testing

Ran:

.\.venv\Scripts\python.exe -m pytest tests/schemas/test_openapi.py::TestFieldMapping -q -p no:cacheprovider

Result:

6 passed, 18 subtests passed

Also ran:

.\.venv\Scripts\python.exe -m pytest tests/schemas/test_openapi.py -q -p no:cacheprovider

Result:

8 passed, 51 skipped, 18 subtests passed

The skipped tests are due to uritemplate not being installed locally.

@browniebroke browniebroke added this to the 3.18 milestone Jun 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 only None as “unset”, preserving zero-valued min_value/max_value.
  • Add regression tests covering FloatField and IntegerField children inside ListField with min_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 auvipy merged commit cf582fb into encode:main Jun 10, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants