fix(openapi): align arrivals-and-departures-for-stop time + arrival m…#725
Conversation
aaronbrethorst left a comment
There was a problem hiding this comment.
Aditya, thanks for digging into the spec and finding the time parameter format mismatch and the interface{} fields — both are legitimate spec-compliance issues worth fixing. However, there's a conflict with an in-flight PR that needs to be resolved first.
Critical Issues (1 found)
-
Frequencyfield change from*Frequencytostringconflicts with open PR #680This PR changes
ArrivalAndDeparture.Frequencyfrom*Frequency(struct pointer) tostringwithomitempty. While the OpenAPI spec does sayfrequency: type: string, PR #680 (GTFS Frequencies Phase 3) is actively building on the*Frequencytype — it populates this field with real frequency data:// PR #680, arrivals_and_departure_for_stop.go: arrival.Frequency = api.lookupTripFrequency(ctx, tripID, serviceMidnight, currentTime) // returns *models.Frequency
// PR #680, arrival_and_departure_for_stop_handler.go: arrival.Frequency = &freq // where freq is models.Frequency
If this PR merges first, PR #680 will fail to compile. If #680 merges first, this PR will have merge conflicts. These two PRs need to be coordinated.
The OpenAPI spec says
type: string, but this appears to be an under-specification — the production OBA Java server returns frequency as a structured object (FrequencyBean) when present, not a string. The spec likely inherited a simplified representation. The real behavior is closer to what #680 implements.Resolution options:
Important Issues (1 found)
-
The singular
arrival-and-departure-for-stophandler still parsestimeas Unix msThis PR fixes the plural handler (
arrivals_and_departure_for_stop.go) to parsetimeas RFC3339, but the singular handler (arrival_and_departure_for_stop_handler.go:58) still usesstrconv.ParseInt:// arrival_and_departure_for_stop_handler.go:58 — still Unix ms if timeMs, err := strconv.ParseInt(timeStr, 10, 64); err == nil {
Interestingly, the OpenAPI spec itself has different types for these two endpoints:
- Plural endpoint:
time: type: string, format: date-time(RFC3339) - Singular endpoint:
time: type: integer(Unix ms)
So the singular handler is actually correct per its own spec entry. However, this inconsistency between the two endpoints is worth noting in the PR description so future readers understand it's intentional, not an oversight.
- Plural endpoint:
Suggestions (1 found)
-
The
omitemptychanges on interval fields are correct but deserve a noteChanging
PredictedArrivalInterval,PredictedDepartureInterval,ScheduledArrivalInterval, andScheduledDepartureIntervalfrominterface{}(serialized asnull) tostringwithomitempty(omitted entirely) changes the JSON wire format. Previously clients received"predictedArrivalInterval": null; now they won't see the field at all when empty. This is spec-compliant (the fields aren't markedrequired), but any clients relying on the key being present may break. Worth noting in the PR description.
Strengths
- The
timeparameter fix to RFC3339 is correct per the OpenAPI spec for this endpoint - Good use of
url.QueryEscapein tests for RFC3339 values containing+characters - The new conformance test for
arrivals-and-departures-for-stopis a valuable addition - The
omitemptytest (TestArrivalAndDepartureJSON) properly verifies the fields are absent from marshaled JSON
Align
arrivals-and-departures-for-stopwith OpenAPI spec + fixArrivalAndDepartureschema driftFixes #724
Problem
timeas Unix milliseconds instead of RFC3339date-timeas the OpenAPI spec requires, breaking spec-compliant requests.ArrivalAndDeparturemodel had drifted from the OpenAPIArrivalDepartureForStopschema (interface{}/null shapes, missingomitemptyon optional fields).Changes
Handler (
arrivals_and_departure_for_stop.go)timeas RFC3339 only; return 400 on invalid input.Handler Tests (
arrivals_and_departures_for_stop_handler_test.go)timeas RFC3339 and URL-escape values so+05:30offsets aren't decoded as spaces.Model (
arrival_and_departure.go)interface{}/null fields withstring; addomitemptyon optional fields to match spec.Model Tests (
arrival_and_departure_test.go)Conformance (
openapi_conformance_test.go)testdata/openapi.yml.Notes
testdata/openapi.ymlis unchanged — all fixes are implementation-side only.Validation Passed
make test