Skip to content

API v2: send the limits in validation field errors as structured values #3897

Open

Description

@Quick104

Problem

When a v2 validation error names a limit, the limit exists only in the English detail text. Examples are "Keep the name under 100 characters." and "expected length <= 64". Clients that show their interface in another language translate a field error from its code (error.field.<code> in the shared translation catalog). They can't pull the number out of English text, so the translated message loses it. A Spanish administrator sees "This value isn't valid" where English says what the limit is.

This came up in review of #3894 (finding F1), where the web app's translated problem messages replace these details with the generic text for invalid. Every client that translates problem details has the same gap.

Proposal

An additive v2 change. A field error carries the values its message depends on as structured data, so each client can format a translated message with them:

{
  "location": "body.name",
  "code": "out_of_range",
  "detail": "Keep the name under 100 characters.",
  "params": { "max": 100 }
}
  • params is an optional object on ProblemError, keyed by name, with number or string values (max, min, and count where it helps). detail stays as it is: English clients and older clients keep showing it.
  • A failure that today uses invalid but names a limit gets the code that describes it (out_of_range, or a narrower new code if the contract review prefers one), so the client picks the right message.
  • The shared catalog gets matching messages with placeholders, such as "Keep it under {max} characters", next to the existing error.field.<code> texts.

Where v2 builds field errors

  • internal/apiv2/problem.go: ProblemError (location, code, detail). huma.NewError routes schema-validation failures through validationCode and validationDetail. These map Huma's "expected length", "expected array length" and "expected number" messages to out_of_range. Huma's ErrorDetail has only message, location and value, so the limit has to come from the operation's schema, or from Huma's message as a last resort.
  • About 105 ProblemError literals in about 47 handler files, mostly code: invalid with an English detail written in the handler or passed through from a service. For example, requestProblem in internal/apiv2/requests.go maps every mediarequests.ValidationError field to invalid, with details such as "Keep the name under 100 characters." from internal/requests/routes_admin.go.
  • Shared helpers: validationProblem in internal/apiv2/home.go, and the per-domain *Problem mappers (groupProblem, adminSectionError, catalogProblem, and others) that turn service errors into field errors.

The schema-validation path covers most limits in one place. The handler-built errors that name a limit can move over one domain at a time.

Contract

  • Additive under the pre-1.0 rules in docs/architecture/api-contract.md: one new optional member on ProblemError, and possibly new code values. Clients must already tolerate unknown codes.
  • Advertise it with a capability flag, so a client knows when params can appear, without version sniffing.
  • /api/v1 and jellycompat are unchanged.

Client follow-ups

Each client already translates field errors by code and falls back to detail. Each needs to read params and fill the matching catalog message:

  • Web: problemFieldDetail in web/src/api/v2/request.ts (added in feat(web): translate v2 problem details #3894).
  • Android: ServerText.kt in android-shared (common/i18n), on the translation stack.
  • Apple: the problem mapping in APIv2Models.swift, on the translation stack.
  • Roku: source/api/problem.bs, on the translation stack.

Related: #3894

AI disclosure: drafted by Claude Code (claude-opus-5-5) from the v2 source on main; the code references were checked against the source.

Activity

  1. added
    enhancement
    on Nov 9, 2026
  2. added
    api-v2
    priority: P2
    triaged
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-v2enhancementpriority: P2triaged

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions