Skip to content

Commit

Permalink
make version property in kas json schema more strict
Browse files Browse the repository at this point in the history
Previously all integers and the string "0.10" were supported. We make
this more strict by limiting the schema to versions which are actually
supported (e.g. no later versions than x). This helps users that use an
IDE with schema support to learn about the latest supported schema.

We further load the supported schema versions from the schema itself to
have a single source of truth.

Proposed-by: Konrad Weihmann <[email protected]>
Signed-off-by: Felix Moessbauer <[email protected]>
Signed-off-by: Jan Kiszka <[email protected]>
  • Loading branch information
fmoessbauer authored and jan-kiszka committed Nov 18, 2024
1 parent acfa8b6 commit acb5a52
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
10 changes: 10 additions & 0 deletions docs/devguide.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ able to call it from anywhere.
For local development, use the **run-kas** wrapper from the project root
directory. In this case, replace ``kas`` with ``path/to/run-kas``.

Changes of the project configuration
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

When changing the project configuration, you need to update the json
configuration schema (``schema-kas.json``). Further, a short description of
the changes needs to be added to :doc:`format-changelog`.
After making the changes, you need to update the minimum and maximum values
of ``header.version``. If the version was already updated after the last
release, the version bump is not required.


Container image build
---------------------
Expand Down
4 changes: 2 additions & 2 deletions kas/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
"""

from .__version__ import __version__
from .__version__ import __file_version__, __compatible_file_version__
from .configschema import CONFIGSCHEMA
from .configschema import CONFIGSCHEMA, \
__file_version__, __compatible_file_version__

__license__ = 'MIT'
__copyright__ = 'Copyright (c) Siemens AG, 2017-2018'
Expand Down
4 changes: 0 additions & 4 deletions kas/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,3 @@
__copyright__ = 'Copyright (c) Siemens AG, 2017-2020'

__version__ = '4.5'

# Please update docs/format-changelog.rst when changing the file version.
__file_version__ = 18
__compatible_file_version__ = 1
20 changes: 16 additions & 4 deletions kas/configschema.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,24 @@
This module contains the schema of the configuration file.
'''
__license__ = 'MIT'
__copyright__ = 'Copyright (c) Siemens AG, 2017-2018'
__copyright__ = 'Copyright (c) Siemens AG, 2017-2024'

import json
import os

cwd = os.path.dirname(os.path.realpath(__file__))

with open(os.path.join(cwd, 'schema-kas.json'), 'r') as f:
CONFIGSCHEMA = json.load(f)
def _load_schema():
global CONFIGSCHEMA
global __file_version__
global __compatible_file_version__

cwd = os.path.dirname(os.path.realpath(__file__))
with open(os.path.join(cwd, 'schema-kas.json'), 'r') as f:
CONFIGSCHEMA = json.load(f)
header_node = CONFIGSCHEMA['properties']['header']
version_node = header_node['properties']['version']['oneOf'][1]
__file_version__ = version_node["maximum"]
__compatible_file_version__ = version_node["minimum"]


_load_schema()
4 changes: 3 additions & 1 deletion kas/schema-kas.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
]
},
{
"type": "integer"
"type": "integer",
"minimum": 1,
"maximum": 18
}
]
},
Expand Down

0 comments on commit acb5a52

Please sign in to comment.