Skip to content

Commit

Permalink
feat: Allow developers to mark schema fields as deprecated
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Jan 15, 2025
1 parent b3610ca commit f1dd781
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
12 changes: 12 additions & 0 deletions singer_sdk/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,8 @@ def __init__( # noqa: PLR0913
*,
nullable: bool | None = None,
title: str | None = None,
deprecated: bool | None = None,
**kwargs: t.Any,
) -> None:
"""Initialize Property object.
Expand All @@ -671,6 +673,8 @@ def __init__( # noqa: PLR0913
displayed to the user as hints of the expected format of inputs.
nullable: If True, the property may be null.
title: Optional. A short, human-readable title for the property.
deprecated: If True, mark this property as deprecated.
**kwargs: Additional keyword arguments to pass to the parent class.
"""
self.name = name
self.wrapped = wrapped
Expand All @@ -682,6 +686,8 @@ def __init__( # noqa: PLR0913
self.examples = examples or None
self.nullable = nullable
self.title = title
self.deprecated = deprecated
self.kwargs = kwargs

@property
def type_dict(self) -> dict: # type: ignore[override]
Expand Down Expand Up @@ -739,6 +745,12 @@ def to_dict(self) -> dict:
type_dict.update({"enum": self.allowed_values})
if self.examples:
type_dict.update({"examples": self.examples})

if self.deprecated is not None:
type_dict["deprecated"] = self.deprecated

type_dict.update(self.kwargs)

return {self.name: type_dict}


Expand Down
2 changes: 2 additions & 0 deletions tests/core/test_jsonschema_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,12 +495,14 @@ def test_inbuilt_type(json_type: JSONTypeHelper, expected_json_schema: dict):
IntegerType,
allowed_values=[1, 2, 3, 4, 5, 6, 7, 8, 9],
examples=[1, 2, 3],
deprecated=True,
),
{
"my_prop9": {
"type": ["integer", "null"],
"enum": [1, 2, 3, 4, 5, 6, 7, 8, 9],
"examples": [1, 2, 3],
"deprecated": True,
},
},
{is_integer_type},
Expand Down

0 comments on commit f1dd781

Please sign in to comment.