From 3e0c557308c74fb281c7e7ffea1ba9bc7bafc6ef Mon Sep 17 00:00:00 2001 From: Yash Patel Date: Fri, 26 Apr 2024 14:20:03 -0700 Subject: [PATCH 1/3] Update custom schema validation function to accept YAML file and parsed Map --- config/schema/schema.config | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/config/schema/schema.config b/config/schema/schema.config index bb1f23e..a1a4f88 100644 --- a/config/schema/schema.config +++ b/config/schema/schema.config @@ -1,4 +1,5 @@ import org.yaml.snakeyaml.Yaml +includeConfig "./custom_schema_types.config" /** * This schema namespace is used to valide the params defined in config file(s) using a schema * YAML file. This config script should be included and called through `schema.validate()` at the @@ -252,12 +253,21 @@ schema { /** * Fine-grained validation entrypoint; to be used for validating specific namespaces with certain parameters excluded - * file_path: path to schema YAML to be used for validation + * schema_to_validate: path to schema YAML to be used for validation * params_to_validate: Map of parameters to validate against schema * keys_to_exclude: params to skip during validation + * @throws IllegalArgumentException when invalid format of schema is provided */ - validate_specific = { String file_path, Map params_to_validate, List keys_to_exclude=[] -> - def params_schema = schema.load_schema(file_path) + validate_specific = { Object schema_to_validate, Map params_to_validate, List keys_to_exclude=[] -> + def params_schema; + if (custom_schema_types.is_string(schema_to_validate)) { + params_schema = schema.load_schema(schema_to_validate) + } else if (schema_to_validate in Map) { + params_schema = schema_to_validate + } else { + throw new IllegalArgumentException("The given schema must be a path to the schema YAML or a Map, received `${schema_to_validate.getClass()}` instead.") + } + params_schema.removeAll{ key, val -> keys_to_exclude.contains(key) } params_schema.each { key, val -> schema.validate_parameter(params_to_validate, key, val) From a0d34c446b973a78f9d98f6fd844bf0938103193 Mon Sep 17 00:00:00 2001 From: Yash Patel Date: Fri, 26 Apr 2024 14:20:42 -0700 Subject: [PATCH 2/3] Update README --- config/schema/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/schema/README.md b/config/schema/README.md index b45bcae..40f43e1 100644 --- a/config/schema/README.md +++ b/config/schema/README.md @@ -93,7 +93,7 @@ input: - Positional args: |position|name|type|required|default|description| |:--:|:--:|:--:|:--:|:--:|:--:| - |1|`file_path`|String|Yes|none|Path to the `schema.yaml` file| + |1|`file_path`|String or Map|Yes|none|Path to the `schema.yaml` file or loaded schema as a Map| |2|`params_to_validate`|Map|Yes|none|Namespace of parameters to validate| |3|`keys_to_exclude`|List|No|`[]`|List of parameters to skip validation| From 46e7b67023d606ede632c6c6fcf8c9121ba75f3f Mon Sep 17 00:00:00 2001 From: Yash Patel Date: Fri, 26 Apr 2024 14:22:10 -0700 Subject: [PATCH 3/3] Update main CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71e69b4..3f5fdd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm ### Changed - Allow `set_resources_allocation` to use maximum allocation values defined in params - Add `def`s to multiple variables that should not be globally defined +- Allow specific schema validation function to accept pre-loaded schema as input ---