Repository navigation
Emit CycloneDX XML component and metadata elements in schema order - #22
Merged
andrew merged 1 commit intoOct 30, 2026
Merged
Conversation
andrew
approved these changes
Oct 30, 2026
andrew
left a comment
Contributor
There was a problem hiding this comment.
Order matches the 1.5 XSD for both component and metadata. One small thing for next time: the comment on cdxComponentXML (cyclonedx.go:57-58) could be the single line // Element order follows the CycloneDX XSD component sequence. to match the metadata one. "Decoding does not depend on element order" is the reasoning for the change rather than something the struct needs to say.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #21
Summary
The CycloneDX XSD defines element children as an
xs:sequence, so the XML encoder must emit them in schema order.cdxComponentXMLwrote<licenses>after<purl>, which made any component with both a PURL and a license fail validation against the 1.5 XSD.cdxComponentXMLto follow the XSD component sequence:supplier,author,name,version,description,hashes,licenses,copyright,purl,pedigree,externalReferences,properties,components. This fixes the reachablelicensescase plus the misplacedsupplier,author,hashesandcopyright.cdxMetadataXMLsomanufactureprecedessupplier, as the XSD metadata sequence requires.Encodedoes not emitmanufacturetoday, so this is preventive.Only struct field order changes. Decoding is unaffected because
encoding/xmlmatches elements by name regardless of order. JSON output is unchanged.Tests
Encode: a package with a PURL and a license now emitsname,version,licenses,purl,properties.The three order tests fail without the fix. Existing parse tests pass unchanged.
Verification
gofmt,go vet,go mod tidy -diffgo test -race ./...golangci-lint run ./...