Skip to content

Commit 97c3294

Browse files
authored
relax validation
1 parent 18c2383 commit 97c3294

File tree

1 file changed

+14
-16
lines changed

1 file changed

+14
-16
lines changed

caltechdata_api/customize_schema.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -480,18 +480,17 @@ def validate_metadata(json_record):
480480
errors.append("Each 'subject' must have a 'subject' key.")
481481

482482
# Check for 'dates'
483-
if "dates" not in json_record:
484-
errors.append("'dates' field is missing.")
485-
elif not isinstance(json_record["dates"], list) or len(json_record["dates"]) == 0:
486-
errors.append("'dates' should be a non-empty list.")
487-
else:
488-
for date in json_record["dates"]:
489-
if (
490-
not isinstance(date, dict)
491-
or "date" not in date
492-
or "dateType" not in date
493-
):
494-
errors.append("Each 'date' must have 'date' and 'dateType'.")
483+
if "dates" in json_record:
484+
if not isinstance(json_record["dates"], list) or len(json_record["dates"]) == 0:
485+
errors.append("'dates' should be a non-empty list.")
486+
else:
487+
for date in json_record["dates"]:
488+
if (
489+
not isinstance(date, dict)
490+
or "date" not in date
491+
or "dateType" not in date
492+
):
493+
errors.append("Each 'date' must have 'date' and 'dateType'.")
495494

496495
# Check for 'creators'
497496
if "creators" not in json_record:
@@ -601,10 +600,9 @@ def validate_metadata(json_record):
601600
errors.append("'publisher' should be a string.")
602601

603602
# Check for 'publicationYear'
604-
if "publicationYear" not in json_record:
605-
errors.append("'publicationYear' field is missing.")
606-
elif not isinstance(json_record["publicationYear"], str):
607-
errors.append("'publicationYear' should be a string.")
603+
if "publicationYear" in json_record:
604+
if not isinstance(json_record["publicationYear"], str):
605+
errors.append("'publicationYear' should be a string.")
608606

609607
# Check for 'types'
610608
if "types" not in json_record:

0 commit comments

Comments
 (0)