#1645

feat: describe the v1 API as an OpenAPI spec, and serve it

Draftjubianchiwants to merge intofrom

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

  1. Export. composer generate:openapi runs scramble:export, which reads the api/v1 routes, 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.
  2. Kept in sync. OpenApiSpecTest exports the spec again and fails when it differs from the committed one.
  3. 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 optional poll, its author, and its body length as links count.
  4. 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 documented118
Left outsign-in, the Mac app's update check, live updates, the web session, signed media URLs

Validation

CheckResult
pest --parallel --coverage --exactly=100.0 (full suite)6519 passed, 100.0%
pest --type-coverage --min=100100.0%
pint --test, rector --dry-run, phpstanclean
TSX tests, tsc1134 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 light390 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.

WhereWhat the spec saysWhy
POST /remotes/@{handle}/messages, POST /remotes/orgs/{org}/messagesno bodymessageRules() is built at runtime
GET /log/{log}pending[] and arrived[] are requiredScramble 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, OrgThreadResourcea field typed stringScramble only resolves resources wrapping a class
whenCounted / when fields such as stars_countinteger | objectScramble shows MissingValue as an object
GET /commits/{commit}, GET /users/{handle}the 200 description names its resource twiceScramble repeats the resource name
GET /headlinesdata is an array of empty objectsthe controller builds its JsonResponse by hand
22 endpointsno summaryno docblock on their controller method

Activity

5
coderabbitai[bot]13d ago

IMPORTANT

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

This pull request is a draft

Merging is unavailable until it is marked ready for review.