Preserve `null` values in user-provided OpenAPI `example`/`examples` by AshNicolus · Pull Request #15646 · fastapi/fastapi · GitHub
Skip to content

Preserve null values in user-provided OpenAPI example/examples#15646

Open
AshNicolus wants to merge 2 commits into
fastapi:masterfrom
AshNicolus:fix/openapi-preserve-null-in-examples
Open

Preserve null values in user-provided OpenAPI example/examples#15646
AshNicolus wants to merge 2 commits into
fastapi:masterfrom
AshNicolus:fix/openapi-preserve-null-in-examples

Conversation

@AshNicolus

Copy link
Copy Markdown
Contributor

Summary

Reported across #8401, #12048, and #5559 (29+ community votes total): user-provided null values inside example and examples are silently dropped from the generated OpenAPI document, even when null is a legitimate documented value (e.g. a nullable required field in a response example).

The root cause is the final pass in get_openapi:

return jsonable_encoder(OpenAPI(**output), by_alias=True, exclude_none=True)

@codspeed-hq

codspeed-hq Bot commented May 30, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant