block

endpointExample

Wire value: "endpointExample"

Appears on: Documentation Topic, Tutorial Article

1. How swift-docc-render consumes this

endpointExample is one of the block-content kinds dispatched by the shared renderNode() function inside components/ContentNode.vue's BlockType map (endpointExample: 'endpointExample', line 40). The switch (node.type) case for it is:

case BlockType.endpointExample: {
  const props = {
    request: node.request,
    response: node.response,
  };
  return createElement(EndpointExample, { props }, renderChildren(node.summary || []));
}

(src/components/ContentNode.vue#L283-L289). Only request and response (each a CodeExample object, see section 3) are passed through as props, untouched; the optional summary array of RenderBlockContent is recursively rendered via renderChildren and handed to the component's default <slot>, exactly like the sibling dictionaryExample kind. There is no metadata/renderFigure branch here either — an endpointExample node is always rendered as an EndpointExample component.

The leaf component, components/ContentNode/EndpointExample.vue, is where the interesting behavior lives. Its template:

<Row class="endpoint-example">
  <Column class="example-code">
    <slot />
    <Tabnav v-model="currentTab">
      <TabnavItem :value="Tab.request">{{ $t('tab.request') }}</TabnavItem>
      <TabnavItem :value="Tab.response">{{ $t('tab.response') }}</TabnavItem>
    </Tabnav>
    <div class="output">
      <div v-if="isCurrent(Tab.request)" class="code">
        <CollapsibleCodeListing v-bind="request" :collapsed="isCollapsed" showLineNumbers />
      </div>
      <div v-if="isCurrent(Tab.response)" class="code">
        <CollapsibleCodeListing v-bind="response" :collapsed="isCollapsed" showLineNumbers />
      </div>
    </div>
    <div class="controls" v-if="isCollapsible">…</div>
  </Column>
</Row>

Two independent pieces of client-side state drive this component's data() (EndpointExample.vue#L64-L69):

Unlike dictionaryExample's call site, EndpointExample.vue always passes a real (initially true) collapsed prop, so the collapse/expand toggle is live and reachable here, not dead code.

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

2. Example JSON and rendered mockup

Real fixture: Tests/SwiftDocCTests/Rendering/Rendering Fixtures/rest-symbol.json in the pinned swift-docc checkout, found inside the REST symbol's discussion (ContentRenderSection) content array, and exercised by Tests/SwiftDocCTests/Rendering/RESTSymbolsTests.swift's testDecodeRESTSymbol().

{
  "type": "endpointExample",
  "summary": [
    {
      "type": "paragraph",
      "inlineContent": [
        {
          "type": "text",
          "text": "The summary of this endpoint example."
        }
      ]
    }
  ],
  "request": {
    "type": "file",
    "syntax": "http",
    "content": [
      {
        "collapsible": false,
        "code": ["Request content"]
      }
    ]
  },
  "response": {
    "type": "file",
    "syntax": "json",
    "content": [
      {
        "collapsible": true,
        "code": ["Response content"]
      }
    ]
  }
}

As with dictionaryExample, note the fixture's request.type / response.type fields ("file") reflect swift-docc's internal CodeExample.type property (Sources/SwiftDocC/Model/Rendering/Symbol/RESTExampleRenderSection.swift:24) but are not declared on the vendored wire schema's CodeExample object (section 3); a strict decode against the generated Components.Schemas.CodeExample would ignore that key.

The summary of this endpoint example.

Request Response
Request content
+ More

3. Data sheet

Schema object: #/components/schemas/EndpointExample in Sources/DocCArchive/Vendored/RenderNode.spec.json:1142-1167, one of the variants referenced from the RenderBlockContent discriminated union (spec line 474). It references #/components/schemas/CodeExample (spec line 1125-1141) twice (for request and response), which in turn references #/components/schemas/CodeExampleContent (spec line 1107-1124). Generated Swift: Components.Schemas.EndpointExample, a Codable, Hashable, Sendable struct at Sources/DocCArchive/generated/Types.swift:4731-4768; its request/response fields are each typed Components.Schemas.CodeExample (Types.swift:4708-4729), whose content field is [Components.Schemas.CodeExampleContent] (Types.swift:4685-4706). The Swift-side authoring model, RenderBlockContent.EndpointExample, is declared at Sources/SwiftDocC/Model/Rendering/Content/RenderBlockContent.swift:509-523.

FieldTypeRequired?Enum values / defaultNote
typestringyes"endpointExample"Discriminator; generated as _TypePayload with the single case .endpointExample.
summary[RenderBlockContent]no—Optional introductory content, rendered into the component's default slot ahead of the tab navigator.
requestCodeExampleyes—Bound to the "Request" tab's CollapsibleCodeListing.
responseCodeExampleyes—Bound to the "Response" tab's CollapsibleCodeListing.
CodeExample.syntaxstringno—Declared on the wire schema but not read anywhere in EndpointExample.vue / CollapsibleCodeListing.vue — no per-language highlighting is driven by it in this render path.
CodeExample.content[CodeExampleContent]yes—One array element per visually-groupable chunk of lines; bound via v-bind="request"/v-bind="response" so the whole object's keys become props on CollapsibleCodeListing.
CodeExampleContent.collapsiblebooleanyes—Drives both the .collapsible styling class and, combined with EndpointExample's own isCollapsed state, the isCollapsible computed that shows/hides the "more"/"less" toggle for the currently selected tab.
CodeExampleContent.code[string]yes—The chunk's source lines, one array element per line (no embedded newlines).

Note swift-docc's own CodeExample Swift model (Sources/SwiftDocC/Model/Rendering/Symbol/RESTExampleRenderSection.swift:14-29) declares an additional optional type: String? field that is present in the real fixture (section 2) but absent from the vendored JSON schema and generated Swift type in this repository — a gap between swift-docc's authoring-side model and the wire schema DocCArchive vendors.

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 that operate on a whole RenderNode and return a hardcoded HTML comment / empty string respectively, so an endpointExample block encountered while walking a parsed archive would decode correctly into Components.Schemas.EndpointExample but has no dedicated conversion logic in this repository today.

4. HTML/CSS mapping in DocC-Render output

Root elements: <Row class="endpoint-example"><Column class="example-code"> (GridRow/GridColumn wrappers, EndpointExample.vue#L12-L13). Inside it:

CSS spacing between an endpointExample block and its siblings is not handled by EndpointExample.vue itself but by the parent components/DocumentationTopic/ContentNode.vue#L60, whose between-els('.endpoint-example') selector adds margin-top: var(--spacing-stacked-margin-xlarge) whenever an .endpoint-example block is adjacent to another block-level sibling. CSS custom properties consumed at paint time (via CollapsibleCodeListing.vue's scoped SCSS): --background / --color-code-background, --colors-grid / --color-grid, --text / --color-code-plain, --color-code-collapsible-background / --color-code-collapsible-text; and (via EndpointExample.vue's own scoped SCSS, importing docc-render/styles/_core.scss) --colors-text / --color-text for the toggle link's color.

5. Modern CSS-only alternative

Partial

Current behavior, precisely: EndpointExample.vue holds currentTab in component data(), mutated through Tabnav's v-model when a TabnavItem's @click.prevent handler calls the injected selectTab(value); the template then conditionally mounts/unmounts one of two <div v-if="isCurrent(Tab.request)"> / v-if="isCurrent(Tab.response)"> panels. Separately, isCollapsed (also component data()) is flipped by showMore()/showLess() click handlers on a "more"/"less" link and passed as a :collapsed prop into CollapsibleCodeListing, which combines it with each line-chunk's own collapsible flag to add/remove a .collapsed class.

The tab-switching half of this maps cleanly onto a native mechanism: a radio-input + :checked + general-sibling-selector pattern. Two hidden <input type="radio" name="endpoint-tab" id="tab-request" checked> / <input type="radio" name="endpoint-tab" id="tab-response"> elements placed before two <label for="tab-request">/<label for="tab-response"> tab labels and two content panels would let #tab-request:checked ~ .output .response-panel { display: none; } (and the mirrored rule for the request panel) hold exactly the "only one panel visible" state that currentTab holds today, with the browser's native radio-group semantics (and default keyboard support) doing the exclusivity that Tabnav's injected selectTab currently does in JavaScript.

The collapse/expand half is a comparably clean fit for <details>/<summary>: wrapping each collapsible-flagged CodeExampleContent chunk in its own <details> (with the "more"/"less" link becoming the native disclosure triangle) would let the browser hold the open/closed state per chunk instead of a single component-wide isCollapsed boolean — arguably a behavior improvement, since today one isCollapsed flag toggles every collapsible chunk in the visible tab at once via :collapsed="isCollapsed", section 1.

The verdict is "partial" rather than "applicable" because the two states are not fully independent in the current markup contract: isCollapsible is computed from whichever tab is currentTab-selected (it inspects request.content or response.content depending on the active tab), so a pure CSS reimplementation would need the collapse controls duplicated per tab-panel (each panel getting its own <details> elements) rather than a single shared toggle outside the radio-selected region — achievable, but it is a real structural change to the component, not a drop-in CSS swap of the existing DOM.