reference

topic

Wire value: "topic"

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

1. How swift-docc-render consumes this

"topic" is the type discriminator used on entries in a RenderNode's top-level references dictionary that point at another page of documentation (as opposed to an image, a download file, an external link, etc.). Swift-docc's TopicRenderReference is the Swift model for this shape; on the wire it is keyed by its identifier (a doc:// URL) inside RenderNode.references, and other parts of the render node — most commonly a "Topics" section's identifiers list — reference it by that identifier instead of inlining the full object repeatedly.

The resolution and rendering chain in swift-docc-render is:

  1. referencesProvider (a Vue mixin) exposes the render node's whole references map as a computed property, backed by the app's Vuex-like store.state.references: src/mixins/referencesProvider.js#L11-L27.
  2. TopicsTable.vue (the component behind a page's rendered "Topics" section) takes each section.identifiers entry and looks it up in that map (this.references[id]), building a section.topics array of resolved TopicRenderReference objects: TopicsTable.vue#L108-L118. It then either hands each resolved topic to TopicsLinkBlock (list style, the default) or the whole array to TopicsLinkCardGrid (grid/card style), switching on a topicStyle prop: TopicsTable.vue#L35-L50.
  3. TopicsLinkBlock.vue is the component that actually renders one topic reference as a link row. Its root element is <div class="link-block">, containing a <router-link> (internal) or <a> (when topic.type === 'link') wrapping a TopicLinkBlockIcon (role glyph), the title (as DecoratedTopicTitle if the reference carries symbol fragments, else plain text), and a following .abstract block with the topic's abstract content, badges for beta/deprecated status, and any tags: TopicsLinkBlock.vue#L11-L57. The component's own prop validator (not just documentation) enumerates the exact shape it expects a resolved topic reference to satisfy: TopicsLinkBlock.vue#L104-L119.
  4. Separately, the generic Reference.vue component (used for inline cross-references inside prose, not just the "Topics" section) accepts a kind prop whose valid values are documented in its header comment as "See DocumentationRenderNode.kind"/TopicRenderReference.type in the JSON schema, and uses it (together with role) to decide whether to render a symbol-styled link (ReferenceInternalSymbol/ReferenceExternalSymbol) or a plain link (ReferenceInternal/ReferenceExternal): Reference.vue#L40-L96.

The role-to-icon mapping used by TopicLinkBlockIcon (shown next to each topic link, driven by the reference's role field, e.g. symbol, article, collection) lives at TopicLinkBlockIcon.vue#L17-L47.

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

2. Example JSON and rendered mockup

Real fixture example, taken from this repository's own test fixture at Tests/DocCArchiveTests/Fixtures/SampleLibrary.doccarchive/data/documentation/samplelibrary.json, the entry for doc://SampleLibrary/documentation/SampleLibrary/SampleClass inside that render node's references dictionary:

{
  "abstract": [],
  "fragments": [
    { "kind": "keyword", "text": "class" },
    { "kind": "text", "text": " " },
    { "kind": "identifier", "text": "SampleClass" }
  ],
  "identifier": "doc://SampleLibrary/documentation/SampleLibrary/SampleClass",
  "kind": "symbol",
  "navigatorTitle": [
    { "kind": "identifier", "text": "SampleClass" }
  ],
  "role": "symbol",
  "title": "SampleClass",
  "type": "topic",
  "url": "/documentation/samplelibrary/sampleclass"
}

This particular reference has an empty abstract array and no tags, images, beta, or deprecated flags in the fixture, so the mockup below adds a short abstract and a beta badge (clearly labeled) purely to illustrate what TopicsLinkBlock.vue shows when those optional fields are present.

{}
SampleClass BETA (illustrative, not in fixture)
A sample class used to demonstrate documentation. (illustrative abstract, not in fixture)

3. Data sheet

Field table for the TopicRenderReference schema object, from Sources/DocCArchive/Vendored/RenderNode.spec.json (schema #/components/schemas/TopicRenderReference, lines 1742-1840) cross-checked against the generated Components.Schemas.TopicRenderReference struct in Sources/DocCArchive/generated/Types.swift (lines 2473-2600).

FieldTypeRequired?Enum values / defaultNote
typestringyes"topic", "section"Discriminator; generated as _TypePayload (renamed from type because type collides with Swift keyword handling).
identifierstringyes—The doc://-scheme key this object is stored under in RenderNode.references.
titlestringyes—Display title of the destination page (variant-aware in the Swift model via titleVariants, but the wire field is a plain string).
urlstringyes—Root-relative path to the destination page.
kindstringyesarticle, project, section, overview, symbol, rootThe kind of the referenced page, not of this reference object itself. Generated as KindPayload. Note this enum is narrower than the full RenderNode.Kind enum on the Swift-docc authoring side (which also has tutorial, tutorialTableOfContents, volume, video, etc.); swift-docc's decoder falls back to .tutorial if kind is missing entirely, for backwards compatibility with older archives.
abstractarray of RenderInlineContentnodefault []Short inline-content summary of the destination page.
requiredbooleannodefault falseWhether the referenced symbol is a required protocol member.
defaultImplementationsnumberno—Count of default implementations for the referenced symbol; generated as Swift.Double? even though it is conceptually an integer count.
fragmentsarray of DeclarationTokenno—Abbreviated declaration tokens shown inline in the link (e.g. class SampleClass).
navigatorTitlearray of DeclarationTokenno—Abbreviated declaration tokens for the navigator sidebar.
roleDocumentationRole (string enum)noe.g. symbol, article, collection, collectionGroup, ...Drives the icon shown in TopicLinkBlockIcon.vue.
imagesarray of TopicImageno—Author-provided icon/card images for this page.
conformanceConformanceSectionno—Conditional-conformance info, symbols only.
estimatedTimestringno—Estimated time to complete (tutorials).
betabooleannodefault false; JSON schema oddly lists "format": "true"Whether the symbol is beta; only emitted when true (swift-docc's encoder omits it when false).
deprecatedbooleannodefault false; same "format": "true" quirkWhether the symbol is deprecated; only emitted when true.
titleStylestringnotitle, symbolOnly meaningful for property-list-key/entitlement-key references.
namestringno—Raw plist/entitlement key name (wire key name maps to Swift's propertyListKeyNames.rawKey).
ideTitlestringno—Wire key ideTitle maps to Swift's propertyListKeyNames.displayName.
tagsarray of SymbolTagno—Free-text tags; TopicsLinkBlock.vue renders only the first one as a badge.

Note: the JSON schema's type enum ("topic", "section") is slightly broader than what its own name suggests — the same TopicRenderReference struct is reused with type: "section" for references to task-group / volume "section" pages inside tutorials, per swift-docc's own doc comment on RenderReferenceType (Sources/SwiftDocC/Model/Rendering/References/RenderReference.swift:29).

4. HTML/CSS mapping in DocC-Render output

SCSS: the scoped <style> block inside TopicsLinkBlock.vue defines .link-block, .link, .abstract, .topic-required, and .deprecated rules and imports the shared docc-render/styles/_core.scss. It consumes two SCSS variables defined centrally in src/styles/core/_vars.scss: $topic-link-icon-width (1.294rem) and $topic-link-icon-spacing (1rem), used to indent the abstract/badges so they line up with the title text after the icon. The scoped style block inside TopicsTable.vue separately sets the vertical spacing (margin-top: 15px) between successive .topic entries.

5. Modern CSS-only alternative

Not applicable

A resolved topic reference, as rendered by TopicsLinkBlock.vue, is not an interactive/stateful widget: there is no client-side toggle, tab, disclosure, or modal state being held in Vue component data for a single topic link row. It is a link (an <a> or Vue-Router <router-link>) with a decorated label, an optional abstract, and optional status badges — all computed once from static props (topic.title, topic.abstract, topic.beta, topic.deprecated, etc.) and rendered declaratively; nothing in TopicsLinkBlock.vue's computed block reacts to user interaction (clicking simply navigates, which is native browser/router behavior, not a piece of UI state a CSS mechanism like :checked or :target would need to replace). The one piece of "dynamism" — API-diff highlighting via changesClasses — is itself just a class computed from external route/query state (which diff view is selected), not something toggled by user interaction with this component. There is therefore no equivalent click-driven show/hide, tab-switch, or expand/collapse behavior for a native HTML mechanism (<details>, radio+:checked, :target, Popover API, <dialog>) to take over; this kind is a static, link-based rendering.