section

restEndpoint

Wire value: "restEndpoint"

Appears on: Documentation Topic

1. How swift-docc-render consumes this

restEndpoint is one of the section kinds a REST-symbol page's primaryContentSections array can contain (alongside restParameters, restHeaders, restCookies, restBody, restResponses, and the ordinary symbol sections). The dispatch table lives in PrimaryContent.vue, which keys a componentFor(section) lookup and a parallel propsFor(section) lookup off section.kind, using the SectionKind constant map defined in constants/PrimaryContentSection.js:

componentFor(section) {
  return {
    ...
    [SectionKind.restEndpoint]: RestEndpoint,
    ...
  }[section.kind];
},
propsFor(section) {
  const { tokens, title, ... } = section;
  return {
    ...
    [SectionKind.restEndpoint]: { tokens, title },
    ...
  }[kind];
},

Unlike restBody, there is no key renaming here — tokens and title pass straight through from the wire section object to component props. The target component is RestEndpoint.vue, whose entire template is two elements:

<section>
  <LinkableHeading :anchor="anchor">{{ title }}</LinkableHeading>
  <DeclarationSource :tokens="tokens" />
</section>

The heading text is the section's title (in practice always "URL" or "Sandbox URL", see §3), anchored via a local computed property anchor: ({ title }) => anchorize(title). The tokens array is handed directly to DeclarationSource.vue — the same component that renders ordinary Swift/Objective-C declarations sections — which wraps the tokens in a <pre><code> block and maps each one through DeclarationToken.vue. That component's render function switches on token.kind, but its known cases are Swift declaration-token kinds (keyword, identifier, typeIdentifier, attribute, added/removed, etc.) — none of which match the REST-specific kinds method, baseURL, path, or parameter defined for this section's own token schema (see §3). Those four therefore fall through to the default branch of the switch, which renders each token via SyntaxToken.vue: a bare <span class="token-{kind}">{text}</span>. The fifth REST token kind, text, does match a real DeclarationToken case and is instead rendered by RawText.vue as plain text with no wrapping element.

The section also participates in on-this-page navigation: in onThisPageRegistrator.js, restEndpoint is grouped with the other primary-content-anchor kinds (properties, restBody, restCookies, restHeaders, restParameters, restResponses) to register a level-2 on-this-page entry titled from the section's own title field, anchored via anchorize(section.title) — the same anchor computed inside RestEndpoint.vue itself for its LinkableHeading. A dedicated unit test, RestEndpoint.spec.js, confirms the component renders the title through LinkableHeading and forwards the tokens array unmodified to DeclarationSource.

2. Example JSON and rendered mockup

Real fixture, from swift-docc's test suite: Tests/SwiftDocCTests/Rendering/Rendering Fixtures/rest-symbol.json (the first entry of its primaryContentSections array), cross-checked against the assertions in Tests/SwiftDocCTests/Rendering/RESTSymbolsTests.swift (lines 52–63), which decodes this exact section and checks its 5 tokens' text values.

{
  "kind": "restEndpoint",
  "title": "URL",
  "tokens": [
    {
      "kind": "method",
      "text": "GET"
    },
    {
      "kind": "text",
      "text": " "
    },
    {
      "kind": "baseURL",
      "text": "https://www.example.com"
    },
    {
      "kind": "path",
      "text": "/v1/me/library/artists/"
    },
    {
      "kind": "parameter",
      "text": "{id}"
    }
  ]
}
URL
GET https://www.example.com/v1/me/library/artists/{id}

mockup: an h2-level heading ("URL") followed by a single-line, monospaced declaration block. Only the method token (GET) gets a dedicated bold style from DeclarationToken.vue's CSS; baseURL, path, and parameter tokens render as plain token-*-classed spans with no additional built-in color or weight.

3. Data sheet

Source: Sources/DocCArchive/Vendored/RenderNode.spec.json, schema object #/components/schemas/RESTEndpointRenderSection (lines 2878–2899) and its child schema #/components/schemas/EndpointToken (lines 2901–2916), one branch of the DocumentationPrimaryRenderSection discriminated union (lines 2507–2546); cross-checked against the generated Components.Schemas.RESTEndpointRenderSection and Components.Schemas.EndpointToken structs in Sources/DocCArchive/generated/Types.swift (lines 6513–6576).

FieldTypeRequiredEnum values / defaultNote
kind string yes "restEndpoint" (sole enum value) Discriminator. Generated as a dedicated KindPayload frozen enum with the single case restEndpoint. swift-docc's own RenderSectionKind enum (Model/Rendering/RenderSection.swift line 23) lists restEndpoint alongside the other REST section kinds, and Model/Rendering/RenderNode/CodableContentSection.swift (lines 60–61) dispatches decoding to RESTEndpointRenderSection(from: decoder) directly on this discriminator.
title string yes — No enum constraint in the schema, but in practice always exactly "URL" or "Sandbox URL" — swift-docc's HTTPEndpointSectionTranslator hard-codes one of those two literal strings depending on whether it is building the production or sandbox endpoint section (see §1/§3 authoring note below).
tokens array of EndpointToken yes — The tokenized endpoint declaration, in display order. Generated as [Components.Schemas.EndpointToken]; swift-docc's own Swift-side model (Model/Rendering/Symbol/RESTEndpointRenderSection.swift line 56) types the equivalent field as let tokens: [Token], a nested type with the identical two fields.
EndpointToken.kind string yes "method", "baseURL", "path", "parameter", "text" A closed 5-value enum, generated as its own frozen KindPayload enum on EndpointToken. This is a different token-kind vocabulary from the general DeclarationToken.kind enum used by ordinary declarations sections (which has values like keyword/identifier/typeIdentifier and does not include any of these five) — see §1 for the rendering consequence of that mismatch.
EndpointToken.text string yes — The literal text of this token (an HTTP method, a base URL, a path segment, a {parameter}-braced placeholder, or filler text such as the single space between method and URL).

