@classmethod
def _validate_doc(cls, doc):
    """Emit a warning or raise an exception if the document is invalid. Returns doc."""
    try:
        for key in doc.keys():
            cls._validate_doc(doc[cls._validate_key(key)])
    except AttributeError:
        return
    return doc
