support default value in union types #1164
Closed
eli-bl
started this conversation in
Feature request
Replies: 1 comment
-
Oh, good grief, never mind - I was looking at the wrong thing, the default value is being applied. The limitations I described still apply but that would be a separate discussion. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently, if you declare a property like this—
—or, equivalently (they end up becoming the same thing in the parser logic)—
—the default value is simply ignored.
UnionProperty.build
takes it as a parameter, but discards it.However,
UnionProperty.convert_value
is implemented to validate a default value against each of the variants. It just isn't getting called. So, ifbuild
actually calledconvert_value
at the end, as we do with many other property types, it looks to me like it would work.It would still have a few limitations due to how defaults are implemented in general:
123
or a booleantrue
, you would not actually get that value; instead it would convert them to strings. That's becausestring
appears first in the variant list andStringProperty.convert_value
intentionally coerces non-string types. (I'm not sure that that coercion is always desirable, but changing it would definitely be a breaking change... and this is one area where JSON Schema is fairly vague about what the correct behavior is.) Anyway, it would work as expected if you put the string type at the end of the list instead.Beta Was this translation helpful? Give feedback.
All reactions