duplicates_validator
trestle.core.duplicates_validator
¤
Validate by confirming no duplicate uuids.
Classes¤
DuplicatesValidator (Validator)
¤
Validator to check for duplicate uuids and param_ids in the model.
Source code in trestle/core/duplicates_validator.py
class DuplicatesValidator(Validator):
"""Validator to check for duplicate uuids and param_ids in the model."""
def model_is_valid(self, model: OscalBaseModel, quiet: bool, trestle_root: Optional[pathlib.Path] = None) -> bool:
"""
Test if the model is valid and contains no duplicate uuids or param_ids.
args:
model: An Oscal model that can be passed to the validator.
quiet: Don't report msgs unless invalid.
returns:
True (valid) if the model does not contain duplicate uuid's.
"""
if not ModelUtils.has_no_duplicate_values_by_name(model, 'uuid'):
return False
# only profile, comp-def and ssp have set-params and only set-params have param_id
# param_id is required to be unique in profiles but not in other models
if isinstance(model, Profile):
return ModelUtils.has_no_duplicate_values_by_name(model, 'param_id')
return True
Methods¤
model_is_valid(self, model, quiet, trestle_root=None)
¤
Test if the model is valid and contains no duplicate uuids or param_ids.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
OscalBaseModel |
An Oscal model that can be passed to the validator. |
required |
quiet |
bool |
Don't report msgs unless invalid. |
required |
Returns:
Type | Description |
---|---|
bool |
True (valid) if the model does not contain duplicate uuid's. |
Source code in trestle/core/duplicates_validator.py
def model_is_valid(self, model: OscalBaseModel, quiet: bool, trestle_root: Optional[pathlib.Path] = None) -> bool:
"""
Test if the model is valid and contains no duplicate uuids or param_ids.
args:
model: An Oscal model that can be passed to the validator.
quiet: Don't report msgs unless invalid.
returns:
True (valid) if the model does not contain duplicate uuid's.
"""
if not ModelUtils.has_no_duplicate_values_by_name(model, 'uuid'):
return False
# only profile, comp-def and ssp have set-params and only set-params have param_id
# param_id is required to be unique in profiles but not in other models
if isinstance(model, Profile):
return ModelUtils.has_no_duplicate_values_by_name(model, 'param_id')
return True
handler: python