mirror of
https://forge.fsky.io/oneflux/omegafox.git
synced 2026-04-11 09:02:03 -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.
|
||||
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
|
|
@ -724,4 +735,4 @@ graph TD
|
|||
### Escaping Characters
|
||||
|
||||
- `!`: Escapes commas, slashes, and other jsonvv characters within strings.
|
||||
- `\`: Escapes within a regex pattern.
|
||||
- `\`: Escapes within a regex pattern.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
from typing import Any, Dict, List
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from .exceptions import (
|
||||
MissingGroupKey,
|
||||
|
|
@ -48,11 +48,16 @@ class JsonValidator:
|
|||
)
|
||||
|
||||
# Register group dependencies
|
||||
if (idx := key.rfind('$')) != -1:
|
||||
base_key, group = key[:idx], key[idx + 1 :]
|
||||
orig_key: Optional[str] = None
|
||||
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:
|
||||
self.groups[group] = []
|
||||
self.groups[group].append(base_key)
|
||||
self.groups[group].append(orig_key)
|
||||
|
||||
if isinstance(value, dict):
|
||||
# Recursively validate and parse nested dictionaries
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
|
|||
|
||||
[tool.poetry]
|
||||
name = "jsonvv"
|
||||
version = "0.2.0"
|
||||
version = "0.2.1"
|
||||
description = "JSON value validator"
|
||||
authors = ["daijro <daijro.dev@gmail.com>"]
|
||||
license = "MIT"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue