Doc for a property with non-public setter is generated as get set

We are using DocC for our SDK that gets released as a Swift package.

The compiled doc will show a property that has a custom property wrapper as { get set } even if its setter is marked internal(set).

The expected behavior of the doc is to show it as read-only { get } . Consider the following trivial example in a Swift package project:

@propertyWrapper struct Percent {
    var storage: Double

    public internal(set) var wrappedValue: Double {
        get {
            max(min(storage, 100), 0)
        }
        set {
            storage = newValue
        }
    }

    public var projectedValue: Double {
        storage
    }

    public init(wrappedValue: Double) {
        storage = wrappedValue
    }
}

// In another file.
public struct TestDocCSetter {
    @Percent
    public var value = 50
}

The generated doc looks like below.

image

If I change internal(set) to private(set), the doc looks correct. But since we need to use some custom property wrappers across our SDK, their wrappedValue setter needs to be internal.

Is it a bug in DocC? Thanks.

I can't say for certain because I'm not sure how you're generating the documentation, which can make a difference in what protection level is documented. The default for generating documentation for libraries displays public protected elements, but if you're generating documentation for an executable (aka "an app"), then the documentation defaults to providing documentation for internal symbols as well.

If you're generating documentation on the command line, there are also specific controls that you like over-ride the choice of access level that's documented. Those configurations are unavailable when generating documentation through Xcode.

Based on your screenshot, I suspect you're generating documentation entirely through Xcode. If that's the case, is the project you're working on an App by chance? (Even a test app)? Or a library only - for example, by opening a Package.swift directly?

1 Like

For this repro case and our usecase, it is Swift package only. Paste the code into a newly created Swift package, use Xcode Product > Build Documentation, and you'll see the value property is marked as get-set.

Based on your screenshot, I suspect you're generating documentation entirely through Xcode.

That is correct for this repro case. But we are using CLI to generate the docs for production. Is there a way to specifically override a custom property wrapper's access level display in the doc?

Thanks for your response.

I don't think internal should be treated as public especially for a framework. This seems like the fix should belong in swift symbol graph generation @QuietMisdreavus mind confirming and having a look?

2 Likes