Defining multiple types in schema (x OR type y)? #181
-
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! |
Beta Was this translation helpful? Give feedback.
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. |
Beta Was this translation helpful? Give feedback.
-
Thank you I don't know how I missed this! |
Beta Was this translation helpful? Give feedback.
-
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: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
I think your example is just right. This is explained in the second how-to link from the Using StrictYAML section.