mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Import `GenerateJsonSchema from fastapi._compat.v2`
where it is modified since https://github.com/fastapi/fastapi/commit/e8b98d21871f64234520c1e770f39e6bfea3b0d5#diff-1086603fdd56511aafd1d279396b142b803e48164327148e6de26cef4cdaed81
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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,
|
||||
)
|
||||
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user