-
-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dynamic key support in GuardedStruct #11
Comments
Hi dear @svsool , |
Hi @shahryarjb, For example: defmodule ShardStruct do
use GuardedStruct
guardedstruct do
field(:node, String.t(), derive: "sanitize(trim) validate(ipv4)")
# ... other fields here ...
end
end
# map with dynamic keys
defmodule ShardsMapStruct do
use GuardedStruct
guardedstruct do
# dynamic key ⬇️ <--- this feature basically would be great to have
field(~r/\d+$/, struct(), struct: ShardStruct, derive: "validate(map, not_empty)")
end
end
defmodule ShardingPlanStruct do
use GuardedStruct
guardedstruct do
field(:shards_map, struct: ShardsMapStruct, enforce: true)
# ... other plan fields here created_at, status etc ...
end
end In Ajv it's called patternProperties. |
@svsool I’m sorry to say this, but I might consider it in the future, or I’d be really happy if someone submits a pull request. The macro's goal was to avoid being too dynamic and to have strict mode check the keys and build a schema. But this feature also has its own use case and would be great to have if added. Thanks for taking the time to explain.
|
Hi,
Are dynamic keys supported in GuardedStruct?
For example with such input:
Would be nice to avoid using custom validator in such cases.
Thanks!
The text was updated successfully, but these errors were encountered: