openapi: add test for mixed Pydantic v1/v2 models #14450
+144
−0
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.
Hi! The label check is failing because this PR has no labels and I don’t have permission to set them.
Could someone please add the
internallabel (or another appropriate one frombreaking,security,feature,bug,refactor,upgrade,docs,lang-all,internal) so the label checker passes?Thanks!
Summary
Add regression tests to verify OpenAPI schema generation when Pydantic v1 and v2 models are mixed in the same FastAPI application, both with and without separate_input_output_schemas.
Motivation
FastAPI supports applications that:
OpenAPI generation must correctly merge schemas and references from both versions. This PR adds explicit tests to ensure:
Changes
New test module: tests/test_openapi_mixed_pydantic_versions.py
Defines Pydantic v1 models via may_v1.BaseModel: AddressV1, UserV1
Defines Pydantic v2 models via pydantic.BaseModel: AddressV2, UserV2 (nesting both v1 and v2 models)
Adds:
test_openapi_mixed_pydantic_models_with_separate_input_output_schemas
test_openapi_mixed_pydantic_models_without_separate_input_output_schemas
Tests are guarded by:
Testing
Executed from the repo root, in a virtual environment with requirements.txt installed:
python -m pytest tests/test_openapi_mixed_pydantic_versions.py -q
All tests pass.