Skip to content

Commit

Permalink
fix: tools' services/components omit empty (#1180)
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Kowalleck <[email protected]>
Co-authored-by: jkowalleck <[email protected]>
  • Loading branch information
jkowalleck and jkowalleck authored Nov 20, 2024
1 parent 1ad0dd3 commit 85a8f5e
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
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) {
children.push({
type: 'element',
name: 'services',
Expand Down

0 comments on commit 85a8f5e

Please sign in to comment.