|
39 | 39 | from cyclonedx.output import make_outputter |
40 | 40 | from cyclonedx.output.json import JsonV1Dot5 |
41 | 41 | from cyclonedx.schema import OutputFormat, SchemaVersion |
42 | | -from cyclonedx.validation import BaseSchemabasedValidator, make_schemabased_validator |
43 | | -from cyclonedx.validation.json import JsonStrictValidator |
44 | 42 | from extra_platforms import current_platform |
45 | 43 | from packageurl import PackageURL |
46 | 44 | from spdx_tools.spdx.model import ( |
@@ -390,25 +388,23 @@ def add_package(self, manager: PackageManager, package: Package) -> None: |
390 | 388 | ) |
391 | 389 |
|
392 | 390 | def export(self) -> str: |
393 | | - validator: BaseSchemabasedValidator |
394 | | - if self.export_format == ExportFormat.JSON: |
395 | | - content = JsonV1Dot5(self.document).output_as_string(indent=2) |
396 | | - validator = JsonStrictValidator(SchemaVersion.V1_5) |
| 391 | + """Serialize the document to its string representation. |
397 | 392 |
|
398 | | - elif self.export_format == ExportFormat.XML: |
399 | | - writer = make_outputter(self.document, OutputFormat.XML, SchemaVersion.V1_6) |
400 | | - content = writer.output_as_string(indent=2) |
401 | | - validator = make_schemabased_validator( |
402 | | - writer.output_format, writer.schema_version |
403 | | - ) |
| 393 | + .. note:: |
404 | 394 |
|
405 | | - else: |
406 | | - raise ValueError(f"{self.export_format} not supported.") |
| 395 | + Unlike :py:meth:`SPDX.export`, the generated document is not |
| 396 | + validated against its schema here. CycloneDX schema validation |
| 397 | + relies on ``cyclonedx-python-lib``'s ``[validation]`` extra, which |
| 398 | + pulls in ``jsonschema`` and, transitively, ``rfc3987-syntax``, |
| 399 | + ``lark``, and ``lxml``. To keep that stack out of ``mpm``'s runtime |
| 400 | + dependencies, the validation runs in the test suite instead. See |
| 401 | + ``tests/test_cli_sbom.py``. |
| 402 | + """ |
| 403 | + if self.export_format == ExportFormat.JSON: |
| 404 | + return JsonV1Dot5(self.document).output_as_string(indent=2) |
407 | 405 |
|
408 | | - logging.debug("Validate document...") |
409 | | - errors = validator.validate_str(content) |
410 | | - if errors: |
411 | | - logging.debug(content) |
412 | | - raise ValueError(f"Document is not valid. Errors: {errors}") |
| 406 | + if self.export_format == ExportFormat.XML: |
| 407 | + writer = make_outputter(self.document, OutputFormat.XML, SchemaVersion.V1_6) |
| 408 | + return writer.output_as_string(indent=2) |
413 | 409 |
|
414 | | - return content |
| 410 | + raise ValueError(f"{self.export_format} not supported.") |
0 commit comments