Skip to content

Commit

Permalink
Fail validation on duplicate titles
Browse files Browse the repository at this point in the history
  • Loading branch information
reconman committed Mar 22, 2024
1 parent 930f057 commit 675a9bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# PlexAniSync files
custom_mappings_schema.json
venv
10 changes: 9 additions & 1 deletion validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import logging
import sys
from typing import List
from jsonschema import validate
from jsonschema.exceptions import ValidationError
from ruamel.yaml import YAML
Expand All @@ -23,7 +24,7 @@
response = requests.get(schema_url)
response.raise_for_status()
schema = response.json()

# Save the fetched schema locally
with open(local_schema_path, 'w', encoding='utf-8') as f:
json.dump(schema, f, indent=4)
Expand All @@ -38,6 +39,13 @@
try:
# Validate data against the schema.
validate(file_mappings, schema)
titles: List[str] = []
for entry in file_mappings["entries"]:
title: str = entry["title"]
if title.lower() in titles:
raise ValidationError(f"{title} is already mapped", instance=entry)

titles.append(title.lower())
except ValidationError as e:
logger.error(f"Custom Mappings validation failed for {file}!")
logger.error(f"{e.message} at entry {e.instance}")
Expand Down

0 comments on commit 675a9bd

Please sign in to comment.