reference

download

Wire value: "download"

Appears on: Documentation Topic, Tutorial (Project), Tutorial Article

1. How swift-docc-render consumes this

download is not a block/inline content kind dispatched from ContentNode.vue's render() switch — like file and link, it is a reference-tier object. A RenderNode carries a top-level references dictionary keyed by identifier string, and other parts of the tree point at an entry in that dictionary rather than embedding the download's URL/checksum inline. A literal search of swift-docc-render/src/components/ and src/views/ for the string "download" turns up no component or SCSS file named after this reference kind specifically (the only file-name hits are Icons/DownloadIcon.vue and Icons/InlineDownloadIcon.vue, two small SVG glyph components with no reference-resolution logic of their own). There are exactly two places in the render tree that dereference a download reference by identifier:

projectFilesUrl() {
  return this.projectFiles ? normalizePath(this.references[this.projectFiles].url) : null;
}

That computed value is passed down to Hero.vue#L55 (:projectFilesUrl="projectFilesUrl") into components/Tutorial/HeroMetadata.vue#L40-L51, which renders it as a plain anchor next to a download glyph:

<div class="item" v-if="projectFilesUrl">
  <DownloadIcon class="item-large-icon icon-inline" />
  <div class="content bottom">
    <a class="content-link project-download" :href="projectFilesUrl">
      {{ $t('tutorials.project-files') }}
      <InlineDownloadIcon class="small-icon icon-inline" />
    </a>
  </div>
</div>

No type === 'download' check happens anywhere in this path — the reference's url field is read directly by name, and the wire-level type discriminator is never inspected at render time (it only round-trips through Swift's Codable decoding; see Section 3).

<div v-if="sampleCodeDownload">
  <DownloadButton class="sample-download" :action="sampleCodeDownload.action" linksToAsset />
</div>

