Coverage for src/lilbee/core/config/validators.py: 100%

16 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-08-14 11:46 +0000

1"""Pydantic ``Field`` wrapper with lilbee-specific schema metadata.""" 

2 

3from typing import Any 

4 

5from pydantic import Field 

6 

7 

8def ConfigField( # noqa: N802 pydantic Field wrapper; matches Field's PascalCase 

9 *args: Any, 

10 writable: bool = False, 

11 reindex: bool = False, 

12 write_only: bool = False, 

13 public: bool = True, 

14 **kwargs: Any, 

15) -> Any: 

16 """Wrap pydantic ``Field`` and attach metadata via ``json_schema_extra``.""" 

17 extra: dict[str, bool] = {} 

18 if writable: 

19 extra["writable"] = True 

20 if reindex: 

21 extra["reindex"] = True 

22 if write_only: 

23 extra["write_only"] = True 

24 if not public: 

25 extra["public"] = False 

26 if extra: 

27 # Merge rather than assign: a caller passing its own json_schema_extra 

28 # had it silently dropped, with lilbee's flags winning. 

29 supplied = kwargs.get("json_schema_extra") 

30 kwargs["json_schema_extra"] = {**supplied, **extra} if isinstance(supplied, dict) else extra 

31 return Field(*args, **kwargs)