section

declarations

Wire value: "declarations"

Appears on: Documentation Topic

1. How swift-docc-render consumes this

declarations is one of the kind values of the DocumentationPrimaryRenderSection union (a symbol page's primaryContentSections array). Unlike most primary-content-section kinds, it is not dispatched through PrimaryContent.vue's generic section-kind switch. Instead DocumentationTopic.vue pulls every section with kind === SectionKind.declarations out of primaryContentSections into its own declarations computed property, and explicitly excludes that same kind from the array handed to the generic PrimaryContentSectionsSanitized/PrimaryContent path (lines 593–602):

primaryContentSectionsSanitized({ primaryContentSections = [], symbolKind }) {
  return primaryContentSections.filter(({ kind }) => {
    if (kind === SectionKind.mentions) {
      return symbolKind !== SymbolKind.module;
    }
    return kind !== SectionKind.declarations;
  });
},
declarations({ primaryContentSections = [] }) {
  return primaryContentSections.filter(({ kind }) => kind === SectionKind.declarations);
},

The SectionKind.declarations constant itself is defined in src/constants/PrimaryContentSection.js (declarations: 'declarations'). The reason for the special-case: declarations are promoted out of the normal in-page-content flow and rendered up in the page's hero/header region, not in the body. In the template (lines 75–88), each extracted section is passed to a Declaration component inside a div.declarations-container that lives directly under DocumentationHero, right after the page's Availability block:

<div
  v-if="declarations.length"
  class="declarations-container"
  :class="{ 'minimized-container': enableMinimized }"
>
  <Declaration
    v-for="(declaration, index) in declarations"
    :key="index"
    :conformance="conformance"
    :declarations="declaration.declarations"
    :source="remoteSource"
    :declListExpanded.sync="declListExpanded"
  />
</div>

Declaration.vue is the per-section wrapper (a <section class="declaration">): it either shows a DeclarationDiff (API-changes diff view, when the page has an unexpanded change) or, in the normal case, loops over the section's declarations array (one entry per platform/language variant) rendering a DeclarationList for each, followed by an optional source-link and conditional-conformance-constraints footer.

DeclarationList.vue is where the "other declarations" (overload) behavior lives. Its declarationTokens computed (lines 100–123) splices the current declaration into its sibling otherDeclarations.declarations array at otherDeclarations.displayIndex, then renders every entry as a div.declaration-pill wrapping a DeclarationGroup, each pill wrapped in a transition-expand for the animated collapse/expand. Only the selected pill is shown until the "show all overloads" toggle (rendered by the parent DocumentationTopic.vue as button.declaration-list-toggle, driving the shared declListExpanded boolean) is clicked; clicking any other pill while expanded re-selects it and, after a short animation delay, routes to that symbol's own page via this.$router.push. Finally, DeclarationGroup.vue renders an optional platform-list caption and delegates the actual token array to DeclarationSource.vue, which wraps a CodeBlock/Token sequence in a <pre> (applying, for Swift, some post-tokenization reflow logic to break long parameter lists onto their own lines — see formattedSwiftTokens in that file).

2. Example JSON and rendered mockup

Real fixture, from Tests/DocCArchiveTests/Fixtures/SampleLibrary.doccarchive/data/documentation/samplelibrary/samplestruct/count.json (the declarations entry of that RenderNode's primaryContentSections, documenting SampleStruct.count: UInt). This fixture does not exercise the optional title field or the otherDeclarations overload mechanism described above (no fixture JSON in either DocCArchive's or swift-docc's test suites was found with otherDeclarations present on the wire).

{
  "kind": "declarations",
  "declarations": [
    {
      "languages": [
        "swift"
      ],
      "platforms": [
        "macOS"
      ],
      "tokens": [
        { "kind": "keyword", "text": "let" },
        { "kind": "text", "text": " " },
        { "kind": "identifier", "text": "count" },
        { "kind": "text", "text": ": " },
        {
          "kind": "typeIdentifier",
          "preciseIdentifier": "s:Su",
          "text": "UInt"
        }
      ]
    }
  ]
}
let count: UInt

mockup: a single declaration pill (macOS/Swift) rendered as monospaced, syntax-colored tokens inside DeclarationSource.vue's <pre>. With no otherDeclarations, there is exactly one pill and no expand/collapse toggle is shown for this symbol; on a page with overloads, additional pills for other platforms/overloads would stack below with a "Show All Declarations" toggle button.

3. Data sheet

Source: Sources/DocCArchive/Vendored/RenderNode.spec.json, schema objects #/components/schemas/DeclarationsRenderSection, #/components/schemas/Declaration, #/components/schemas/OtherDeclarations, #/components/schemas/OtherDeclaration, and #/components/schemas/DeclarationToken (lines 2561–2676), cross-checked against the generated types in Sources/DocCArchive/generated/Types.swift (Components.Schemas.DeclarationsRenderSection at lines 6045–6077, Components.Schemas.Declaration at lines 6078–6106, Components.Schemas.OtherDeclarations at lines 6107–6129, Components.Schemas.OtherDeclaration at lines 6130–6158, and Components.Schemas.DeclarationToken1—note the generator-assigned 1 suffix, since a distinct top-level DeclarationToken schema also exists—at lines 6159–6201).

FieldTypeRequiredEnum values / defaultNote
kind string yes "declarations" Generated as a single-case KindPayload enum. Matches swift-docc's DeclarationsRenderSection.kind: RenderSectionKind = .declarations default.
title string no — Present in the wire schema, but swift-docc's own DeclarationsRenderSection Swift struct has no corresponding stored property (its documented default is a static, always-nil title) — no emitter of a populated value was found. Not read by any of the render-side Declaration components examined above.
declarations array of Declaration yes — One entry per platform/language declaration variant. Consumed by Declaration.vue as its declarations prop.
Declaration.platforms array of string yes — Platform names this declaration variant applies to (e.g. "macOS"). Rendered as a caption above the code block by DeclarationGroup.vue when shouldCaption is true (i.e. when the page has more than one set of platforms represented across its declarations).
Declaration.tokens array of DeclarationToken yes — The syntax-highlighted token stream, rendered by DeclarationSource.vue.
Declaration.otherDeclarations OtherDeclarations no — Present only when this symbol has overloads. Drives the "show all declarations" expand/collapse UI in DeclarationList.vue.
OtherDeclarations.declarations array of OtherDeclaration yes — The sibling overload declarations (excluding the current symbol itself, which gets spliced back in at displayIndex).
OtherDeclarations.displayIndex integer yes — Position at which the current declaration should be inserted among the declarations array to reconstruct display order.
OtherDeclaration.tokens array of DeclarationToken yes — Token stream for the overload's own declaration.
OtherDeclaration.identifier string yes — Reference identifier used to resolve the overload's URL (for routing on pill click) via the page's references map.
OtherDeclaration.conformance ConformanceSection no — Optional conditional-conformance metadata for that overload.
DeclarationToken.text string yes — The literal token text.
DeclarationToken.kind string yes keyword, attribute, number, string, identifier, typeIdentifier, genericParameter, text, internalParam, externalParam, label Drives the syntax-highlighting CSS class via DeclarationToken.vue.
DeclarationToken.identifier string no — Format-hinted as a reference into the page's references map (a TopicRenderReference) when the token is a known symbol, used to render it as a link.
DeclarationToken.preciseIdentifier string no — Symbol-graph precise identifier for the token's referenced symbol, e.g. "s:Su" for UInt in the example above.
DeclarationToken.highlight string no "changed" Marks a token as changed for API-diff rendering; consumed by DeclarationSource.vue's extraClassesFor() to add a .highlighted class.

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

Gap between the wire schema and swift-docc's Swift model: swift-docc's actual DeclarationRenderSection struct (the Swift-side counterpart to the wire Declaration schema, defined at DeclarationsRenderSection.swift lines 59–72) also encodes an optional languages: [String]? field (the source languages this declaration variant applies to, e.g. ["swift"] in the example above) that the vendored wire schema's Declaration object does not declare at all. It is visibly present on the wire in the real fixture used above, so it is genuinely emitted — but the generated Components.Schemas.Declaration Swift type in this repository has no languages property, and a DocCArchive consumer decoding through the generated type will silently drop it.

4. HTML/CSS mapping in DocC-Render output

Rendered DOM shape, assembled across the component chain in section 1:

SCSS lives inline in each component's own scoped <style lang="scss"> block (DocumentationTopic.vue, Declaration.vue, DeclarationList.vue, DeclarationGroup.vue, DeclarationSource.vue), all importing the shared docc-render/styles/_core.scss. Key CSS custom properties consumed:

DocCArchive transform status: not yet implemented. MyHTMLTransformer and MyMarkdownTransformer in Sources/DocCArchive/DocCArchive.swift are still stub placeholders (the HTML transformer returns a hardcoded <!-- what? --> comment and the Markdown transformer returns an empty string) — there is no kind-specific handling of DeclarationsRenderSection today, and given the languages field gap documented in section 3, a future implementation decoding via the generated type would need to either widen the vendored schema or fall back to raw JSON to reproduce that data faithfully.

5. Modern CSS-only alternative

PARTIAL

Current behavior: a single boolean, declListExpanded, lives in DocumentationTopic.vue's component data() and is passed down via .sync to both Declaration.vue (as isExpanded, forwarded again via .sync) and ultimately to every DeclarationList.vue instance on the page, so that clicking the single button.declaration-list-toggle expands or collapses all overload lists on the page in lockstep. Inside an expanded list, v-if="!hasOtherDeclarations || declaration.identifier === selectedIdentifier || isExpanded" decides which pills are in the DOM at all, and a second piece of state, selectedIdentifier (local data() in DeclarationList.vue), tracks which pill is highlighted/active; clicking a non-selected pill while expanded updates selectedIdentifier, waits a tick, collapses the list again (isExpanded = false), waits ~500ms for the collapse animation, then performs a client-side route navigation to that overload's own page.

The pure show/hide half of this — toggling between "one pill visible" and "all pills visible" — maps mechanically onto a checkbox/radio-driven CSS toggle: a hidden <input type="checkbox" id="decl-expand"> placed as a preceding sibling of .declaration-list, a <label for="decl-expand"> standing in for button.declaration-list-toggle, and a rule like #decl-expand:checked ~ .declaration-list .declaration-pill { display: block; } (paired with a default rule hiding all but the first/selected pill) would hold the expanded/collapsed state in the checkbox's own :checked attribute instead of in Vue's synced declListExpanded boolean — no JS required for that part, and the existing transition-expand height animation is approximable with a CSS max-height/grid-template-rows transition gated on the same :checked selector. The verdict is partial, not fully applicable, because the second behavior — selecting a different overload pill and then navigating the browser to that overload's own documentation page after the collapse animation finishes — is a real client-side-router side effect keyed off a value normally read from the DOM (a data-href/reference-map lookup), not a pure visual state; CSS has no mechanism to perform navigation after a delay, so selectDeclaration()'s this.$router.push(...) call (and its waitFor(500) animation-sequencing) would still need to remain in script even if the expand/collapse itself moved to CSS.