Skip to content

docs, test: #280 review follow-ups (include / sort 400 citations, precedence tests) - #283

Merged
thomasfosterau merged 2 commits into
trunkfrom
issue-261-include-sort-followup
Oct 8, 2026
Merged

thomasfosterau merged 2 commits into
trunkfrom
issue-261-include-sort-followup

Conversation

@thomasfosterau

@thomasfosterau thomasfosterau commented Oct 8, 2026 •

Copy link
Copy Markdown
Owner

Summary

Follow-up to #280. Refs #261.

These are the review follow-ups to #280, which made include / sort on an endpoint that doesn't declare them answer 400. The changes are docs, pending changeset text and tests only. Runtime behaviour doesn't change.

Each item was checked on trunk 7bc44ec before editing.

1. Spec citation for sort on a single-resource endpoint. The pending changeset reject-unsupported-include-sort.md, the SchemaErrorsLive doc comment and the README "Query parameters" paragraph cited §Sorting for GET /articles/1?sort=title. §Sorting's MUST only covers collection endpoints. They now cite both sections: §Sorting for an endpoint that responds with a resource collection, and the general §Implementation-Specific Query Parameters rule for any other endpoint. Four places in src/Middleware.ts made the same claim, and I corrected all four: the module header, the SUPPORT_FAMILIES comment, checkQueryParameters and schemaErrorsLayer. So did the comment heading the #261 test block. The runtime detail strings are unchanged.

Quoted from the spec source, _format/1.1/index.md on json-api/json-api gh-pages (bde79ce):

  • L1241-1242, §Inclusion of Related Resources: "If an endpoint does not support the include parameter, it MUST respond with 400 Bad Request to any requests that include it."
  • L1388-1389, §Sorting: "If the server does not support sorting as specified in the query parameter sort, it MUST return 400 Bad Request."
  • L1397-1398, the same section's scope: "Note: This section applies to any endpoint that responds with a resource collection as primary data, regardless of the request type."
  • L2124-2126, §Implementation-Specific Query Parameters: "If a server encounters a query parameter that does not follow the naming conventions above, or the server does not know how to process it as a query parameter from this specification, it MUST return 400 Bad Request."

2. .changeset/reject-reserved-query-parameters.md (pending, 0.17.0). Its parenthetical listed include, fields, sort, page, filter as spec-defined names that pass through. It now lists fields, page and filter, and points to the separate include / sort entry. Without this, the 0.17.0 CHANGELOG would seem to contradict itself.

3. README "Reserved query parameters". I added one sentence there. Listing include or sort in allowedQueryParameters switches off the specification's 400 for that family on every endpoint that doesn't declare it, and that endpoint then ignores the parameter. An endpoint that declares it still decodes it. The QueryParameterOptions JSDoc already says this. No other README text changed apart from the citation in item 1.

4. Tests (src/Middleware.query.test.ts).

5. Review nits (second commit).

  • Changeset punctuation. In reject-unsupported-include-sort.md the quoted §Sorting sentence ended …return \400 Bad Request`." (that section "applies to …"). For`, which is double punctuation. The period inside the quote is dropped, so the sentence now ends after the parenthetical.
  • "An endpoint that declares it still decodes it" is now pinned. Under Middleware.layerWith({ allowedQueryParameters: ["sort"] }), GET /posts?sort=title on Endpoint.list(Post, { sort: true }) answers 200, and the handler's decoded query is { sort: [{ field: "title", direction: "asc" }] }, not {}. GET /posts?sort=nope is still the codec's 400 naming sort. The existing allowed-family test only covered the undeclared side.

Issue edits and filings.

Verification

All gates ran in a fresh clone, one at a time, on the tree committed as the head commit:

  • pnpm install --frozen-lockfile: pass
  • vp run build: pass ("Build complete")
  • vp check: pass. 0 errors, 4340 warnings, all existing warn-tier debt. The per-rule warning counts for src/Middleware.ts and src/Middleware.query.test.ts are identical with the trunk and head versions of the two files, so this adds no warn-tier site.
  • vp run check (sources, type-level tests, examples, emitted declarations): pass ("check: every type gate green")
  • vp run -r test:unit: pass. Root: 2356 tests. Examples: 45 / 41 / 54.
  • vp run docgen (every JSDoc @example compiled and executed): pass (224 examples, "Docs generation succeeded!")
  • fallow audit --base origin/trunk: pass ("No issues in 5 changed files"; the gate excluded one inherited finding, the sourceOf CRAP score in src/Middleware.ts). Agent gate fallow audit --format json --quiet --explain --gate-marker agent: verdict pass.

All gates were re-run, in the same order and with the same results, on the head commit after the review nits (item 5). vp check again reports 0 errors and 4340 warnings, and the root suite now has 2356 tests.

Mutation checks (vp test run src/Middleware.query.test.ts, 84 tests on the first commit and 85 on head, each mutation reverted afterwards):

Changeset

  • No new changeset. This changes only docs, tests and the text of two pending changesets (reject-unsupported-include-sort.md, reject-reserved-query-parameters.md), and published behaviour is unchanged.

Notes

🤖 Generated with Claude Code


Generated by Claude Code

claude added 2 commits October 8, 2026 13:31
Cite JSON:API 1.1 precisely for `sort` on an endpoint that does not
declare it: §Sorting covers an endpoint that responds with a resource
collection, and on a single-resource endpoint the 400 rests on the
general §Implementation-Specific Query Parameters rule. Updated in the
pending changeset, the SchemaErrorsLive / schemaErrorsLayer /
checkQueryParameters doc comments and the README.

The pending reserved-query-parameters changeset now lists only
`fields`, `page` and `filter` as passed through, and points to the
include / sort entry. The README's "Reserved query parameters" section
says that listing `include` or `sort` in `allowedQueryParameters` turns
off the 400 for that family on an endpoint that does not declare it.

Tests: `include` / `sort` beat a 406 and a 415, under Middleware.layer
and with schemaErrorsLayer wired directly. The HTTP repeated-key case,
which a dropped `Arr.dedupe` cannot fail (the middleware reads record
keys), is replaced by a checkQueryParameters case over
URLSearchParams#keys, which it does.

Refs #261.

Claude-Session: https://claude.ai/code/session_0187g2QpzaHqEzX8GJxiJBVc
Co-Authored-By: Claude <noreply@anthropic.com>
… sort)

Drop the period inside the quoted §Sorting sentence in the
reject-unsupported-include-sort changeset, so the parenthetical that
follows it no longer leaves double punctuation.

Pin the README claim that listing `sort` in allowedQueryParameters
leaves an endpoint that declares it decoding it: `/posts?sort=title`
answers 200 with the decoded sort, and `/posts?sort=nope` is still the
codec's 400.

Refs #261.

Claude-Session: https://claude.ai/code/session_0187g2QpzaHqEzX8GJxiJBVc
Co-Authored-By: Claude <noreply@anthropic.com>
@thomasfosterau
thomasfosterau merged commit 1d27e89 into trunk Oct 8, 2026
1 check passed
@thomasfosterau
thomasfosterau deleted the issue-261-include-sort-followup branch October 8, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants