mirror of
https://forge.fsky.io/oneflux/omegafox.git
synced 2026-04-11 12:22:07 -07:00
jsonvv: Group stacking 0.2.1
This commit is contained in:
parent
17f8bb0563
commit
99801bd139
3 changed files with 22 additions and 6 deletions
|
|
@ -187,6 +187,17 @@ Fields that end with `$group_name` are grouped together. If one of the keys is s
|
||||||
|
|
||||||
This will require both `value` is set if and only if `isEnabled` is set.
|
This will require both `value` is set if and only if `isEnabled` is set.
|
||||||
|
|
||||||
|
Multiple `$` can be used to create more complex group dependencies.
|
||||||
|
|
||||||
|
```python
|
||||||
|
keyOne$group1: "any"
|
||||||
|
keyTwo$group2: "any"
|
||||||
|
keyThree$group1$group2: "any"
|
||||||
|
```
|
||||||
|
|
||||||
|
If `keyThree` is set, both `keyOne` and `keyTwo` must also be set.
|
||||||
|
|
||||||
|
However, if `keyOne` is set, `keyThree` needs to be set but `keyTwo` does not.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
from .exceptions import (
|
from .exceptions import (
|
||||||
MissingGroupKey,
|
MissingGroupKey,
|
||||||
|
|
@ -48,11 +48,16 @@ class JsonValidator:
|
||||||
)
|
)
|
||||||
|
|
||||||
# Register group dependencies
|
# Register group dependencies
|
||||||
if (idx := key.rfind('$')) != -1:
|
orig_key: Optional[str] = None
|
||||||
base_key, group = key[:idx], key[idx + 1 :]
|
while (idx := key.rfind('$')) != -1:
|
||||||
|
# Get the original key before all $
|
||||||
|
if orig_key is None:
|
||||||
|
orig_key = key.split('$', 1)[0]
|
||||||
|
# Add to group registry
|
||||||
|
key, group = key[:idx], key[idx + 1 :]
|
||||||
if group not in self.groups:
|
if group not in self.groups:
|
||||||
self.groups[group] = []
|
self.groups[group] = []
|
||||||
self.groups[group].append(base_key)
|
self.groups[group].append(orig_key)
|
||||||
|
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
# Recursively validate and parse nested dictionaries
|
# Recursively validate and parse nested dictionaries
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
|
||||||
|
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "jsonvv"
|
name = "jsonvv"
|
||||||
version = "0.2.0"
|
version = "0.2.1"
|
||||||
description = "JSON value validator"
|
description = "JSON value validator"
|
||||||
authors = ["daijro <daijro.dev@gmail.com>"]
|
authors = ["daijro <daijro.dev@gmail.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue