1. How swift-docc-render consumes this
file is not a block/inline content kind dispatched from ContentNode.vue's
render() switch — it is a reference-tier object. RenderNodes carry a top-level
references dictionary keyed by identifier string, and other parts of the tree (here, a
tutorial Step) point at an entry in that dictionary by identifier rather than embedding
the object inline. The tutorial-only chain that resolves a file reference is:
-
components/Tutorial/SectionSteps.vue#L44-L57— for the active step's asset, ifvisibleAsset.codeis set (a reference identifier string taken from the step'scodefield), it renders<CodePreview :code="visibleAsset.code" :preview="visibleAsset.runtimePreview" .../>. -
components/Tutorial/CodePreview.vue#L106-L159—CodePreviewinjects the shared tutorialstoreand resolves the actual reference object with a plain dictionary lookup:
references: ({ tutorialState }) => tutorialState.references,
...
codeProps() {
return this.references[this.code];
},
(CodePreview.vue#L107-L159).
this.code is the identifier string; this.references is the RenderNode's
references map; this.references[this.code] is therefore the raw
FileRenderReference JSON object (with its type: "file",
identifier, fileName, fileType, syntax,
content, highlights fields) for that step.
That whole object is then spread onto the leaf component in the template:
<CodeListing v-if="code" v-bind="codeProps" showLineNumbers />
(CodePreview.vue#L14).
v-bind="codeProps" is a whole-object prop spread: Vue maps each of the reference's keys
onto a same-named prop of
components/ContentNode/CodeListing.vue,
which happens to declare props named fileName, fileType, syntax,
content, and highlights — an exact match to the reference's field names (the
extra type/identifier keys are simply ignored as unrecognized props). No
code here inspects type === 'file' explicitly; the "dispatch" is really just "this step
has a code identifier, so look it up and spread it," and the schema tag file
is never tested at render time — it only round-trips through JSON decoding on the Swift side (see
section 3).
Inside CodeListing.vue, the fileName prop conditionally renders a
<Filename> (CodeListingFilename.vue) header showing a file-type icon
(CodeListingFileIcon.vue, which special-cases fileType === 'swift' to show a
Swift file glyph and falls back to a generic file glyph otherwise —
CodeListingFileIcon.vue#L11-L20)
plus the fileName text; the content lines are syntax-highlighted per
syntax and rendered into a line-numbered <pre>; and highlights
drives which lines get the highlighted background/border treatment. CodePreview.vue
always passes showLineNumbers as a bare boolean attribute, so tutorial code steps always
show a line-number gutter (unlike a plain codeListing block, where that is opt-in). On
small/mobile breakpoints the analogous lookup happens in
components/Tutorial/MobileCodePreview.vue,
which feeds the same reference fields into ContentNode/MobileCodeListing.vue (a windowed,
scroll-following variant of the same rendering, showing only a few lines around the current
highlight).
See also: The references map — how this and every other reference-dictionary lookup works across kinds.
2. Example JSON and rendered mockup
No literal JSON fixture containing "type": "file" was found in either
Tests/DocCArchiveTests/Fixtures/ in this repository (its two archives,
ExampleDocs.doccarchive and SampleLibrary.doccarchive, contain no tutorial
content, so they never emit file references) or in
swift-docc's Tests/SwiftDocCTests/Rendering/Rendering Fixtures/ JSON files.
swift-docc's own test suite does construct real FileReference values as Swift literals —
Tests/SwiftDocCTests/DocumentationService/ConvertService/ConvertServiceTests.swift:979-989 —
which was used as the factual basis (field values, not exact JSON) for the hand-written example below:
{
"type": "file",
"identifier": "after.swift",
"fileName": "Something.swift",
"fileType": "swift",
"syntax": "swift",
"content": [
"// This is an example swift file",
"let something = 0"
],
"highlights": [
{ "line": 2 }
]
}
3. Data sheet
Schema object: #/components/schemas/FileRenderReference in
Sources/DocCArchive/Vendored/RenderNode.spec.json:1636-1676, with a companion
#/components/schemas/FileRenderReferenceHighlight object at lines 1677-1693. Generated
Swift: Components.Schemas.FileRenderReference, a plain Codable, Hashable, Sendable
struct at Sources/DocCArchive/generated/Types.swift:2309-2365, and
Components.Schemas.FileRenderReferenceHighlight at Types.swift:2366-2394. It
is reachable as the .FileRenderReference case of the generated top-level references-map
value enum (Types.swift:2121, also duplicated at Types.swift:4809 for a
second occurrence of the same discriminated union elsewhere in the spec).
| Field | Type | Required? | Enum values / default | Note |
|---|---|---|---|---|
type | string | yes | "file" | Discriminator; generated as _TypePayload with the single case .file. Matches RenderReferenceType.file in swift-docc's Swift model (RenderReference.swift:29). |
identifier | string | yes | — | Key used to look this object up from the RenderNode's top-level references dictionary, and the value a step's code field points at. |
fileName | string | yes | — | Display name of the file, e.g. "Something.swift". Drives the optional filename header in CodeListing.vue. |
fileType | string | yes | — | Typically a file extension (e.g. "swift"). Only actually branched on by CodeListingFileIcon.vue (=== 'swift' selects the Swift glyph, anything else falls back to a generic file glyph). |
syntax | string | yes | — | Highlighter language id, e.g. "swift"; drives which grammar CodeListing.vue loads for syntax highlighting. |
content | [string] | yes | — | Line-by-line file contents, one array element per line (no embedded newlines). |
highlights | [FileRenderReferenceHighlight] | no | defaults to [] in swift-docc's Swift FileReference initializer/decoder (FileReference.swift:40,75); generated Swift type is optional (nil when absent), not defaulted, since OpenAPI Generator does not synthesize schema-level defaults | Each entry: required line (integer), optional start/length (integers, character-range within the line — not consumed anywhere in swift-docc-render's rendering path found in step 1, which only reads .line). |
A closely related but distinct reference kind is fileType
(FileTypeRenderReference, wire value "fileType", spec lines 1694-1717): a
reference to a category of file (display name + Base64 icon), not to one specific file's
contents. It is out of scope for this page.
Authoring side (context, not schema-authoritative): a file reference is produced when a
tutorial author writes a @Code(file: "Something.swift", name: "Something.swift")
directive inside a @Step in a .tutorial file. See
Sources/SwiftDocC/Semantics/Tutorial/Tasks/Steps/Code.swift:14-51: the directive's
file argument names the source file to load from the bundle
(fileReference/previousFileReference, resolved via
ResourceReference), and its name argument becomes the reference's
fileName; an optional previousFile plus a reset flag support
showing a diff between two consecutive steps' files (the diff itself is realized as two separate
file references, one per step, not as an extra field on this schema).
4. HTML/CSS mapping in DocC-Render output
There is no dedicated root element "for a file reference" as such — the reference is pure
data; the DOM it produces is entirely CodeListing.vue's markup (shared with the
codeListing block-content kind), wrapped by the tutorial-specific
CodePreview.vue chrome:
<div class="code-preview">(root ofCodePreview.vue, modifier classidewhen embedded in an Xcode-hosted context) contains the code panel and, absolutely positioned, a runtime-preview panel.- Inside it,
<CodeTheme>wraps<CodeListing v-bind="codeProps" showLineNumbers />, i.e. the same<div class="code-listing" data-syntax="…">markup documented on thecodeListingblock-kind page: an optional<span class="filename">(icon + text), a<div class="container-general">holding the copy button and the<pre><code>block of per-line<span class="code-line-container">elements. <div class="runtime-preview">— a collapsible panel (modifier classescollapsed,disabled,runtime-preview-ide) with a<button class="header">toggle and a<div class="runtime-preview-asset">that projects the<slot/>(anAssetimage/video keyed by the step'sruntimePreviewreference, unrelated to thefilereference itself).
Styling: CodePreview.vue's own <style scoped lang="scss"> block
(imports docc-render/styles/_core.scss) sets the sticky, full-height code panel
(height: calc(100vh - $nav-height), 100vh when .ide) and the
absolutely positioned, width-transitioning runtime-preview box. CSS custom properties consumed:
--background / --color-step-background (code panel background),
--text / --color-code-plain (code text color),
--color-runtime-preview-background, --color-runtime-preview-text /
--colors-runtime-preview-text, and a locally scoped
--color-runtime-preview-shadow that flips value under @include prefers-dark.
CodeListing.vue's own scoped SCSS (documented in full on the codeListing
page) additionally consumes --color-code-line-highlight,
--color-code-line-highlight-border, --color-fill-gray-tertiary,
--color-fill-gray, and --code-indentationWidth.
5. Modern CSS-only alternative
Not applicable
file itself is a static reference-tier data record — an entry in the RenderNode's
references dictionary with no independent interactive behavior of its own. All of the
stateful JS in this page's render path (the runtime-preview show/hide toggle in
CodePreview.vue, the copy-to-clipboard button state, and the asynchronous
client-side syntax highlighter) belongs to the consuming components
(CodePreview.vue, CodeListing.vue) and is exactly the same machinery already
analyzed, mechanism-by-mechanism, on the codeListing block-kind page — none of it is
specific to, or triggered by, the fact that the data came from a file reference rather
than being inline block content. There is nothing left at the level of "what does a file
reference itself hold or toggle" for a native CSS mechanism to replace: the schema's own fields
(fileName, fileType, syntax, content,
highlights) are plain strings/arrays with no client-side state machine attached to the
reference object as such.