Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: tools' services/components omit empty #1180

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ All notable changes to this project will be documented in this file.
* Static function `Models.Tool.fromComponent()` (via [#1163])
* Static function `Models.Tool.fromService()` (via [#1163])
* New class `Models.Tools` ([#1152] via [#1163])
* New serialization/normalization for `Models.Tools` ([#1152] via [#1163])
* New serialization/normalization for `Models.Tools` ([#1152] via [#1163], [#1180])
* Changed
* Serializers and `Bom`-Normalizers will take changed `Models.Bom.tools` into account ([#1152] via [#1163])
* Dependencies
Expand All @@ -24,6 +24,7 @@ All notable changes to this project will be documented in this file.
[#1152]: https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1152
[#1163]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1163
[#1173]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1173
[#1180]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1180

## 6.13.0 -- 2024-11-18

Expand Down
8 changes: 6 additions & 2 deletions src/serialize/json/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,12 @@ export class ToolsNormalizer extends BaseJsonNormalizer<Models.Tools> {
)), options)
}
return {
components: this._factory.makeForComponent().normalizeIterable(data.components, options),
services: this._factory.makeForService().normalizeIterable(data.services, options)
components: data.components.size > 0
? this._factory.makeForComponent().normalizeIterable(data.components, options)
: undefined,
services: data.services.size > 0
? this._factory.makeForService().normalizeIterable(data.services, options)
: undefined
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/serialize/json/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ export namespace Normalized {

/** since CDX 1.5 */
export interface Tools {
components: Component[]
services: Service[]
components?: Component[]
services?: Service[]
}

export type ToolsType = Tools | Tool[]
Expand Down
2 changes: 1 addition & 1 deletion src/serialize/xml/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export class ToolsNormalizer extends BaseXmlNormalizer<Models.Tools> {
children: this._factory.makeForComponent().normalizeIterable(data.components, options, 'component')
})
}
if (data.components.size > 0) {
if (data.services.size > 0) {
jkowalleck marked this conversation as resolved.
Show resolved Hide resolved
children.push({
type: 'element',
name: 'services',
Expand Down