Repository navigation
Conversation
579c307 to
fec16cd
Compare
Danger ReportNo issues found. |
samsonjs
left a comment
There was a problem hiding this comment.
This changes behaviour of object responses in addition to collections. Previously a namespace root: was ignored and the response key was derived from the returned object's class. This isn't a feature that I use and I'm honestly unsure if this is intentional, but it seems at least worth documenting and adding to the changelog.
Merge serializer options from actual namespace scopes, preserving outer-to-inner precedence, and forward root through render. Document adapter selection, root precedence, empty collections, root:false behavior, and unwrapped arrays. Cover each documented response shape with request-level regressions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
fec16cd to
81bac6b
Compare
|
Keeping this fix collection-only preserves compatibility. For example, with Applying namespace roots uniformly to collections and single objects could be a reasonable long-term API, but that would be a deliberate breaking change for a major release, not part of this collection-root fix. Posted by Copilot, an AI, on behalf of @dblock. |
What this fixes
With the AMS JSON adapter, collections already have a root envelope. This PR fixes two ignored root overrides; it does not introduce collection wrapping or change its defaults.
For example:
{"users": [...]}{"members": [...]}{"user": {...}}{"users": [...]}Explicit collection roots follow inner namespace > outer namespace, route > namespace, and render > route precedence. Empty collections retain an explicit root too.
What stays unchanged
Namespace roots remain collection-only: the earlier draft unintentionally renamed single-object responses, and that regression is removed. Existing route-level roots continue to work. The attributes adapter still returns bare arrays; root:false does not remove the JSON adapter envelope; JSON:API retains its standard data structure. Grape format :json still does not select the AMS adapter.
The implementation reads only namespace root options for collections rather than broadly changing namespace-option handling. Documentation explains adapter selection and precedence, and nine request-level cases cover collection behavior and preservation of single-object roots.
Validation
All 84 examples and RuboCop pass locally with Grape 4 on Ruby 4.0. No dependency changes, new source exclusions, or increased lint limits.
Hosted CI passes the compatibility matrix and lint. Danger also passes.
Closes #81.
Created by Copilot, an AI, on behalf of @dblock.