Skip to content

Commit

Permalink
schema: replace use of oneOf by anyOf
Browse files Browse the repository at this point in the history
The schema definition "oneOf" is discouraged if not explicitly needed,
as it requires the checker to check against all variants to ensure that
only exactly one matches. It also makes it harder for IDEs to provide
meaningful auto-completions. As our schema is written in a way that all
matches are exclusive anyways, we can safely switch to anyOf.

Signed-off-by: Felix Moessbauer <[email protected]>
  • Loading branch information
fmoessbauer committed Jan 30, 2025
1 parent 70dc2f8 commit 9a902f6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
28 changes: 14 additions & 14 deletions docs/userguide/project-configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,18 +223,18 @@ Configuration reference
An item in this list can have one of two types:

item: string
:kasschemadesc:`header.properties.includes.items.oneOf[0]`
:kasschemadesc:`header.properties.includes.items.anyOf[0]`

item: dict
:kasschemadesc:`header.properties.includes.items.oneOf[1]`
:kasschemadesc:`header.properties.includes.items.anyOf[1]`

``repo``: string [required]
:kasschemadesc:`header.properties.includes.items.oneOf[1].properties.repo`
:kasschemadesc:`header.properties.includes.items.anyOf[1].properties.repo`
The repo needs to be defined in the ``repos`` dictionary as
``<repo-id>``.

``file``: string [required]
:kasschemadesc:`header.properties.includes.items.oneOf[1].properties.file`
:kasschemadesc:`header.properties.includes.items.anyOf[1].properties.file`

``build_system``: string [optional]
:kasschemadesc:`build_system`
Expand Down Expand Up @@ -298,28 +298,28 @@ Configuration reference
:kasschemadesc:`repos`

``<repo-id>``: dict [optional]
:kasschemadesc:`repos.additionalProperties.oneOf[0]`
:kasschemadesc:`repos.additionalProperties.anyOf[0]`

``name``: string [optional]
:kasschemadesc:`repos.additionalProperties.oneOf[0].properties.name`
:kasschemadesc:`repos.additionalProperties.anyOf[0].properties.name`

``url``: string [optional]
:kasschemadesc:`repos.additionalProperties.oneOf[0].properties.url`
:kasschemadesc:`repos.additionalProperties.anyOf[0].properties.url`

``type``: string [optional]
:kasschemadesc:`repos.additionalProperties.oneOf[0].properties.type`
:kasschemadesc:`repos.additionalProperties.anyOf[0].properties.type`

``commit``: string [optional]
:kasschemadesc:`repos.additionalProperties.oneOf[0].properties.commit`
:kasschemadesc:`repos.additionalProperties.anyOf[0].properties.commit`

``branch``: string or nothing (``null``) [optional]
:kasschemadesc:`repos.additionalProperties.oneOf[0].properties.branch`
:kasschemadesc:`repos.additionalProperties.anyOf[0].properties.branch`

``tag``: string or nothing (``null``) [optional]
:kasschemadesc:`repos.additionalProperties.oneOf[0].properties.tag`
:kasschemadesc:`repos.additionalProperties.anyOf[0].properties.tag`

``path``: string [optional]
:kasschemadesc:`repos.additionalProperties.oneOf[0].properties.path`
:kasschemadesc:`repos.additionalProperties.anyOf[0].properties.path`
If the ``url`` and ``path`` is missing, the repository where the
current configuration file is located is defined.
If the ``url`` is missing and the path defined, this entry references
Expand All @@ -330,7 +330,7 @@ Configuration reference
In case of a relative path name ``kas_work_dir`` is prepended.

``layers``: dict [optional]
:kasschemadesc:`repos.additionalProperties.oneOf[0].properties.layers`
:kasschemadesc:`repos.additionalProperties.anyOf[0].properties.layers`
This allows combinations:

.. code-block:: yaml
Expand All @@ -355,7 +355,7 @@ Configuration reference
of a layer in latter loaded configuration files.

``patches``: dict [optional]
:kasschemadesc:`repos.additionalProperties.oneOf[0].properties.patches`
:kasschemadesc:`repos.additionalProperties.anyOf[0].properties.patches`

