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
Copy link
Copy Markdown

codspeed-hq Bot commented May 30, 2026

Merging this PR will not alter performance

✅ 20 untouched benchmarks


Comparing AshNicolus:fix/openapi-preserve-null-in-examples (5bee710) with master (1990ecb)1

Open in CodSpeed

Footnotes

  1. No successful run was found on master (ee22a4b) during the generation of this report, so 1990ecb was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

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