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": { "repos": _one_or_list({"$ref": "#/definitions/repo"}),
"type": "array",
"items": {"$ref": "#/definitions/repo"},
},
"repos": {
"anyOf": [
{"$ref": "#/definitions/repo"},
{"$ref": "#/definitions/list_of_repos"},
]
},
"list_of_strings": { "list_of_strings": {
"type": "array", "type": "array",
"items": {"type": "string"}, "items": {"type": "string"},
}, },
"strings": { "strings": _one_or_list({"type": "string"}),
"anyOf": [
{"type": "string"},
{"$ref": "#/definitions/list_of_strings"},
]
},
"optional_string": { "optional_string": {
"anyOf": [ "anyOf": [
@ -921,17 +906,9 @@ def make_schema():
"additionalProperties": False, "additionalProperties": False,
}), }),
"live_images": _variant_arch_mapping({ "live_images": _variant_arch_mapping(
"anyOf": [ _one_or_list({"$ref": "#/definitions/live_image_config"})
{"$ref": "#/definitions/live_image_config"}, ),
{
"type": "array",
"items": {
"$ref": "#/definitions/live_image_config"
}
}
]
}),
"image_build": { "image_build": {
"type": "object", "type": "object",
@ -1014,17 +991,7 @@ def make_schema():
# Warning: this pattern is a variant uid regex, but the # Warning: this pattern is a variant uid regex, but the
# format does not let us validate it as there is no regular # format does not let us validate it as there is no regular
# expression to describe all regular expressions. # expression to describe all regular expressions.
".+": { ".+": _one_or_list({"$ref": "#/definitions/osbs_config"}),
"anyOf": [
{"$ref": "#/definitions/osbs_config"},
{
"type": "array",
"items": {
"$ref": "#/definitions/osbs_config",
},
},
],
},
}, },
"additionalProperties": False, "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. # 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 # The key in this mapping is the trigger for the check. When the option is