Skip to content

Standardise API date range validation - #1673

Open
skyfallwastaken wants to merge 2 commits into
mainfrom
fix/consistent-api-date-parsing-20260901
Open

Standardise API date range validation#1673
skyfallwastaken wants to merge 2 commits into
mainfrom
fix/consistent-api-date-parsing-20260901

Conversation

@skyfallwastaken

@skyfallwastaken skyfallwastaken commented Sep 1, 2026

Copy link
Copy Markdown
Member

Summary of the problem

API date ranges are parsed differently across hours, heartbeats, summary and stats endpoints. Malformed values can raise, be ignored or return inconsistent errors, while reversed ranges are accepted. Project discovery also skips malformed aliases and the aggregate stats error responses are documented with the wrong media type.

Describe your changes

Centralise range validation in the existing DateParsing controller concern while preserving each endpoint's documented formats, aliases and defaults. Malformed, incomplete and reversed supplied ranges now return the same 400 JSON error. Validate project discovery aliases at the controller boundary while preserving their precedence and 30-day defaults. Keep the aggregate stats success response as text while documenting its errors as JSON. Add request and Rswag coverage, then regenerate Swagger.

Screenshots / Media

Not applicable. This is an API-only change.

@greptile-apps

greptile-apps Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR centralizes API date-range parsing and validation while retaining endpoint-specific formats, aliases, and defaults.

  • Adds shared malformed, incomplete, and reversed-range validation through DateParsing.
  • Applies the shared validation to summary, hours, heartbeat, and stats endpoints.
  • Adds request, controller, and generated Swagger coverage for the standardized responses.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
app/controllers/concerns/date_parsing.rb Introduces the shared range parser, ordering validation, and standardized bad-request response.
app/controllers/api/summary_controller.rb Routes explicit summary ranges through shared validation and stops processing after rendered errors.
app/controllers/api/v1/authenticated/hours_controller.rb Replaces independent date conversion with shared range parsing while preserving defaults.
app/controllers/api/v1/my/heartbeats_controller.rb Validates heartbeat time bounds consistently before querying the authenticated user's records.
app/controllers/api/v1/stats_controller.rb Applies shared validation across global, user, span, and project-stat date ranges.
swagger/v1/swagger.yaml Regenerates API documentation for standardized invalid-range responses.

Reviews (2): Last reviewed commit: "Validate project discovery date ranges" | Re-trigger Greptile

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.

1 participant