Add format-neutral LinkContentType enum for OPDS feed links (PP-3675)#3065
Open
jonathangreen wants to merge 7 commits intomainfrom
Open
Add format-neutral LinkContentType enum for OPDS feed links (PP-3675)#3065jonathangreen wants to merge 7 commits intomainfrom
jonathangreen wants to merge 7 commits intomainfrom
Conversation
Replace hardcoded OPDS1 content types in annotators with semantic LinkContentType values (OPDS_FEED, OPDS_ENTRY) so serializers can map them to the correct format-specific types. This makes the intermediate representation format-neutral, treating OPDS1 and OPDS2 as equal peers rather than privileging OPDS1 conventions. - Add LinkContentType StrEnum to feed/types.py - Update annotators to use LinkContentType instead of OPDSFeed constants - Standardize profile link rel from Palace-specific to "profile" - Add _resolve_type()/_resolve_rel() to OPDS1 serializer - Add _resolve_type() to OPDS2 serializer
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #3065 +/- ##
=======================================
Coverage 93.18% 93.18%
=======================================
Files 489 489
Lines 44943 44971 +28
Branches 6191 6195 +4
=======================================
+ Hits 41880 41908 +28
+ Misses 1986 1985 -1
- Partials 1077 1078 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The enum values are opaque identifiers, not meaningful strings. Widen type annotations with a LinkType alias (str | LinkContentType) so the type system enforces that serializers resolve enum values before emitting output.
Match the pattern used by _serialize_link: resolve type and rel from the link's fields up front instead of mutating the TypedDict returned by link_attribs().
Remove Link.link_attribs() and its LinkAttributes TypedDict since serializers now resolve fields directly. Document why OPDS1 needs _REL_MAP while OPDS2 does not.
tdilauro
approved these changes
Feb 20, 2026
|
|
||
|
|
||
| #: Union type for link type fields that accept either concrete MIME types or | ||
| #: semantic :class:`LinkContentType` values resolved at serialization time. |
Contributor
There was a problem hiding this comment.
I had to go look up this format. I didn't realize there was a way to document variables like this. 🤷🏽♂️ 🚀
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add a
LinkContentTypeenum that replaces hardcoded OPDS1 content types in annotators with format-neutral semantic values. Each serializer maps these to its format-specific content type, making the intermediate representation (annotator → serializer) truly format-neutral.Changes:
feed/types.py: AddLinkContentTypeenum withOPDS_FEEDandOPDS_ENTRYmembersfeed/annotator/circulation.py: Replace allOPDSFeed.ENTRY_TYPE/OPDSFeed.ACQUISITION_FEED_TYPEreferences withLinkContentTypevalues acrosspermalink_for(),borrow_link(),annotate_work_entry(),add_author_links(),add_series_link(), andannotate_feed()feed/annotator/loan_and_hold.py: Standardize profile linkrelfrom Palace-specific"http://librarysimplified.org/terms/rel/user-profile"to standard"profile"feed/serializer/opds.py: Add_resolve_type()and_resolve_rel()toBaseOPDS1Serializerthat map semantic values back to OPDS1-specific types/rels during serializationfeed/serializer/opds2.py: Add_resolve_type()toOPDS2Serializerthat maps semantic values to OPDS2-specific types (application/opds+json,application/opds-publication+json)LinkContentTypeOPDS_FEEDapplication/atom+xml;profile=opds-catalog;kind=acquisitionapplication/opds+jsonOPDS_ENTRYapplication/atom+xml;type=entry;profile=opds-catalogapplication/opds-publication+jsonMotivation and Context
The feed annotator previously embedded OPDS1-specific content types throughout, making OPDS2 a second-class citizen that had to remap OPDS1 conventions. This change makes the intermediate representation format-neutral so neither OPDS1 nor OPDS2 is privileged. This is groundwork for aligning OPDS2 feeds with the OPDS 2.0 Borrowing Best Practices specification.
How Has This Been Tested?
tests/manager/feed/andtests/manager/opds/)_resolve_type()and_resolve_rel()in both serializersLinkContentTypevalues are correctly resolved during link serializationChecklist