diff --git a/apps_ci/scripts/catalog_update.py b/apps_ci/scripts/catalog_update.py index fd8662c..cb1c51d 100644 --- a/apps_ci/scripts/catalog_update.py +++ b/apps_ci/scripts/catalog_update.py @@ -50,7 +50,7 @@ def validate_train_data(train_data): except (json.JSONDecodeError, JsonValidationError) as e: verrors.add( 'catalog_json', - f'Failed to validate contents of train data ({".".join(list(e.path))}): {e!r}' + f'Failed to validate contents of train data ({".".join([str(p) for p in e.path])}): {e!r}' ) verrors.check() diff --git a/apps_validation/json_schema_utils.py b/apps_validation/json_schema_utils.py index 964222d..573f4eb 100644 --- a/apps_validation/json_schema_utils.py +++ b/apps_validation/json_schema_utils.py @@ -1,3 +1,22 @@ +APP_ITEM_JSON_SCHEMA = { + 'type': 'object', + 'properties': { + 'categories': { + 'type': 'array', + 'items': {'type': 'string'}, + }, + 'tags': { + 'type': 'array', + 'items': {'type': 'string'}, + }, + 'screenshots': { + 'type': 'array', + 'items': {'type': 'string'}, + }, + 'icon_url': {'type': 'string'}, + }, + 'required': ['categories'], +} APP_METADATA_JSON_SCHEMA = { 'type': 'object', 'properties': { @@ -79,6 +98,14 @@ 'required': ['description', 'host_path'], }, }, + 'screenshots': { + 'type': 'array', + 'items': {'type': 'string'}, + }, + 'categories': { + 'type': 'array', + 'items': {'type': 'string'}, + }, }, 'required': [ 'name', 'train', 'version', 'app_version', 'title', 'description', 'home', diff --git a/apps_validation/validate_app.py b/apps_validation/validate_app.py index e48b203..d94380a 100644 --- a/apps_validation/validate_app.py +++ b/apps_validation/validate_app.py @@ -2,11 +2,13 @@ import json import yaml +from jsonschema import validate as json_schema_validate, ValidationError as JsonValidationError + from apps_ci.names import CACHED_VERSION_FILE_NAME from apps_exceptions import ValidationErrors +from .json_schema_utils import APP_ITEM_JSON_SCHEMA from .validate_app_version import validate_catalog_item_version_data, validate_catalog_item_version -from .utils import validate_key_value_types def validate_catalog_item(catalog_item_path: str, schema: str, train_name: str, validate_versions: bool = True): @@ -37,12 +39,10 @@ def validate_catalog_item(catalog_item_path: str, schema: str, train_name: str, with open(os.path.join(catalog_item_path, 'item.yaml'), 'r') as f: item_config = yaml.safe_load(f.read()) - # TODO: Remove validate key value type function and have json schemas for all of this - validate_key_value_types( - item_config, ( - ('categories', list), ('tags', list, False), ('screenshots', list, False), - ), verrors, f'{schema}.item_config' - ) + try: + json_schema_validate(item_config, APP_ITEM_JSON_SCHEMA) + except JsonValidationError as e: + verrors.add(f'{schema}.item_config', f'Invalid format specified for item configuration: {e}') cached_version_file_path = os.path.join(catalog_item_path, CACHED_VERSION_FILE_NAME) if os.path.exists(cached_version_file_path):