File tree Expand file tree Collapse file tree 3 files changed +154
-0
lines changed
Expand file tree Collapse file tree 3 files changed +154
-0
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,30 @@ struct Manifest: Decodable, Equatable {
5252 }
5353 var platformName : Name
5454 var version : String
55+
56+ init ( platformName: Manifest . Platform . Name , version: String ) {
57+ self . platformName = platformName
58+ self . version = version
59+ }
60+
61+ enum CodingKeys : CodingKey {
62+ case platformName
63+ case version
64+ }
65+
66+ init ( from decoder: any Decoder ) throws {
67+ let container = try decoder. container ( keyedBy: CodingKeys . self)
68+
69+ do { // case-insensitive decoding of Platform.Name
70+ let rawValue = try container. decode ( String . self, forKey: CodingKeys . platformName) . lowercased ( )
71+ guard let name = Name ( rawValue: rawValue) else {
72+ throw DecodingError . dataCorrupted ( . init( codingPath: [ CodingKeys . platformName] ,
73+ debugDescription: " invalid rawValue: \( rawValue) " ) )
74+ }
75+ self . platformName = name
76+ }
77+ self . version = try container. decode ( String . self, forKey: CodingKeys . version)
78+ }
5579 }
5680
5781 enum LibraryType : String , Decodable {
Original file line number Diff line number Diff line change 1+ {
2+ "cLanguageStandard" : null ,
3+ "cxxLanguageStandard" : null ,
4+ "dependencies" : [
5+ {
6+ "sourceControl" : [
7+ {
8+ "identity" : " swift" ,
9+ "location" : {
10+ "remote" : [
11+ {
12+ "urlString" : " https://github.com/airbnb/swift"
13+ }
14+ ]
15+ },
16+ "productFilter" : null ,
17+ "requirement" : {
18+ "range" : [
19+ {
20+ "lowerBound" : " 1.0.1" ,
21+ "upperBound" : " 2.0.0"
22+ }
23+ ]
24+ }
25+ }
26+ ]
27+ }
28+ ],
29+ "name" : " Lottie" ,
30+ "packageKind" : {
31+ "root" : [
32+ " /Users/sas/Projects/SPI/spi-server/SPI-checkouts/github.com-airbnb-lottie-ios"
33+ ]
34+ },
35+ "pkgConfig" : null ,
36+ "platforms" : [
37+ {
38+ "options" : [
39+
40+ ],
41+ "platformName" : " ios" ,
42+ "version" : " 11.0"
43+ },
44+ {
45+ "options" : [
46+
47+ ],
48+ "platformName" : " macos" ,
49+ "version" : " 10.11"
50+ },
51+ {
52+ "options" : [
53+
54+ ],
55+ "platformName" : " tvos" ,
56+ "version" : " 11.0"
57+ },
58+ {
59+ "options" : [
60+
61+ ],
62+ "platformName" : " visionOS" ,
63+ "version" : " 1.0"
64+ }
65+ ],
66+ "products" : [
67+ {
68+ "name" : " Lottie" ,
69+ "settings" : [
70+
71+ ],
72+ "targets" : [
73+ " Lottie"
74+ ],
75+ "type" : {
76+ "library" : [
77+ " automatic"
78+ ]
79+ }
80+ }
81+ ],
82+ "providers" : null ,
83+ "swiftLanguageVersions" : null ,
84+ "targets" : [
85+ {
86+ "dependencies" : [
87+
88+ ],
89+ "exclude" : [
90+ " Private/EmbeddedLibraries/README.md" ,
91+ " Private/EmbeddedLibraries/ZipFoundation/README.md" ,
92+ " Private/EmbeddedLibraries/EpoxyCore/README.md" ,
93+ " Private/EmbeddedLibraries/LRUCache/README.md"
94+ ],
95+ "name" : " Lottie" ,
96+ "packageAccess" : false ,
97+ "path" : " Sources" ,
98+ "resources" : [
99+ {
100+ "path" : " PrivacyInfo.xcprivacy" ,
101+ "rule" : {
102+ "copy" : {
103+
104+ }
105+ }
106+ }
107+ ],
108+ "settings" : [
109+
110+ ],
111+ "type" : " regular"
112+ }
113+ ],
114+ "toolsVersion" : {
115+ "_version" : " 5.7.0"
116+ }
117+ }
Original file line number Diff line number Diff line change @@ -192,4 +192,17 @@ class ManifestTests: XCTestCase {
192192 ] )
193193 }
194194
195+ func test_issue_2875( ) throws {
196+ // Support decoding custom platform with different capitalisation
197+ // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/2875
198+ let data = try fixtureData ( for: " Lottie-ios.json " )
199+ let m = try JSONDecoder ( ) . decode ( Manifest . self, from: data)
200+ XCTAssertEqual ( m. platforms, [
201+ . init( platformName: . ios, version: " 11.0 " ) ,
202+ . init( platformName: . macos, version: " 10.11 " ) ,
203+ . init( platformName: . tvos, version: " 11.0 " ) ,
204+ . init( platformName: . visionos, version: " 1.0 " ) ,
205+ ] )
206+ }
207+
195208}
You can’t perform that action at this time.
0 commit comments