Skip to content

Commit ed2cb1e

Browse files
authored
Update JSON package collection models (#3067)
According to https://forums.swift.org/t/package-collection-format/42071 - Rename `title` to `name` - Consistent naming of `collection.overview` and `package.summary` instead of `description` - Add `keywords` to `Collection.Package` - Add `minimumPlatformVersions` to `Collection.Package.Version` - Add `createdBy` to `Collection` API models and tests are updated as well.
1 parent 53c086c commit ed2cb1e

18 files changed

+448
-128
lines changed

Fixtures/Collections/JSON/good.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
{
22
"name": "Sample Package Collection",
3-
"description": "This is a sample package collection listing made-up packages.",
3+
"overview": "This is a sample package collection listing made-up packages.",
44
"keywords": ["sample package collection"],
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",
11-
"description": "Package One",
14+
"summary": "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" },
@@ -45,7 +52,7 @@
4552
},
4653
{
4754
"url": "https://www.example.com/repos/RepoTwo.git",
48-
"description": "Package Two",
55+
"summary": "Package Two",
4956
"readmeURL": "https://www.example.com/repos/RepoTwo/README",
5057
"versions": [
5158
{

Sources/PackageCollections/CMakeLists.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
# See http://swift.org/CONTRIBUTORS.txt for Swift project authors
88

99
add_library(PackageCollections
10-
Model/CVE.swift
10+
JSONModel/JSONCollection.swift
11+
JSONModel/JSONCollection+v1.swift
1112
Model/Collection.swift
13+
Model/CVE.swift
1214
Model/License.swift
1315
Model/Package.swift
1416
Model/Search.swift
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
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 Collection: 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 overview: 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.Collection.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 `Collection`
47+
public init(
48+
name: String,
49+
overview: String? = nil,
50+
keywords: [String]? = nil,
51+
packages: [JSONPackageCollectionModel.V1.Collection.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.overview = overview
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+
public struct Author: Equatable, Codable {
70+
/// The author name.
71+
public let name: String
72+
73+
/// Creates an `Author`
74+
public init(name: String) {
75+
self.name = name
76+
}
77+
}
78+
}
79+
}
80+
81+
extension JSONPackageCollectionModel.V1.Collection {
82+
public struct Package: Equatable, Codable {
83+
/// The URL of the package. Currently only Git repository URLs are supported.
84+
public let url: Foundation.URL
85+
86+
/// A description of the package.
87+
public let summary: String?
88+
89+
/// An array of keywords that the package is associated with.
90+
public let keywords: [String]?
91+
92+
/// An array of version objects representing the most recent and/or relevant releases of the package.
93+
public let versions: [JSONPackageCollectionModel.V1.Collection.Package.Version]
94+
95+
/// The URL of the package's README.
96+
public let readmeURL: Foundation.URL?
97+
98+
/// Creates a `Package`
99+
public init(
100+
url: URL,
101+
summary: String? = nil,
102+
keywords: [String]? = nil,
103+
versions: [JSONPackageCollectionModel.V1.Collection.Package.Version],
104+
readmeURL: URL? = nil
105+
) {
106+
self.url = url
107+
self.summary = summary
108+
self.keywords = keywords
109+
self.versions = versions
110+
self.readmeURL = readmeURL
111+
}
112+
}
113+
}
114+
115+
extension JSONPackageCollectionModel.V1.Collection.Package {
116+
public struct Version: Equatable, Codable {
117+
/// The semantic version string.
118+
public let version: String
119+
120+
/// The name of the package.
121+
public let packageName: String
122+
123+
/// An array of the package version's targets.
124+
public let targets: [JSONPackageCollectionModel.V1.Target]
125+
126+
/// An array of the package version's products.
127+
public let products: [JSONPackageCollectionModel.V1.Product]
128+
129+
/// The tools (semantic) version specified in `Package.swift`.
130+
public let toolsVersion: String
131+
132+
/// An array of the package version’s supported platforms specified in `Package.swift`.
133+
public let minimumPlatformVersions: [JSONPackageCollectionModel.V1.PlatformVersion]?
134+
135+
/// An array of platforms in which the package version has been tested and verified.
136+
public let verifiedPlatforms: [JSONPackageCollectionModel.V1.Platform]?
137+
138+
/// An array of Swift versions that the package version has been tested and verified for.
139+
public let verifiedSwiftVersions: [String]?
140+
141+
/// The package version's license.
142+
public let license: JSONPackageCollectionModel.V1.License?
143+
144+
/// Creates a `Version`
145+
public init(
146+
version: String,
147+
packageName: String,
148+
targets: [JSONPackageCollectionModel.V1.Target],
149+
products: [JSONPackageCollectionModel.V1.Product],
150+
toolsVersion: String,
151+
minimumPlatformVersions: [JSONPackageCollectionModel.V1.PlatformVersion]? = nil,
152+
verifiedPlatforms: [JSONPackageCollectionModel.V1.Platform]? = nil,
153+
verifiedSwiftVersions: [String]? = nil,
154+
license: JSONPackageCollectionModel.V1.License? = nil
155+
) {
156+
self.version = version
157+
self.packageName = packageName
158+
self.targets = targets
159+
self.products = products
160+
self.toolsVersion = toolsVersion
161+
self.minimumPlatformVersions = minimumPlatformVersions
162+
self.verifiedPlatforms = verifiedPlatforms
163+
self.verifiedSwiftVersions = verifiedSwiftVersions
164+
self.license = license
165+
}
166+
}
167+
}
168+
169+
extension JSONPackageCollectionModel.V1 {
170+
public struct Target: Equatable, Codable {
171+
/// The target name.
172+
public let name: String
173+
174+
/// The module name if this target can be imported as a module.
175+
public let moduleName: String?
176+
177+
/// Creates a `Target`
178+
public init(name: String, moduleName: String? = nil) {
179+
self.name = name
180+
self.moduleName = moduleName
181+
}
182+
}
183+
184+
public struct Product: Equatable, Codable {
185+
/// The product name.
186+
public let name: String
187+
188+
/// The product type.
189+
public let type: ProductType
190+
191+
/// An array of the product’s targets.
192+
public let targets: [String]
193+
194+
/// Creates a `Product`
195+
public init(
196+
name: String,
197+
type: ProductType,
198+
targets: [String]
199+
) {
200+
self.name = name
201+
self.type = type
202+
self.targets = targets
203+
}
204+
}
205+
206+
public struct PlatformVersion: Equatable, Codable {
207+
/// The name of the platform (e.g., macOS, Linux, etc.).
208+
public let name: String
209+
210+
/// The semantic version of the platform.
211+
public let version: String
212+
213+
/// Creates a `PlatformVersion`
214+
public init(name: String, version: String) {
215+
self.name = name
216+
self.version = version
217+
}
218+
}
219+
220+
public struct Platform: Equatable, Codable {
221+
/// The name of the platform (e.g., macOS, Linux, etc.).
222+
public let name: String
223+
224+
/// Creates a `Platform`
225+
public init(name: String) {
226+
self.name = name
227+
}
228+
}
229+
230+
public struct License: Equatable, Codable {
231+
/// License name (e.g., Apache-2.0, MIT, etc.)
232+
public let name: String
233+
234+
/// The URL of the license file.
235+
public let url: URL
236+
237+
/// Creates a `License`
238+
public init(name: String, url: URL) {
239+
self.name = name
240+
self.url = url
241+
}
242+
}
243+
}
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+
}

0 commit comments

Comments
 (0)