Commit 5625fcce authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

erp5_json_type: fix validate local json to not rise when no data is available

parent 9d1be6f1
...@@ -60,11 +60,12 @@ class JSONType(XMLObject): ...@@ -60,11 +60,12 @@ class JSONType(XMLObject):
Validate contained JSON with the Schema defined in the Portal Type. Validate contained JSON with the Schema defined in the Portal Type.
""" """
portal = self.getPortalObject() portal = self.getPortalObject()
defined_schema = json.loads(portal.portal_types[self.getPortalType()].asJSONText()) defined_schema = portal.portal_types[self.getPortalType()].getTextContent()
text_content = self.asJSONText() text_content = self.asJSONText()
if not defined_schema or text_content is None:
if text_content is None: # No errors if nothing is defined
return False return True
defined_schema = json.loads(defined_schema)
current_schema = json.loads(text_content) current_schema = json.loads(text_content)
try: try:
jsonschema.validate(current_schema, defined_schema, format_checker=jsonschema.FormatChecker()) jsonschema.validate(current_schema, defined_schema, format_checker=jsonschema.FormatChecker())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment