Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more options for specific validation function #63

Merged
merged 3 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

---

Expand Down
2 changes: 1 addition & 1 deletion config/schema/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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|

Expand Down
16 changes: 13 additions & 3 deletions config/schema/schema.config
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
Loading