config: Reduce duplication in schema

This patch adds a helper function for easy creation of a structure where
either X or list of Xs is accepted.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2017-08-03 14:42:25 +02:00
parent c12bad295f
commit 9780f36e37

View File

@ -454,29 +454,14 @@ def make_schema():
]
},
"list_of_repos": {
"type": "array",
"items": {"$ref": "#/definitions/repo"},
},
"repos": {
"anyOf": [
{"$ref": "#/definitions/repo"},
{"$ref": "#/definitions/list_of_repos"},
]
},
"repos": _one_or_list({"$ref": "#/definitions/repo"}),
"list_of_strings": {
"type": "array",
"items": {"type": "string"},
},
"strings": {
"anyOf": [
{"type": "string"},
{"$ref": "#/definitions/list_of_strings"},
]
},
"strings": _one_or_list({"type": "string"}),
"optional_string": {
"anyOf": [
@ -921,17 +906,9 @@ def make_schema():
"additionalProperties": False,
}),
"live_images": _variant_arch_mapping({
"anyOf": [
{"$ref": "#/definitions/live_image_config"},
{
"type": "array",
"items": {
"$ref": "#/definitions/live_image_config"
}
}
]
}),
"live_images": _variant_arch_mapping(
_one_or_list({"$ref": "#/definitions/live_image_config"})
),
"image_build": {
"type": "object",
@ -1014,17 +991,7 @@ def make_schema():
# Warning: this pattern is a variant uid regex, but the
# format does not let us validate it as there is no regular
# expression to describe all regular expressions.
".+": {
"anyOf": [
{"$ref": "#/definitions/osbs_config"},
{
"type": "array",
"items": {
"$ref": "#/definitions/osbs_config",
},
},
],
},
".+": _one_or_list({"$ref": "#/definitions/osbs_config"}),
},
"additionalProperties": False,
},
@ -1102,6 +1069,19 @@ def _variant_arch_mapping(value):
}
def _one_or_list(value):
"""Require either `value` or a list of `value`s."""
return {
"anyOf": [
value,
{
"type": "array",
"items": value,
},
],
}
# This is a mapping of configuration option dependencies and conflicts.
#
# The key in this mapping is the trigger for the check. When the option is