Skip to content

feat!: implement ModelValidator and remove Bom.validate()#935

Open
saquibsaifee wants to merge 8 commits intoCycloneDX:mainfrom
saquibsaifee:feat/refactor-validation-to-model-validator
Open

feat!: implement ModelValidator and remove Bom.validate()#935
saquibsaifee wants to merge 8 commits intoCycloneDX:mainfrom
saquibsaifee:feat/refactor-validation-to-model-validator

Conversation

@saquibsaifee
Copy link
Copy Markdown
Contributor

@saquibsaifee saquibsaifee commented Feb 15, 2026

Description

Implements #455 as a breaking change.

Bom.validate() is removed and replaced by ModelValidator in cyclonedx.validation.model, which provides the "more advanced" validation API — typed errors with severity levels, side-effect free, and fully testable.

Changes

cyclonedx/validation/model.py

  • New ModelValidationErrorSeverity enum (ERROR / WARNING) for typed severity
  • ModelValidationError gains a severity field (default ERROR)
  • ModelValidator.validate(bom) returns Iterable[ModelValidationError] — fully side-effect free
  • Bug fix: nested components under metadata.component are now included in license validation (previously only the root was checked)
  • Bug fix: top-level d.ref values in bom.dependencies are now validated against known BOM components (previously only nested refs were checked)
  • Incomplete dependency graph check now yields a ModelValidationError(severity=WARNING) with UserWarning data, instead of emitting a Python warnings.warn() — making it visible to callers and testable via ModelValidator

cyclonedx/model/bom.py

  • Bom.validate() removed (breaking change)

cyclonedx/output/__init__.py, json.py, xml.py

  • Dependency graph normalization (register_dependency) and model validation are consolidated into a single BaseOutput._prepare() hook, shared by both JSON and XML serializers — eliminating duplicated logic

Migration

Replace bom.validate() calls with:

from cyclonedx.validation.model import ModelValidationErrorSeverity, ModelValidator

errors = [e for e in ModelValidator().validate(bom)
          if e.severity is ModelValidationErrorSeverity.ERROR]

AI Tool Disclosure

  • My contribution includes AI-generated content, as disclosed below:
    • AI Tools: Claude Code
    • LLMs and versions: Claude Sonnet 4.6

Affirmation

@read-the-docs-community
Copy link
Copy Markdown

read-the-docs-community Bot commented Feb 15, 2026

Documentation build overview

📚 CycloneDX Python Library | 🛠️ Build #32417460 | 📁 Comparing d726148 against latest (4ef5bc3)

  🔍 Preview build  

3 files changed
± genindex.html
± autoapi/cyclonedx/model/bom/index.html
± autoapi/cyclonedx/validation/model/index.html

Signed-off-by: Saquib Saifee <saquibsaifee2@gmail.com>
@saquibsaifee saquibsaifee force-pushed the feat/refactor-validation-to-model-validator branch from 228bc94 to 745d773 Compare February 15, 2026 04:44
@codacy-production
Copy link
Copy Markdown

codacy-production Bot commented Apr 25, 2026

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 7 complexity · 0 duplication

Metric Results
Complexity 7
Duplication 0

View in Codacy

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.

saquibsaifee and others added 4 commits April 29, 2026 16:41
…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>
@saquibsaifee saquibsaifee marked this pull request as ready for review April 29, 2026 20:43
@saquibsaifee saquibsaifee requested a review from a team as a code owner April 29, 2026 20:43
@saquibsaifee saquibsaifee changed the title feat: refactor Bom.validate() to ModelValidator... feat!: implement ModelValidator and remove Bom.validate() (resolves #455) Apr 29, 2026
@saquibsaifee saquibsaifee changed the title feat!: implement ModelValidator and remove Bom.validate() (resolves #455) feat!: implement ModelValidator and remove Bom.validate() Apr 29, 2026
@saquibsaifee
Copy link
Copy Markdown
Contributor Author

@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.

@jkowalleck jkowalleck added enhancement New feature or request breaking change labels Apr 30, 2026
@jkowalleck jkowalleck linked an issue Apr 30, 2026 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

move model.bom.Bom.validate() to validation.models

2 participants