-
Notifications
You must be signed in to change notification settings - Fork 215
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
Feature request or bug: adding properties directly to map keys. #86
Comments
Excellent observation, I was sure there was an issue about it, but seems there wasn't. My first thought was that the key properties could be merged into child (here: value) properties, but it would raise an ambiguity issue: Another option to resolve this would be to introduce parent/child relationship between schema instances. This way, we could look parent properties at runtime when needed. Similar example with [:and {:error/message "fail"} int? [:> 18]] for maps, we could create what do you think? |
related #80 (the parent/child) |
I think that creating a |
Should be resolved for first alpha. |
@ikitommi are you still thinking the parent / child relationship is the way to go on this? Would this mean that transformers would end up being able to reference them via It may be worth stating that this could end up leading to inconsistent behavior for transformers, specifically if some of them end up checking parent properties, while others don't. I imagine it will be easy enough to get them to be consistent in In the case of merging properties into the child, and specifically merging ie. aren't [:map [:name {:optional true} string?]] and [:map [:name {:optional true} [string? {:optional true} ;; this optional basically has no effect anyway
;; and is the result of "merging" the parent
;; into the child
] essentially equivalent? Even if they aren't, it may be worth thinking whether writing the merge logic for parent to child properties is more complex than having parent / child. As always, no strong opinions, just thinking out loud. |
Not happy with merge as the properties would be copied to children, potentially masking child properties. Also, things like serialization and walking over schemas would just see the copied properties. (m/form [:map [:x {:optional true} :string]])
; => [:map [:x {:optional true} [:string {:optional true}]]] In top-level, I guess the options are: 1) it's a feature
2) have a generic way for childs to access the parent data
3) have a way for each schema application (transformation, value generation etc) to resolve this
... for the 3, there are few options, but I'll take the simplest path first and create a draft PR for reviews, have a good hunch how to do that without too many tears. |
Started on the PR: #212 |
3 sounds promising. I agree with the hesitation for blanket overriding. The only question I have is whether this somehow limits extension outside of code in core, but since it looks like your approach is via a |
I think this is resolved now, using 3. final part was the humanization, fixed in #462. |
as a side note, not 100% happy how the handling of entries complexes everything. Maybe this can be simplified with 1.0.0? |
Hi Tommi!
I was surprised that it is not possible to add properties to keys directly, but I don't know if it is intended behavior or not. I found this when I was playing around with error messages, so the example focuses on that. As you can see the first expression evaluates with the error message, while the second one does not.
If this is intended behavior, maybe the the fact that the second example does not work could be included in the docs.
The text was updated successfully, but these errors were encountered: