Skip to content

fix: lossless flattening of dependency graph during JSON serialization#993

Merged
jkowalleck merged 31 commits into
mainfrom
fix/dependencygraph-flatten-in-json
Jun 11, 2026
Merged

fix: lossless flattening of dependency graph during JSON serialization#993
jkowalleck merged 31 commits into
mainfrom
fix/dependencygraph-flatten-in-json

Conversation

@jkowalleck

@jkowalleck jkowalleck commented Jun 8, 2026

Copy link
Copy Markdown
Member

Description

flatten nested dependency tree when rendering JSON.

Resolves or fixes issue: #941

AI Tool Disclosure

  • My contribution does not include any AI-generated content
  • My contribution includes AI-generated content, as disclosed below:
    • AI Tools: [e.g. GitHub CoPilot, ChatGPT, JetBrains Junie etc.]
    • LLMs and versions: [e.g. GPT-4.1, Claude Haiku 4.5, Gemini 2.5 Pro etc.]
    • Prompts: [Summarize the key prompts or instructions given to the AI tools]

Affirmation

stefan6419846 and others added 4 commits March 5, 2026 17:03
Relates to #941.

Signed-off-by: stefan6419846 <96178532+stefan6419846@users.noreply.github.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
@jkowalleck jkowalleck requested a review from a team as a code owner June 8, 2026 14:26
@jkowalleck jkowalleck added the bug Something isn't working label Jun 8, 2026
@jkowalleck jkowalleck marked this pull request as draft June 8, 2026 14:26
@jkowalleck jkowalleck linked an issue Jun 8, 2026 that may be closed by this pull request
@read-the-docs-community

read-the-docs-community Bot commented Jun 8, 2026

Copy link
Copy Markdown

@codacy-production

codacy-production Bot commented Jun 8, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 17 complexity · 1 duplication

Metric Results
Complexity 17
Duplication 1

View in Codacy

🟢 Coverage 100.00% diff coverage

Metric Results
Coverage variation Report missing for a8579b81
Diff coverage 100.00% diff coverage (80.00%)

View coverage diff in Codacy

Coverage variation details
Coverable lines Covered lines Coverage
Common ancestor commit (a8579b8) Report Missing Report Missing Report Missing
Head commit (76f1830) 6079 5729 94.24%

Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: <coverage of head commit> - <coverage of common ancestor commit>

Diff coverage details
Coverable lines Covered lines Diff coverage
Pull request (#993) 3 3 100.00%

Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: <covered lines added or modified>/<coverable lines added or modified> * 100%

1 Codacy didn't receive coverage data for the commit, or there was an error processing the received data. Check your integration for errors and validate that your coverage setup is correct.

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.

Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Comment thread tests/test_output_json.py Fixed
Comment thread tests/test_output_json.py Fixed
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Comment thread tests/test_output_json.py Outdated
@jkowalleck

jkowalleck commented Jun 8, 2026

Copy link
Copy Markdown
Member Author

@stefan6419846 see this proposed fix for #941
the original test data is from your branch in #942.

Implementation is working as expected.

if you have additional test cases, just pull-request them to the branch of this PR.

Comment thread tests/test_output_json.py Outdated
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Comment thread cyclonedx/output/json.py Fixed
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Comment thread cyclonedx/contrib/bom/utils.py Fixed
Comment thread cyclonedx/contrib/bom/utils.py Fixed
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses #941 by ensuring nested cyclonedx.model.dependency.Dependency graphs are flattened into the CycloneDX JSON-required “flat list of nodes” form during JSON rendering, so nested dependency information is not silently lost.

Changes:

  • Added a BomDependencyGraphFlatMerger utility (context manager) to flatten/merge nested dependency trees into a flat dependency list.
  • Wrapped JSON output generation with the dependency flattener to produce correct JSON dependencies output.
  • Added tests + new snapshot fixtures covering the nested-dependency scenario across schema versions.

Reviewed changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cyclonedx/output/json.py Applies dependency flattening during JSON generation via a context manager.
cyclonedx/contrib/bom/utils.py Introduces BomDependencyGraphFlatMerger to flatten/merge nested dependency graphs.
cyclonedx/contrib/bom/__init__.py Adds contrib BOM package marker/docstring.
tests/test_contrib/test_bom_utils.py Adds unit tests for flatten/merge + reset behavior.
tests/test_contrib/__init__.py Adds test package marker.
tests/_data/models.py Adds a new BOM factory reproducing issue #941.
tests/_data/snapshots/*issue941* Adds expected XML/JSON snapshots demonstrating correct serialization output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread cyclonedx/contrib/bom/utils.py Outdated
Comment thread cyclonedx/contrib/bom/utils.py
@jkowalleck

jkowalleck commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

This PR shall be split in two:

  1. feat: add this new contrib utility - feat: add contrib.bom.utils.BomDependencyGraphFlatMerger #997
  2. fix: have JSON dep tree flattened - this PR

Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
Signed-off-by: Jan Kowalleck <jan.kowalleck@gmail.com>
@jkowalleck jkowalleck requested a review from Copilot June 11, 2026 10:18
@jkowalleck jkowalleck changed the title [WIP] fix: dependencygraph flatten in json fix: looseless flatten dependencygraph in JSON serializzation Jun 11, 2026
@jkowalleck jkowalleck marked this pull request as ready for review June 11, 2026 10:19
@jkowalleck jkowalleck changed the title fix: looseless flatten dependencygraph in JSON serializzation fix: Lossless flattening of dependency graph during JSON serialization Jun 11, 2026
@jkowalleck jkowalleck changed the title fix: Lossless flattening of dependency graph during JSON serialization fix: lossless flattening of dependency graph during JSON serialization Jun 11, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Comment thread cyclonedx/output/json.py
@jkowalleck jkowalleck merged commit d0e10ca into main Jun 11, 2026
93 of 95 checks passed
@jkowalleck jkowalleck deleted the fix/dependencygraph-flatten-in-json branch June 11, 2026 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nested cyclonedx.model.dependency.Dependency not serialized to JSON

3 participants