Skip to content
This repository was archived by the owner on Sep 23, 2026. It is now read-only.
This repository was archived by the owner on Sep 23, 2026. It is now read-only.

Paginated read drops items when the list response body is a top-level array #6

Description

@michielbdejong

Problem

fetchAllItems (src/client/client.ts) only extracts items from an enveloped response when a pagination scheme applies:

const itemsField = locateItemsField(responseSchema, scheme);
// ...
const { body, headers } = await requestJsonWithHeaders(url);
const pageItems = itemsField ? body[itemsField] : undefined;
if (Array.isArray(pageItems)) {
  items.push(...(pageItems as Record<string, unknown>[]));
}

When the response body is a top-level array ([ {...}, {...} ]), the 200 response schema is type: array, so locateItemsField returns undefined (it only inspects object properties / common envelope field names). itemsField is therefore undefined, pageItems is undefined, and nothing is pushed — the paginated walk visits every page but collects zero items.

The non-paginated path already handles this case:

const items = Array.isArray(body)
  ? (body as Record<string, unknown>[])
  : extractItemsFromEnvelope(body, responseSchema);

but the paginated path has no equivalent bare-array fallback.

Why it matters here

This is the common shape for GitHub REST list endpoints: GET /repos/{owner}/{repo}/issues and GET /repos/{owner}/{repo}/issues/{issue_number}/comments both return a bare JSON array and paginate via the Link header. The existing GitHub nextLink pagination scheme (github.com/api.github.com/1.1.4/pagination-overlay.yaml in localthought/overlays) auto-detects on the Link header, so these lists go through fetchAllItems — and today come back empty. Reflector can't list issues or comments to reflect them (localthought/reflector#23, #25, #28) until this is fixed.

Request

In fetchAllItems, when the page body is an array, treat the body itself as the page's items (mirroring fetchCollectionSnapshot):

const pageItems = Array.isArray(body)
  ? body
  : itemsField
    ? body[itemsField]
    : undefined;

Acceptance

  • A paginated GET whose body is a top-level array (with a Link-header nextLink scheme) collects items across all pages.
  • Enveloped responses are unchanged.
  • Test covering a multi-page bare-array response.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions