Summary
Handler::generateResponseSpec() always points the default (non-200) OpenAPI response to the static GenericErrorResponseModel schema (v1 shape: httpCode/httpMessage/message messageTranslations), regardless of the module's errorSchemaVersion. Modules that opt into errorSchemaVersion: '2.0' (T432798) use ErrorFormatterV2 at runtime, which produces a different shape (message always present, tracing: {module, request_id} nested, no httpMessage/messageTranslations). A third shape, RESTBase-compat, also exists. As a result, the published OpenAPI spec misrepresents the actual error response shape for vNext modules.
Technical notes
Planned in two phases:
- Phase A: move/expose the error OpenAPI schema fragment per ErrorFormatter subclass (v1, v2, RESTBase-compat each own their fragment), and have generateResponseSpec() pick the correct $ref based on the module' errorSchemaVersion instead of always using GenericErrorResponseModel.
- Phase B (follow-up, right after A): replace the inline PHP schemas with external $refs to the schemas published on schema.wikimedia.org (e.g. http://schema.wikimedia.org/mediawiki/api/fragments/error-v1.json, error-v2.json, error-restbase-compat.json) drafted in T438207. This is blocked on the puppet deploy in T438208 (the URL is not live yet), so Phase B should be sequenced/blocked accordingly.
Other considerations:
- Three shapes need handling (v1, v2, RESTBase-compat), not just two.
- The errorSchemaVersion concept already exists on the routing/error-formatting side (Router.php); it's missing only on the OpenAPI-generation side (Handler::generateResponseSpec() / ResponseFactory::getResponseComponents()).
- RESTBase-compat is structurally different from v1/v2: it is not a static module property. Router::isRestbaseCompatEnabled() selects it per-request from the x-restbase-compat header (T374136), and it unconditionally overrides whatever errorSchemaVersion the module declares (Router.php:749-751). generateResponseSpec() has no RequestInterface and runs at spec-generation time, so it cannot know whether a future call will carry that header — any endpoint can be called with it. This means Phase A likely can't pick a single $ref per module for the default error response; it probably needs a oneOf: [module's v1-or-v2 schema, RESTBase-compat schema] on every endpoint, rather than one fixed schema chosen by errorSchemaVersion alone.
- Check whether test/validation tooling (e.g. ModuleSpecHandlerTest.php) dereferences external $refs — a not-yet-live URL could break CI once Phase B lands.
- Pre-routing errors (404, unknown module prefix, handled by Router::buildErrorExtraData()) always stay in v1/legacy shape — not every endpoint can "choose" v2 the same way.
Related: T432798 (introduced errorSchemaVersion), T438207 (drafted the 3 error JSON Schemas), T438208 (blocks Phase B). See also T438209 (validates the actual error response *body* against these schemas at runtime/complementary but distinct from this task, which is about what the OpenAPI *document* declares).
Acceptance criteria
- generateResponseSpec() selects the error response schema(s) based on the module's errorSchemaVersion, accounting for RESTBase-compat being available on any endpoint via request header (Phase A)
- Once T438208 lands, the OpenAPI spec references the external schema.wikimedia.org fragments instead of inline PHP schemas (Phase B)