Closed roopeshvaddepally closed 8 years ago
class NFS(jsl.Document):
class Options:
additional_properties = False
definition_id = 'nfs'
type = jsl.StringField(enum=['nfs'], required=True)
remotePath = jsl.StringField(pattern='^(/[^/]+)+$', required=True)
server = jsl.OneOfField([
jsl.StringField(format='host-name'),
jsl.StringField(format='ipv4'),
jsl.StringField(format='ipv6'),
], required=True)
validate({
"type": "nfs",
"server": "my.nfs.server",
"remotePath": "/exports/mypath"
}, NFS.get_schema())
results in
jsonschema.exceptions.ValidationError: 'my.nfs.server' is valid under each of {'type': 'string', 'format': 'ipv4'}, {'type': 'string', 'format': 'ipv6'}, {'type': 'string', 'format': 'host-name'}
The problem is that jsonschema.validate
does not check formats by default (see jsonschema docs). If a format checker is specified, validation passes:
import jsonschema
jsonschema.validate({
"type": "nfs",
"server": "my.nfs.server",
"remotePath": "/exports/mypath"
}, NFS.get_schema(), format_checker=jsonschema.FormatChecker())
I took the jsonschema example of fstab file, your example in tutorial write up to FSTabEntry, but doesn't implement the FSTab part of it, so I tried to complete it. This fails to validate the schema for format 'host-name' in NFS class and server attribute.
If I change server part to simple StringField it passes.
Here is the complete code I used.
Here is the traceback: