Skip to content

Commit 3e1cab0

Browse files
committed
fix: Make all reference fields optional
Fixes #176
1 parent 014d004 commit 3e1cab0

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

SCHEMA.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ constraints:
251251
### Reference
252252

253253
Bibliographic pointer.
254-
Requires a `title` and `authors` and optionally includes a `link` to the material.
254+
Requires either a `title` or a `link` and optionally a list of `authors`.
255255

256256
```yaml
257257
references:

src/opltools/schema.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,16 +73,18 @@ def __hash__(self):
7373

7474

7575
class Reference(BaseModel):
76-
title: str
77-
authors: list[str]
76+
title: str | None = None
77+
authors: list[str] | None = None
7878
link: Link | None = None
7979

80+
@model_validator(mode="after")
81+
def _validate(self) -> Self:
82+
if self.title is None and self.link is None:
83+
raise ValueError("References must have either a title or a link.")
84+
return self
85+
8086
def __hash__(self):
81-
return (
82-
hash(self.title)
83-
+ sum([hash(author) for author in self.authors])
84-
+ hash(self.link)
85-
)
87+
return hash(self.title) + hash(self.link)
8688

8789

8890
class Usage(BaseModel):

0 commit comments

Comments
 (0)