Few fixes and improvements to the library, plus Github Actions setup (#31)
CI / Build and test (push) Canceled after 0s
Documentation / Build documentation (push) Canceled after 0s
Documentation / Deploy to GitHub Pages (push) Canceled after 0s

This PR contains the work done to fix a cancellation-mapping bug in `AmiiboLiveClient`, bring the client under offline test coverage, add the conformances SwiftUI and persistence need, and moves CI and documentation publishing to GitHub Actions. All public API changes are additive.

### Fix

- `AmiiboLiveClient` reported an early task cancellation as `.unknown("CancellationError()")`. The OpenAPI runtime wraps every error in `ClientError`, so the `CancellationError` check never matched; it now also checks the wrapped error and throws `.cancelled`.

### Tests

- `ThrowingTransport` and `StubTransport` test doubles let the live client run offline. New tests cover error mapping, HTTP status → error mapping, `oneOf` object-vs-list decoding, `"amiibo": null`, sorting, filter → query encoding, `Platform`/`Release` mapping, and the date transcoder.
- Models gained `package` memberwise initializers so tests can build real fixtures without `@testable`. These are not public API.
- The test target now depends on `OpenAPIRuntime` and `HTTPTypes` (both already in the dependency graph).

### API
- Models are `Codable` and `Identifiable` (`Amiibo.id` is its `identifier`; the key/name models use `key`).
- Filters are `Hashable`.

### Documentation
- Doc comments trimmed library-wide; one repeated `- Throws:` sentence appeared 24 times. `Library.md` and the README tightened to match.

### CI and docs publishing
- `ci.yml`: build and offline tests on PRs and pushes to `main`.
- `live-tests.yml`: weekly and on-demand run against the live API.
- `docs.yml`: builds DocC on PRs, deploys to GitHub Pages on `main`. Pinned to Xcode 26 because swift-docc-plugin 1.5.0 fails to launch its tools under Xcode 27.
- The generated `docs/` folder (327 files) is removed from the repository and ignored.

Reviewed-on: #31
Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
This commit was merged in pull request #31.
This commit is contained in:
javier authored and Javier Cicchelli committed 2026-10-25 19:54:30 +00:00
1 parent 44bfaca553
commit 13b9c74a38
361 files changed
+1395 -863

No files matched your search

@@ -18,13 +18,11 @@ extension DateFormatter {
// MARK: Properties
/// An ISO date formatter.
///
/// This formatter implements the `yyyy-MM-dd` date format.
/// An ISO date formatter for the `yyyy-MM-dd` format.
static let isoDate: DateFormatter = {
let formatter = DateFormatter()
// A fixed-format date requires the POSIX locale, as the user's locale or 12/24-hour setting could otherwise alter the parsing.
// The POSIX locale keeps the user's locale and 12/24-hour setting from altering fixed-format parsing.
formatter.locale = .init(identifier: "en_US_POSIX")
formatter.dateFormat = "yyyy-MM-dd"
formatter.timeZone = .init(secondsFromGMT: 0)
@@ -32,14 +30,13 @@ extension DateFormatter {
return formatter
}()
/// An ISO timestamp formatter.
/// An ISO timestamp formatter for the `yyyy-MM-dd'T'HH:mm:ss.SSSSSS` format.
///
/// This formatter implements the `yyyy-MM-dd'T'HH:mm:ss.SSSSSS` custom date format.
/// Within the context of this library, this formatter is solely used to decode a date formatted as a timestamp that is returned by the ``AmiiboService/getLastUpdated()`` function.
/// Used only to decode the timestamp returned by ``AmiiboService/getLastUpdated()``.
static let isoTimestamp: DateFormatter = {
let formatter = DateFormatter()
// A fixed-format date requires the POSIX locale, as the user's locale or 12/24-hour setting could otherwise alter the parsing.
// The POSIX locale keeps the user's locale and 12/24-hour setting from altering fixed-format parsing.
formatter.locale = .init(identifier: "en_US_POSIX")
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
formatter.timeZone = .init(secondsFromGMT: 0)
@@ -12,8 +12,8 @@
//
// ===----------------------------------------------------------------------===
/// A protocol that defines filters containing optional `key` and/or `name` values for querying resources.
protocol KeyNameFilter {
/// A protocol for filters with optional `key` and `name` values.
protocol KeyNameFilter: Hashable {
// MARK: Properties
@@ -13,7 +13,7 @@
// ===----------------------------------------------------------------------===
/// A protocol that defines models containing a `key` and `name` pair.
protocol KeyNameModel: Sendable, Hashable {
protocol KeyNameModel: Sendable, Hashable, Codable, Identifiable {
// MARK: Properties
@@ -15,15 +15,15 @@
import Foundation
import OpenAPIRuntime
/// A type that allows the decoding and encoding of ISO dates, supporting both the `yyyy-MM-dd'T'HH:mm:ss.SSSSSS` timestamp format and the `yyyy-MM-dd` date-only format.
/// A transcoder for ISO dates in the `yyyy-MM-dd'T'HH:mm:ss.SSSSSS` timestamp and `yyyy-MM-dd` date-only formats.
struct ISODateTimeTranscoder {
// MARK: Properties
/// A formatter to use to decode and encode ISO timestamp dates.
/// The ISO timestamp formatter.
private let timestampFormatter: DateFormatter = .isoTimestamp
/// A formatter to use to decode and encode ISO date-only strings.
/// The ISO date-only formatter.
private let dateFormatter: DateFormatter = .isoDate
}
@@ -34,17 +34,13 @@ extension ISODateTimeTranscoder: DateTranscoder {
// MARK: Functions
/// Encodes a date into an ISO timestamp string.
/// - Parameter date: A date to encode.
/// - Returns: A string representation of the date in `yyyy-MM-dd'T'HH:mm:ss.SSSSSS` format.
/// Encodes a date as an ISO timestamp string.
func encode(_ date: Date) throws -> String {
timestampFormatter.string(from: date)
}
/// Decodes an ISO date string into a date, trying the timestamp format first and falling back to the date-only format.
/// - Parameter string: A string to decode.
/// - Returns: A date parsed from the string.
/// - Throws: A `DecodingError` if the string cannot be parsed into a valid date.
/// Decodes an ISO date string, trying the timestamp format before the date-only one.
/// - Throws: A `DecodingError` if the string matches neither format.
func decode(_ string: String) throws -> Date {
if let date = timestampFormatter.date(from: string) {
return date