Authoring-side note: there is no Markdown/directive syntax an author writes directly to produce a restEndpoint section. swift-docc's HTTPEndpointSectionTranslator builds the section by reading a symbol's httpEndpointSection (populated from a SymbolGraph symbol mixin, typically produced by converting an OpenAPI specification into a symbol graph upstream of DocC) and tokenizing its method, baseURL (endpoint.baseURL for the production translator instance, or endpoint.sandboxURL for the sandbox instance — the translator is parameterized by an endpointType: RESTEndpointType of .production or .sandbox, which also selects the hard-coded "URL" vs. "Sandbox URL" title), and path, splitting any {curly-brace}-delimited dynamic segments out into their own parameter tokens via a regular expression (tokensFor(method:baseURL:path:), lines 44–77). The underlying plain-data struct, RESTEndpointRenderSection.swift, carries a doc comment with a fully worked example: for the endpoint GET https://www.example.com/api/artists/{id}, the token sequence is (method) GET, (baseURL) https://www.example.com, (path) /api/artists/, (parameter) {id} — matching the fixture in §2 exactly (that fixture additionally has an explicit (text) " " filler token between the method and the base URL, which the doc comment's prose description omits but the translator code inserts at line 49).

DocCArchive transform status: MyHTMLTransformer and MyMarkdownTransformer in Sources/DocCArchive/DocCArchive.swift (lines 242–254) are still stub placeholders (the HTML transformer returns a hardcoded <!-- what? --> comment and the Markdown transformer returns an empty string) — neither has any kind-specific handling for restEndpoint (or any other render section) today. A future implementation would need to render the title as a heading and the token array as a single-line declaration-style code block, mapping each EndpointToken.kind to its own styling (mirroring RestEndpoint.vue and DeclarationToken.vue's default/SyntaxToken fallback path).

4. HTML/CSS mapping in DocC-Render output

Rendered DOM shape, from RestEndpoint.vue's template and the DeclarationSource.vue/DeclarationToken.vue/SyntaxToken.vue chain it delegates to:

SCSS: RestEndpoint.vue itself has no <style> block at all — all visual styling comes from the components it delegates to. DeclarationSource.vue's scoped SCSS (importing docc-render/styles/_core.scss) styles the .source root: background via var(--background, var(--color-code-background)), text color via var(--text, var(--color-code-plain)), a bordered/rounded box (border-color: var(--color-grid), border-radius: $large-border-radius), and padding: var(--code-block-style-elements-padding). DeclarationToken.vue's own scoped SCSS defines .token-method { font-weight: $font-weight-bold; } plus rules for token kinds not used here (.token-keyword, .token-string, etc., driven by --syntax-* custom properties) — there is no dedicated .token-baseURL, .token-path, or .token-parameter rule anywhere in that stylesheet, so those three token kinds inherit plain text color from the surrounding .source block.

CSS custom properties consumed: --background/--color-code-background and --text/--color-code-plain (code-block theming), --color-grid (border color), and --code-block-style-elements-padding (interior padding) — all consumed by DeclarationSource.vue's .source rule and shared with every other declaration-style code block in DocC-Render, not specific to restEndpoint itself.

5. Modern CSS-only alternative

NOT APPLICABLE

Current behavior: RestEndpoint.vue is a pure, stateless template — two elements (LinkableHeading, DeclarationSource), both fed directly from props with no v-if, no computed toggle, and no event handler beyond what LinkableHeading itself provides for its permalink-scroll behavior (which is a navigation/anchor concern shared by every heading in DocC-Render, not something introduced by this section kind). The only JavaScript-driven decision specific to this component chain is DeclarationToken.vue's render-time switch on token.kind, which selects which child component to instantiate per token — but that dispatch happens once, at render time, from static data; it is not a runtime state machine that responds to user interaction and has nothing to toggle after the page has rendered.

Because there is no interactive state to hold or reveal/hide in response to a user action, none of the stateful-CSS mechanisms (<details>/<summary>, a checked radio input plus a general sibling selector, :target, the Popover API, <dialog>, :has(), container queries, CSS anchor positioning, view transitions) have anything to attach to here. A static HTML/CSS rendering of this section is simply a heading element followed by a <pre><code> block with per-token <span>s carrying token-{kind} classes — entirely reproducible with plain markup and a handful of static CSS color/weight rules, no scripting or CSS pseudo-state trick required.