Updated the AmiiboLiveClient type in the library target based on the latest changes to the OpenAPI specification document.
This commit is contained in:
@@ -181,16 +181,16 @@ private extension AmiiboLiveClient {
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
response = try await client.getAmiibos(.init(query: .init(
|
response = try await client.getAmiibos(.init(query: .init(
|
||||||
|
id: filter.identifier,
|
||||||
|
head: filter.head,
|
||||||
|
tail: filter.tail,
|
||||||
|
name: filter.name,
|
||||||
|
_type: filter.type,
|
||||||
amiiboSeries: filter.series,
|
amiiboSeries: filter.series,
|
||||||
character: filter.gameCharacter,
|
character: filter.gameCharacter,
|
||||||
gameseries: filter.gameSeries,
|
gameseries: filter.gameSeries,
|
||||||
head: filter.head,
|
|
||||||
id: filter.identifier,
|
|
||||||
name: filter.name,
|
|
||||||
showgames: filter.showGames,
|
showgames: filter.showGames,
|
||||||
showusage: filter.showUsage,
|
showusage: filter.showUsage
|
||||||
tail: filter.tail,
|
|
||||||
_type: filter.type
|
|
||||||
)))
|
)))
|
||||||
} catch {
|
} catch {
|
||||||
try handle(error: error)
|
try handle(error: error)
|
||||||
@@ -200,7 +200,16 @@ private extension AmiiboLiveClient {
|
|||||||
case let .ok(ok):
|
case let .ok(ok):
|
||||||
switch ok.body {
|
switch ok.body {
|
||||||
case let .json(output):
|
case let .json(output):
|
||||||
return map(output)
|
switch output.amiibo {
|
||||||
|
case let .Amiibo(object):
|
||||||
|
return [Amiibo(object)]
|
||||||
|
case let .AmiiboList(list):
|
||||||
|
return list
|
||||||
|
.map { Amiibo($0) }
|
||||||
|
.sorted { $0.identifier < $1.identifier }
|
||||||
|
case .none:
|
||||||
|
return []
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case .badRequest:
|
case .badRequest:
|
||||||
throw AmiiboServiceError.badRequest
|
throw AmiiboServiceError.badRequest
|
||||||
@@ -235,7 +244,14 @@ private extension AmiiboLiveClient {
|
|||||||
case let .ok(ok):
|
case let .ok(ok):
|
||||||
switch ok.body {
|
switch ok.body {
|
||||||
case let .json(output):
|
case let .json(output):
|
||||||
return map(output)
|
switch output.amiibo {
|
||||||
|
case let .AmiiboSeries(payload):
|
||||||
|
return [AmiiboSeries(payload.value1)]
|
||||||
|
case let .AmiiboSeriesList(list):
|
||||||
|
return list
|
||||||
|
.map { AmiiboSeries($0.value1) }
|
||||||
|
.sorted { $0.key < $1.key }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case .badRequest:
|
case .badRequest:
|
||||||
throw AmiiboServiceError.badRequest
|
throw AmiiboServiceError.badRequest
|
||||||
@@ -270,7 +286,14 @@ private extension AmiiboLiveClient {
|
|||||||
case let .ok(ok):
|
case let .ok(ok):
|
||||||
switch ok.body {
|
switch ok.body {
|
||||||
case let .json(output):
|
case let .json(output):
|
||||||
return map(output)
|
switch output.amiibo {
|
||||||
|
case let .AmiiboType(payload):
|
||||||
|
return [AmiiboType(payload.value1)]
|
||||||
|
case let .AmiiboTypeList(list):
|
||||||
|
return list
|
||||||
|
.map { AmiiboType($0.value1) }
|
||||||
|
.sorted { $0.key < $1.key }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case .badRequest:
|
case .badRequest:
|
||||||
throw AmiiboServiceError.badRequest
|
throw AmiiboServiceError.badRequest
|
||||||
@@ -305,7 +328,14 @@ private extension AmiiboLiveClient {
|
|||||||
case let .ok(ok):
|
case let .ok(ok):
|
||||||
switch ok.body {
|
switch ok.body {
|
||||||
case let .json(output):
|
case let .json(output):
|
||||||
return map(output)
|
switch output.amiibo {
|
||||||
|
case let .GameCharacter(payload):
|
||||||
|
return [GameCharacter(payload.value1)]
|
||||||
|
case let .GameCharacterList(list):
|
||||||
|
return list
|
||||||
|
.map { GameCharacter($0.value1) }
|
||||||
|
.sorted { $0.key < $1.key }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case .badRequest:
|
case .badRequest:
|
||||||
throw AmiiboServiceError.badRequest
|
throw AmiiboServiceError.badRequest
|
||||||
@@ -340,7 +370,14 @@ private extension AmiiboLiveClient {
|
|||||||
case let .ok(ok):
|
case let .ok(ok):
|
||||||
switch ok.body {
|
switch ok.body {
|
||||||
case let .json(output):
|
case let .json(output):
|
||||||
return map(output)
|
switch output.amiibo {
|
||||||
|
case let .GameSeries(payload):
|
||||||
|
return [GameSeries(payload.value1)]
|
||||||
|
case let .GameSeriesList(list):
|
||||||
|
return list
|
||||||
|
.map { GameSeries($0.value1) }
|
||||||
|
.sorted { $0.key < $1.key }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case .badRequest:
|
case .badRequest:
|
||||||
throw AmiiboServiceError.badRequest
|
throw AmiiboServiceError.badRequest
|
||||||
@@ -371,10 +408,6 @@ private extension AmiiboLiveClient {
|
|||||||
case let .json(output):
|
case let .json(output):
|
||||||
return output.lastUpdated
|
return output.lastUpdated
|
||||||
}
|
}
|
||||||
case .badRequest:
|
|
||||||
throw AmiiboServiceError.badRequest
|
|
||||||
case .notFound:
|
|
||||||
throw AmiiboServiceError.notFound
|
|
||||||
case .internalServerError:
|
case .internalServerError:
|
||||||
throw AmiiboServiceError.notAvailable
|
throw AmiiboServiceError.notAvailable
|
||||||
case let .undocumented(statusCode, _):
|
case let .undocumented(statusCode, _):
|
||||||
@@ -413,36 +446,4 @@ private extension AmiiboLiveClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Retrieves a list of amiibo items from a wrapper container.
|
|
||||||
/// - Parameter wrapper: A wrapper container that either has an object or a list of items.
|
|
||||||
/// - Returns: A list of amiibo items, sorted by identifiers.
|
|
||||||
func map(
|
|
||||||
_ wrapper: Components.Schemas.AmiiboWrapper
|
|
||||||
) -> [Amiibo] {
|
|
||||||
switch wrapper.amiibo {
|
|
||||||
case let .Amiibo(object):
|
|
||||||
return [Amiibo(object)]
|
|
||||||
case let .AmiiboList(list):
|
|
||||||
return list
|
|
||||||
.map { Amiibo($0) }
|
|
||||||
.sorted { $0.identifier < $1.identifier }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Retrieves a list of items that conforms to the `KeyNameModel` protocol from a wrapper container.
|
|
||||||
/// - Parameter wrapper: A wrapper container that either has an object or a list of items.
|
|
||||||
/// - Returns: A list of items that conforms to the `KeyNameModel` protocol, sorted by keys.
|
|
||||||
func map<Model: KeyNameModel>(
|
|
||||||
_ wrapper: Components.Schemas.TupleWrapper
|
|
||||||
) -> [Model] {
|
|
||||||
switch wrapper.amiibo {
|
|
||||||
case let .Tuple(payload):
|
|
||||||
return [Model(payload)]
|
|
||||||
case let .TupleList(list):
|
|
||||||
return list
|
|
||||||
.map { Model($0) }
|
|
||||||
.sorted { $0.key < $1.key }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -552,6 +552,8 @@ enum Input {
|
|||||||
.init(tail: "00000002"),
|
.init(tail: "00000002"),
|
||||||
.init(tail: "0002"),
|
.init(tail: "0002"),
|
||||||
.init(identifier: "0000000000000002"),
|
.init(identifier: "0000000000000002"),
|
||||||
|
.init(identifier: "0000000000000000"),
|
||||||
|
.init(identifier: "0000000"),
|
||||||
.init(name: "zelda"),
|
.init(name: "zelda"),
|
||||||
.init(name: "Something"),
|
.init(name: "Something"),
|
||||||
.init(name: "zel"),
|
.init(name: "zel"),
|
||||||
@@ -587,8 +589,6 @@ enum Input {
|
|||||||
static let amiibosThrows: [AmiiboFilter] = [
|
static let amiibosThrows: [AmiiboFilter] = [
|
||||||
.init(head: .empty),
|
.init(head: .empty),
|
||||||
.init(tail: .empty),
|
.init(tail: .empty),
|
||||||
.init(identifier: "0000000000000000"),
|
|
||||||
.init(identifier: "0000000"),
|
|
||||||
.init(identifier: .empty),
|
.init(identifier: .empty),
|
||||||
.init(type: "0x"),
|
.init(type: "0x"),
|
||||||
.init(series: "0x"),
|
.init(series: "0x"),
|
||||||
@@ -659,9 +659,9 @@ enum Input {
|
|||||||
|
|
||||||
enum Output {
|
enum Output {
|
||||||
/// A list of number of items that are expected from the `assertAmiibos` assertion.
|
/// A list of number of items that are expected from the `assertAmiibos` assertion.
|
||||||
static let amiibos: [Int] = [.totalAmiibos, 7, 7, 1, 1, 1, 5, .zero, 7, .totalAmiibos, 235, 235, .zero, .zero, .zero, .zero, 96, 26, .zero, .zero, 63, .totalAmiibos, 12, 6, .zero, .zero, .zero, .totalAmiibos, 49, 32, .zero, .zero, 147, .totalAmiibos, .totalAmiibos, .totalAmiibos]
|
static let amiibos: [Int] = [.totalAmiibos, 7, 7, 1, 1, 1, .zero, .zero, 5, .zero, 7, .totalAmiibos, 235, 235, .zero, .zero, .zero, .zero, 96, 26, .zero, .zero, 63, .totalAmiibos, 12, 6, .zero, .zero, .zero, .totalAmiibos, 49, 32, .zero, .zero, 147, .totalAmiibos, .totalAmiibos, .totalAmiibos]
|
||||||
/// A list of errors are expected to be thrown from the `assertAmiibosThrows` assertion.
|
/// A list of errors are expected to be thrown from the `assertAmiibosThrows` assertion.
|
||||||
static let amiibosThrows: [AmiiboServiceError] = [.badRequest, .badRequest, .decoding, .decoding, .badRequest, .badRequest, .badRequest, .badRequest, .badRequest]
|
static let amiibosThrows: [AmiiboServiceError] = [.badRequest, .badRequest, .badRequest, .badRequest, .badRequest, .badRequest, .badRequest]
|
||||||
/// A list of number of items that are expected from the `assertAmiiboSeries` assertion.
|
/// A list of number of items that are expected from the `assertAmiiboSeries` assertion.
|
||||||
static let amiiboSeries: [Int] = [.totalAmiiboSeries, 1, 1, 1, .totalAmiiboSeries]
|
static let amiiboSeries: [Int] = [.totalAmiiboSeries, 1, 1, 1, .totalAmiiboSeries]
|
||||||
/// A list of errors are expected to be thrown from the `assertAmiiboSeriesThrows` assertion.
|
/// A list of errors are expected to be thrown from the `assertAmiiboSeriesThrows` assertion.
|
||||||
|
|||||||
Reference in New Issue
Block a user