Repository navigation
fix: read include / sort support off the family's own vocabulary (#294 follow-up) - #300
Merged
Merged
Conversation
…follow-up) Follow-up to #294 (refs #282) and the shared declared-name walk (closes #297). - The include and sort codecs publish a dedicated internal vocabulary annotation (src/internal/vocabulary.ts), which the error-meta renderer also reads, in place of the generic error-meta annotation. Its shape also covers the page, filter and per-type fields vocabularies. - The support check reads only the decoded property named include / sort, follows unions and Schema.suspend with a visited set, and counts a family unsupported only when every value it can decode draws on an empty vocabulary. A codec with no vocabulary, or a non-empty vocabulary in any union member, keeps it supported. - Middleware.ts imports declaredNames from src/internal/declaredQuery.ts instead of carrying its own copy. - Tests: the hand-built queries the review reproduced, Suspend, the mixed-vocabulary unions, and 406/415 precedence on an empty vocabulary. - Docs and pending changesets: allow-listed empty vocabularies are decoded rather than ignored; empty-vocabulary endpoints now answer 400 where they used to answer 406/415. Claude-Session: https://claude.ai/code/session_0187g2QpzaHqEzX8GJxiJBVc Co-Authored-By: Claude <noreply@anthropic.com>
…r the spec citation The sentence sat between the empty-vocabulary list and "JSON:API 1.1 requires it", so "it" no longer read as the 400. Claude-Session: https://claude.ai/code/session_0187g2QpzaHqEzX8GJxiJBVc Co-Authored-By: Claude <noreply@anthropic.com>
Merged
8 tasks done
This was referenced Oct 9, 2026
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 #294. Refs #282. Closes #297.
This fixes the review findings on merged #294, which applied the owner decision on #282 that an empty
include/sortvocabulary means unsupported. It also swapsMiddleware.ts's private declared-name walk for the shared one from #296 (#297). Behaviour changes only where the review found a misclassification (item 3) and forSuspend(item 2). Item 1's guard keeps its behaviour, and the example apps' GET responses are byte-identical to trunk's (see "Behaviour check" below).1. Should-fix: the untested "no vocabulary" guard and
everyI reproduced the reviewer's result on trunk
4a2ba0f. DroppingArr.isReadonlyArrayNonEmpty(vocabularies) &&passed the whole suite (2539 tests), and so did changingeverytosome.The new
src/Middleware.query.test.tsblock, "which declaredinclude/sortan endpoint supports (#282)", serves hand-built endpoints throughSchemaErrorsLive. Each "supports" case asserts the 200 and the decoded query:include: Query.IncludeList, with a value and with an empty value;sort: Schema.String;includecodec that has no vocabulary;Union([Query.schema(Tag, { include: { paths: [] } }), Query.schema(Post, { include: true })]);sort: Union([Query.Sort([]), Query.Sort(["title"])]);include: Union([Query.Include(Tag), Query.IncludeList]).On trunk, removing the guard fails the
IncludeList, custom-sort and recursive-codec cases. Changingeverytosomefails both union cases.2. Nit:
SuspendThe new walk follows
Suspendboth at query level and inside the family's property. It keeps a per-path visited list, so a recursive schema can't loop it. The tests:Schema.suspend(() => Query.schema(Tag, { include: { paths: [] } }))now answers the unsupported 400, for?include=authorand for?include=. On trunk these gave the codec's 400 and a 200.Schema.suspend(() => Query.Include(Tag))property is treated the same way.3. Design: a dedicated vocabulary annotation, read off the family's own property
src/internal/vocabulary.ts.Query.Includeand the sort codec now publish aVocabularyannotation ({ family, values }) in place of the generic error-meta annotation.internal/errorMeta.tsreads that annotation to rendermeta.includablePaths/meta.sortableFields. The family-to-meta-key mapping lives there, so the renderedmetais unchanged. The genericerrorMeta(...)producer had no other caller, so it is removed.Vocabularyis a union. It already spellspageandfilter, andfieldswith a requiredtype(theTYPEoffields[TYPE]). So the owner-decided 400 for undeclaredfields/page/filter(bug:?include=/?sort=on an endpoint that does not support them is ignored, though the spec makes it a 400 #261) can publish those vocabularies under the same annotation. That change is not implemented here.admitsNoValue(query, family). It reads only the decoded property namedinclude/sort, across union members and throughSuspend. A family is unsupported only when every such property draws all its values from empty vocabularies:undefinedmember, as fromSchema.optional, carries no value);{ include: Query.IncludeList, Other: Query.Include(Tag) }now answers?include=authorwith 200. Trunk answered the unsupported 400.{ include: Query.Include(Tag), other: Query.Include(Post) }now answers?include=authorwith the unsupported 400. Trunk answered the codec's "This endpoint supports no include paths." 400 withmeta. The same holds forsortbeside a non-emptyorder.4. Nits
Middleware.layerand underschemaErrorsLayerbesideContentNegotiationLive./tags/1?include=authorwith a parameterisedAcceptgets the 400, and/tags/1alone gets the 406./tags?sort=with a parameterisedContent-Typegets the 400, and/tagsalone gets the 415. On the commit before fix: treat an include / sort with an empty vocabulary as unsupported (#282) #294 (2521e53sources), the same test gets the 406..changeset/empty-vocabulary-unsupported.mdnow says that such a request with an unacceptableAcceptor unsupportedContent-Typeanswers this 400 where it used to answer 406/415. A second paragraph says only the family's own decoded property counts, followed through unions andSchema.suspend.QueryParameterOptions.allowedQueryParametersdoc, the pendingreject-unsupported-include-sort.mdand the README's "Reserved query parameters" now say the same thing. With the family allow-listed, an endpoint that doesn't declare it ignores it, and one that declares it with an empty vocabulary decodes it, so the codec rejects any path or field. TheSchemaErrorsLivedoc also says which property decides it.5. #297: the shared declared-name walk
src/Middleware.tsnow importsdeclaredNamesfrom./internal/declaredQuery.jsand drops its privatedeclaredNames/familyPrefixand the now-unusedPredicateimport. Behaviour is identical: trunk's private copy anddeclaredQuery.tsdiffer only byexport(I diffed the function bodies). So no differential test is added, because only one implementation is left to test. The existing "what an endpoint's query schema declares" tests (union, suspend, open record) cover the walk.fallow auditno longer reports the clone group (duplication: 0 introduced, 0 inherited).Mutation checks
T0 to T2 ran the new tests against trunk's sources. Every M row applied one mutation alone to the final code. I ran
vp test run src/Middleware.query.test.ts src/Query.test.ts src/Middleware.test.ts(373 tests), then reverted the mutation.d3f63b1sources, unfixed (the new tests only)Middleware.query.test.ts:Include(Tag) | IncludeList,IncludeListbesideOther, the two "beside another name" cases and the threeSuspendcasesIncludeList, custom-sortand recursive-codec casesevery→some(the reviewer's mutation)IncludeList×2, customsort, both union cases and the foreign-family caseevery→some(item 1)sortunion,Include(Tag) | IncludeListevery→someover the propertiessort: true/include: trueover nothingSuspendnot followed at query level (item 2)Suspendnot followed inside the property (item 2)includecodecQuery.Sort([])underincludeundefinedunion member not skippedSchema.optional(Query.Include(Tag))metametatestssome→everysortempty-vocabulary caseBehaviour check
1and2, through 19 query strings, with and without a parameterisedAccept. The query strings includeinclude/sortwith names, empty values and bracketed members, plus unknown,fields,pageandfilterparameters. Responses were compared on status, headers and body. blog (456 requests), github (912) and northwind (1596) were byte-identical between trunk sources and this branch's.vp lintper changed file, trunk → head:src/Middleware.ts37 → 36;src/internal/errorMeta.ts18 → 13;src/internal/vocabulary.ts(new) 0;src/Query.ts144 → 144,src/internal/codecs.ts32 → 32,src/Middleware.query.test.ts1 → 1,test/entry-points.test.ts29 → 29.test/entry-points.test.tslistsinternal/vocabulary.tsinHTTP_TIER. The module useseffectsubpath imports, asdeclaredQuery.tsdoes.Verification
Run one at a time in a fresh clone, at head
4c58211(rebased on trunkd3f63b1; the second commit only moves a sentence in theSchemaErrorsLivedoc, and every gate was re-run on it):pnpm install --frozen-lockfile: passvp run build: pass ("Build complete")vp check: pass ("Found 0 errors and 4333 warnings in 131 files"; no changed file's count rose, see above)vp run check(sources, type-level tests, examples, emitted declarations): pass ("check: every type gate green")vp run -r test:unit: pass (root 2570; examples 45 / 41 / 54)vp run docgen(every JSDoc@examplecompiled and executed): pass ("Docs generation succeeded!", "every class example compiled and ran")fallow audit --base origin/trunk: pass ("No issues in 10 changed files"; it excluded 5 inherited findings: unusedSortTermand the duplicateSortexport incodecs.ts/Query.ts, and complexity inQuery.schema,Middleware.sourceOfand theentry-pointsvisit). Agent gatefallow audit --format json --quiet --explain --gate-marker agent: verdictpass, 0 introduced.Changeset
.changeset/empty-vocabulary-unsupported.md(patch) gains the 406/415 sentence and a paragraph on which property counts..changeset/reject-unsupported-include-sort.mdgets the allow-list wording fix.Suspendfixes refine fix: treat an include / sort with an empty vocabulary as unsupported (#282) #294's unreleased behaviour, so they are described in its entry rather than in a separate one. chore: import the shared query declared-name walk in Middleware.ts #297 alone needs none.Notes
Vocabulary,vocabularyAnnotation,vocabularyOfandadmitsNoValueare@internal.errorMetaOfandErrorMetago back to module-private, as they were before fix: treat an include / sort with an empty vocabulary as unsupported (#282) #294.Suspendalready on the path counts as admitting values. So a recursive codec can never cause a wrong 400, only a missed one.src/internal/schemaExt.ts,src/Resource.undeclared.test.ts(fix: render a null member that declares no fields as "Expected object" (#286) #293's area, merged while this was in progress; the rebase was clean) andsrc/internal/conformance/*.?include=/?sort=on an endpoint that does not support them is ignored, though the spec makes it a 400 #261 follow-up): the 400 for undeclaredfields/page/filter, andallowedQueryParametersrefusing spec family names. Their codecs would publish{ family: "fields", type, values }and thepage/filtervocabularies throughvocabularyAnnotation.https://claude.ai/code/session_0187g2QpzaHqEzX8GJxiJBVc
🤖 Generated with Claude Code
Generated by Claude Code