Replaced the Tuple schema for the OpenAPI specification document in the library target with per-type key-name payloads.

This commit is contained in:
2026-07-26 02:06:40 +02:00
parent c1c6f147f6
commit 64117bea5c
8 changed files with 102 additions and 67 deletions
@@ -27,6 +27,6 @@ protocol KeyNameModel: Sendable, Hashable {
/// Initializes this model from a given payload.
/// - Parameter payload: A payload that contains the values for the model.
init(_ payload: Components.Schemas.Tuple)
init(_ payload: some KeyNamePayload)
}
@@ -0,0 +1,33 @@
// ===----------------------------------------------------------------------===
//
// This source file is part of the Amiibo Service open source project
//
// Copyright (c) 2026 Röck+Cöde VoF. and the Amiibo Service project authors
// Licensed under Apache license v2.0
//
// See LICENSE for license information
// See CONTRIBUTORS for the list of Amiibo Service project authors
//
// SPDX-License-Identifier: Apache-2.0
//
// ===----------------------------------------------------------------------===
/// A protocol that unifies the generated payload types containing a `key` and `name` pair.
protocol KeyNamePayload {
// MARK: Properties
/// A hexadecimal key that uniquely identifies this payload.
var key: String { get }
/// A display name for this payload.
var name: String { get }
}
// MARK: - Conformances
extension Components.Schemas.AmiiboSeries: KeyNamePayload {}
extension Components.Schemas.AmiiboType: KeyNamePayload {}
extension Components.Schemas.GameCharacter: KeyNamePayload {}
extension Components.Schemas.GameSeries: KeyNamePayload {}
@@ -191,9 +191,9 @@ private extension AmiiboLiveClient {
case let .json(output):
switch output.amiibo {
case let .AmiiboSeries(payload):
return makeModels(from: [payload.value1])
return makeModels(from: [payload])
case let .case2(list):
return makeModels(from: list.map(\.value1))
return makeModels(from: list)
}
}
case .badRequest:
@@ -227,9 +227,9 @@ private extension AmiiboLiveClient {
case let .json(output):
switch output.amiibo {
case let .AmiiboType(payload):
return makeModels(from: [payload.value1])
return makeModels(from: [payload])
case let .case2(list):
return makeModels(from: list.map(\.value1))
return makeModels(from: list)
}
}
case .badRequest:
@@ -263,9 +263,9 @@ private extension AmiiboLiveClient {
case let .json(output):
switch output.amiibo {
case let .GameCharacter(payload):
return makeModels(from: [payload.value1])
return makeModels(from: [payload])
case let .case2(list):
return makeModels(from: list.map(\.value1))
return makeModels(from: list)
}
}
case .badRequest:
@@ -299,9 +299,9 @@ private extension AmiiboLiveClient {
case let .json(output):
switch output.amiibo {
case let .GameSeries(payload):
return makeModels(from: [payload.value1])
return makeModels(from: [payload])
case let .case2(list):
return makeModels(from: list.map(\.value1))
return makeModels(from: list)
}
}
case .badRequest:
@@ -350,11 +350,11 @@ private extension AmiiboLiveClient {
}
}
/// Maps a list of key-name tuples into a sorted list of models.
/// - Parameter tuples: A list of tuples to map into models.
/// Maps a list of key-name payloads into a sorted list of models.
/// - Parameter payloads: A list of payloads to map into models.
/// - Returns: A list of models sorted by their keys in ascending order.
func makeModels<Model: KeyNameModel>(from tuples: [Components.Schemas.Tuple]) -> [Model] {
tuples
func makeModels<Model: KeyNameModel>(from payloads: [some KeyNamePayload]) -> [Model] {
payloads
.map { Model($0) }
.sorted { $0.key < $1.key }
}
@@ -27,7 +27,7 @@ public struct AmiiboSeries: KeyNameModel {
/// Initializes this model from a given payload.
/// - Parameter payload: A payload that contains the values for the model.
init(_ payload: Components.Schemas.Tuple) {
init(_ payload: some KeyNamePayload) {
self.key = payload.key
self.name = payload.name
}
@@ -27,7 +27,7 @@ public struct AmiiboType: KeyNameModel {
/// Initializes this model from a given payload.
/// - Parameter payload: A payload that contains the values for the model.
init(_ payload: Components.Schemas.Tuple) {
init(_ payload: some KeyNamePayload) {
self.key = payload.key
self.name = payload.name
}
@@ -27,7 +27,7 @@ public struct GameCharacter: KeyNameModel {
/// Initializes this model from a given payload.
/// - Parameter payload: A payload that contains the values for the model.
init(_ payload: Components.Schemas.Tuple) {
init(_ payload: some KeyNamePayload) {
self.key = payload.key
self.name = payload.name
}
@@ -27,7 +27,7 @@ public struct GameSeries: KeyNameModel {
/// Initializes this model from a given payload.
/// - Parameter payload: A payload that contains the values for the model.
init(_ payload: Components.Schemas.Tuple) {
init(_ payload: some KeyNamePayload) {
self.key = payload.key
self.name = payload.name
}
+52 -50
View File
@@ -439,24 +439,34 @@ components:
format: date-time
AmiiboSeries:
description: A type that represents an amiibo series.
allOf:
- $ref: '#/components/schemas/Tuple'
- type: object
properties:
key:
description: The hexadecimal key that uniquely identifies this amiibo series.
name:
description: The name of this amiibo series.
type: object
properties:
key:
description: The hexadecimal key that uniquely identifies this amiibo series.
type: string
pattern: "^0x[0-9a-fA-F]+$"
minLength: 3
name:
description: The name of this amiibo series.
type: string
required:
- key
- name
AmiiboType:
description: A type that represents an amiibo type (e.g., Figure, Card, Yarn, Band).
allOf:
- $ref: '#/components/schemas/Tuple'
- type: object
properties:
key:
description: The hexadecimal key that uniquely identifies this amiibo type.
name:
description: The name of this amiibo type.
type: object
properties:
key:
description: The hexadecimal key that uniquely identifies this amiibo type.
type: string
pattern: "^0x[0-9a-fA-F]+$"
minLength: 3
name:
description: The name of this amiibo type.
type: string
required:
- key
- name
AmiiboUsage:
description: A type that represents how an amiibo is used within a game.
type: object
@@ -472,24 +482,34 @@ components:
- write
GameCharacter:
description: A type that represents a game character.
allOf:
- $ref: '#/components/schemas/Tuple'
- type: object
properties:
key:
description: The hexadecimal key that uniquely identifies this game character.
name:
description: The name of this game character.
type: object
properties:
key:
description: The hexadecimal key that uniquely identifies this game character.
type: string
pattern: "^0x[0-9a-fA-F]+$"
minLength: 3
name:
description: The name of this game character.
type: string
required:
- key
- name
GameSeries:
description: A type that represents a game series.
allOf:
- $ref: '#/components/schemas/Tuple'
- type: object
properties:
key:
description: The hexadecimal key that uniquely identifies this game series.
name:
description: The name of this game series.
type: object
properties:
key:
description: The hexadecimal key that uniquely identifies this game series.
type: string
pattern: "^0x[0-9a-fA-F]+$"
minLength: 3
name:
description: The name of this game series.
type: string
required:
- key
- name
LastUpdated:
description: A type that contains the date and time when the service data was last updated.
type: object
@@ -500,24 +520,6 @@ components:
format: date-time
required:
- lastUpdated
Tuple:
description: |
A base type composed of a `key` and `name` pair.
This type is the base schema for the `AmiiboSeries`, `AmiiboType`, `GameCharacter`, and `GameSeries` types.
type: object
properties:
key:
description: A hexadecimal key that uniquely identifies this resource.
type: string
pattern: "^0x[0-9a-fA-F]+$"
minLength: 3
name:
description: A display name for this resource.
type: string
required:
- key
- name
# Wrapper Entities
AmiiboWrapper:
description: A response wrapper that contains zero, one, or more amiibos.