From f8fc4bdcf8b3db19080cf162be3611758d4ad101 Mon Sep 17 00:00:00 2001 From: dennis6p Date: Thu, 21 Nov 2024 20:32:08 +0100 Subject: [PATCH] Fix `to_dict()` / `to_json()` export for field `$schema` (#25) * [refactor] Remove unused loc * [fix] Set alternative field_name in config() function --- adaptive_cards/card.py | 2 +- adaptive_cards/utils.py | 4 ++-- adaptive_cards/validation.py | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/adaptive_cards/card.py b/adaptive_cards/card.py index 791bb4a..9105891 100644 --- a/adaptive_cards/card.py +++ b/adaptive_cards/card.py @@ -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") diff --git a/adaptive_cards/utils.py b/adaptive_cards/utils.py index eab43a9..812e898 100644 --- a/adaptive_cards/utils.py +++ b/adaptive_cards/utils.py @@ -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 @@ -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} diff --git a/adaptive_cards/validation.py b/adaptive_cards/validation.py index 98e1a48..d7a7a7c 100644 --- a/adaptive_cards/validation.py +++ b/adaptive_cards/validation.py @@ -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(