Browse Source

stopping point of expiriment w/jsonschema

jsonschema
Ross McFarland 5 months ago
parent
commit
8f5f888d55
No known key found for this signature in database GPG Key ID: 943B179E15D3B22A
2 changed files with 19 additions and 10 deletions
  1. +12
    -8
      octodns/record/base.py
  2. +7
    -2
      tests/test_octodns_record.py

+ 12
- 8
octodns/record/base.py View File

@ -94,25 +94,28 @@ class Record(EqualityTupleMixin):
data_validator.iter_errors(data),
)
for error in errors:
print('error:')
# some of the jsonschema error messages are opaque and useless
# to end uses, this provides a mechinism to translate them.
schema = error.schema
print(f'schema={schema}')
try:
message = schema['$error_message']
print(f'$error_message: message={message}')
cls.log.debug('new: $error_message=`%s`, instance=%s', message, error.instance)
except KeyError:
path = '.'.join(str(p) for p in error.schema_path)
print(f'$error_messages: path={path}')
try:
messages = schema['$error_messages']
print(f'$error_messages: messages={messages}')
cls.log.debug('new: $error_messages=%s, path=%s', messages, path)
message = messages[path]
print(f'$error_messages: message={message}')
cls.log.debug('new: $error_message=`%sr`, instance=%s', message, error.instance)
message = message.format(instance=error.instance)
cls.log.debug('new: $error_message.format=`%sr`', message)
except KeyError:
message = error.message
print(f'error.messages: message={message}')
cls.log.debug('new: error.message=`%sr`', message)
else:
instance = error.instance
message = message, instance=error.instance)
cls.log.debug('new: $error_message.format=`%s`', message)
reasons.append(message)
else:
# original .validate
@ -139,7 +142,8 @@ class Record(EqualityTupleMixin):
return {
'properties': {
'name': {'type': 'string'},
'fqdn': {'type': 'string', 'maxLength': 253},
'fqdn': {'type': 'string', 'maxLength': 253,
'$error_message': 'invalid fqdn, "{instance} is too long at {len(instance)}, max is 253"'},
},
'allOf': [
{


+ 7
- 2
tests/test_octodns_record.py View File

@ -583,8 +583,13 @@ class TestRecordValidation(TestCase):
self.zone, name, {'ttl': 300, 'type': 'A', 'value': '1.2.3.4'}
)
reason = ctx.exception.reasons[0]
self.assertTrue(reason.startswith("'xxxx"))
self.assertTrue(reason.endswith("xxxx.unit.tests.' is too long"))
print(reason)
self.assertTrue(reason.startswith('invalid fqdn, "xxxx'))
self.assertTrue(
reason.endswith(
'.unit.tests." is too long at 254 chars, max is 253'
)
)
# label length, DNS defines max as 63
with self.assertRaises(ValidationError) as ctx:


Loading…
Cancel
Save