Skip to content

Fix API documentation and request handling mismatches#391

Open
jbrooksuk wants to merge 1 commit into
mainfrom
fix/api-docs-4618
Open

Fix API documentation and request handling mismatches#391
jbrooksuk wants to merge 1 commit into
mainfrom
fix/api-docs-4618

Conversation

@jbrooksuk

Copy link
Copy Markdown
Member

Fixes cachethq/cachet#4618.

The API reference is generated from this repo via Scramble, so the broken create schedule example (and several similar issues found while reviewing the rest of the API docs) are fixed at the source.

Issues from cachethq/cachet#4618

  1. Errors required an Accept: application/json header — a new ForceJsonResponse middleware now leads the api_middleware group, so the API always returns JSON errors (422/401) instead of HTML redirects. This also resolves the error-handling complaints in Improve API error handling cachet#4587. Note: installs that have already published config/cachet.php need to add the middleware manually.
  2. ISO 8601 dates were rejected despite the docs showing them — schedule and schedule update date fields used a rigid Y-m-d H:i:s cast. A new FlexibleDateTimeCast (Carbon-based) accepts exactly what the date validation rule allows, so the documented ISO example now works as-is.
  3. components[].status appeared optional in the docs — Scramble doesn't translate required_with, so the generated example omitted it. The wildcard rules now use plain required (identical runtime behavior) and the schema emits required: ["id", "status"].

Additional fixes from reviewing the rest of the API docs

  • meta was documented as an array of strings on all create/update endpoints; it's now documented as a nullable key/value object with a description and example.
  • CreateMetricRequestData accepted calc_type, display_chart and places with no validation rules — they were unvalidated and invisible in the docs. Now validated (enum / boolean / int 0–4) and documented.
  • template_vars on incident creation is now documented as a key/value object.
  • Metric point timestamp now documents that it accepts a date/time or Unix timestamp and defaults to now.
  • Date fields now describe their accepted formats.
  • Removed dead bodyParameters() methods left over from Scribe.

Tests

New tests cover ISO 8601 schedule creation, JSON validation errors without an Accept header, rejection of components missing a status, and validation of the new metric fields. Full suite (752 passed) and PHPStan are green.

🤖 Generated with Claude Code

Fixes cachethq/cachet#4618 by correcting the generated OpenAPI docs and
the API behavior they describe:

- Force JSON responses on all API routes so validation and auth errors
  return JSON instead of HTML redirects, without requiring an Accept
  header
- Accept ISO 8601 dates (as documented) for schedule and schedule
  update date fields via a new FlexibleDateTimeCast matching the "date"
  validation rule
- Mark components.*.id and components.*.status as required so the
  generated schema and examples include them
- Document meta and template_vars as key/value objects instead of
  arrays of strings
- Validate and document calc_type, display_chart and places on metric
  creation
- Describe accepted date formats and the metric point timestamp field
- Remove leftover Scribe bodyParameters() methods

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

Fix API documentation example for create schedule

1 participant