Fix API documentation and request handling mismatches#391
Open
jbrooksuk wants to merge 1 commit into
Open
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes cachethq/cachet#4618.
The API reference is generated from this repo via Scramble, so the broken
create scheduleexample (and several similar issues found while reviewing the rest of the API docs) are fixed at the source.Issues from cachethq/cachet#4618
Accept: application/jsonheader — a newForceJsonResponsemiddleware now leads theapi_middlewaregroup, 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 publishedconfig/cachet.phpneed to add the middleware manually.Y-m-d H:i:scast. A newFlexibleDateTimeCast(Carbon-based) accepts exactly what thedatevalidation rule allows, so the documented ISO example now works as-is.components[].statusappeared optional in the docs — Scramble doesn't translaterequired_with, so the generated example omitted it. The wildcard rules now use plainrequired(identical runtime behavior) and the schema emitsrequired: ["id", "status"].Additional fixes from reviewing the rest of the API docs
metawas 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.CreateMetricRequestDataacceptedcalc_type,display_chartandplaceswith no validation rules — they were unvalidated and invisible in the docs. Now validated (enum / boolean / int 0–4) and documented.template_varson incident creation is now documented as a key/value object.timestampnow documents that it accepts a date/time or Unix timestamp and defaults to now.bodyParameters()methods left over from Scribe.Tests
New tests cover ISO 8601 schedule creation, JSON validation errors without an
Acceptheader, 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