Skip to content

Add includeTrip parameter to trips-for-route - #1217

Merged
burma-shave merged 3 commits into
OneBusAway:mainfrom
3rabiii:fix-trips-for-route-gap2
Jul 31, 2026
Merged

Add includeTrip parameter to trips-for-route#1217
burma-shave merged 3 commits into
OneBusAway:mainfrom
3rabiii:fix-trips-for-route-gap2

Conversation

@3rabiii

@3rabiii 3rabiii commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Implements the includeTrip query parameter for the trips-for-route endpoint. Previously, the handler conflated includeTrip with includeSchedule, passing the wrong flag to buildTripReferences. This caused includeTrip=false to be silently ignored and includeSchedule=false to incorrectly drop trip beans from data.references.trips.

Changes

  • internal/restapi/trips_for_route_handler.go:
    • Added includeTrip parsing alongside the existing includeSchedule and includeStatus parameters (defaults to true).
    • Updated the buildTripReferences calls in both the early empty-list return path and the main response path to use includeTrip instead of includeSchedule.
  • internal/restapi/trips_for_route_handler_test.go:
    • Added a new table-driven test TestTripsForRouteHandler_TripInclusion with four cases: default inclusion, explicit inclusion, explicit exclusion, and a regression guard (excluding schedule but keeping trips).

Closes: #1208

Summary by CodeRabbit

  • New Features

    • Added an includeTrip option for controlling trip references in trips-for-route responses.
    • Trip references are included by default and support explicit true/false values.
  • Bug Fixes

    • Standardized trip-reference handling across response formats.
    • Preserved trip identifiers on returned trip entries regardless of reference inclusion settings.
    • Improved handling of uppercase and numeric option values.

The trips-for-route handler previously conflated the includeTrip
parameter with includeSchedule. It passed includeSchedule to the
buildTripReferences function as the trip-beans flag. This caused
includeTrip=false to have no effect, and includeSchedule=false to
wrongly drop trip beans from the references block.

This commit parses includeTrip from the query parameters with a
default of true, and passes it independently to buildTripReferences.
Both the empty-list and main response paths are updated.

Table-driven tests are added to verify all inclusion combinations
and guard against future regressions.
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 5e93c63c-4e92-4ccb-97d4-794cd87cbbbc

📥 Commits

Reviewing files that changed from the base of the PR and between b9e5863 and 184491b.

📒 Files selected for processing (2)
  • internal/restapi/trips_for_route_handler.go
  • internal/restapi/trips_for_route_handler_test.go

📝 Walkthrough

Walkthrough

The trips-for-route handler now reads includeTrip independently from includeSchedule, defaults it to true, and uses it to control trip references. Table-driven tests verify reference counts and preserve trip IDs in list entries.

Changes

Trip reference inclusion

Layer / File(s) Summary
Handler includeTrip control
internal/restapi/trips_for_route_handler.go
The handler parses includeTrip with a true default and applies it when building trip references in both response paths.
Trip inclusion validation
internal/restapi/trips_for_route_handler_test.go
Table-driven tests cover default, false-like, and includeSchedule combinations. They verify successful responses, reference counts, and non-empty list-entry trip IDs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: burma-shave, ahmedhossamdev, arcoder181105

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: adding the includeTrip parameter to the trips-for-route endpoint.
Linked Issues check ✅ Passed The implementation independently parses includeTrip, defaults it to true, preserves tripId values, and prevents includeSchedule from controlling trip beans [#1208].
Out of Scope Changes check ✅ Passed The code and tests directly support the includeTrip behavior required by the linked issue, with no unrelated changes identified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/trips_for_route_handler.go`:
- Line 32: Replace the direct includeTrip string comparison in the route handler
with the shared parseIncludeTrip logic used by the location handler, preserving
its handling of false, zero, case variants, and malformed values. Add regression
coverage for invalid and case-variant includeTrip query values.
🪄 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: Repository UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 7a531cfc-3a82-4e00-815c-312c106ae16f

📥 Commits

Reviewing files that changed from the base of the PR and between 5d59661 and b9e5863.

📒 Files selected for processing (2)
  • internal/restapi/trips_for_route_handler.go
  • internal/restapi/trips_for_route_handler_test.go

Comment thread internal/restapi/trips_for_route_handler.go Outdated
Addresses automated review feedback to use the shared parseIncludeTrip
function, which correctly handles case-variants and numeric boolean
values (e.g., 'FALSE', '0') unlike the naive string comparison.
Added corresponding test cases.
@aaronbrethorst

Copy link
Copy Markdown
Member

@3rabiii this has merge conflicts

@aaronbrethorst

Copy link
Copy Markdown
Member

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

🤖 Generated with Claude Code

@aaronbrethorst aaronbrethorst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved on the merits — this is a good catch and a clean fix.

The bug is a genuinely sneaky one: buildTripReferences's third parameter is already named includeTrip and gates references.trips, but the handler was passing includeSchedule into it. So includeSchedule=false was silently also emptying the trip references, and includeTrip did nothing at all. Two conflated flags in one argument position is exactly the kind of thing that survives review by looking correct at the call site.

I checked the behavior against the spec and it lines up:

  • includeTrip defaults to true when the parameter is omitted, which is what the spec requires.
  • With includeTrip=false, references.trips is empty but data.list[].tripId is still populated — that's spec extension 5a verbatim ("the trip ID is still present in the list entry but no detail is available in references"). Your test asserts both halves, which is the part that matters.
  • Reusing the existing parseIncludeTrip helper instead of hand-rolling a string comparison was the right call.

The table-driven test covering omitted / true / false / FALSE / 0 plus an includeSchedule=false regression guard is more thorough than I'd have asked for.

One thing before this can land: it has merge conflicts. Since you opened it, main wrapped both buildTripReferences call sites in an if includeReferences { ... } block. The conflict is purely textual — the same one-argument swap re-applies cleanly on the other side of that guard — so no re-review needed once it's rebased. Please merge main in and resolve, and I'll merge it.

One non-blocking observation for whenever you or someone else is next in this area: parseIncludeTrip returns false for a present-but-malformed value (includeTrip=yes, or an empty includeTrip=), whereas the analogous ShouldIncludeReferences falls back to the documented default on a parse failure. Since the documented default here is true, malformed input currently drops all trip references silently. That's pre-existing behavior in the shared helper and reusing it was correct, so I don't want it in this PR — just worth knowing it's there.

# Conflicts:
#	internal/restapi/trips_for_route_handler.go
@sonarqubecloud

Copy link
Copy Markdown

@burma-shave
burma-shave merged commit d702de2 into OneBusAway:main Jul 31, 2026
9 checks passed
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.

includeTrip parameter is not implemented

3 participants