Skip to content

Commit

Permalink
Fix to_dict() / to_json() export for field $schema (#25)
Browse files Browse the repository at this point in the history
* [refactor] Remove unused loc

* [fix] Set alternative field_name in config() function
  • Loading branch information
dennis6p authored Nov 21, 2024
1 parent c09bd89 commit f8fc4bd
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
2 changes: 1 addition & 1 deletion adaptive_cards/card.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class AdaptiveCard:
type: str = field(default=TYPE, metadata=utils.get_metadata("1.0"))
version: str = field(default=VERSION, metadata=utils.get_metadata("1.0"))
schema: str = field(
default=SCHEMA, metadata=utils.get_metadata("1.0") | {"field_name": "$schema"}
default=SCHEMA, metadata=utils.get_metadata("1.0", field_name="$schema")
)
refresh: Optional[ct.Refresh] = field(
default=None, metadata=utils.get_metadata("1.4")
Expand Down
4 changes: 2 additions & 2 deletions adaptive_cards/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
is_none: Any = lambda f: f is None


def get_metadata(min_version: str) -> dict[str, Any]:
def get_metadata(min_version: str, field_name: str | None = None) -> dict[str, Any]:
"""
Get default metadata information for dataclass field
Expand All @@ -19,4 +19,4 @@ def get_metadata(min_version: str) -> dict[str, Any]:
Returns:
dict[str, Any]: Metadata information
"""
return config(exclude=is_none) | {"min_version": min_version}
return config(exclude=is_none, field_name=field_name) | {"min_version": min_version}
2 changes: 0 additions & 2 deletions adaptive_cards/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,9 @@ def __validate_elements(self, items: Any):

if isinstance(value, list):
iterables.append(value)
# self.__validate_elements(value)

elif dataclasses.is_dataclass(value):
custom_types.append(value)
# self.__validate_elements(value)

else:
self.__validate_field_version(
Expand Down

0 comments on commit f8fc4bd

Please sign in to comment.