@@ -550,8 +550,6 @@ def _build_schema_resource(fields):
550550
551551def _to_schema_fields (schema ):
552552 """TODO docstring
553- QUESTION: do we want a flag to force the generation of a Schema object?
554-
555553 CAST a list of elements to either:
556554 * a Schema object with SchemaFields and an attribute
557555 * a list of SchemaFields but no attribute
@@ -829,8 +827,6 @@ def serde_info(self) -> Any:
829827 prop = _get_sub_prop (self ._properties , ["serDeInfo" ])
830828 if prop is not None :
831829 prop = StorageDescriptor ().from_api_repr (prop )
832- print (f"DINOSAUR prop: { prop } " )
833-
834830 return prop
835831
836832 @serde_info .setter
@@ -957,6 +953,7 @@ def from_api_repr(cls, resource: dict) -> SerDeInfo:
957953
958954
959955class Schema :
956+ # TODO docstrings and type hints
960957 def __init__ (self , fields = None , foreign_type_info = None ):
961958 self ._properties = {}
962959 self ._fields = [] if fields is None else list (fields ) # Internal List
@@ -998,13 +995,38 @@ def __iter__(self):
998995 return iter (self ._fields )
999996
1000997 def __str__ (self ):
1001- return str (self ._fields )
998+ return str (self ._fields ) # This does not handle the case where FTI exists
1002999
10031000 def __repr__ (self ):
1004- return f"Schema({ self .foreign_type_info !r} , { self ._fields !r} )"
1001+ return f"Schema({ self ._fields !r} , { self .foreign_type_info !r} )"
10051002
10061003 def append (self , item ):
10071004 self ._fields .append (item )
10081005
10091006 def extend (self , iterable ):
10101007 self ._fields .extend (iterable )
1008+
1009+ def to_api_repr (self ) -> dict :
1010+ """Build an API representation of this object.
1011+
1012+ Returns:
1013+ Dict[str, Any]:
1014+ A dictionary in the format used by the BigQuery API.
1015+ """
1016+ return copy .deepcopy (self ._properties )
1017+
1018+ @classmethod
1019+ def from_api_repr (cls , resource : dict ) -> Schema :
1020+ """Factory: constructs an instance of the class (cls)
1021+ given its API representation.
1022+
1023+ Args:
1024+ resource (Dict[str, Any]):
1025+ API representation of the object to be instantiated.
1026+
1027+ Returns:
1028+ An instance of the class initialized with data from 'resource'.
1029+ """
1030+ config = cls ("" )
1031+ config ._properties = copy .deepcopy (resource )
1032+ return config
0 commit comments