FastAPI generates different OpenAPI in different environments #10474
-
First Check
Commit to Help
Example Codefrom fastapi import FastAPI
from fastapi.openapi.utils import get_openapi
fastapi_app = FastAPI(
title=<title>,
description=<desc>,
responses=<res>,
openapi_url=<url>,
dependencies=<deps>,
)
openapi_file = json.dumps(
get_openapi(
title=fastapi_app.title,
version=fastapi_app.version,
openapi_version=fastapi_app.openapi_version,
description=fastapi_app.description,
routes=fastapi_app.routes,
),
indent=4,
)
# ^ then either print or save to file or something...DescriptionPart of our tests is that it verifies that the openapi file is up to date. This is done by generating a temporary openapi file that is compared to the manually generated one. This is done both locally and in git when it is building a pull request. After updating FastAPI, this still works fine locally, but in git when it's building the PR it fails and generates a different openapi file (both the manual and temporary openapi files are generated using the same code). Here is example of a section that is what is generated locally (and expected), and what is generated in git. This issue in particular is affecting the It doesn't matter which result we get, as long as we get them to generate the same way in both environments. What reasons could there be for it to generate differently? Operating SystemWindows Operating System DetailsNo response FastAPI Version0.104.0 Pydantic Version1.10.8 Python VersionPython 3.11.3 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
This seemed to be caused by the pydantic version, which I wouldn't have known without taking a deep dive into how the openapi file is generated. Apparently pip isn't smart enough to update the package dependencies, so I had to delete the pydantic folders from site packages and then reinstall requirements. (we don't have pydantic as explicit requirement, it is only required through fastapi). Perhaps you need to add a rule that enforces newer pydantic version in the current fastapi version. The current version that got installed is 2.4.2, while the old one is shown in the original post. |
Beta Was this translation helpful? Give feedback.
This seemed to be caused by the pydantic version, which I wouldn't have known without taking a deep dive into how the openapi file is generated. Apparently pip isn't smart enough to update the package dependencies, so I had to delete the pydantic folders from site packages and then reinstall requirements. (we don't have pydantic as explicit requirement, it is only required through fastapi).
Perhaps you need to add a rule that enforces newer pydantic version in the current fastapi version. The current version that got installed is 2.4.2, while the old one is shown in the original post.