Skip to content

Commit

Permalink
fix: Avoid duplicate entries in required array of JSON schema helpe…
Browse files Browse the repository at this point in the history
…rs (#1214)

* fix: Avoid duplicate entries in `required` array of JSON schema helpers

* Update snapshots
  • Loading branch information
edgarrmondragon authored Dec 17, 2022
1 parent ee570e0 commit e0a24b8
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 9 deletions.
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

0 comments on commit e0a24b8

Please sign in to comment.