mundane.api.schemas

Translate action JSON (a tagged union) into engine action dataclasses.

Every action body carries a type discriminator, e.g. {"type": "play_card", "player": 0, "hand_index": 0}. The tags are exactly the keys of the engine’s canonical ACTION_TYPES registry, so the HTTP surface mirrors the engine and the round-trip action_to_dict -> parse_action() is the identity (covered by a test).

A body that does not describe a valid action — unknown type, missing field, wrong field type — is rejected with IllegalAction, which the app maps to HTTP 422. No legality lives here; this is pure translation.

Functions

_require_int(→ int)

Return body[key] as an int, or reject the action if it is missing or not an integer.

_optional_int(→ int | None)

Return body[key] as an int, or None when it is absent or explicitly null.

parse_action(→ mundane.engine.actions.Action)

Parse a tagged-union action body into the matching action dataclass.

Module Contents

mundane.api.schemas._require_int(body: dict[str, object], key: str) int[source]

Return body[key] as an int, or reject the action if it is missing or not an integer.

mundane.api.schemas._optional_int(body: dict[str, object], key: str) int | None[source]

Return body[key] as an int, or None when it is absent or explicitly null.

mundane.api.schemas.parse_action(body: dict[str, object]) mundane.engine.actions.Action[source]

Parse a tagged-union action body into the matching action dataclass.