Skip to content

Conversation

@ynehra0777
Copy link

Summary

Clarifies how request body fields can be required while still allowing null
values when using Optional[T] without a default.

Motivation

While reading the documentation, I found it unclear why a field annotated as
Optional[str] could still be required. This PR adds a short explanation and
example to clarify the distinction between:

  • required but nullable fields
  • truly optional fields with a default value

This directly addresses the confusion described in #12965.

Changes

  • Added a new documentation subsection explaining required-but-nullable fields
  • Included minimal examples and valid/invalid request bodies

Notes

Documentation-only change. No runtime or API behavior is affected.

@github-actions github-actions bot added the docs Documentation about how to use FastAPI label Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Documentation about how to use FastAPI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant