Repository navigation
docs, test: #280 review follow-ups (include / sort 400 citations, precedence tests) - #283
Merged
Merged
Conversation
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>
9 tasks done
This was referenced Oct 8, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #280. Refs #261.
These are the review follow-ups to #280, which made
include/sorton 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
7bc44ecbefore editing.1. Spec citation for
sorton a single-resource endpoint. The pending changesetreject-unsupported-include-sort.md, theSchemaErrorsLivedoc comment and the README "Query parameters" paragraph cited §Sorting forGET /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 insrc/Middleware.tsmade the same claim, and I corrected all four: the module header, theSUPPORT_FAMILIEScomment,checkQueryParametersandschemaErrorsLayer. So did the comment heading the #261 test block. The runtime detail strings are unchanged.Quoted from the spec source,
_format/1.1/index.mdonjson-api/json-apigh-pages(bde79ce):includeparameter, it MUST respond with400 Bad Requestto any requests that include it."sort, it MUST return400 Bad Request."400 Bad Request."2.
.changeset/reject-reserved-query-parameters.md(pending, 0.17.0). Its parenthetical listedinclude, fields, sort, page, filteras spec-defined names that pass through. It now listsfields,pageandfilter, 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
includeorsortinallowedQueryParametersswitches 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. TheQueryParameterOptionsJSDoc already says this. No other README text changed apart from the citation in item 1.4. Tests (
src/Middleware.query.test.ts).describe("is decided before content negotiation")sits inside the bug:?include=/?sort=on an endpoint that does not support them is ignored, though the spec makes it a 400 #261 block and matches Unknown query parameters are ignored rather than rejected, though the spec makes an all-lowercase unrecognised name a 400 #148's 406 test.GET /posts/1?sort=titlewith a parameterisedAcceptanswers the 400, and withoutsortthe same request is the 406.GET /people/1?include=authorwith a parameterisedContent-Typeanswers the 400, and withoutincludeit's the 415. Each case runs underMiddleware.layerand withschemaErrorsLayer()wired directly besideContentNegotiationLive.Arr.dedupe. The HTTP case?include=author&include=authorcouldn't catch a droppedArr.dedupe. The middleware reads the keys of the parsed search params record, which are already unique, so the case passed with dedupe removed. I replaced it with acheckQueryParameterscase overURLSearchParams("include=a&sort=x&include=a&sort=y").keys(), which yields a repeated key once per occurrence. That case expects one error each forincludeandsort. Unknown query parameters are ignored rather than rejected, though the spec makes an all-lowercase unrecognised name a 400 #148's HTTP repeated-key case still covers the HTTP-level behaviour.5. Review nits (second commit).
reject-unsupported-include-sort.mdthe 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.Middleware.layerWith({ allowedQueryParameters: ["sort"] }),GET /posts?sort=titleonEndpoint.list(Post, { sort: true })answers 200, and the handler's decoded query is{ sort: [{ field: "title", direction: "asc" }] }, not{}.GET /posts?sort=nopeis still the codec's 400 namingsort. The existing allowed-family test only covered the undeclared side.Issue edits and filings.
include/sorton an endpoint that does not declare them (#261) #278 body: I removed the sentence saying the work was deferred because bug: a write fixture that throws an unstringifiable value is reported as Errored, not Skipped #271 was editing the kit (bug: a write fixture that throws an unstringifiable value is reported as Errored, not Skipped #271 is closed, fixed by fix(Conformance): render a throwing write fixture's value totally (#271) #277). I added a bullet saying thesortprobe should target a collection endpoint withoutsort, quoting the two rules above. Its footer is kept. feat(Conformance): probeinclude/sorton an endpoint that does not declare them (#261) #278 is not implemented here.include/sortwith an empty vocabulary is rejected with detail "Expected never" #282 (bug): aninclude/sortwith an empty vocabulary is rejected withdetail: "Expected never". I reproduced it on trunk forinclude: trueon a resource with no relationships, forinclude: { paths: [] }, and forsort: trueon a resource with no attributes. The status,source.parameterandmeta.includablePaths: []/meta.sortableFields: []are fine; only the detail is unhelpful. I checked open and closed issues for a duplicate first and found none. The fix is not part of this PR.Verification
All gates ran in a fresh clone, one at a time, on the tree committed as the head commit:
pnpm install --frozen-lockfile: passvp run build: pass ("Build complete")vp check: pass. 0 errors, 4340 warnings, all existing warn-tier debt. The per-rule warning counts forsrc/Middleware.tsandsrc/Middleware.query.test.tsare 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@examplecompiled 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, thesourceOfCRAP score insrc/Middleware.ts). Agent gatefallow audit --format json --quiet --explain --gate-marker agent: verdictpass.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 checkagain 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):SPEC_FAMILIESrestored to the five families (include / sort passed through again): 17 fail, including all four new precedence cases and the new dedupe case..middleware(ContentNegotiation)/.middleware(SchemaErrors)order swapped insrc/Endpoint.ts(negotiation outer): 5 fail. These are the four new precedence cases and Unknown query parameters are ignored rather than rejected, though the spec makes an all-lowercase unrecognised name a 400 #148's 406 case.Arr.dedupedropped inrejectQueryParameters: 2 fail, the newinclude/sortcase and the existingURLSearchParams#keyscase. Before this change, the same mutation failed only theURLSearchParams#keyscase (1 of 80). The removed HTTP case and Unknown query parameters are ignored rather than rejected, though the spec makes an all-lowercase unrecognised name a 400 #148's HTTP repeated-key case both passed under it.schemaErrorsLayerstrips allowed names fromParsedSearchParamsbefore the endpoint decodes (item 5): 1 of 85 fails, the new test (expected [ {} ] to deeply equal [ { sort: [ … ] } ]). The existing allowed-family test passes under this mutation. With the 200 / decoded-query assertions removed, the?sort=nopeassertion alone also fails under it (expected 200 to be 400).Changeset
reject-unsupported-include-sort.md,reject-reserved-query-parameters.md), and published behaviour is unchanged.Notes
sortanywhere else. The 400 itself is unchanged.fields/page/filtershould get a 400; whether the allow-list may admitinclude/sort; whethersort: []andsort: truewith no attributes should behave the same. bug: aninclude/sortwith an empty vocabulary is rejected with detail "Expected never" #282 is written so it doesn't decide the last one.?include=/?sort=on an endpoint that does not support them is ignored, though the spec makes it a 400 #261's state: the GitHub API shows bug:?include=/?sort=on an endpoint that does not support them is ignored, though the spec makes it a 400 #261 as open. This PR only references it and doesn't close it.🤖 Generated with Claude Code
Generated by Claude Code