Skip to content

Conversation

@patshaughnessy
Copy link
Contributor

Bug/issue #, if applicable: rdar://164210651

Summary

RenderContentMetadata, which is part of the Render JSON schema, doesn’t have a public initializer. This prevents other applications linking to Swift DocC from creating new metadata instances. This change adds a public initializer.

Dependencies

None.

Testing

Write a small Swift CLI executable program that links to Swift DocC, and then test that you can create an instance of RenderContentMetadata using this new public initializer.

let package = Package(
    name: "CreateRenderMetadata",
    platforms: [.macOS(.v15) ],
    dependencies: [
      .package(url: "git@github.com:patshaughnessy/swift-docc.git", branch: "r164210651-add-public-initializer-RenderContentMetadata"),
    ],
    targets: [
        .executableTarget(
            name: "CreateRenderMetadata",
            dependencies: [
                .product(name: "SwiftDocC", package: "swift-docc")
            ]
        ),
    ]
)
import SwiftDocC

@main
struct CreateRenderMetadata {
    static func main() {
        print("Hello, world!")
        let metadata = RenderContentMetadata()
        print(metadata)
    }
}

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added tests
  • Ran the ./bin/test script and it succeeded

Copy link
Contributor

@d-ronnqvist d-ronnqvist Nov 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's fine to have this test but I don't find it important to test that initializers set the properties of a structure because the compiler will already enforce that the initializer assigns a value to every property.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking about this unit test some more, I've decided to rename & move the Swift file and test class to something more generic. I think this test file could be generally useful in the future for testing public access to various DocC API.

See: c587ac9

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think running a test is a good mechanism for verifying that a piece of API is public. To my knowledge we don't do that for any other public API.

I personally don't think that having this test will meaningfully help us remember to make other future API in other types public and I think that the odds that this test protects us against unintentionally removing this API or changing it to a lower access level is abysmal.

I don't think it's harmful to have this test but I think the value it adds is fairly close to zero.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify; I'm not requesting that we remove this test, but I feel that the discussion around adding it has already cost more time and productivity that we'll ever regain from having this test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants