Skip to content

Commit 06737e0

Browse files
authored
Add request argument to opt-out of source file path information (#526) (#528)
rdar://107075861
1 parent e4011bb commit 06737e0

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

Sources/SwiftDocC/DocumentationService/Convert/ConvertService.swift

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,7 @@ public struct ConvertService: DocumentationService {
184184
fallbackInfo: request.bundleInfo,
185185
additionalSymbolGraphFiles: []
186186
),
187-
// We're enabling the inclusion of symbol declaration file paths
188-
// in the produced render json here because the render nodes created by
189-
// `ConvertService` are intended for local uses of documentation where
190-
// this information could be relevant and we don't have the privacy concerns
191-
// that come with including this information in public releases of docs.
192-
emitSymbolSourceFileURIs: true,
187+
emitSymbolSourceFileURIs: request.emitSymbolSourceFileURIs,
193188
emitSymbolAccessLevels: true
194189
)
195190

Sources/SwiftDocC/DocumentationService/Models/Services/Convert/ConvertRequest.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ public struct ConvertRequest: Codable {
111111
/// the client to pass a more up-to-date value than is available in the symbol graph.
112112
public var overridingDocumentationComments: [String: [Line]]? = nil
113113

114+
/// Whether the conversion's rendered documentation should include source file location metadata.
115+
public var emitSymbolSourceFileURIs: Bool
116+
114117
/// The article and documentation extension file data included in the documentation bundle to convert.
115118
///
116119
/// ## See Also
@@ -166,6 +169,7 @@ public struct ConvertRequest: Codable {
166169
self.tutorialFiles = []
167170
self.miscResourceURLs = miscResourceURLs
168171
self.featureFlags = FeatureFlags()
172+
self.emitSymbolSourceFileURIs = true
169173

170174
self.bundleInfo = DocumentationBundle.Info(
171175
displayName: displayName,
@@ -185,6 +189,7 @@ public struct ConvertRequest: Codable {
185189
/// - symbolGraphs: The symbols graph data included in the documentation bundle to convert.
186190
/// - overridingDocumentationComments: The mapping of external symbol identifiers to lines of a
187191
/// documentation comment that overrides the value in the symbol graph.
192+
/// - emitSymbolSourceFileURIs: Whether the conversion's rendered documentation should include source file location metadata.
188193
/// - knownDisambiguatedSymbolPathComponents: The mapping of external symbol identifiers to
189194
/// known disambiguated symbol path components.
190195
/// - markupFiles: The article and documentation extension file data included in the documentation bundle to convert.
@@ -200,6 +205,7 @@ public struct ConvertRequest: Codable {
200205
symbolGraphs: [Data],
201206
overridingDocumentationComments: [String: [Line]]? = nil,
202207
knownDisambiguatedSymbolPathComponents: [String: [String]]? = nil,
208+
emitSymbolSourceFileURIs: Bool = true,
203209
markupFiles: [Data],
204210
tutorialFiles: [Data] = [],
205211
miscResourceURLs: [URL]
@@ -211,6 +217,13 @@ public struct ConvertRequest: Codable {
211217
self.symbolGraphs = symbolGraphs
212218
self.overridingDocumentationComments = overridingDocumentationComments
213219
self.knownDisambiguatedSymbolPathComponents = knownDisambiguatedSymbolPathComponents
220+
221+
// The default value for this is `true` to enable the inclusion of symbol declaration file paths
222+
// in the produced render json by default.
223+
// This default to true, because the render nodes created by `ConvertService` are intended for
224+
// local uses of documentation where this information could be relevant and we don't have the
225+
// privacy concerns that come with including this information in public releases of docs.
226+
self.emitSymbolSourceFileURIs = emitSymbolSourceFileURIs
214227
self.markupFiles = markupFiles
215228
self.tutorialFiles = tutorialFiles
216229
self.miscResourceURLs = miscResourceURLs

Tests/SwiftDocCTests/DocumentationService/ConvertService/ConvertServiceTests.swift

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,40 @@ class ConvertServiceTests: XCTestCase {
193193
}
194194
}
195195

196+
func testRemoteSourceInformationOptOut() throws {
197+
let symbolGraphFile = Bundle.module.url(
198+
forResource: "mykit-one-symbol",
199+
withExtension: "symbols.json",
200+
subdirectory: "Test Resources"
201+
)!
202+
203+
let symbolGraph = try Data(contentsOf: symbolGraphFile)
204+
205+
let request = ConvertRequest(
206+
bundleInfo: testBundleInfo,
207+
externalIDsToConvert: ["s:5MyKit0A5ClassC10myFunctionyyF"],
208+
documentPathsToConvert: [],
209+
symbolGraphs: [symbolGraph],
210+
emitSymbolSourceFileURIs: false,
211+
markupFiles: [],
212+
miscResourceURLs: []
213+
)
214+
215+
try processAndAssert(request: request) { message in
216+
XCTAssertEqual(message.type, "convert-response")
217+
XCTAssertEqual(message.identifier, "test-identifier-response")
218+
219+
let renderNodes = try JSONDecoder().decode(
220+
ConvertResponse.self, from: XCTUnwrap(message.payload)).renderNodes
221+
222+
XCTAssertEqual(renderNodes.count, 1)
223+
let data = try XCTUnwrap(renderNodes.first)
224+
let renderNode = try JSONDecoder().decode(RenderNode.self, from: data)
225+
226+
XCTAssertNil(renderNode.metadata.remoteSource, "No remote source when 'emitSymbolSourceFileURIs' is 'false'")
227+
}
228+
}
229+
196230
func testOverridesDocumentationComments() throws {
197231
let symbolGraphFile = Bundle.module.url(
198232
forResource: "mykit-one-symbol",

0 commit comments

Comments
 (0)