section

restResponses

Wire value: "restResponses"

Appears on: Documentation Topic

1. How swift-docc-render consumes this

restResponses is one of the "Rest symbol sections" cases of RenderSectionKind in swift-docc, declared at Sources/SwiftDocC/Model/Rendering/RenderSection.swift:23 alongside restParameters, restBody, restEndpoint, and properties. It is produced by RESTResponseRenderSection, whose kind defaults to .restResponses and which wraps a title and an array of RESTResponse values (each an HTTP status/reason/MIME-type/type-declaration/content tuple). This section appears in the primaryContentSections array of a symbol RenderNode for REST endpoint documentation (e.g. an @Response directive under a @RESTResponses-style authoring construct in a symbol-graph-derived REST operation).

On the render side, the dispatch table lives in src/components/DocumentationTopic/PrimaryContent.vue, which is the shared dispatcher for every entry in a symbol page's primaryContentSections (content, parameters, properties, all the rest* kinds, etc.). It keys a literal component map and a literal props map off SectionKind.restResponses (itself just the string 'restResponses', defined in src/constants/PrimaryContentSection.js):

componentFor(section) {
  return {
    ...
    [SectionKind.restResponses]: RestResponses,
    ...
  }[section.kind];
},
propsFor(section) {
  const { ..., items, kind, title, ... } = section;
  return {
    ...
    [SectionKind.restResponses]: { responses: items, title },
    ...
  }[kind];
},

Note the field rename here: the wire property is items, but PrimaryContent.vue passes it into the child component as a prop named responses. The matched component is src/components/DocumentationTopic/PrimaryContent/RestResponses.vue, which renders a <LinkableHeading> for the section title (anchored via anchorize(title)) followed by a shared ParametersTable.vue (the same grid-row/grid-column table component used by Parameters.vue and RestParameters.vue), keyed by each response's status rather than the usual name (key-by="status"):

<ParametersTable :parameters="sanitizedResponses" :changes="propertyChanges" key-by="status">
  <template #symbol="{ status, type, reason, content, changes }">
    <div class="response-name">
      <code>{{ status }} <span class="reason">{{ reason }}</span></code>
    </div>
    <PossiblyChangedType v-if="!shouldShiftType(...)" :type="type" :changes="changes.type" />
  </template>
  <template #description="{ content, mimeType, reason, type, status, changes }">
    <PossiblyChangedType v-if="shouldShiftType(...)" :type="type" :changes="changes.type" />
    <div class="response-reason"><code>{{ reason }}</code></div>
    <ContentNode v-if="content" :content="content" />
    <PossiblyChangedMimetype v-if="mimeType" :mimetype="mimeType" :changes="changes.mimetype" :change="changes.change" />
  </template>
</ParametersTable>

The "symbol" column shows the numeric HTTP status code plus its reason phrase (e.g. 200 OK) and, normally, the declared response type tokens rendered via PossiblyChangedType.vue (itself delegating to DeclarationTokenGroup.vue). The "description" column holds the free-form content (rendered through the generic block-content dispatcher, ContentNode.vue) plus an optional MIME-type badge. A local shouldShiftType method (!(content.length || reason) && status) moves the type declaration into the description column instead when a response has neither prose content nor a reason string, so the symbol column isn't left holding only a bare status code. A local sanitizeResponse method also normalizes a legacy/alternate JSON spelling: some data sources emit mimetype (lowercase t) instead of the documented mimeType, and RestResponses.vue re-keys it before handing rows to ParametersTable.

Separately, restResponses also participates in the page's "on this page" navigation sidebar: src/mixins/onThisPageRegistrator.js groups it with the other rest*/properties section kinds and registers one navigation entry per section using the section's own title and anchorize(title) as the anchor — the same anchor LinkableHeading uses for the in-page deep link.

Within this repository (DocCArchive), a decoded RESTResponsesRenderSection would reach Sources/DocCArchive/DocCArchive.swift's MyHTMLTransformer/MyMarkdownTransformer only as an entry inside Components.Schemas.RenderNode.primaryContentSections, but transform support for it is not yet implemented — both transformers are still stub placeholders (a hardcoded HTML comment and an empty string, respectively) that do not branch on section kind at all.

2. Example JSON and rendered mockup

A real fixture exists in swift-docc's test suite: Tests/SwiftDocCTests/Rendering/Rendering Fixtures/rest-symbol.json contains a restResponses section (lines 223–250 as pinned) used by Tests/SwiftDocCTests/Rendering/RESTSymbolsTests.swift. The example below is that fixture's restResponses object, reproduced verbatim.

{
  "kind": "restResponses",
  "title": "Response Codes",
  "items": [
    {
      "status": 200,
      "reason": "OK",
      "mimeType": "application/json",
      "type": [
        {
          "kind": "typeIdentifier",
          "text": "LibraryArtistResponse",
          "identifier": "doc://org.swift.docc/applemusicapi/libraryartistresponse"
        }
      ],
      "content": [
        {
          "type": "paragraph",
          "inlineContent": [
            { "type": "text", "text": "The request was successful." }
          ]
        }
      ]
    }
  ]
}
Response Codes
200 OK
LibraryArtistResponse

The request was successful.

Content-Type: application/json

3. Data sheet

