Support for custom tags?
- Dominant language
- Python
- Stars
- 297
- Forks
- 84
- PR merge metrics
- No merged PRs in 30d
Description
I apologize if I missed this in the docs for kwalify or pykwalify, or if this was already addressed in an earlier issue (I have searched but cannot find anything). I'd like to validate a schema that uses custom tags. Between the pyyaml and pykwalify documentation this is the best I was able to come up with. But its obviously not right. Example:
```python
import yaml
from pykwalify.core import Core
class MyTag(yaml.YAMLObject):
yaml_tag = u'!MyTag'
def __init__(self, name, parameter):
self.name = name
self.parameter = parameter
def __repr__(self):
return "%s(name=%r, parameter=%r)" % (
self.__class__.__name__, self.name, self.parameter)
data = yaml.load("""
!MyTag
name: "aname"
parameter: 2
""")
print("dump: {}".format(yaml.dump(data)))
schema = yaml.load("""
type: !!python/object:__main__.MyTag
type: map
mapping:
name:
type: str
parameter:
type: int
""")
c = Core(source_data=data, schema_data=schema)
c.validate(raise_exception=True)
```
Output:
```
dump: !MyTag {name: aname, parameter: 2}
Traceback (most recent call last):
File "example.py", line 34, in
c.validate(raise_exception=True)
File "/usr/local/lib/python2.7/dist-packages/pykwalify/core.py", line 155, in validate
self._start_validate(self.source)
File "/usr/local/lib/python2.7/dist-packages/pykwalify/core.py", line 197, in _start_validate
root_rule = Rule(schema=self.schema)
File "/usr/local/lib/python2.7/dist-packages/pykwalify/rule.py", line 66, in __init__
self.init(schema, "")
File "/usr/local/lib/python2.7/dist-packages/pykwalify/rule.py", line 399, in init
path=path,
pykwalify.errors.RuleError:
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.