Add missing fields to packages API

This commit is contained in:
rubenwardy
2021-02-02 22:47:46 +00:00
parent 12e364969b
commit 90aeb6e1a7
4 changed files with 80 additions and 27 deletions

View File

@@ -39,14 +39,18 @@ def get_license(name):
name_re = re.compile("^[a-z0-9_]+$")
TYPES = {
"name": str,
any = "?"
ALLOWED_FIELDS = {
"type": any,
"title": str,
"name": str,
"short_description": str,
"short_desc": str,
"desc": str,
"tags": list,
"content_warnings": list,
"license": any,
"media_license": any,
"desc": str,
"repo": str,
"website": str,
"issue_tracker": str,
@@ -63,9 +67,12 @@ def is_int(val):
def validate(data: dict):
for key, typ in TYPES.items():
if data.get(key) is not None:
check(isinstance(data[key], typ), key + " must be a " + typ.__name__)
for key, value in data.items():
if value is not None:
typ = ALLOWED_FIELDS.get(key)
check(typ is not None, key + " is not a known field")
if typ != any:
check(isinstance(value, typ), key + " must be a " + typ.__name__)
if "name" in data:
name = data["name"]