Skip to content

[FEAT] Define hierarchical and flat merge methods #909

Open

Description

@woshiwuja

The C# Library and the CLI tool expose to the user the methods for merging different SBOMs using either hierarchical or flat strategies. This is completely absent in the python library and forces to user to write them leading to differences in implementations. Would it make sense to expose this function/method? The C# library HierarchicalMerge function takes in a list of boms and the merge component, so i guess it would be something like

def hierachical_merge(boms, metadata_component):
    # merge stuff
    return merged_bom

while the flat merge

def flat_merge(boms):
    return merged_bom

Activity

  1. woshiwuja commented on Nov 12, 2025

    @woshiwuja
    Author

    The implementation for the flat merge on the other hand is really simple

            public static Bom FlatMerge(IEnumerable<Bom> boms)
            {
                var result = new Bom();
    
                foreach (var bom in boms)
                {
                    result = FlatMerge(result, bom);
                }
    
                return result;
            }
    
  2. jkowalleck commented on Nov 12, 2025

    @jkowalleck
    Member

    Currently, there is no common ground for such a feature in the library.
    This might change in the future, feel free to discuss.


    Some trivia:

    [...] methods for merging different SBOMs using either hierarchical or flat strategies.
    This is completely absent in the python library and forces to user to write them leading to differences in implementations. Would it make sense to expose this function/method?

    The merge topic is disputable and no consensus was found - see CycloneDX/specification#320.
    Every user has different requirements to the merge result, and an authoritative guide to merging does not exist.

    This is completely absent in the python library [...]

    This is for the following reasons

    • there is a working implementation already: the CyclonedX CLI tool - not an API, but a stable CLI that can be used programmatically for merging things.
    • merging is disputable - as stated above
    • this library enables everybody to implement the merge algorithm as they need it - it is either trivial (-> no need to have this snipped as part of the library) or complex and "different" (-> no common implementation -> no way to have this snipped as part of the library)
  3. woshiwuja commented on Nov 12, 2025

    @woshiwuja
    Author

    You are right for the most part, but isnt using the CLI tool just a more complex way to use the .Net library?
    This forces you to either:

    • implement it yourself (which, as i understood, you think its a good way to go about it)
    • use the cli (relying on C# libraries)

    It doesnt make sense for a developer using the python library having to resort to C# stuff or cli binaries, expecially when despite no consensus on the implementation it is indeed implemented inside the official tool, implementing the 2 algorithms inside the library doesnt take away the choice of making your own, it just exposes an implementation of the ones used by the official cli tool.

    Instead of just doing python bom objects -> merged_objects this forces devs to do python bom objects -> produce sbom json/xml -> cli tool merge -> python load merged bom -> python merged bom object.

    This creates WAY more possibile points of failure imho

  4. woshiwuja commented on Nov 25, 2025

    @woshiwuja
    Author

    i have written the merge function myself, if its welcomed i can make a pr.

  5. jkowalleck commented on Nov 25, 2025

    @jkowalleck
    Member

    i have written the merge function myself, if its welcomed i can make a pr.

    why not have it as a "contrib" extension.

    please pull-request your implementation(s) to a path like /cyclonedx/contrib/<my_functionality>.py

    PS: see the ongoing prep in #916

  6. added
    enhancementNew feature or request
    contribContributed features not part of the core library.
    on Nov 25, 2025
  7. jkowalleck commented on Dec 2, 2025

    @jkowalleck
    Member

    since #916
    was merged, the proper place for these merge methods could be one of these:

    • cyclonedx/contrib/merge
    • cyclonedx/contrib/bom/merge
  8. woshiwuja commented on Dec 10, 2025

    @woshiwuja
    Author

    I'll probably pr this with my work email, i implemented the hierarchical merge, do you think the flat version would be useful as well? I honestly cant find a good reason to use it

  9. jkowalleck commented on Dec 10, 2025

    @jkowalleck
    Member

    I'll probably pr this with my work email, i implemented the hierarchical merge, do you think the flat version would be useful as well? I honestly cant find a good reason to use it

    Just do how you feel.
    With that new contrib area being wild, everything is possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    contribContributed features not part of the core library.enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions