Skip to content

Commit af7c45f

Browse files
Fix the OpenAPI spec for LinkableEntities (#423)
The OpenAPI spec for linkable entities has fallen out of date since we’ve updated the file to support language variants. This brings the file up-to-date. I verified the spec against DocC output using an OpenAPI schema validator and it now successfully passes. Resolves rdar://102342486
1 parent 27f3303 commit af7c45f

File tree

2 files changed

+56
-10
lines changed

2 files changed

+56
-10
lines changed

Sources/SwiftDocC/Model/SourceLanguage.swift

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,31 @@ public struct SourceLanguage: Hashable, Codable {
149149

150150
/// The list of programming languages that are known to DocC.
151151
public static var knownLanguages: [SourceLanguage] = [.swift, .objectiveC, .javaScript, .data, .metal]
152+
153+
enum CodingKeys: CodingKey {
154+
case name
155+
case id
156+
case idAliases
157+
case linkDisambiguationID
158+
}
159+
160+
public init(from decoder: Decoder) throws {
161+
let container = try decoder.container(keyedBy: SourceLanguage.CodingKeys.self)
162+
163+
let name = try container.decode(String.self, forKey: SourceLanguage.CodingKeys.name)
164+
let id = try container.decode(String.self, forKey: SourceLanguage.CodingKeys.id)
165+
let idAliases = try container.decodeIfPresent([String].self, forKey: SourceLanguage.CodingKeys.idAliases) ?? []
166+
let linkDisambiguationID = try container.decodeIfPresent(String.self, forKey: SourceLanguage.CodingKeys.linkDisambiguationID)
167+
168+
self.init(name: name, id: id, idAliases: idAliases, linkDisambiguationID: linkDisambiguationID)
169+
}
170+
171+
public func encode(to encoder: Encoder) throws {
172+
var container = encoder.container(keyedBy: SourceLanguage.CodingKeys.self)
173+
174+
try container.encode(self.name, forKey: SourceLanguage.CodingKeys.name)
175+
try container.encode(self.id, forKey: SourceLanguage.CodingKeys.id)
176+
try container.encodeIfNotEmpty(self.idAliases, forKey: SourceLanguage.CodingKeys.idAliases)
177+
try container.encode(self.linkDisambiguationID, forKey: SourceLanguage.CodingKeys.linkDisambiguationID)
178+
}
152179
}

Sources/SwiftDocC/SwiftDocC.docc/Resources/LinkableEntities.json

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
},
1717
"LinkDestinationSummary": {
1818
"type": "object",
19+
"additionalProperties": false,
1920
"required": [
2021
"kind",
2122
"language",
@@ -67,7 +68,7 @@
6768
"usr": {
6869
"type": "string"
6970
},
70-
"declarationFragments": {
71+
"fragments": {
7172
"type": "array",
7273
"items": {
7374
"$ref": "#/components/schemas/DeclarationToken"
@@ -99,6 +100,15 @@
99100
},
100101
"id": {
101102
"type": "string"
103+
},
104+
"idAliases": {
105+
"type": "array",
106+
"items": {
107+
"type": "string"
108+
}
109+
},
110+
"linkDisambiguationID": {
111+
"type": "string"
102112
}
103113
}
104114
},
@@ -122,6 +132,7 @@
122132
},
123133
"LinkDestinationSummaryVariant": {
124134
"type": "object",
135+
"additionalProperties": false,
125136
"required": [
126137
"traits"
127138
],
@@ -133,37 +144,45 @@
133144
}
134145
},
135146
"kind": {
136-
"type": "string"
147+
"type": "string",
148+
"nullable": true
137149
},
138150
"language": {
139-
"type": "string"
151+
"$ref": "#/components/schemas/SourceLanguage",
152+
"nullable": true
140153
},
141154
"path": {
142-
"type": "string"
155+
"type": "string",
156+
"nullable": true
143157
},
144158
"title": {
145-
"type": "string"
159+
"type": "string",
160+
"nullable": true
146161
},
147162
"abstract": {
148163
"type": "array",
149164
"items": {
150165
"$ref": "#/components/schemas/RenderInlineContent"
151-
}
166+
},
167+
"nullable": true
152168
},
153169
"usr": {
154-
"type": "string"
170+
"type": "string",
171+
"nullable": true
155172
},
156-
"declarationFragments": {
173+
"fragments": {
157174
"type": "array",
158175
"items": {
159176
"$ref": "#/components/schemas/DeclarationToken"
160-
}
177+
},
178+
"nullable": true
161179
},
162180
"taskGroups": {
163181
"type": "array",
164182
"items": {
165183
"$ref": "#/components/schemas/TaskGroup"
166-
}
184+
},
185+
"nullable": true
167186
}
168187
}
169188
},

0 commit comments

Comments
 (0)