diff --git a/singer_sdk/typing.py b/singer_sdk/typing.py index 6bf8d9527..7be54b5cc 100644 --- a/singer_sdk/typing.py +++ b/singer_sdk/typing.py @@ -52,6 +52,7 @@ from __future__ import annotations +import functools import json import typing as t @@ -1086,6 +1087,49 @@ def __iter__(self) -> t.Iterator[Property]: return self.wrapped.values().__iter__() +@functools.singledispatch +def _sa_type_to_jsonschema(sa_type: sa.types.TypeEngine) -> dict: # noqa: ARG001 + return StringType.type_dict + + +@_sa_type_to_jsonschema.register +def _sa_type_to_jsonschema_datetime(sa_type: sa.types.DateTime) -> dict: # noqa: ARG001 + return DateTimeType.type_dict + + +@_sa_type_to_jsonschema.register +def _sa_type_to_jsonschema_date(sa_type: sa.types.Date) -> dict: # noqa: ARG001 + return DateType.type_dict + + +@_sa_type_to_jsonschema.register +def _sa_type_to_jsonschema_integer(sa_type: sa.types.Integer) -> dict: # noqa: ARG001 + return IntegerType.type_dict + + +@_sa_type_to_jsonschema.register +def _sa_type_to_jsonschema_float(sa_type: sa.types.Numeric) -> dict: # noqa: ARG001 + return NumberType.type_dict + + +@_sa_type_to_jsonschema.register +def _sa_type_to_jsonschema_string(sa_type: sa.types.String) -> dict: # noqa: ARG001 + # TODO: Enable support for maxLenght. + # if sa_type.length: + # return StringType(max_length=sa_type.length).type_dict # noqa: ERA001 + return StringType.type_dict + + +@_sa_type_to_jsonschema.register +def _sa_type_to_jsonschema_boolean(sa_type: sa.types.Boolean) -> dict: # noqa: ARG001 + return BooleanType.type_dict + + +@_sa_type_to_jsonschema.register +def _sa_type_to_jsonschema_time(sa_type: sa.types.Variant) -> dict: # noqa: ARG001 + return TimeType.type_dict + + def to_jsonschema_type( from_type: str | sa.types.TypeEngine | type[sa.types.TypeEngine], ) -> dict: @@ -1122,7 +1166,7 @@ def to_jsonschema_type( if isinstance(from_type, str): type_name = from_type elif isinstance(from_type, sa.types.TypeEngine): - type_name = type(from_type).__name__ + return _sa_type_to_jsonschema(from_type) elif isinstance(from_type, type) and issubclass( from_type, sa.types.TypeEngine,