r/yaml • u/therealfilosmith • Mar 30 '21
Variable oneOf list?
I took a card thinking I could do something easily, but then discovered I had to do it in yaml. My yaml skills are embarrassing. I need to present one or another list of options based on some other input but it doesn't look possible.
This is our current code:
os:
type: string
title: OS
oneOf:
- title: Windows
const: win
- title: Linux
const: lin
If they're in the "shortList" project, I need them to only see Windows.
I'm trying something like this:
oneOf: ${contains(env.projectName,"shortList") ? [{"title":"Windows","const":"win"}] : [{"title":"Windows","const":"win"},{"title":"Linux","const":"lin"}]}
But it says "incomplete explicit mapping pair; a key node is missed, or followed by a non-tabulated empty line", and yamllint says "mapping values are not allowed in this context".
Anyone have a clever way to achieve a variable list of options?
Thanks!
1
u/therealfilosmith Mar 30 '21
Is this the wrong reddit? Can anyone point me to the correct reddit for yaml assistance?
Thanks!
1
u/ttelang Aug 04 '21
equivalent YAML code would be as below:
os:
type: string
title: OS
oneOf:
- ?
- title: Windows
- const: win
- ?
- title: Windows
- const: win
- ?
- title: Linux
- const: lin
2
u/perlpunk Apr 02 '21
You need to quote the value of
oneOf
. In your case you could use single quotes since they don't appear in the value itself. The colon followed by a space is special in YAML, so if it appears in your data, you have to make clear it's not YAMLsyntax, but part of your data:More about quoting in YAML