added context manager method for using validation of dynamic template

This commit is contained in:
iLLiCiTiT 2021-07-12 17:36:54 +02:00
parent 41218b61ec
commit 027cb48a13

View file

@ -3,6 +3,7 @@ import re
import json
import copy
import inspect
import contextlib
from .exceptions import (
SchemaTemplateMissingKeys,
@ -167,6 +168,23 @@ class SchemasHub:
return True
return False
@contextlib.contextmanager
def validating_dynamic(self, template_name):
"""Template name is validating and validated.
Context manager that cares about storing template name validations of
template.
This is to avoid infinite loop of dynamic children validation.
"""
self._validating_dynamic.add(template_name)
try:
yield
self._validated_dynamic.add(template_name)
finally:
self._validating_dynamic.remove(template_name)
def get_schema(self, schema_name):
"""Get schema definition data by it's name.