Skip to content

fix(api): serve the API's JSON errors as RFC 9457 problem details - #9985

Merged
rubenvdlinde merged 7 commits into
mainfrom
fix/api-problem-json
Nov 12, 2026
Merged

rubenvdlinde merged 7 commits into
mainfrom
fix/api-problem-json

Conversation

@rubenvdlinde

Copy link
Copy Markdown
Contributor

What this changes

OpenRegister's own REST API now answers its JSON errors as RFC 9457 problem details (application/problem+json).

  • ProblemDetailsMiddleware (Nextcloud middleware, registered first so its afterController sees the final response, including the responses other middlewares build from exceptions) turns a 4xx or 5xx JSONResponse under /api/ into a problem document with type (about:blank), title (the reason phrase), status, detail (from the body's message, else error) and instance (the request path without its query string).
  • The body keeps every member it already had, with its value unchanged, so callers reading error or message see no difference. A member that already uses a problem name (for example status: "error") is kept as it is; RFC 9457 section 3.1 tells consumers to ignore a member with the wrong type.
  • A list body, a response that is already problem details (the OAS validation 422) and a non-JSON response are left alone.
  • The document is built by the existing ProblemDetailsBuilder; its interface gains build(), which the class already had.

Protocol paths left untouched

StandardProtocolPaths lists them: MCP (/api/mcp, JSON-RPC 2.0, and its /api/mcp/v1 discovery), GraphQL (/api/graphql), OGC WFS (/api/geo/{register}/{schema}/wfs), iCalendar feeds (/api/public/calendar-feeds/), Prometheus metrics (/api/metrics), the health check (/api/health) and federation between instances (/api/federation/, which older peers parse). .well-known, oauth2 and webpush are not under /api/, so the middleware never sees them.

appinfo/routes.php has no ZGW (ZRC/ZTC/DRC) or OData route: those APIs are served by other apps, so there was nothing of theirs to exclude here.

OpenAPI document

Every 4xx and 5xx response in the root openapi.json is now application/problem+json with allOf: [Problem, <the endpoint's existing error schema>]. The four error responses that had no content (Nextcloud's own 401 and 412) get the Problem schema too. info.description says errors are problem details.

Spectral, NL API Design Rules ruleset

npx @stoplight/spectral-cli lint openapi.json --ruleset https://static.developer.overheid.nl/adr/ruleset.yaml

  • main: 100 findings
  • fix/openapi-api-design-rules, which this branch builds on: 54 findings, 52 of them use-problem-schema
  • this branch: 2 findings, use-problem-schema 52 to 0. Left: 1 paths-kebab-case (filesMultipart) and 1 include-major-version-in-uri, which the path aliases PR handles.

Stacking

Built on fix/openapi-api-design-rules (queued for the integrator), with main merged in. Merge that one first; this diff then shrinks to this change.

Tests

  • ProblemDetailsMiddlewareTest (9), StandardProtocolPathsTest (16), MiddlewareRegistrarTest (new order) and OpenApiControllerTest::testErrorResponsesAreProblemDetails. All fail on main: the classes do not exist there, the registrar order differs, and the document test fails against the old document (checked by restoring it).

Verified locally

  • Diff check against origin/main (hydra/scripts/diff-check.sh): no NEW findings. units, floor compare, php -l, phpcs, phpstan and the touched-class PHPUnit runs pass. The gate runner hit the diff check's 300 s cut-off, so it ran once on its own: every gate passes except gate 67 (openregister-contract-parity), which reports lib/Contract/EmailLinkReaderInterface.php and ObjectServiceInterface.php out of step with hydra-gates; this branch does not touch lib/Contract/, so that is inherited.
  • composer check:strict was not run: the box is shared and memory-limited today, and the brief's checks (diff check, touched-class tests, floor compare) cover this change.
  • Touched-class tests and ComponentDefinitionTest: OK.
  • phpcs reports 256 inherited findings in appinfo/routes.php on lines this change does not touch.

Assumptions

  • Problem members already present in a body are kept rather than rewritten, because rewriting them would break the callers that read them.
  • Federation, metrics and health count as protocol paths: other software parses them.

AI assistance: drafted with Claude Code (claude-opus-5-5) and reviewed before submission.

… serve it

Assisted-by: ClaudeCode:claude-opus-5-5
…component

Assisted-by: ClaudeCode:claude-opus-5-5
ProblemDetailsMiddleware turns a 4xx or 5xx JSON response under /api/ into
application/problem+json with type, title, status, detail and instance,
keeping every member the body already had. MCP, GraphQL, WFS, iCalendar
feeds, metrics, health and federation keep their own formats.

The root OpenAPI document describes every error response with a Problem
schema.

Assisted-by: ClaudeCode:claude-opus-5-5
@rubenvdlinde
rubenvdlinde merged commit 3d128d4 into main Nov 12, 2026
15 of 22 checks passed
This was referenced Nov 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Quality Report — ConductionNL/openregister @ 1ffae6f

Check PHP Vue Security License Tests
lint ✅
phpcs ❌
phpmd ❌
psalm ❌
phpstan ❌
phpmetrics ✅
eslint ❌
stylelint ✅
build ✅
check-specs ✅
test-l10n ❌
test-l10n-parity ❌
format ❌
check-schema-l10n ✅
test-newman-route-ratchet ✅
composer ✅ ✅ 169/169
npm ✅ ✅ 639/639
app:check-code ⏭️
info.xml ✅
REUSE ✅
lockfile sync ✅
PHPUnit ❌ 56591/56799 · 27 skipped (worst of 3 legs: PHP 8.3, NC stable32, pgsql; counts from 3 of 8 legs)
Newman ❌
Playwright ❌ 237/324 · 5 skipped · 164 did not run
Hydra gates ❌

Quality workflow — 2026-11-14 08:52 UTC

Download the full PDF report from the workflow artifacts.

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