WARNING
Depends on #1644, still open. Until it merges, this diff also shows its changes and the earlier ones; this pull request's own changes.
Summary
Nothing tells a developer what the v1 API offers but the code. Scramble (a dev dependency) exports it as an OpenAPI 3.1 spec, committed as resources/api/openapi.json and served at /api/v1/openapi.json. Fourth of five pull requests splitting #1533.
Changes
- Export.
composer generate:openapirunsscramble:export, which reads theapi/v1routes, form requests, resources and docblocks. It needs a migrated database (model columns). Nothing generates it at deploy or at runtime: production serves the committed file, and the provider does nothing without Scramble. - Kept in sync.
OpenApiSpecTestexports the spec again and fails when it differs from the committed one. - Transformers in
app/OpenApi: leave out what only the apps use, name path parameters after what routes read, mark signed and optionally signed endpoints, describe 401 and 429 as the API answers them, a request with images as JSON or a signed multipart upload, a commit's optionalpoll, its author, and its body length as links count. - Links. The docs link to the spec from their sidebar and their Introduction.
Endpoints keep Scramble's grouping by controller here; #1646 groups them as the docs list them. You can skip openapi.json (16k generated lines, marked linguist-generated).
| Endpoints documented | 118 |
| Left out | sign-in, the Mac app's update check, live updates, the web session, signed media URLs |
Validation
| Check | Result |
|---|---|
pest --parallel --coverage --exactly=100.0 (full suite) | 6519 passed, 100.0% |
pest --type-coverage --min=100 | 100.0% |
pint --test, rector --dry-run, phpstan | clean |
TSX tests, tsc | 1134 passed, clean |
Visual evidence
Only the docs' links to the spec change on screen: an openapi.json item under elsewhere in the sidebar (one more tab on a phone) and a spec row in the Introduction. Captured on this branch at 1440×900, 1366×650 and 390×844, light and dark: CLS 0 on load, no horizontal overflow, no console error.
| Introduction, 1440 light | 390 dark |
|---|---|
Device verification
Emulation only (390×844, DPR 2, touch): no hardware or simulator.
Independent review
Fresh read-only reviewers, given the guidelines, the stack, the validation results and the captures. A first round on the previous heads found should-fix points (fixtures and options ahead of their PR, the Errors table hiding its meanings on a phone, the Guilds preview, captures from before production's guild fields), all fixed. Re-review on base 1aa85cf4, head 016eac3a: CODE: PASS, VISUAL: PASS, no blocker or should-fix.
Limitations
Scramble can't infer a few things yet; each can be fixed with a targeted transformer.
| Where | What the spec says | Why |
|---|---|---|
POST /remotes/@{handle}/messages, POST /remotes/orgs/{org}/messages | no body | messageRules() is built at runtime |
GET /log/{log} | pending[] and arrived[] are required | Scramble reads the required pending.* items as the list being required, though it is sometimes |
GET /users/{handle} | bio_profiles is a string | (object) cast in UserController |
CallMemberResource, RemoteCandidateResource, OrgThreadResource | a field typed string | Scramble only resolves resources wrapping a class |
whenCounted / when fields such as stars_count | integer | object | Scramble shows MissingValue as an object |
GET /commits/{commit}, GET /users/{handle} | the 200 description names its resource twice | Scramble repeats the resource name |
GET /headlines | data is an array of empty objects | the controller builds its JsonResponse by hand |
| 22 endpoints | no summary | no docblock on their controller method |
Activity
5This pull request is a draft
Merging is unavailable until it is marked ready for review.
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