From b3bfb458846d9f6e981c01ed41421330499da567 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Sat, 28 Feb 2026 18:24:13 +0000 Subject: [PATCH] Import ``GenerateJsonSchema`` from ``fastapi._compat.v2`` where it is modified since https://github.com/fastapi/fastapi/commit/e8b98d21871f64234520c1e770f39e6bfea3b0d5#diff-1086603fdd56511aafd1d279396b142b803e48164327148e6de26cef4cdaed81 --- lib/galaxy/schema/generics.py | 12 ------------ lib/galaxy/webapps/galaxy/fast_app.py | 21 ++++++++++++++++++++- lib/galaxy/webapps/openapi/_compat/v2.py | 2 +- lib/galaxy/webapps/openapi/utils.py | 2 +- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/galaxy/schema/generics.py b/lib/galaxy/schema/generics.py index bcbd83e6840..eac8874bd0e 100644 --- a/lib/galaxy/schema/generics.py +++ b/lib/galaxy/schema/generics.py @@ -6,7 +6,6 @@ from typing import ( ) from pydantic import BaseModel -from pydantic.json_schema import GenerateJsonSchema from typing_extensions import override from galaxy.schema.fields import ( @@ -42,17 +41,6 @@ class GenericModel(BaseModel): return suffix -class CustomJsonSchema(GenerateJsonSchema): - def get_defs_ref(self, core_mode_ref): - full_def = super().get_defs_ref(core_mode_ref) - choices = self._prioritized_defsref_choices[full_def] - ref, mode = core_mode_ref - if ref in ref_to_name: - for i, choice in enumerate(choices): - choices[i] = choice.replace(choices[0], ref_to_name[ref]) # type: ignore[call-overload] - return full_def - - class PatchGenericPickle: """A mixin that allows generic pydantic models to be serialized and deserialized with pickle. diff --git a/lib/galaxy/webapps/galaxy/fast_app.py b/lib/galaxy/webapps/galaxy/fast_app.py index 2f05d8c86df..b30e7269bb8 100644 --- a/lib/galaxy/webapps/galaxy/fast_app.py +++ b/lib/galaxy/webapps/galaxy/fast_app.py @@ -1,5 +1,6 @@ from typing import ( Any, + TYPE_CHECKING, ) from urllib.parse import urljoin @@ -18,7 +19,7 @@ from slowapi.util import get_remote_address from starlette.middleware.cors import CORSMiddleware from tuspyserver import create_tus_router -from galaxy.schema.generics import CustomJsonSchema +from galaxy.schema.generics import ref_to_name from galaxy.version import VERSION from galaxy.webapps.base.api import ( add_exception_handler, @@ -28,8 +29,15 @@ from galaxy.webapps.base.api import ( include_all_package_routers, ) from galaxy.webapps.base.webapp import config_allows_origin +from galaxy.webapps.openapi._compat.v2 import GenerateJsonSchema from galaxy.webapps.openapi.utils import get_openapi +if TYPE_CHECKING: + from pydantic.json_schema import ( + CoreModeRef, + DefsRef, + ) + # https://fastapi.tiangolo.com/tutorial/metadata/#metadata-for-tags api_tags_metadata = [ { @@ -164,6 +172,17 @@ def get_fastapi_instance(root_path="") -> FastAPI: ) +class CustomJsonSchema(GenerateJsonSchema): + def get_defs_ref(self, core_mode_ref: "CoreModeRef") -> "DefsRef": + full_def = super().get_defs_ref(core_mode_ref) + choices = self._prioritized_defsref_choices[full_def] + ref, mode = core_mode_ref + if ref in ref_to_name: + for i, choice in enumerate(choices): + choices[i] = choice.replace(choices[0], ref_to_name[ref]) # type: ignore[call-overload] + return full_def + + def get_openapi_schema() -> dict[str, Any]: """ Dumps openAPI schema without starting a full app and webserver. diff --git a/lib/galaxy/webapps/openapi/_compat/v2.py b/lib/galaxy/webapps/openapi/_compat/v2.py index 458adaddc90..c3796db4c15 100644 --- a/lib/galaxy/webapps/openapi/_compat/v2.py +++ b/lib/galaxy/webapps/openapi/_compat/v2.py @@ -8,6 +8,7 @@ from typing import ( from fastapi._compat.v2 import ( _has_computed_fields, + GenerateJsonSchema as GenerateJsonSchema, get_flat_models_from_fields, ModelField, ) @@ -15,7 +16,6 @@ from fastapi.openapi.constants import REF_TEMPLATE from fastapi.types import ModelNameMap from pydantic.fields import FieldInfo as FieldInfo from pydantic.json_schema import ( - GenerateJsonSchema as GenerateJsonSchema, JsonSchemaValue as JsonSchemaValue, ) diff --git a/lib/galaxy/webapps/openapi/utils.py b/lib/galaxy/webapps/openapi/utils.py index 52d00761d47..69146230f2b 100644 --- a/lib/galaxy/webapps/openapi/utils.py +++ b/lib/galaxy/webapps/openapi/utils.py @@ -31,10 +31,10 @@ from fastapi.openapi.utils import ( get_fields_from_routes, get_openapi_path, ) -from pydantic.json_schema import GenerateJsonSchema from starlette.routing import BaseRoute from ._compat import get_definitions +from ._compat.v2 import GenerateJsonSchema def get_openapi(