Defining multiple types in schema (x OR type y)? #181
Answered
by
kputyra
DVAlexHiggs
asked this question in
Q&A
|
I have a YAML schema. I would like to allow a key in a Mapping to either have a List of Strings or just a String. Something like: Map(
{"my_keys":
Map({"my_key_1": Str() | Seq(Str()),
"my_key_2": Str()})
})Which would validate the following YAML, either: my_keys:
my_key_1: "my_string"
my_key_2: "my_other_string"OR my_keys:
my_key_1:
- "my_string"
- "my_second_string"
my_key_2: "my_other_string"How do I do this with StrictYAML? I could not find anything in the docs. Thanks! |
Answered by
kputyra
Apr 21, 2022
Replies: 3 comments 1 reply
|
I think your example is just right. This is explained in the second how-to link from the Using StrictYAML section. |
0 replies
Answer selected by
DVAlexHiggs
|
Thank you I don't know how I missed this! |
0 replies
|
Reverse Str() | Seq(Str())
Use Seq(Str()) | Str() instead.
Note that due to the overwhelming complexity of matching multiple complex
types and reporting errors you can only "or" one complex type followed by
one or more scalar types using |
This looks like it shouldnt be a problem for you though.
…On Sat, 16 Apr 2022, 15:21 Alex Higgs, ***@***.***> wrote:
I have a YAML schema. I would like to allow a key in a Mapping to either
have a List of Strings or just a String.
Something like:
Map({"my_key_1": Str() | Seq(Str()),
"my_key_2": Str()})
—
Reply to this email directly, view it on GitHub
<#181>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABOJKNPEVUE6RNAF3KRXQ3TVFLEFVANCNFSM5TSOCVVQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think your example is just right. This is explained in the second how-to link from the Using StrictYAML section.