-
Notifications
You must be signed in to change notification settings - Fork 228
Expose alternate publication identifiers via metadata.altIdentifiers #837
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
raphi011
wants to merge
2
commits into
readium:develop
Choose a base branch
from
raphi011:feat/epub-isbn-metadata
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| // | ||
| // Copyright 2026 Readium Foundation. All rights reserved. | ||
| // Use of this source code is governed by the BSD-style license | ||
| // available in the top-level LICENSE file of the project. | ||
| // | ||
|
|
||
| import Foundation | ||
| import ReadiumInternal | ||
|
|
||
| /// An alternate identifier for a publication, i.e. an identifier other than the | ||
| /// primary ``Metadata/identifier``. | ||
| /// | ||
| /// https://readium.org/webpub-manifest/contexts/default/#identifier | ||
| /// https://readium.org/webpub-manifest/schema/altIdentifier.schema.json | ||
| public struct AltIdentifier: Hashable, Sendable, JSONValueDecodable, JSONValueEncodable { | ||
| /// The identifier value. | ||
| public var value: String | ||
|
|
||
| /// URI of the identifier's scheme, when known (e.g. `urn:isbn`). | ||
| public var scheme: String? | ||
|
|
||
| public init(value: String, scheme: String? = nil) { | ||
| self.value = value | ||
| self.scheme = scheme | ||
| } | ||
|
|
||
| /// Parses an ``AltIdentifier`` from its RWPM JSON representation, which is | ||
| /// either a bare URI string or an object carrying a `value` and an optional | ||
| /// `scheme`. | ||
| public init?<T: JSONValueEncodable>(json: T?, warnings: WarningLogger?) throws { | ||
| guard let json = json?.jsonValue else { | ||
| return nil | ||
| } | ||
|
|
||
| if let value = json.string { | ||
| self.init(value: value) | ||
| } else if let object = json.object, let value = object["value"]?.string { | ||
| self.init(value: value, scheme: object["scheme"]?.string) | ||
| } else { | ||
| warnings?.log("Invalid AltIdentifier object", model: Self.self, source: json, severity: .minor) | ||
| throw JSONError.parsing(Self.self) | ||
| } | ||
| } | ||
|
|
||
| /// Serializes to a bare string when no scheme is set – the schema's compact | ||
| /// form – or to an object otherwise. | ||
| public var jsonValue: JSONValue { | ||
| guard let scheme = scheme else { | ||
| return .string(value) | ||
| } | ||
| return .object([ | ||
| "value": .string(value), | ||
| "scheme": .string(scheme), | ||
| ]) | ||
| } | ||
| } | ||
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| // | ||
| // Copyright 2026 Readium Foundation. All rights reserved. | ||
| // Use of this source code is governed by the BSD-style license | ||
| // available in the top-level LICENSE file of the project. | ||
| // | ||
|
|
||
| @testable import ReadiumShared | ||
| import XCTest | ||
|
|
||
| class AltIdentifierTests: XCTestCase { | ||
| func testParseJSONString() { | ||
| XCTAssertEqual( | ||
| try? AltIdentifier(json: "urn:isbn:9781449325862"), | ||
| AltIdentifier(value: "urn:isbn:9781449325862") | ||
| ) | ||
| } | ||
|
|
||
| func testParseMinimalJSON() { | ||
| XCTAssertEqual( | ||
| try? AltIdentifier(json: ["value": "9781449325862"]), | ||
| AltIdentifier(value: "9781449325862") | ||
| ) | ||
| } | ||
|
|
||
| func testParseFullJSON() { | ||
| XCTAssertEqual( | ||
| try? AltIdentifier(json: [ | ||
| "value": "9781449325862", | ||
| "scheme": "urn:isbn", | ||
| ] as JSONValue), | ||
| AltIdentifier(value: "9781449325862", scheme: "urn:isbn") | ||
| ) | ||
| } | ||
|
|
||
| func testParseJSONRequiresValue() { | ||
| XCTAssertThrowsError(try AltIdentifier(json: [ | ||
| "scheme": "urn:isbn", | ||
| ])) | ||
| } | ||
|
|
||
| /// Without a scheme, the value collapses to a bare string. | ||
| func testGetMinimalJSON() { | ||
| XCTAssertEqual( | ||
| AltIdentifier(value: "urn:isbn:9781449325862").jsonValue, | ||
| .string("urn:isbn:9781449325862") | ||
| ) | ||
| } | ||
|
|
||
| func testGetFullJSON() { | ||
| XCTAssertEqual( | ||
| AltIdentifier(value: "9781449325862", scheme: "urn:isbn").jsonValue, | ||
| [ | ||
| "value": "9781449325862", | ||
| "scheme": "urn:isbn", | ||
| ] as JSONValue | ||
| ) | ||
| } | ||
| } |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?xml version="1.0"?> | ||
| <package xmlns="http://www.idpf.org/2007/opf" unique-identifier="pub-id" version="2.0"> | ||
| <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" | ||
| xmlns:opf="http://www.idpf.org/2007/opf"> | ||
| <dc:title>Programming Scala</dc:title> | ||
| <dc:identifier id="pub-id" opf:scheme="UUID">urn:uuid:7408D53A-5383-40AA-8078-5256C872AE41</dc:identifier> | ||
| <dc:identifier opf:scheme="ISBN">978-1-4493-2586-2</dc:identifier> | ||
| </metadata> | ||
| <manifest> | ||
| <item id="titlepage" href="titlepage.xhtml" media-type="application/xhtml+xml" /> | ||
| </manifest> | ||
| <spine> | ||
| <itemref idref="titlepage"/> | ||
| </spine> | ||
| </package> |
16 changes: 16 additions & 0 deletions
16
Tests/StreamerTests/Fixtures/OPF/alt-identifier-multiple.opf
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| <?xml version="1.0"?> | ||
| <package xmlns="http://www.idpf.org/2007/opf" unique-identifier="pub-id" version="2.0"> | ||
| <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" | ||
| xmlns:opf="http://www.idpf.org/2007/opf"> | ||
| <dc:title>Programming Scala</dc:title> | ||
| <dc:identifier id="pub-id" opf:scheme="UUID">urn:uuid:7408D53A-5383-40AA-8078-5256C872AE41</dc:identifier> | ||
| <dc:identifier opf:scheme="ISBN">9781449325862</dc:identifier> | ||
| <dc:identifier opf:scheme="ISBN">1449325866</dc:identifier> | ||
| </metadata> | ||
| <manifest> | ||
| <item id="titlepage" href="titlepage.xhtml" media-type="application/xhtml+xml" /> | ||
| </manifest> | ||
| <spine> | ||
| <itemref idref="titlepage"/> | ||
| </spine> | ||
| </package> |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <?xml version="1.0"?> | ||
| <package xmlns="http://www.idpf.org/2007/opf" unique-identifier="pub-id" version="3.0"> | ||
| <metadata xmlns:dc="http://purl.org/dc/elements/1.1/" | ||
| xmlns:opf="http://www.idpf.org/2007/opf"> | ||
| <dc:title>Programming Scala</dc:title> | ||
| <dc:identifier id="pub-id">urn:uuid:7408D53A-5383-40AA-8078-5256C872AE41</dc:identifier> | ||
| <dc:identifier>urn:isbn:9781449325862</dc:identifier> | ||
| </metadata> | ||
| <manifest> | ||
| <item id="titlepage" href="titlepage.xhtml" media-type="application/xhtml+xml" /> | ||
| </manifest> | ||
| <spine> | ||
| <itemref idref="titlepage"/> | ||
| </spine> | ||
| </package> |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This scheme is only for identifiers that cannot be represented as a URI. For example, the scheme
https://www.example.com/has the identifierabc123. An ISBN would be represented asurn:isbn:9789510184356without ascheme.