22import json
33
44class Serializable :
5- """Parent class to
5+ """Parent class for all components of adaptive cards.
66
7+ Each component should inherit from this class and then specify, from
8+ its properties, which fall into the following two categories:
9+
10+ * Simple properties are text properties like "type" or "id"
11+ * Serializable properties are properties that can themselfes be serilized.
12+ This includes lists of items (i.e. the 'body' field of the adaptive card) or
13+ single objects that also inherit from Serializable
714 """
815 def __init__ (self , serializable_properties , simple_properties ):
16+ """Creates a serializable object.
17+
18+ See class docstring for an explanation what the different types of
19+ properties are.
20+
21+ Args:
22+ serializable_properties(list): List of all serializable properties
23+ simple_properties(list): List of all simple properties.
24+ """
925 self .serializable_properties = serializable_properties
1026 self .simple_properties = simple_properties
1127
1228 def to_json (self , pretty = False ):
29+ """Create json from a serializable component
30+
31+ This function is used to render the json from a component. While all
32+ components do support this operation it is mainly used on the
33+ AdaptiveCard to generate the json for the attachment.
34+
35+ Args:
36+ pretty(boolean): If true, the returned json will be sorted by keys
37+ and indented with 4 spaces to make it more human-readable
38+
39+ Returns:
40+ A Json representation of this component
41+ """
1342 ret = None
1443 if pretty :
1544 ret = json .dumps (self .to_dict (), indent = 4 , sort_keys = True )
@@ -26,6 +55,10 @@ def to_dict(self):
2655 (i.e. {'version': "1.2"}) while a serializable property is another
2756 subcomponent that also implements a to_dict() method.
2857
58+ The to_dict() method is used to recursively create a dict representation
59+ of the adaptive card. This dictionary representation can then be
60+ converted into json for usage with the API.
61+
2962 Returns:
3063 dict: Dictionary representation of this component.
3164 """
@@ -53,10 +86,3 @@ def to_dict(self):
5386 export [cp ] = l
5487
5588 return export
56-
57- class Component :
58- def __init__ (self , component_type ):
59- self .component_type = component_type
60-
61- def get_type (self ):
62- return self .component_type
0 commit comments