Skip to content

Commit

Permalink
Add Apple Vision Pro to Device class (#209)
Browse files Browse the repository at this point in the history
* Add spec patch

* Update README.md

* Regenerate

* Update DeviceClass+PrettyName.swift
  • Loading branch information
MortenGregersen authored Nov 4, 2024
1 parent 7a2713b commit e440ade
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 8 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ In the OpenAPI spec for the App Store Connect API the “CertificateType” sche
When creating certificates on [the developer portal](https://developer.apple.com/account/resources/certificates/add), it is also possible to select the G2 Sub-CA (which corresponds to “DEVELOPER_ID_APPLICATION_G2”.
#### **FB15681740**: App Store Connect API Spec is missing "APPLE_VISION_PRO" type for the Device class type schema
* Submitted: November 4th 2024.
In the OpenAPI spec for the App Store Connect API the “Device.deviceClass” schema is said to not include "APPLE_VISION_PRO”. This is not right as “Devices” endpoints can have a “APPLE_VISION_PRO” type.

### Closed feedback (removed patches)

* **FB13540097**: Almost all of the schemas ending in “WithoutIncludesResponse” has wrong "data" type
Expand Down
13 changes: 7 additions & 6 deletions Sources/Bagbutik-Models/Extensions/DeviceClass+PrettyName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ public extension Device.Attributes.DeviceClass {
/// A pretty name for the case.
var prettyName: String {
switch self {
case .appleWatch: return "Apple Watch"
case .iPad: return "iPad"
case .iPhone: return "iPhone"
case .iPod: return "iPod"
case .appleTV: return "Apple TV"
case .mac: return "Mac"
case .appleWatch: "Apple Watch"
case .appleVisionPro: "Apple Vision Pro"
case .iPad: "iPad"
case .iPhone: "iPhone"
case .iPod: "iPod"
case .appleTV: "Apple TV"
case .mac: "Mac"
}
}
}
1 change: 1 addition & 0 deletions Sources/Bagbutik-Models/Provisioning/Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public struct Device: Codable, Sendable, Identifiable {

public enum DeviceClass: String, Sendable, Codable, CaseIterable {
case appleTV = "APPLE_TV"
case appleVisionPro = "APPLE_VISION_PRO"
case appleWatch = "APPLE_WATCH"
case iPad = "IPAD"
case iPhone = "IPHONE"
Expand Down
22 changes: 22 additions & 0 deletions Sources/BagbutikSpecDecoder/Spec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,28 @@ public struct Spec: Decodable {
components.schemas["Device"] = .object(deviceSchema)
patchedSchemas.append(.object(deviceSchema))
}

// Add the case `APPLE_VISION_PRO` to DeviceClass
// Apple's OpenAPI spec doesn't include the Apple Vision Pro for Device class.
if case .object(var deviceSchema) = components.schemas["Device"],
var deviceAttributesSchema: ObjectSchema = deviceSchema.subSchemas.compactMap({ (subSchema: SubSchema) -> ObjectSchema? in
guard case .objectSchema(let subSchema) = subSchema,
subSchema.name == "Attributes" else {
return nil
}
return subSchema
}).first,
var classProperty = deviceAttributesSchema.properties["deviceClass"],
case .enumSchema(var classEnum) = classProperty.type {
var values = classEnum.cases
values.append(EnumCase(id: "appleVisionPro", value: "APPLE_VISION_PRO"))
classEnum.cases = values
classProperty.type = PropertyType.enumSchema(classEnum)
deviceAttributesSchema.properties["deviceClass"] = classProperty
deviceSchema.properties["attributes"]?.type = .schema(deviceAttributesSchema)
components.schemas["Device"] = .object(deviceSchema)
patchedSchemas.append(.object(deviceSchema))
}

// Add the case `DEVELOPER_ID_APPLICATION_G2` to CertificateType
// Apple's OpenAPI spec doesn't include the role for generating individual keys. Reported to Apple 28/3/24 as FB13701181.
Expand Down
13 changes: 11 additions & 2 deletions Tests/BagbutikSpecDecoderTests/SpecTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,10 @@ final class SpecTests: XCTestCase {
"type" : "string",
"enum" : [ "ENABLED", "DISABLED" ]
},
"deviceClass" : {
"type" : "string",
"enum" : [ "APPLE_WATCH", "IPAD", "IPHONE", "IPOD", "APPLE_TV", "MAC" ]
},
}
},
"links" : {
Expand Down Expand Up @@ -893,13 +897,18 @@ final class SpecTests: XCTestCase {
return subSchema
}).first,
let statusProperty = deviceAttributesSchema.properties["status"],
case .enumSchema(let deviceStatusSchema) = statusProperty.type else {
case .enumSchema(let deviceStatusSchema) = statusProperty.type,
let classProperty = deviceAttributesSchema.properties["deviceClass"],
case .enumSchema(let deviceClassSchema) = classProperty.type else {
XCTFail(); return
}
let deviceStatusCaseValues = deviceStatusSchema.cases.map(\.value)
let deviceClassCaseValues = deviceClassSchema.cases.map(\.value)
XCTAssertEqual(deviceStatusCaseValues.count, 3)
XCTAssertTrue(deviceStatusCaseValues.contains("PROCESSING"))

XCTAssertEqual(deviceClassCaseValues.count, 7)
XCTAssertTrue(deviceClassCaseValues.contains("APPLE_VISION_PRO"))

guard case .object(let errorResponse) = spec.components.schemas["ErrorResponse"],
case .arrayOfSubSchema(let errorSchema) = errorResponse.properties["errors"]?.type,
case .oneOf(_, let oneOfSchema) = errorSchema.properties["source"]?.type
Expand Down

0 comments on commit e440ade

Please sign in to comment.