Skip to content

feat(api): serve every API path under /api/v1, problem details and an OpenAPI document - #1598

Merged
rubenvdlinde merged 5 commits into
developmentfrom
quality/api-v1-hermiq
Nov 13, 2026
Merged

rubenvdlinde merged 5 commits into
developmentfrom
quality/api-v1-hermiq

Conversation

@rubenvdlinde

Copy link
Copy Markdown
Contributor

What

Hermiq's own JSON API now follows the NL API Design Rules that hold for every endpoint, using the scheme OpenRegister introduced (ConductionNL/openregister#9985 for problem details, ConductionNL/openregister#9995 for /api/v1 paths), adapted to the fleet's ApiContractMiddleware.

  • Versioned paths (/core/uri-version): appinfo/routes.php passes its table through ApiPathAliases::withVersionedAliases(), which adds a /api/v1/ twin of every unversioned API route with the same controller, requirements and defaults, under a v1 postfix. The twins come right after the last route the app already declares under /api/v1/ (so those keep their paths) and before everything else (so no /api/{slug} route or catch-all can answer a /api/v1/ request).
  • Deprecation (/core/deprecation-schedule): a response on an unversioned path keeps its answer and gains Deprecation: @1794441600 (2026-11-12) and Link: </index.php/apps/hermiq/api/v1/...>; rel="successor-version".
  • Problem details (RFC 9457) and API-Version on every API response, by ApiContractMiddleware, registered first so it sees the final response of every other middleware. Error bodies keep every member they had.
  • External protocol paths stay excluded, as decided: MCP, inbound agent webhooks, server-sent event streams, the health check and the Prometheus metrics. They get no alias, no deprecation, no version header and no problem details rewrite (lib/Middleware/Support/StandardProtocolPaths.php).
  • openapi.json (new): OpenAPI 3.0.3, server https://{host}/index.php/apps/hermiq/api/v1, 225 operations drawn from appinfo/routes.php and the controllers (docblocks, signatures, status codes, auth attributes), served at GET /api/v1/openapi.json (public, Access-Control-Allow-Origin: *).
  • openspec/specs/api-contract/spec.md describes the contract.

Tests

  • ApiContractMiddlewareTest: version header, problem details, deprecation and successor headers, no deprecation on a versioned path, protocol paths untouched.
  • ApiPathAliasesTest: successors; alias placement; the API fallback gets no alias; route parity: every deprecated route of the shipped table has a /api/v1/ twin with the same name, requirements and defaults, and a request on the twin's path reaches it (the router is simulated in declaration order); no alias takes a request meant for a declared versioned route.
  • OpenApiDocumentTest: the server is versioned, and openapi.json and routes.php describe the same versioned operations, both ways.
  • OpenApiControllerTest: the document is served publicly with CORS, 404 when missing.

Verified locally

  • hydra/scripts/diff-check.sh --base origin/development: php -l, phpcs, phpstan and phpunit green on the changed files.
  • composer check:strict once: lint, phpcs and psalm green; phpmd and phpstan red on inherited findings; PHPUnit see below.
  • Checker CLI (npm run scan:local -- <checkout> --register --api-spec openapi.json): openapi fail (no specification) before, pass after; adrvalidator warn (no specification) before, pass after (Spectral with the ADR ruleset: 0 errors, 0 warnings).
  • The register golden (tests/Fixtures/Golden/application-registrations.json) is re-recorded: it now starts with the ApiContractMiddleware registration.
  • The check:strict PHPUnit run reported 142 errors and 26 more failures, all from tests that refuse the OpenRegister analysis stubs (ToolGrantResolver, ToolGrantSet) when no openregister checkout sits beside the app. With one beside it, the affected classes (McpRun, ToolCatalog, ToolDetailDrive, ToolOversight, AgentWaiverChangeListener, ToolLoop, OutsideAgentGateway) all pass.
  • Inherited, not touched by this change: phpmd and phpstan findings elsewhere.

Notes

  • Assumption: the deprecation date is the day this lands (2026-11-12); no sunset date is announced yet.
  • The alias, protocol-path and middleware code is the same across the fleet apps that get this change. It could move to nextcloud-vue's PHP side or a common package later; for now each app carries its own copy so none depends on another app's internals.
  • openapi.json is generated from the routes and controllers, so response schemas are generic ({}); it describes paths, parameters, auth, status codes and media types, not body shapes.

This change was prepared with AI assistance (Claude Code) and reviewed before submission.

OpenAPI document

Hermiq's own JSON API now follows the NL API Design Rules that hold for
every endpoint:

- every route under /api/ is also served under /api/v1/, with the same
  controller, requirements and defaults; the unversioned paths keep
  answering and announce their successor with a Deprecation header
  (@1794441600, 2026-11-12) and a Link header with rel="successor-version";
- every API response carries API-Version, the installed version;
- a JSON error response is served as application/problem+json with type,
  title, status and detail, keeping every member it already had;
- GET /api/v1/openapi.json serves openapi.json, public, with
  Access-Control-Allow-Origin: *.

External protocol paths (MCP, inbound agent webhooks, server-sent event
streams, the health check and the Prometheus metrics) are left alone: no
alias, no version
header, no problem details rewrite.

openapi.json is new: it describes the 225 versioned operations, drawn from
appinfo/routes.php and the controllers' docblocks, signatures and status
codes. Spectral with the ADR ruleset finds nothing.

Tests pin the middleware, the aliases (a twin for every unversioned route,
no alias taking a request meant for another route) and keep openapi.json and
routes.php in step both ways.

Assisted-by: ClaudeCode:claude-opus-5-5
… ci]

Unversioned /api paths keep their existing error bodies and content
type; they only gain the API-Version, Deprecation and Link headers.

Assisted-by: ClaudeCode:claude-opus-5-5
Development already serves every /api route under /api/v1 and publishes
the OpenAPI document; its routes.php, OpenApiController and
ApiVersionMiddleware are kept. This branch adds the Deprecation and Link
headers and problem details on /api/v1 on top: the legacy
/api/conversations routes name /api/v1/sessions as their successor, and
the OpenAPI document drops the /api/v1/conversations paths that are not
routed.

Assisted-by: ClaudeCode:claude-opus-5-5
@rubenvdlinde
rubenvdlinde merged commit 66af8e4 into development Nov 13, 2026
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