Source: Sources/DocCArchive/Vendored/RenderNode.spec.json (schema objects RESTResponsesRenderSection and RESTResponse), cross-checked against the generated Components.Schemas.RESTResponsesRenderSection / Components.Schemas.RESTResponse in Sources/DocCArchive/generated/Types.swift.

FieldTypeRequiredEnum / defaultNote / source
kindstringyesenum: ["restResponses"]Discriminator; generated as RESTResponsesRenderSection.KindPayload, a single-case enum.
titlestringyes—Section heading text; used both as the visible <LinkableHeading> text and (via anchorize) as its DOM anchor id.
itemsarray of RESTResponseyes—Wire name is items; PrimaryContent.vue renames it to the responses prop when instantiating RestResponses.vue. Swift authoring API (RESTResponseRenderSection) names the equivalent property responses with an explicit CodingKeys mapping to items.
RESTResponse.statusnumberyes—HTTP status code. Schema type is JSON number (generated as Swift.Double in DocCArchive's OpenAPI-generated types); swift-docc's own hand-written RESTResponse struct instead uses UInt. Used as the key-by="status" row key in ParametersTable.
RESTResponse.reasonstringno—Plain-text HTTP reason phrase (e.g. "OK"); shown next to the status code and, on small breakpoints, promoted into its own bolded row via the .response-reason style.
RESTResponse.mimeTypestringno—Response content-type. RestResponses.vue's sanitizeResponse also accepts a legacy/lowercase mimetype key from some data sources and re-keys it to mimeType before rendering.
RESTResponse.typearray of DeclarationTokenyes—Declaration-style type tokens for the response body (can link to a documented type). Generated field is named _type in DocCArchive's Types.swift because type collides with the Swift keyword-adjacent property pattern used by the generator; rendered via PossiblyChangedType.vue → DeclarationTokenGroup.vue.
RESTResponse.contentarray of RenderBlockContentnolarge oneOf (paragraph, aside, codeListing, etc.)Free-form prose describing the response; rendered through the generic ContentNode.vue block-content dispatcher, only when present (v-if="content").

Note on required-ness in practice: swift-docc's own hand-written RESTResponse.init(from:) decodes reason, mimeType, and content with decodeIfPresent, matching the schema's optional marking; type and status are decoded unconditionally. swift-docc's unit tests (RESTResponseRenderSectionTests.testDecodingWithoutRESTResponseContent and testDecodingWithoutRESTResponseReason) exercise exactly these two optional-field-omitted cases and pass, confirming the schema's optionality is authoritative and enforced by the authoring-side decoder as well.

4. HTML/CSS mapping in DocC-Render output

RestResponses.vue's template root is a bare <section> (no class), containing a <LinkableHeading> (which renders as an <h2> in this context, with an id equal to the anchorized title and, when linkable, a router-link wrapper carrying class header-anchor) and the shared ParametersTable. ParametersTable.vue renders <div class="parameters-table"> containing one GridRow (<div class="row param">, plus changed changed-{added|removed|modified} when API-diffing is active) per response, each split into two GridColumns (<div class="col param-symbol"> and <div class="col param-content">).

Inside the symbol column, RestResponses.vue's own scoped SCSS (in the same .vue file) adds .response-name (bold status/reason line) and .response-reason (bold reason line shown only in the description column on small breakpoints, via @include breakpoint(small) { display: none / initial } toggles on .response-reason and .response-name > code > .reason respectively — this is the mechanism that moves the reason phrase between the two columns responsively). Type tokens are rendered by PossiblyChangedType.vue as <DeclarationTokenGroup class="property-metadata property-type">, which consumes the CSS custom property --color-figure-gray-secondary for its muted text color.

SCSS files involved: RestResponses.vue (scoped, imports docc-render/styles/_core.scss), ParametersTable.vue (scoped, same import, defines the .param/.param-symbol/.param-content spacing and the change-highlight-target/change-highlight-end-spacing mixins used when a diff/API-changes overlay is active), and PossiblyChangedType.vue (scoped). Custom properties consumed across this chain include --spacing-param, --color-figure-gray-secondary, and (only under the diffing/"changed" state) --colors-grid/--color-grid by way of the shared _core.scss mixins.

5. Modern CSS-only alternative

Not applicable

The actual JS/Vue behavior here is (1) a one-time, render-time dispatch from the JSON discriminator string "restResponses" to the RestResponses component in PrimaryContent.vue's literal lookup object, and (2) inside RestResponses.vue, a pure per-row computed decision (shouldShiftType) about which of two already-rendered slots should display the type declaration, plus a CSS breakpoint toggle (.response-reason / .response-name > code > .reason) that already is plain CSS (@include breakpoint(small) { display: none / initial } media-query rules, not JS state). None of this is a user-driven interactive widget with hidden/revealed state — there is no click-to-expand, tab, or modal behavior anywhere in this component tree; every response row and its full content is always present in the DOM and simply laid out into columns. Because there is no client-side interactive state to replace, none of <details>/<summary>, a radio+:checked sibling selector, :target, the Popover API, or <dialog> apply here; the one piece of "state" that exists (the responsive column-to-row reflow of the reason text) is already implemented with a native mechanism, plain CSS media-query breakpoints, so there is nothing left to port.