Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Avoid duplicate entries in required array of JSON schema helpers #1214

Merged
merged 6 commits into from
Dec 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions singer_sdk/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@

import json
import sys
from typing import Any, Generic, Mapping, TypeVar, Union, cast
from typing import Any, Generic, ItemsView, Mapping, TypeVar, Union, cast

import sqlalchemy
from jsonschema import validators
Expand Down Expand Up @@ -544,7 +544,7 @@ def __init__(
}
}
"""
self.wrapped: list[Property] = list(properties)
self.wrapped: dict[str, Property] = {prop.name: prop for prop in properties}
self.additional_properties = additional_properties
self.pattern_properties = pattern_properties

Expand All @@ -557,7 +557,7 @@ def type_dict(self) -> dict: # type: ignore # OK: @classproperty vs @property
"""
merged_props = {}
required = []
for w in self.wrapped:
for w in self.wrapped.values():
merged_props.update(w.to_dict())
if not w.optional:
required.append(w.name)
Expand Down Expand Up @@ -604,21 +604,21 @@ def type_dict(self) -> dict: # type: ignore # OK: @classproperty vs @property
class PropertiesList(ObjectType):
"""Properties list. A convenience wrapper around the ObjectType class."""

def items(self) -> list[tuple[str, Property]]:
def items(self) -> ItemsView[str, Property]:
"""Get wrapped properties.

Returns:
List of (name, property) tuples.
"""
return [(p.name, p) for p in self.wrapped]
return self.wrapped.items()

def append(self, property: Property) -> None:
"""Append a property to the property list.

Args:
property: Property to add
"""
self.wrapped.append(property)
self.wrapped[property.name] = property


def to_jsonschema_type(
Expand Down
1 change: 0 additions & 1 deletion tests/snapshots/jsonschema/required_duplicates.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
}
},
"required": [
"email",
"email",
"username"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
}
},
"required": [
"email",
"email",
"username"
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
}
},
"required": [
"email",
"email",
"username"
],
Expand Down