feat(api): define public problem errors, pagination, and retry contract

This commit is contained in:
shira committed 2026-10-05 22:09:36 +03:00
1 parent b2f6e87bfe
commit 565ca94bbb
86 files changed
+8200 -154

No files matched your search

+141 -2
View File
@@ -1,9 +1,148 @@
# generated by datamodel-codegen:
# filename: openapi.bundle.yml
from typing import Literal
from typing import Annotated, Literal
from pydantic import BaseModel, ConfigDict
from pydantic import BaseModel, ConfigDict, Field, RootModel
class ProblemCode(
RootModel[
Literal[
"validation_failed",
"unauthenticated",
"forbidden",
"not_found",
"method_not_allowed",
"idempotency_in_progress",
"state_conflict",
"version_conflict",
"payload_too_large",
"unsupported_media_type",
"idempotency_key_reused",
"precondition_required",
"rate_limited",
"internal",
"not_implemented",
]
]
):
root: Annotated[
Literal[
"validation_failed",
"unauthenticated",
"forbidden",
"not_found",
"method_not_allowed",
"idempotency_in_progress",
"state_conflict",
"version_conflict",
"payload_too_large",
"unsupported_media_type",
"idempotency_key_reused",
"precondition_required",
"rate_limited",
"internal",
"not_implemented",
],
Field(
description="Stable public error code. Adding a code is a contract change; renaming or removing one is a breaking change. Clients must handle an unknown code by its HTTP status.\n\n- validation_failed (400): parameters or body do not match the contract, or a body violates a domain rule such as salary_from <= salary_to; `errors` points at the fields.\n- unauthenticated (401): no valid session or credentials.\n- forbidden (403): the caller is authenticated but not allowed.\n- not_found (404): the route or object does not exist or is not visible.\n- method_not_allowed (405): the route does not support the method.\n- idempotency_in_progress (409): a request with the same Idempotency-Key is still being processed.\n- state_conflict (409): the operation conflicts with the current state of the resource, for example an invitation that was already accepted.\n- version_conflict (412): If-Match does not match the current version.\n- payload_too_large (413): the request body exceeds the limit.\n- unsupported_media_type (415): the request Content-Type is not accepted.\n- idempotency_key_reused (422): the Idempotency-Key was already used with a different request.\n- precondition_required (428): the operation requires If-Match.\n- rate_limited (429): too many requests; see Retry-After.\n- internal (500): unexpected server error.\n- not_implemented (501): the operation is in the contract but not implemented yet."
),
]
class ProblemFieldLocation(RootModel[Literal["body", "query", "path", "header", "cookie"]]):
root: Annotated[
Literal["body", "query", "path", "header", "cookie"],
Field(description="Part of the request that contains the invalid field."),
]
class ProblemFieldError(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
in_: Annotated[ProblemFieldLocation, Field(alias="in")]
pointer: Annotated[
str,
Field(
description="JSON Pointer (RFC 6901). For `body` it points into the request body document, for example `/salary_from`; an empty string means the whole body. For a parameter it is `/` followed by the parameter name, for example `/limit` or `/Idempotency-Key`.",
max_length=1024,
pattern="^(/([^~/]|~[01])*)*$",
),
]
code: Annotated[
str,
Field(
description="Stable field reason. Current values are `required` (missing value) and `invalid` (malformed value or a value outside the schema). Clients must tolerate new values.",
max_length=64,
min_length=1,
pattern="^[a-z][a-z0-9_]*$",
),
]
message: Annotated[
str,
Field(
description="Fixed English message that never echoes the submitted value.",
max_length=500,
min_length=1,
),
]
class Problem(BaseModel):
model_config = ConfigDict(
extra="forbid",
)
type: Annotated[
str,
Field(
description="URI that identifies the problem type. It has the form `urn:lincodex:problem:<code>` and is an identifier, not a link to dereference.",
max_length=256,
),
]
title: Annotated[
str,
Field(
description="Short, fixed English summary of the problem type. It does not change between occurrences.",
max_length=200,
min_length=1,
),
]
status: Annotated[
int, Field(description="HTTP status code generated by the origin server.", ge=400, le=599)
]
code: ProblemCode
detail: Annotated[
str | None,
Field(
description="Safe English explanation of this occurrence. It never contains internal error text or request values.",
max_length=1000,
),
] = None
instance: Annotated[
str | None,
Field(
description="URI reference that identifies this occurrence, when one exists.",
max_length=2048,
),
] = None
trace_id: Annotated[
str | None,
Field(
description="Request identifier of the call when the caller propagated one; it is not a secret.",
max_length=128,
min_length=1,
pattern="^[A-Za-z0-9._-]+$",
),
] = None
errors: Annotated[
list[ProblemFieldError] | None,
Field(
description="Field-level reasons for validation_failed. Other codes omit it.",
max_length=100,
),
] = None
class MLHealthResponse(BaseModel):