fix(api): respect includeReferences query parameter #1049
fix(api): respect includeReferences query parameter #1049ARCoder181105 wants to merge 5 commits into
Conversation
…ping reference queries when false
|
Warning Review limit reached
More reviews will be available in 24 minutes and 57 seconds. Learn how PR review limits work. Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file). ⌛ How to resolve this issue?After more reviews become available, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available. Please see our Fair Usage Limits Policy for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe stop handler now respects the includeReferences query flag: when includeReferences=false the response returns the same stop entry but the references block is present with all arrays empty; when true (default) references are populated as before. ChangesStop Handler includeReferences Query Support
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/restapi/stop_handler_test.go`:
- Around line 534-539: The test omits asserting that references.stopTimes is
empty for the includeReferences=false case; add an assertion like
assert.Empty(t, modelFalse.Data.References.StopTimes, "StopTimes must be empty
when includeReferences=false") in the same block alongside the existing
assertions (referencing modelFalse.Data.References.StopTimes) so the test
verifies all reference arrays per the OpenAPI spec.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: b7fe59ba-4a3e-4ac5-abed-4413ace1391f
📒 Files selected for processing (2)
internal/restapi/stop_handler.gointernal/restapi/stop_handler_test.go
|
@coderabbitai full review |
✅ Action performedFull review finished. |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/restapi/stop_handler.go`:
- Around line 87-103: The includeReferences=true branch in the stop handler
currently ignores errors from GetAgency and returns 200 with partial data;
update the code that calls s.db.GetAgency (in the stop handler function handling
includeReferences) to check the returned error: if err == sql.ErrNoRows return
the same NotFound/404 response used elsewhere, if err != nil return an
operational error/500 (or propagate via the existing error helper), and only add
agency references to the response when GetAgency succeeds; mirror the explicit
error handling used by the other handlers instead of swallowing failures.
- Around line 85-103: references.Agencies is iterated directly causing
nondeterministic ordering; to fix, in the handler that builds stop response
(look for references.Agencies usage in stop_handler.go) first collect the map
keys into a slice, sort that slice (e.g., sort.Strings or appropriate
comparator), then iterate the sorted keys to fetch values and append to the
response so the resulting agencies list is stable across requests; update the
loop that currently ranges over references.Agencies to use the sorted key slice
and append in that deterministic order.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: eed2e230-8243-4b66-b820-1267c2c623e9
📒 Files selected for processing (2)
internal/restapi/stop_handler.gointernal/restapi/stop_handler_test.go
|



Description
This PR resolves the spec gap where the
includeReferencesquery parameter was being ignored, causing the API to unconditionally fetch and populate reference entities.When
includeReferences=falseis requested, thestop_handlernow short-circuits the database queries for routes, agencies, stops, and situations. It returns the required references block with empty arrays, fulfilling the specification requirements and improving endpoint performance.Changes Made
stop_handler.goinside aShouldIncludeReferences(r)condition.TestStopHandler_IncludeReferencesto verify that passingincludeReferences=falsesuccessfully bypasses the reference lookups without affecting the mainentrypayload.Closes: #1047
Summary by CodeRabbit
New Features
Tests