|
| 1 | +Typed Configuration Schema |
| 2 | +========================== |
| 3 | + |
| 4 | +``assets._coerce`` coerces a single value and ``json_schema`` validates JSON |
| 5 | +structure, but nothing bound a resolved config dict into a typed object with |
| 6 | +required-field enforcement and choice constraints. This validates a mapping |
| 7 | +against declared fields, coercing types and reporting actionable errors — a |
| 8 | +stdlib analog of pydantic-settings. |
| 9 | + |
| 10 | +Pure standard library (``dataclasses``); imports no ``PySide6``. Validation is a |
| 11 | +pure function (mapping in, report out), so it is fully deterministic in CI. |
| 12 | + |
| 13 | +Headless API |
| 14 | +------------ |
| 15 | + |
| 16 | +.. code-block:: python |
| 17 | +
|
| 18 | + from je_auto_control import ConfigSchema, ConfigField, validate_config |
| 19 | +
|
| 20 | + schema = ConfigSchema({ |
| 21 | + "port": ConfigField("int", required=True), |
| 22 | + "env": ConfigField("str", default="dev", choices=["dev", "prod"]), |
| 23 | + "debug": ConfigField("bool", default=False), |
| 24 | + }) |
| 25 | + report = schema.validate({"port": "8080", "debug": "yes"}) |
| 26 | + # {"ok": True, "config": {"port": 8080, "env": "dev", "debug": True}, "errors": []} |
| 27 | +
|
| 28 | +``ConfigField`` declares a ``type`` (``str`` / ``int`` / ``float`` / ``bool``), |
| 29 | +optional ``default``, ``required`` flag, ``choices``, and an ``env`` hint. |
| 30 | +``ConfigSchema.validate`` coerces each present value, applies defaults, enforces |
| 31 | +required fields and choices, and returns ``{ok, config, errors}`` (errors as |
| 32 | +``{field, error}``). ``ConfigSchema.from_dict`` builds a schema from a plain |
| 33 | +spec, ``validate_config`` does spec-plus-mapping in one call, and ``coerce`` |
| 34 | +exposes the value coercion (booleans accept ``true``/``yes``/``on`` etc.). |
| 35 | + |
| 36 | +Executor command |
| 37 | +---------------- |
| 38 | + |
| 39 | +``AC_validate_config`` validates a ``config`` mapping against a ``schema`` spec |
| 40 | +and returns ``{ok, config, errors}``. It is exposed as the MCP tool |
| 41 | +``ac_validate_config`` and as a Script Builder command under **Data**. |
0 commit comments