Hi everyone,
I'd like to propose an addition to the render JSON schema to allow a render node to represent documentation data for symbols that are available in multiple languages, for example symbols that are available in Swift and Objective-C.
Motivation
The render JSON schema currently represents documentation content for an API in a single language. To support documenting symbols in frameworks that are available in multiple languages, such as Swift and Objective-C, the render JSON specification needs to evolve.
Proposed Solution
We make an additive change to render JSON to store documentation data for multiple programming language variants. The schema for single-language symbols does not change, which preserves backwards-compatibility with existing clients and renderers.
The addition is a new top-level variantOverrides value which stores variants of documentation data for the symbol. If an API is available in Swift and Objective-C, the variantOverrides value stores content overrides that the renderer should apply when it’s rendering the docs for the Objective-C version of the symbol. These overrides are specified using the JSON Patch schema, which allows clients to easy apply them onto the render JSON.
Here’s an example:
{
"variantOverrides": [
{
// Distinguishing characteristics for the rendering environment. For now,
// just the programming language, but is kept flexible for future uses.
"traits": [{ "interfaceLanguage": "occ" }],
// Overrides to apply to the JSON, using the JSON Patch schema.
"patch": [
{
"op": "replace",
// Replacement of top-level object.
"path": "/abstract",
"value": [
{
"text": "This is the abstract for Objective-C",
"type": "text"
}
]
},
{
"op": "replace",
// Replacement of nested object.
"path": "/metadata/title",
"value": "Page title for Objective-C"
}
]
}
],
"abstract": […same as before…],
"primaryContentSections": [{…}, {…}],
"variants": [
{
"paths": ["/documentation/mykit/myclass"],
"traits": [{ "interfaceLanguage": "swift" }]
},
{
"paths": ["/documentation/mykit/myclass"],
"traits": [{ "interfaceLanguage": "occ" }]
}
],
…same properties as before…
}
Alternatives Considered
One alternative here is for Swift-DocC to produce separate render JSON files for each language a symbol is available in. However, documentation metadata for multi-language symbols is generally the same, for example the kind of a symbol (‘class’, ‘function’, etc.), its relationships to other symbols (e.g., member of a class), etc., is common across the languages the symbol is available in. By default, user-authored documentation content for a symbol is also the same across the languages it's available in, since you only write documentation where the symbol is originally declared. As such, generating a render JSON file per variant would involve storing large amounts of duplicate data, so in this proposal, we preferred to only store the differences between language variants and allow for clients to have an easy way (by using JSON Patch) to apply those variants for the language they're interested in.