prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  travis on master failing, due to metadata violations from new jsonschema checks
  There are two things wrong:
  
   - the validate script assumes a util/reports folder
   - hp is failing; we already know that hp has a custom license and this should be reported elsewhere and is not a schema violation
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `util/validate-metadata.py`
  Content:
  ```
  1 #!/usr/bin/env python3
  2 
  3 import ast
  4 import sys
  5 import json
  6 import jsonschema
  7 import re
  8 
  9 # file paths
  10 data_file = "../registry/ontologies.jsonld"
  11 schema_file = "metadata-schema.json"
  12 schema_lite_file = "metadata-schema-lite.json"
  13 report_file = "reports/metadata-violations.csv"
  14 
  15 # ultra-escaped regex strings
  16 email_sub = 'does not match \'\\^\\[\\^@\\]\\+\\$\''
  17 fmt_sub = ('does not match \'\\^\\[0\\-9A\\-Za\\-z\\-_\\\\\\\\/\\]\\+'
  18           '\\\\\\\\.\\(owl\\|obo\\|json\\|omn\\|ofn\\|owx\\|ttl\\|owl'
  19           '\\\\\\\\.gz\\)\\$\'')
  20 
  21 def validate():
  22 	"""
  23 	Validate registry metadata.
  24 	"""
  25 	print("--- validating metadata against {0} ---".format(schema_file))
  26 	data = load_data()
  27 	schema = load_schema()
  28 	# validate each object
  29 	errors = {}
  30 	for item in data["ontologies"]:
  31 		if 'is_obsolete' in item and item["is_obsolete"] is True:
  32 			continue
  33 		# skip any 'validate: false' ontologies
  34 		if 'validate' in item and item["validate"] is False:
  35 			continue
  36 		ont_id = item["id"]
  37 		try:
  38 			jsonschema.validate(item, schema)
  39 		except jsonschema.exceptions.ValidationError as ve:
  40 			print("ERROR in {0}".format(ont_id))
  41 			errors[ont_id] = format_msg(ve)
  42 	if errors:
  43 		write_errors(errors)
  44 	else:
  45 		print("SUCCESS - no errors found in metadata")
  46 		sys.exit(0)
  47 
  48 def format_msg(ve):
  49 	"""
  50 	Format exception message from jsonchema.validate(...).
  51 	"""
  52 	# replace u characters
  53 	replace_u = re.sub('u\'', '\'', ve.message)
  54 	# replace scary regex strings
  55 	replace_email = re.sub(
  56 		email_sub, 'is not valid for \'contact.label\'', replace_u)
  57 	msg = re.sub(fmt_sub, 'is not valid for \'products.id\'', replace_email)
  58 
  59 	# check if output is for license error
  60 	is_license = re.search('({\'url\'.+?\'label\'.+?})', msg)
  61 	if is_license:
  62 		return format_license_msg(is_license.group(1))
  63 
  64 	# check if output is for list error
  65 	is_list = re.search('(\\[.+?\\]) is not of type \'string\'', msg)
  66 	if is_list:
  67 		return format_list_msg(is_list.group(1), ve)
  68 
  69 	# otherwise return the message
  70 	return msg
  71 
  72 def format_license_msg(substr):
  73 	"""
  74 	Format an exception message for a license issue.
  75 	"""
  76 	# process to dict
  77 	d = json.loads(substr.replace('\'', '"'))
  78 	url = d['url']
  79 	label = d['label']
  80 	return '\'{0}\' <{1}> is not valid for \'license\''.format(label, url)
  81 
  82 def format_list_msg(substr, ve):
  83 	"""
  84 	Format an exception for an unexpected list.
  85 	"""
  86 	l = json.loads(substr.replace('\'', '"'))
  87 	# use the full message to find the violating property
  88 	prop_find = re.search('On instance\\[(\'.+?\')\\]', str(ve))
  89 	if prop_find:
  90 		prop = prop_find.group(1)
  91 		return '{0} expects one value, got {1}'.format(prop, len(l))
  92 	else:
  93 		return substr
  94 
  95 def load_schema():
  96 	"""
  97 	Load the schema to validate against.
  98 	"""
  99 	# read the schema
  100 	with open(schema_file) as f:
  101 		schema = json.load(f)
  102 	return schema
  103 
  104 def load_data():
  105 	"""
  106 	Load the data to validate.
  107 	"""
  108 	# read the JSON-LD data
  109 	with open(data_file) as f:
  110 		data = json.load(f)
  111 	return data
  112 
  113 def write_errors(errors):
  114 	"""
  115 	Write validation errors to a user-friendly report.
  116 	"""
  117 	with open(report_file, 'w+') as f:
  118 		f.write("ID,ERROR\n")
  119 		for ont_id, msg in errors.items():
  120 			f.write('"' + ont_id + '","' + msg + '"\n')
  121 	print(
  122 		"VALIDATION FAILED: {0} errors - see {1} for details".format(
  123 			len(errors), report_file))
  124 	sys.exit(1)
  125 
  126 # run the process!
  127 if __name__ == '__main__':
  128 	validate()
  129
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/util/validate-metadata.py b/util/validate-metadata.py
  --- a/util/validate-metadata.py
  +++ b/util/validate-metadata.py
  @@ -7,9 +7,9 @@
   import re
   
   # file paths
  -data_file = "../registry/ontologies.jsonld"
  -schema_file = "metadata-schema.json"
  -schema_lite_file = "metadata-schema-lite.json"
  +data_file = "registry/ontologies.jsonld"
  +schema_file = "util/metadata-schema.json"
  +schema_lite_file = "util/metadata-schema-lite.json"
   report_file = "reports/metadata-violations.csv"
   
   # ultra-escaped regex strings
  
verification_info: {"golden_diff": "diff --git a/util/validate-metadata.py b/util/validate-metadata.py\n--- a/util/validate-metadata.py\n+++ b/util/validate-metadata.py\n@@ -7,9 +7,9 @@\n import re\n \n # file paths\n-data_file = \"../registry/ontologies.jsonld\"\n-schema_file = \"metadata-schema.json\"\n-schema_lite_file = \"metadata-schema-lite.json\"\n+data_file = \"registry/ontologies.jsonld\"\n+schema_file = \"util/metadata-schema.json\"\n+schema_lite_file = \"util/metadata-schema-lite.json\"\n report_file = \"reports/metadata-violations.csv\"\n \n # ultra-escaped regex strings\n", "issue": "travis on master failing, due to metadata violations from new jsonschema checks\nThere are two things wrong:\r\n\r\n - the validate script assumes a util/reports folder\r\n - hp is failing; we already know that hp has a custom license and this should be reported elsewhere and is not a schema violation\n", "before_files": [{"content": "#!/usr/bin/env python3\n\nimport ast\nimport sys\nimport json\nimport jsonschema\nimport re\n\n# file paths\ndata_file = \"../registry/ontologies.jsonld\"\nschema_file = \"metadata-schema.json\"\nschema_lite_file = \"metadata-schema-lite.json\"\nreport_file = \"reports/metadata-violations.csv\"\n\n# ultra-escaped regex strings\nemail_sub = 'does not match \\'\\\\^\\\\[\\\\^@\\\\]\\\\+\\\\$\\''\nfmt_sub = ('does not match \\'\\\\^\\\\[0\\\\-9A\\\\-Za\\\\-z\\\\-_\\\\\\\\\\\\\\\\/\\\\]\\\\+'\n          '\\\\\\\\\\\\\\\\.\\\\(owl\\\\|obo\\\\|json\\\\|omn\\\\|ofn\\\\|owx\\\\|ttl\\\\|owl'\n          '\\\\\\\\\\\\\\\\.gz\\\\)\\\\$\\'')\n\ndef validate():\n\t\"\"\"\n\tValidate registry metadata.\n\t\"\"\"\n\tprint(\"--- validating metadata against {0} ---\".format(schema_file))\n\tdata = load_data()\n\tschema = load_schema()\n\t# validate each object\n\terrors = {}\n\tfor item in data[\"ontologies\"]:\n\t\tif 'is_obsolete' in item and item[\"is_obsolete\"] is True:\n\t\t\tcontinue\n\t\t# skip any 'validate: false' ontologies\n\t\tif 'validate' in item and item[\"validate\"] is False:\n\t\t\tcontinue\n\t\tont_id = item[\"id\"]\n\t\ttry:\n\t\t\tjsonschema.validate(item, schema)\n\t\texcept jsonschema.exceptions.ValidationError as ve:\n\t\t\tprint(\"ERROR in {0}\".format(ont_id))\n\t\t\terrors[ont_id] = format_msg(ve)\n\tif errors:\n\t\twrite_errors(errors)\n\telse:\n\t\tprint(\"SUCCESS - no errors found in metadata\")\n\t\tsys.exit(0)\n\ndef format_msg(ve):\n\t\"\"\"\n\tFormat exception message from jsonchema.validate(...).\n\t\"\"\"\n\t# replace u characters\n\treplace_u = re.sub('u\\'', '\\'', ve.message)\n\t# replace scary regex strings\n\treplace_email = re.sub(\n\t\temail_sub, 'is not valid for \\'contact.label\\'', replace_u)\n\tmsg = re.sub(fmt_sub, 'is not valid for \\'products.id\\'', replace_email)\n\n\t# check if output is for license error\n\tis_license = re.search('({\\'url\\'.+?\\'label\\'.+?})', msg)\n\tif is_license:\n\t\treturn format_license_msg(is_license.group(1))\n\n\t# check if output is for list error\n\tis_list = re.search('(\\\\[.+?\\\\]) is not of type \\'string\\'', msg)\n\tif is_list:\n\t\treturn format_list_msg(is_list.group(1), ve)\n\n\t# otherwise return the message\n\treturn msg\n\ndef format_license_msg(substr):\n\t\"\"\"\n\tFormat an exception message for a license issue.\n\t\"\"\"\n\t# process to dict\n\td = json.loads(substr.replace('\\'', '\"'))\n\turl = d['url']\n\tlabel = d['label']\n\treturn '\\'{0}\\' <{1}> is not valid for \\'license\\''.format(label, url)\n\ndef format_list_msg(substr, ve):\n\t\"\"\"\n\tFormat an exception for an unexpected list.\n\t\"\"\"\n\tl = json.loads(substr.replace('\\'', '\"'))\n\t# use the full message to find the violating property\n\tprop_find = re.search('On instance\\\\[(\\'.+?\\')\\\\]', str(ve))\n\tif prop_find:\n\t\tprop = prop_find.group(1)\n\t\treturn '{0} expects one value, got {1}'.format(prop, len(l))\n\telse:\n\t\treturn substr\n\ndef load_schema():\n\t\"\"\"\n\tLoad the schema to validate against.\n\t\"\"\"\n\t# read the schema\n\twith open(schema_file) as f:\n\t\tschema = json.load(f)\n\treturn schema\n\ndef load_data():\n\t\"\"\"\n\tLoad the data to validate.\n\t\"\"\"\n\t# read the JSON-LD data\n\twith open(data_file) as f:\n\t\tdata = json.load(f)\n\treturn data\n\ndef write_errors(errors):\n\t\"\"\"\n\tWrite validation errors to a user-friendly report.\n\t\"\"\"\n\twith open(report_file, 'w+') as f:\n\t\tf.write(\"ID,ERROR\\n\")\n\t\tfor ont_id, msg in errors.items():\n\t\t\tf.write('\"' + ont_id + '\",\"' + msg + '\"\\n')\n\tprint(\n\t\t\"VALIDATION FAILED: {0} errors - see {1} for details\".format(\n\t\t\tlen(errors), report_file))\n\tsys.exit(1)\n\n# run the process!\nif __name__ == '__main__':\n\tvalidate()\n", "path": "util/validate-metadata.py"}], "after_files": [{"content": "#!/usr/bin/env python3\n\nimport ast\nimport sys\nimport json\nimport jsonschema\nimport re\n\n# file paths\ndata_file = \"registry/ontologies.jsonld\"\nschema_file = \"util/metadata-schema.json\"\nschema_lite_file = \"util/metadata-schema-lite.json\"\nreport_file = \"reports/metadata-violations.csv\"\n\n# ultra-escaped regex strings\nemail_sub = 'does not match \\'\\\\^\\\\[\\\\^@\\\\]\\\\+\\\\$\\''\nfmt_sub = ('does not match \\'\\\\^\\\\[0\\\\-9A\\\\-Za\\\\-z\\\\-_\\\\\\\\\\\\\\\\/\\\\]\\\\+'\n          '\\\\\\\\\\\\\\\\.\\\\(owl\\\\|obo\\\\|json\\\\|omn\\\\|ofn\\\\|owx\\\\|ttl\\\\|owl'\n          '\\\\\\\\\\\\\\\\.gz\\\\)\\\\$\\'')\n\ndef validate():\n\t\"\"\"\n\tValidate registry metadata.\n\t\"\"\"\n\tprint(\"--- validating metadata against {0} ---\".format(schema_file))\n\tdata = load_data()\n\tschema = load_schema()\n\t# validate each object\n\terrors = {}\n\tfor item in data[\"ontologies\"]:\n\t\tif 'is_obsolete' in item and item[\"is_obsolete\"] is True:\n\t\t\tcontinue\n\t\t# skip any 'validate: false' ontologies\n\t\tif 'validate' in item and item[\"validate\"] is False:\n\t\t\tcontinue\n\t\tont_id = item[\"id\"]\n\t\ttry:\n\t\t\tjsonschema.validate(item, schema)\n\t\texcept jsonschema.exceptions.ValidationError as ve:\n\t\t\tprint(\"ERROR in {0}\".format(ont_id))\n\t\t\terrors[ont_id] = format_msg(ve)\n\tif errors:\n\t\twrite_errors(errors)\n\telse:\n\t\tprint(\"SUCCESS - no errors found in metadata\")\n\t\tsys.exit(0)\n\ndef format_msg(ve):\n\t\"\"\"\n\tFormat exception message from jsonchema.validate(...).\n\t\"\"\"\n\t# replace u characters\n\treplace_u = re.sub('u\\'', '\\'', ve.message)\n\t# replace scary regex strings\n\treplace_email = re.sub(\n\t\temail_sub, 'is not valid for \\'contact.label\\'', replace_u)\n\tmsg = re.sub(fmt_sub, 'is not valid for \\'products.id\\'', replace_email)\n\n\t# check if output is for license error\n\tis_license = re.search('({\\'url\\'.+?\\'label\\'.+?})', msg)\n\tif is_license:\n\t\treturn format_license_msg(is_license.group(1))\n\n\t# check if output is for list error\n\tis_list = re.search('(\\\\[.+?\\\\]) is not of type \\'string\\'', msg)\n\tif is_list:\n\t\treturn format_list_msg(is_list.group(1), ve)\n\n\t# otherwise return the message\n\treturn msg\n\ndef format_license_msg(substr):\n\t\"\"\"\n\tFormat an exception message for a license issue.\n\t\"\"\"\n\t# process to dict\n\td = json.loads(substr.replace('\\'', '\"'))\n\turl = d['url']\n\tlabel = d['label']\n\treturn '\\'{0}\\' <{1}> is not valid for \\'license\\''.format(label, url)\n\ndef format_list_msg(substr, ve):\n\t\"\"\"\n\tFormat an exception for an unexpected list.\n\t\"\"\"\n\tl = json.loads(substr.replace('\\'', '\"'))\n\t# use the full message to find the violating property\n\tprop_find = re.search('On instance\\\\[(\\'.+?\\')\\\\]', str(ve))\n\tif prop_find:\n\t\tprop = prop_find.group(1)\n\t\treturn '{0} expects one value, got {1}'.format(prop, len(l))\n\telse:\n\t\treturn substr\n\ndef load_schema():\n\t\"\"\"\n\tLoad the schema to validate against.\n\t\"\"\"\n\t# read the schema\n\twith open(schema_file) as f:\n\t\tschema = json.load(f)\n\treturn schema\n\ndef load_data():\n\t\"\"\"\n\tLoad the data to validate.\n\t\"\"\"\n\t# read the JSON-LD data\n\twith open(data_file) as f:\n\t\tdata = json.load(f)\n\treturn data\n\ndef write_errors(errors):\n\t\"\"\"\n\tWrite validation errors to a user-friendly report.\n\t\"\"\"\n\twith open(report_file, 'w+') as f:\n\t\tf.write(\"ID,ERROR\\n\")\n\t\tfor ont_id, msg in errors.items():\n\t\t\tf.write('\"' + ont_id + '\",\"' + msg + '\"\\n')\n\tprint(\n\t\t\"VALIDATION FAILED: {0} errors - see {1} for details\".format(\n\t\t\tlen(errors), report_file))\n\tsys.exit(1)\n\n# run the process!\nif __name__ == '__main__':\n\tvalidate()\n", "path": "util/validate-metadata.py"}]}