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 --- 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| 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)