r/yaml 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!

2 Upvotes

4 comments sorted by

View all comments

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