``<patches-id>``: dict [optional]
One entry in patches with its specific and unique id. All available
Expand Down
2 changes: 1 addition & 1 deletion kas/configschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def _load_schema():
with open(__schema_definition__, 'r') as f:
CONFIGSCHEMA = json.load(f)
header_node = CONFIGSCHEMA['properties']['header']
version_node = header_node['properties']['version']['oneOf'][1]
version_node = header_node['properties']['version']['anyOf'][1]
__file_version__ = version_node["maximum"]
__compatible_file_version__ = version_node["minimum"]

Expand Down
22 changes: 11 additions & 11 deletions kas/schema-kas.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"properties": {
"version": {
"description": "Version of the configuration file format.",
"oneOf": [
"anyOf": [
{
"type": "string",
"enum": [
Expand All @@ -37,7 +37,7 @@
"description": "List of configuration files to include (parsed depth-first). They are merged in order they are stated. So a latter one could overwrite settings from previous files. The current file can overwrite settings from every included file.",
"type": "array",
"items": {
"oneOf": [
"anyOf": [
{
"description": "Path to a kas configuration file, relative to the repository root of the current file.",
"type": "string"
Expand Down Expand Up @@ -150,7 +150,7 @@
"target": {
"description": "Single target or a list of targets to build by bitbake. Can be overwritten by the ``KAS_TARGET`` environment variable. Space is used as a delimiter if multiple targets should be specified via the environment variable. For targets prefixed with ``multiconfig:`` or ``mc:``, corresponding entries are added to the ``BBMULTICONFIG`` in ``local.conf``.",
"default": "core-image-minimal",
"oneOf": [
"anyOf": [
{
"type": "string"
},
Expand All @@ -171,7 +171,7 @@
"description": "Definitions of all available repos and layers. The layers are appended to the ``bblayers.conf`` sorted by the repository name first and then by the layer name.",
"type": "object",
"additionalProperties": {
"oneOf": [
"anyOf": [
{
"description": "Definition of a repository and the layers, that should be part of the build. If the value is ``None``, the repository, where the current configuration file is located is defined as ``<repo-id>`` and added as a layer to the build. It is recommended that the ``<repo-id>`` is related to the containing repository/layer to ease cross-project referencing.",
"type": "object",
Expand All @@ -183,7 +183,7 @@
},
"url": {
"description": "Url of the repository. If this is missing, no version control operations are performed.",
"oneOf": [
"anyOf": [
{
"type": "string"
},
Expand All @@ -204,7 +204,7 @@
},
"branch": {
"description": "Upstream branch that should be tracked. If ``commit`` was specified, kas checks that the branch contains the commit. If no ``commit`` was specified, the head of the upstream branch is checked out. The nothing (``null``) value is used to remove a possible default value.",
"oneOf": [
"anyOf": [
{
"type": "string"
},
Expand All @@ -215,7 +215,7 @@
},
"tag": {
"description": "Tag that should be checked out. If a ``commit`` was specified, kas checks that the tag points to this commit. This must not be combined with ``branch``. The nothing (``null``) value is used to remove a possible default value.",
"oneOf": [
"anyOf": [
{
"type": "string"
},
Expand All @@ -230,7 +230,7 @@
},
"path": {
"description": "Path where the repository is stored.",
"oneOf": [
"anyOf": [
{
"type": "string"
},
Expand All @@ -243,7 +243,7 @@
"description": "List of layers to append to the ``bblayers.conf``. If this is missing or ``None`` or an empty dictionary, the path to the repo itself is added as a layer. Additionally, ``.`` is a valid value if the repo itself should be added as a layer.",
"type": "object",
"additionalProperties": {
"oneOf": [
"anyOf": [
{
"type": "null"
},
Expand All @@ -263,7 +263,7 @@
"description": "Patches to apply to the repository.",
"type": "object",
"additionalProperties": {
"oneOf": [
"anyOf": [
{
"type": "object",
"additionalProperties": false,
Expand Down Expand Up @@ -330,7 +330,7 @@
"description": "Menu configuration, auto-generated by menu plugin.",
"type": "object",
"additionalProperties": {
"oneOf": [
"anyOf": [
{
"type": "boolean"
},
Expand Down

0 comments on commit 9a902f6

Please sign in to comment.