feat!: implement ModelValidator and remove Bom.validate() - #935
feat!: implement ModelValidator and remove Bom.validate()#935saquibsaifee wants to merge 13 commits into
Conversation
Documentation build overview
18 files changed ·
|
Signed-off-by: Saquib Saifee <saquibsaifee2@gmail.com>
228bc94 to
745d773
Compare
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 6 |
| Duplication | 0 |
NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.
…ator - Add ModelValidationErrorSeverity enum (ERROR/WARNING) for typed severity - Fix nested components under metadata.component not being license-checked - Fix top-level dependency d.ref not validated against known BOM components - Convert incomplete-dependency-graph warning to typed ModelValidationError with WARNING severity instead of Python warnings.warn() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Saquib Saifee <saquibsaifee2@gmail.com>
Bom.validate() has been removed. Use cyclonedx.validation.model.ModelValidator instead, which provides typed validation errors with severity levels. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Saquib Saifee <saquibsaifee2@gmail.com>
…utput._prepare() Both JSON and XML serializers now share a single _prepare() hook that runs dependency graph normalization (register_dependency) and ModelValidator before serialization, eliminating duplicated logic. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Saquib Saifee <saquibsaifee2@gmail.com>
Replace bom.validate() calls with ModelValidator().validate(bom) across test_model_bom.py and test_real_world_examples.py. Add regression tests for the two bug fixes (nested component license check, top-level dependency ref). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Signed-off-by: Saquib Saifee <saquibsaifee2@gmail.com>
|
@jkowalleck, please have a look. I made it as a breaking change, which might be uncalled for, and happy to make it deprecated with a warning instead. |
CAOShurong
left a comment
There was a problem hiding this comment.
The new ModelValidator behavior looks well covered, but this head removes Bom.validate() outright even though the maintainer direction in issue #455 says the existing public API should be deprecated while the advanced replacement is provided: #455 (comment)
I reproduced the compatibility break against current main (52cb3c9) and this exact head (00df85b): Bom().validate() returns True on main, while this head raises AttributeError: 'Bom' object has no attribute 'validate'. The full candidate suite passes (6,965 tests), so the current tests do not protect that public call path.
Please keep Bom.validate() as a deprecated compatibility wrapper (preserving its normalization, warning, exception, and boolean-return behavior while delegating validation where appropriate), and add a regression that exercises the legacy caller during the deprecation window. The new side-effect-free ModelValidator and output _prepare() path can remain the preferred API.
Verification on exact head 00df85b: 744 focused output/model/validation tests and all 6,965 tests passed; flake8 and mypy passed; sdist/wheel build, clean-wheel install, valid JSON dependency normalization/warning, invalid-license rejection, and unknown-reference validation probes passed.
Review prepared with assistance from OpenAI Codex; I independently ran and checked the commands and results described above.
Description
Implements #455 as a breaking change.
Bom.validate()is removed and replaced byModelValidatorincyclonedx.validation.model, which provides the "more advanced" validation API — typed errors with severity levels, side-effect free, and fully testable.Changes
cyclonedx/validation/model.pyModelValidationErrorSeverityenum (ERROR/WARNING) for typed severityModelValidationErrorgains aseverityfield (defaultERROR)ModelValidator.validate(bom)returnsIterable[ModelValidationError]— fully side-effect freemetadata.componentare now included in license validation (previously only the root was checked)d.refvalues inbom.dependenciesare now validated against known BOM components (previously only nested refs were checked)ModelValidationError(severity=WARNING)withUserWarningdata, instead of emitting a Pythonwarnings.warn()— making it visible to callers and testable viaModelValidatorcyclonedx/model/bom.pyBom.validate()removed (breaking change)cyclonedx/output/__init__.py,json.py,xml.pyregister_dependency) and model validation are consolidated into a singleBaseOutput._prepare()hook, shared by both JSON and XML serializers — eliminating duplicated logicMigration
Replace
bom.validate()calls with:AI Tool Disclosure
Affirmation