Skip to content

Commit 85a8f5e

Browse files
authored
fix: tools' services/components omit empty (#1180)
Signed-off-by: Jan Kowalleck <[email protected]> Co-authored-by: jkowalleck <[email protected]>
1 parent 1ad0dd3 commit 85a8f5e

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

HISTORY.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ All notable changes to this project will be documented in this file.
1313
* Static function `Models.Tool.fromComponent()` (via [#1163])
1414
* Static function `Models.Tool.fromService()` (via [#1163])
1515
* New class `Models.Tools` ([#1152] via [#1163])
16-
* New serialization/normalization for `Models.Tools` ([#1152] via [#1163])
16+
* New serialization/normalization for `Models.Tools` ([#1152] via [#1163], [#1180])
1717
* Changed
1818
* Serializers and `Bom`-Normalizers will take changed `Models.Bom.tools` into account ([#1152] via [#1163])
1919
* Dependencies
@@ -24,6 +24,7 @@ All notable changes to this project will be documented in this file.
2424
[#1152]: https://github.com/CycloneDX/cyclonedx-javascript-library/issues/1152
2525
[#1163]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1163
2626
[#1173]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1173
27+
[#1180]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/1180
2728

2829
## 6.13.0 -- 2024-11-18
2930

src/serialize/json/normalize.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,12 @@ export class ToolsNormalizer extends BaseJsonNormalizer<Models.Tools> {
302302
)), options)
303303
}
304304
return {
305-
components: this._factory.makeForComponent().normalizeIterable(data.components, options),
306-
services: this._factory.makeForService().normalizeIterable(data.services, options)
305+
components: data.components.size > 0
306+
? this._factory.makeForComponent().normalizeIterable(data.components, options)
307+
: undefined,
308+
services: data.services.size > 0
309+
? this._factory.makeForService().normalizeIterable(data.services, options)
310+
: undefined
307311
}
308312
}
309313
}

src/serialize/json/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ export namespace Normalized {
120120

121121
/** since CDX 1.5 */
122122
export interface Tools {
123-
components: Component[]
124-
services: Service[]
123+
components?: Component[]
124+
services?: Service[]
125125
}
126126

127127
export type ToolsType = Tools | Tool[]

src/serialize/xml/normalize.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ export class ToolsNormalizer extends BaseXmlNormalizer<Models.Tools> {
389389
children: this._factory.makeForComponent().normalizeIterable(data.components, options, 'component')
390390
})
391391
}
392-
if (data.components.size > 0) {
392+
if (data.services.size > 0) {
393393
children.push({
394394
type: 'element',
395395
name: 'services',

0 commit comments

Comments
 (0)