Skip to content

Commit 3ad2d24

Browse files
committed
Update JSON package collection models
According to https://forums.swift.org/t/package-collection-format/42071 - Rename `summary` and `title` to `description` and `name`, respectively - Add `keywords` to `PackageCollection.Package` - Add `minimumPlatformVersions` to `PackageCollection.Package.Version` - Add `createdBy` to `PackageCollection` API models and tests are updated as well.
1 parent efec8cd commit 3ad2d24

File tree

13 files changed

+459
-101
lines changed

13 files changed

+459
-101
lines changed

Fixtures/Collections/JSON/good.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
"formatVersion": "1.0",
66
"revision": 3,
77
"generatedAt": "2020-10-22T06:03:52Z",
8+
"generatedBy": {
9+
"name": "Jane Doe"
10+
},
811
"packages": [
912
{
1013
"url": "https://www.example.com/repos/RepoOne.git",
1114
"description": "Package One",
15+
"keywords": ["sample package"],
1216
"readmeURL": "https://www.example.com/repos/RepoOne/README",
1317
"versions": [
1418
{
@@ -30,6 +34,9 @@
3034
}
3135
],
3236
"toolsVersion": "5.1",
37+
"minimumPlatformVersions": [
38+
{ "name": "macOS", "version": "10.15" }
39+
],
3340
"verifiedPlatforms": [
3441
{ "name": "macOS" },
3542
{ "name": "iOS" },
Lines changed: 262 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,262 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2020 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import struct Foundation.Date
12+
import struct Foundation.URL
13+
14+
import PackageModel
15+
16+
extension JSONPackageCollectionModel {
17+
public enum V1 {}
18+
}
19+
20+
extension JSONPackageCollectionModel.V1 {
21+
public struct PackageCollection: Equatable, Codable {
22+
/// The name of the package collection, for display purposes only.
23+
public let name: String
24+
25+
/// A description of the package collection.
26+
public let _description: String?
27+
28+
/// An array of keywords that the collection is associated with.
29+
public let keywords: [String]?
30+
31+
/// An array of package metadata objects
32+
public let packages: [JSONPackageCollectionModel.V1.PackageCollection.Package]
33+
34+
/// The version of the format to which the collection conforms.
35+
public let formatVersion: JSONPackageCollectionModel.FormatVersion
36+
37+
/// The revision number of this package collection.
38+
public let revision: Int?
39+
40+
/// The ISO 8601-formatted datetime string when the package collection was generated.
41+
public let generatedAt: Date
42+
43+
/// The author of this package collection.
44+
public let generatedBy: Author?
45+
46+
/// Creates a `PackageCollection`
47+
public init(
48+
name: String,
49+
description: String? = nil,
50+
keywords: [String]? = nil,
51+
packages: [JSONPackageCollectionModel.V1.PackageCollection.Package],
52+
formatVersion: JSONPackageCollectionModel.FormatVersion,
53+
revision: Int? = nil,
54+
generatedAt: Date = Date(),
55+
generatedBy: Author? = nil
56+
) {
57+
precondition(formatVersion == .v1_0, "Unsupported format version: \(formatVersion)")
58+
59+
self.name = name
60+
self._description = description
61+
self.keywords = keywords
62+
self.packages = packages
63+
self.formatVersion = formatVersion
64+
self.revision = revision
65+
self.generatedAt = generatedAt
66+
self.generatedBy = generatedBy
67+
}
68+
69+
private enum CodingKeys: String, CodingKey {
70+
case name
71+
case _description = "description"
72+
case keywords
73+
case packages
74+
case formatVersion
75+
case revision
76+
case generatedAt
77+
case generatedBy
78+
}
79+
80+
public struct Author: Equatable, Codable {
81+
/// The author name.
82+
public let name: String
83+
84+
/// Creates an `Author`
85+
public init(name: String) {
86+
self.name = name
87+
}
88+
}
89+
}
90+
}
91+
92+
extension JSONPackageCollectionModel.V1.PackageCollection {
93+
public struct Package: Equatable, Codable {
94+
/// The URL of the package. Currently only Git repository URLs are supported.
95+
public let url: Foundation.URL
96+
97+
/// A description of the package.
98+
public let _description: String?
99+
100+
/// An array of keywords that the package is associated with.
101+
public let keywords: [String]?
102+
103+
/// An array of version objects representing the most recent and/or relevant releases of the package.
104+
public let versions: [JSONPackageCollectionModel.V1.PackageCollection.Package.Version]
105+
106+
/// The URL of the package's README.
107+
public let readmeURL: Foundation.URL?
108+
109+
/// Creates a `Package`
110+
public init(
111+
url: URL,
112+
description: String? = nil,
113+
keywords: [String]? = nil,
114+
versions: [JSONPackageCollectionModel.V1.PackageCollection.Package.Version],
115+
readmeURL: URL? = nil
116+
) {
117+
self.url = url
118+
self._description = description
119+
self.keywords = keywords
120+
self.versions = versions
121+
self.readmeURL = readmeURL
122+
}
123+
124+
private enum CodingKeys: String, CodingKey {
125+
case url
126+
case _description = "description"
127+
case keywords
128+
case versions
129+
case readmeURL
130+
}
131+
}
132+
}
133+
134+
extension JSONPackageCollectionModel.V1.PackageCollection.Package {
135+
public struct Version: Equatable, Codable {
136+
/// The semantic version string.
137+
public let version: String
138+
139+
/// The name of the package.
140+
public let packageName: String
141+
142+
/// An array of the package version's targets.
143+
public let targets: [JSONPackageCollectionModel.V1.Target]
144+
145+
/// An array of the package version's products.
146+
public let products: [JSONPackageCollectionModel.V1.Product]
147+
148+
/// The tools (semantic) version specified in `Package.swift`.
149+
public let toolsVersion: String
150+
151+
/// An array of the package version’s supported platforms specified in `Package.swift`.
152+
public let minimumPlatformVersions: [JSONPackageCollectionModel.V1.PlatformVersion]?
153+
154+
/// An array of platforms in which the package version has been tested and verified.
155+
public let verifiedPlatforms: [JSONPackageCollectionModel.V1.Platform]?
156+
157+
/// An array of Swift versions that the package version has been tested and verified for.
158+
public let verifiedSwiftVersions: [String]?
159+
160+
/// The package version's license.
161+
public let license: JSONPackageCollectionModel.V1.License?
162+
163+
/// Creates a `Version`
164+
public init(
165+
version: String,
166+
packageName: String,
167+
targets: [JSONPackageCollectionModel.V1.Target],
168+
products: [JSONPackageCollectionModel.V1.Product],
169+
toolsVersion: String,
170+
minimumPlatformVersions: [JSONPackageCollectionModel.V1.PlatformVersion]? = nil,
171+
verifiedPlatforms: [JSONPackageCollectionModel.V1.Platform]? = nil,
172+
verifiedSwiftVersions: [String]? = nil,
173+
license: JSONPackageCollectionModel.V1.License? = nil
174+
) {
175+
self.version = version
176+
self.packageName = packageName
177+
self.targets = targets
178+
self.products = products
179+
self.toolsVersion = toolsVersion
180+
self.minimumPlatformVersions = minimumPlatformVersions
181+
self.verifiedPlatforms = verifiedPlatforms
182+
self.verifiedSwiftVersions = verifiedSwiftVersions
183+
self.license = license
184+
}
185+
}
186+
}
187+
188+
extension JSONPackageCollectionModel.V1 {
189+
public struct Target: Equatable, Codable {
190+
/// The target name.
191+
public let name: String
192+
193+
/// The module name if this target can be imported as a module.
194+
public let moduleName: String?
195+
196+
/// Creates a `Target`
197+
public init(name: String, moduleName: String? = nil) {
198+
self.name = name
199+
self.moduleName = moduleName
200+
}
201+
}
202+
203+
public struct Product: Equatable, Codable {
204+
/// The product name.
205+
public let name: String
206+
207+
/// The product type.
208+
public let type: ProductType
209+
210+
/// An array of the product’s targets.
211+
public let targets: [String]
212+
213+
/// Creates a `Product`
214+
public init(
215+
name: String,
216+
type: ProductType,
217+
targets: [String]
218+
) {
219+
self.name = name
220+
self.type = type
221+
self.targets = targets
222+
}
223+
}
224+
225+
public struct PlatformVersion: Equatable, Codable {
226+
/// The name of the platform (e.g., macOS, Linux, etc.).
227+
public let name: String
228+
229+
/// The semantic version of the platform.
230+
public let version: String
231+
232+
/// Creates a `PlatformVersion`
233+
public init(name: String, version: String) {
234+
self.name = name
235+
self.version = version
236+
}
237+
}
238+
239+
public struct Platform: Equatable, Codable {
240+
/// The name of the platform (e.g., macOS, Linux, etc.).
241+
public let name: String
242+
243+
/// Creates a `Platform`
244+
public init(name: String) {
245+
self.name = name
246+
}
247+
}
248+
249+
public struct License: Equatable, Codable {
250+
/// License name (e.g., Apache-2.0, MIT, etc.)
251+
public let name: String
252+
253+
/// The URL of the license file.
254+
public let url: URL
255+
256+
/// Creates a `License`
257+
public init(name: String, url: URL) {
258+
self.name = name
259+
self.url = url
260+
}
261+
}
262+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2020 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
public enum JSONPackageCollectionModel {}
12+
13+
extension JSONPackageCollectionModel {
14+
/// Representation of `PackageCollection` JSON schema version
15+
public enum FormatVersion: String, Codable {
16+
case v1_0 = "1.0"
17+
}
18+
}

Sources/PackageCollections/Model/Collection.swift

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extension PackageCollectionsModel {
2222
public struct Collection: Equatable, Codable {
2323
public typealias Identifier = CollectionIdentifier
2424
public typealias Source = CollectionSource
25+
public typealias Author = CollectionAuthor
2526

2627
/// The identifier of the collection
2728
public let identifier: Identifier
@@ -44,6 +45,9 @@ extension PackageCollectionsModel {
4445
/// When this collection was created/published by the source
4546
public let createdAt: Date
4647

48+
/// Who authored this collection
49+
public let createdBy: Author?
50+
4751
/// When this collection was last processed locally
4852
public let lastProcessedAt: Date
4953

@@ -55,6 +59,7 @@ extension PackageCollectionsModel {
5559
keywords: [String]?,
5660
packages: [Package],
5761
createdAt: Date,
62+
createdBy: Author?,
5863
lastProcessedAt: Date = Date()
5964
) {
6065
self.identifier = .init(from: source)
@@ -64,6 +69,7 @@ extension PackageCollectionsModel {
6469
self.keywords = keywords
6570
self.packages = packages
6671
self.createdAt = createdAt
72+
self.createdBy = createdBy
6773
self.lastProcessedAt = lastProcessedAt
6874
}
6975
}
@@ -113,6 +119,14 @@ extension PackageCollectionsModel {
113119
}
114120
}
115121

122+
extension PackageCollectionsModel {
123+
/// Represents the author of a `PackageCollection`
124+
public struct CollectionAuthor: Equatable, Codable {
125+
/// The name of the author
126+
public let name: String
127+
}
128+
}
129+
116130
extension PackageCollectionsModel.CollectionIdentifier: Codable {
117131
public enum DiscriminatorKeys: String, Codable {
118132
case json
@@ -154,8 +168,11 @@ extension PackageCollectionsModel.Collection {
154168
/// Package's repository address
155169
public let repository: RepositorySpecifier
156170

157-
/// A summary about the package
158-
public let summary: String?
171+
/// The description of the package
172+
public let description: String?
173+
174+
/// Keywords for the package
175+
public let keywords: [String]?
159176

160177
/// Published versions of the package
161178
public let versions: [Version]
@@ -166,13 +183,15 @@ extension PackageCollectionsModel.Collection {
166183
/// Initializes a `Package`
167184
init(
168185
repository: RepositorySpecifier,
169-
summary: String?,
186+
description: String?,
187+
keywords: [String]?,
170188
versions: [Version],
171189
readmeURL: URL?
172190
) {
173191
self.reference = .init(repository: repository)
174192
self.repository = repository
175-
self.summary = summary
193+
self.description = description
194+
self.keywords = keywords
176195
self.versions = versions
177196
self.readmeURL = readmeURL
178197
}
@@ -201,6 +220,9 @@ extension PackageCollectionsModel.Collection {
201220

202221
/// The package version's Swift tools version
203222
public let toolsVersion: ToolsVersion
223+
224+
/// The package version's supported platforms
225+
public let minimumPlatformVersions: [SupportedPlatform]?
204226

205227
/// The package version's supported platforms verified to work
206228
public let verifiedPlatforms: [PackageModel.Platform]?

0 commit comments

Comments
 (0)