Skip to content

Commit

Permalink
Allow ListOf/NestedListOf to have docs
Browse files Browse the repository at this point in the history
  • Loading branch information
cdzombak committed Apr 10, 2018
1 parent 87952a2 commit 69be485
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions zschema/compounds.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ def _is_valid_object(name, object_):

class ListOf(Keyable):

def __init__(self, object_, max_items=10, category=None):
def __init__(self, object_, max_items=10, doc=None, category=None):
self.object_ = object_
self.max_items = max_items
self.category = category
self.doc = doc
_is_valid_object("Anonymous ListOf", object_)

@property
Expand All @@ -39,6 +40,8 @@ def docs_bq(self, parent_category=None):
category = self.category or parent_category
retv["category"] = category
retv["repeated"] = True
if self.doc:
retv["doc"] = self.doc
return retv

def to_es(self):
Expand All @@ -48,6 +51,8 @@ def docs_es(self, parent_category=None):
retv = self.object_.docs_es()
category = self.category or parent_category
retv["category"] = category
if self.doc:
retv["doc"] = self.doc
return retv

def validate(self, name, value):
Expand Down Expand Up @@ -197,8 +202,8 @@ def validate(self, name, value):

class NestedListOf(ListOf):

def __init__(self, object_, subrecord_name, max_items=10, category=None):
ListOf.__init__(self, object_, max_items, category=category)
def __init__(self, object_, subrecord_name, max_items=10, doc=None, category=None):
ListOf.__init__(self, object_, max_items, doc=doc, category=category)
self.subrecord_name = subrecord_name

def to_bigquery(self, name):
Expand All @@ -207,6 +212,8 @@ def to_bigquery(self, name):
})
retv = subr.to_bigquery(self.key_to_bq(name))
retv["mode"] = "REPEATED"
if self.doc:
retv["doc"] = self.doc
return retv

def docs_bq(self, parent_category=None):
Expand All @@ -216,6 +223,8 @@ def docs_bq(self, parent_category=None):
category = self.category or parent_category
retv = subr.docs_bq(parent_category=category)
retv["repeated"] = True
if self.doc:
retv["doc"] = self.doc
return retv


Expand Down

0 comments on commit 69be485

Please sign in to comment.