(DocumentationTopic.vue#L64-L69). CallToActionButton.vue hands the action's destination (identifier + optional overriding title) to DestinationDataProvider, whose reference computed does the actual dictionary lookup and picks out the download reference's url field:

reference: ({ references, destination }) => (references[destination.identifier] || {}),
linkUrl: ({ destination, reference }) => ({
  link: destination.destination,
  reference: reference.url,
  text: destination.text,
}[destination.type]),

(DestinationDataProvider.vue#L61-L70). The resolved url/title pair then reaches ButtonLink.vue with linksToAsset forced to true (CallToActionButton.vue#L12-L19), which routes rendering to ContentNode/Reference.vue#L56-L65's isInternal computed — which returns false whenever linksToAsset is set, forcing the plain external-link component ReferenceExternal.vue#L11-L14 (<a :href="url"><slot/></a>) rather than the SPA router link that would otherwise be used for a same-site documentation page. This full sampleCodeDownload section wrapper and button chain is documented in more depth on the sampleDownload section page; this page focuses on the leaf download reference object both paths ultimately resolve.

See also: The references map — how this and every other reference-dictionary lookup works across kinds.

See also: Localization fallback — how $t()/locale-key lookup works across every kind that uses it.

2. Example JSON and rendered mockup

A real fixture exists in swift-docc's own test suite: Tests/SwiftDocCTests/Rendering/Rendering Fixtures/sample-download-symbol.json. Its references map contains one download entry, and its top-level sampleCodeDownload field is the action that points at it (field order below matches the fixture; abbreviated to the two relevant top-level keys):

{
  "sampleCodeDownload": {
    "action": {
      "type": "reference",
      "identifier": "doc://org.swift.docc.example/downloads/sample.zip",
      "isActive": true,
      "overridingTitle": "Download"
    }
  },
  "references": {
    "doc://org.swift.docc.example/downloads/sample.zip": {
      "type": "download",
      "identifier": "project.zip",
      "url": "/downloads/project.zip",
      "checksum": "ad4adacc8ad53230b59d"
    }
  }
}

(fixture: Tests/SwiftDocCTests/Rendering/Rendering Fixtures/sample-download-symbol.json in the pinned swift-docc checkout). Note the two distinct identifiers in play: the reference-map key (doc://org.swift.docc.example/downloads/sample.zip, what action.identifier points at) versus the reference object's own identifier field (project.zip, an internal display/dedup name unrelated to the map key or to the URL's last path component). Rendered as a symbol page's sample-download button (per the sampleCodeDownload path in Section 1):

Rendered instead as a tutorial hero's "Project files" link (the projectFiles path in Section 1, using the same URL):

3. Data sheet

Schema object: #/components/schemas/DownloadRenderReference in Sources/DocCArchive/Vendored/RenderNode.spec.json:1882-1904, one of the oneOf branches of the discriminated #/components/schemas/RenderReference union at RenderNode.spec.json:1491-1520. Because DocCArchive's vendored schemas are merged from multiple source files (RenderNode.spec.json, Assets.json, LinkableEntities.json all separately define a same-named DownloadRenderReference schema), openapi-merge-cli disambiguates the duplicates by suffixing later occurrences, and swift-openapi-generator mirrors that as distinct Swift types. The one reachable from a RenderNode's references map (i.e. the type this page is about) is Components.Schemas.DownloadRenderReference1 — generated from Sources/DocCArchive/Vendored/merged-spec.json:1526-1550 — at Sources/DocCArchive/generated/Types.swift:2623-2661, reachable as the .DownloadRenderReference1 case of the generated references-map value enum (Types.swift:2129, with a decode attempt at Types.swift:2172-2177). The unsuffixed DownloadRenderReference (Types.swift:619-661, from Assets.json's standalone downloads array) and DownloadRenderReference2 (Types.swift:5132-..., from LinkableEntities.json) describe the identical wire shape for other, unrelated contexts and are out of scope here.

FieldTypeRequired?Enum values / defaultNote
typestringyes"download"Discriminator; generated as _TypePayload with the single case .download. Matches RenderReferenceType.download in swift-docc's Swift model (RenderReference.swift:29).
identifierstringyes—An internal display/dedup name for the downloadable item (e.g. "project.zip"), distinct from the reference-map key that other objects use to point at this entry. Wraps swift-docc's RenderReferenceIdentifier (RenderReference.swift:36-59), which is itself just a string.
urlstringyes—Path to the downloadable resource, e.g. "/downloads/project.zip". In swift-docc, encoded either verbatim (JSON round-trip) or filtered through renderURL(for:prefixComponent:) when freshly generated (DownloadReference.swift:81-93).
checksumstringnono default; absent when unknownSHA-512 hash of the file's bytes, computed by swift-docc at conversion time (Checksum.sha512(of: downloadData), RenderNodeTranslator.swift:1911-1928). Not consumed by any swift-docc-render component found in Section 1 — it round-trips through the JSON but is not displayed or verified client-side.

Authoring side (context, not schema-authoritative): a download reference is produced two ways. (1) A tutorial author sets the projectFiles argument on a @Tutorial(projectFiles: "MyProject.zip") { … } directive (Sources/SwiftDocC/Semantics/Tutorial/Tutorial.swift:23-29,78); swift-docc resolves that asset with assetContext: .download (RenderNodeTranslator.swift:196-197,1911-1928) and registers a DownloadReference. (2) For a symbol or article, a bundle-relative sample-code project asset referenced from that page's metadata is resolved the same way and surfaces as the page's sampleCodeDownload.action. In both cases the underlying Swift type constructed is DownloadReference (swiftStructSite, Sources/SwiftDocC/Model/Rendering/Tutorial/References/DownloadReference.swift:14), whose doc comment describes it plainly as "A reference to a resource that can be downloaded," stored under a downloads/ directory in the built archive (DownloadReference.locationName, same file, line 19).

DocCArchive's own transform layer does not yet do anything with this kind: MyHTMLTransformer and MyMarkdownTransformer (Sources/DocCArchive/DocCArchive.swift:242-254) are still stub placeholders (a hardcoded HTML comment and an empty string, respectively) that do not inspect RenderNode.references at all, so a download reference would currently pass through parseRenderNode decoding untouched but produce no HTML/Markdown output.

4. HTML/CSS mapping in DocC-Render output

There is no dedicated root element "for a download reference" as such — the reference is pure data (URL + checksum); the DOM depends entirely on which of the two consumers in Section 1 resolves it:

In neither path does the checksum field surface in the DOM or in any SCSS selector.

5. Modern CSS-only alternative

Not applicable

Current behavior: neither consumption path in Section 1 holds any client-side state or toggles visibility of anything. HeroMetadata.vue's project-files link is a v-if-gated plain <a href> computed once from references[this.projectFiles].url; the sample-code download button resolves its url/title once inside DestinationDataProvider's render-scoped-slot and renders a plain <a href> via ReferenceExternal.vue (forced there by linksToAsset, per Section 1). There is no click handler that opens/closes a panel, no v-show-driven alternate state, and no JavaScript-managed disclosure anywhere in either path — both are ordinary hyperlinks to a static asset URL, which is exactly what an HTML anchor is for. Because there is no interactive state machine here to begin with (unlike, say, a tab navigator or a disclosure triangle), there is no native mechanism (<details>, :target, :has(), etc.) to name as a replacement: this kind's entire "behavior" already is a plain link.