Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Conversation

@SSOBHY2
Copy link

@SSOBHY2 SSOBHY2 commented Dec 4, 2025

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 internal label (or another appropriate one from
breaking, 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:

  • Use Pydantic v2 for new models, and
  • Still rely on Pydantic v1 models (via the compat layer) during migration.

OpenAPI generation must correctly merge schemas and references from both versions. This PR adds explicit tests to ensure:

  • Schemas for both Pydantic v1 and v2 models appear in components.schemas.
  • References to those schemas are valid and correctly scoped.
  • Behavior is consistent when separate_input_output_schemas is enabled or disabled.

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

        • FastAPI(separate_input_output_schemas=True)
        • Ensures components.schemas contains entries for UserV1, UserV2, AddressV1, AddressV2
        • Asserts that references exist for each of those models somewhere in the OpenAPI document
      • test_openapi_mixed_pydantic_models_without_separate_input_output_schemas

        • FastAPI(separate_input_output_schemas=False)
        • Ensures the same schemas are present
        • Asserts that all reference values start with #/components/schemas/ (no broken references)
  • Tests are guarded by:

    • @needs_pydanticv2 (only run with Pydantic v2)
    • @needs_py_lt_314 (skip on Python ≥ 3.14, where Pydantic v1 is not supported)

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.


@SSOBHY2 SSOBHY2 closed this Dec 4, 2025
@SSOBHY2 SSOBHY2 reopened this Dec 4, 2025
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.