قالب¶
این صفحه از docstringهای خود کد ساخته میشود، که به انگلیسیاند.
envelope
¶
The envelope - the one place its shape is assembled.
Every answer has the same top level, success and failure alike:
{"success": true, "status_code": 200, "message": "...", "data": {}}
{"success": true, "status_code": 200, "message": "...", "data": [], "pagination": {}}
{"success": false, "status_code": 409, "message": "...", "data": {}, "error_code": "..."}
Two places building the envelope become two shapes, so nothing else in the library writes these keys.
build_envelope
¶
build_envelope(*, success: bool, status_code: int, message: object, data: Any = None, pagination: Mapping[str, Any] | None = None, error_code: str | None = None) -> dict[str, Any]
The envelope, from its parts.
message may be a lazy translation: it becomes text here, under the
language active when the answer is built. data that says nothing is
{}, never null.
A key is either always there or there for a reason, so a failure must
name its error_code and a success must not, and only a success is a
page.
envelope_schema
¶
envelope_schema(data: Mapping[str, Any], *, pagination: Mapping[str, Any] | None = None, error: bool = False) -> dict[str, Any]
The OpenAPI schema of an envelope around data - the shape above, as a schema.
Kept beside build_envelope so that the shape and its description
change together.