Skip to content

Commit 19e41b0

Browse files
Add support to property list details. (#79)
`plistDetails` mixin created to store detail information about property list keys symbols. rdar://131539008
1 parent dde0f05 commit 19e41b0

File tree

3 files changed

+102
-1
lines changed

3 files changed

+102
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import Foundation
12+
13+
extension SymbolGraph.Symbol {
14+
15+
/// The details about a property list key.
16+
public var plistDetails: PlistDetails? {
17+
(mixins[PlistDetails.mixinKey] as? PlistDetails)
18+
}
19+
20+
/// A mixin that contains details about a property list key.
21+
public struct PlistDetails: Mixin, Codable {
22+
23+
public static let mixinKey = "plistDetails"
24+
25+
/// The name of the key.
26+
public var rawKey: String
27+
/// A human-friendly name of the key.
28+
public var customTitle: String?
29+
/// The plain text name of a symbol's base type. For example, `Int` for an array of integers.
30+
public var baseType: String?
31+
/// Indicates if the base type is an array.
32+
public var arrayMode: Bool?
33+
34+
public init(rawKey: String, customTitle: String? = nil, baseType: String? = nil, arrayMode: Bool? = false) {
35+
self.arrayMode = arrayMode
36+
self.baseType = baseType
37+
self.customTitle = customTitle
38+
self.rawKey = rawKey
39+
}
40+
}
41+
}

Sources/SymbolKit/SymbolGraph/Symbol/Symbol.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -241,6 +241,7 @@ extension SymbolGraph.Symbol {
241241
static let httpParameterSource = HTTP.ParameterSource.symbolCodingInfo
242242
static let httpMediaType = HTTP.MediaType.symbolCodingInfo
243243
static let alternateDeclarations = AlternateDeclarations.symbolCodingInfo
244+
static let plistDetails = PlistDetails.symbolCodingInfo
244245

245246
static let mixinCodingInfo: [String: SymbolMixinCodingInfo] = [
246247
CodingKeys.availability.codingKey.stringValue: Self.availability,
@@ -266,6 +267,7 @@ extension SymbolGraph.Symbol {
266267
CodingKeys.httpParameterSource.codingKey.stringValue: Self.httpParameterSource,
267268
CodingKeys.httpMediaType.codingKey.stringValue: Self.httpMediaType,
268269
CodingKeys.alternateDeclarations.codingKey.stringValue: Self.alternateDeclarations,
270+
CodingKeys.plistDetails.codingKey.stringValue: Self.plistDetails
269271
]
270272

271273
static func == (lhs: SymbolGraph.Symbol.CodingKeys, rhs: SymbolGraph.Symbol.CodingKeys) -> Bool {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
10+
11+
import XCTest
12+
import SymbolKit
13+
14+
final class PlistDetailsTests: XCTestCase {
15+
16+
func testPlistDetailsCanBeDecoded() throws {
17+
let jsonData = """
18+
{
19+
"accessLevel" : "public",
20+
"identifier" : {
21+
"interfaceLanguage" : "plist",
22+
"precise" : "plist:Information_Property_List.plist"
23+
},
24+
"kind" : {
25+
"displayName" : "Property List Key",
26+
"identifier" : "typealias"
27+
},
28+
"names" : {
29+
"navigator" : [
30+
{
31+
"kind" : "identifier",
32+
"spelling" : "plist"
33+
}
34+
],
35+
"title" : "plist"
36+
},
37+
"pathComponents" : [
38+
"Information-Property-List",
39+
"plist"
40+
],
41+
"plistDetails" : {
42+
"arrayMode" : true,
43+
"baseType" : "Information Property List",
44+
"rawKey" : "info-plist"
45+
}
46+
}
47+
""".data(using: .utf8)
48+
49+
let decoder = JSONDecoder()
50+
let symbol = try decoder.decode(SymbolGraph.Symbol.self, from: jsonData!)
51+
52+
let plistDetails = try XCTUnwrap(symbol.plistDetails)
53+
XCTAssertEqual(plistDetails.rawKey, "info-plist")
54+
XCTAssertEqual(plistDetails.baseType, "Information Property List")
55+
XCTAssertEqual(plistDetails.arrayMode, true)
56+
}
57+
58+
}

0 commit comments

Comments
 (0)