Skip to content

Commit e160671

Browse files
committed
fix normalixer of Models.Component.properties with CDX-1.2
* Fixed * JSON- and XML-Normalizer no longer render `Models.Component.properties` with [_CycloneDX_ Specification][CycloneDX-specification]-1.2. ([#152] via [#153]) * XML-Normalizer now has the correct order/position of rendered `Models.Component.properties`. (via [#153]) [#152]: #152 [#153]: #153 [CycloneDX-specification]: https://github.com/CycloneDX/specification/tree/main/schema
1 parent 5f1e1f1 commit e160671

File tree

8 files changed

+52
-98
lines changed

8 files changed

+52
-98
lines changed

HISTORY.md

+11
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
44

55
## unreleased
66

7+
## 1.3.1 - 2022-08-04
8+
9+
* Fixed
10+
* JSON- and XML-Normalizer no longer render `Models.Component.properties`
11+
with [_CycloneDX_ Specification][CycloneDX-specification]-1.2.
12+
([#152] via [#153])
13+
* XML-Normalizer now has the correct order/position of rendered `Models.Component.properties`. (via [#153])
14+
15+
[#152]: https://github.com/CycloneDX/cyclonedx-javascript-library/issues/152
16+
[#153]: https://github.com/CycloneDX/cyclonedx-javascript-library/pull/153
17+
718
## 1.3.0 - 2022-08-03
819

920
* Changed

src/serialize/json/normalize.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -280,11 +280,11 @@ export class ComponentNormalizer extends Base {
280280
externalReferences: data.externalReferences.size > 0
281281
? this._factory.makeForExternalReference().normalizeRepository(data.externalReferences, options)
282282
: undefined,
283+
properties: spec.supportsProperties(data) && data.properties.size > 0
284+
? this._factory.makeForProperty().normalizeRepository(data.properties, options)
285+
: undefined,
283286
components: data.components.size > 0
284287
? this.normalizeRepository(data.components, options)
285-
: undefined,
286-
properties: data.properties.size > 0
287-
? this._factory.makeForProperty().normalizeRepository(data.properties, options)
288288
: undefined
289289
}
290290
: undefined

src/serialize/xml/normalize.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -344,18 +344,18 @@ export class ComponentNormalizer extends Base {
344344
.normalizeRepository(data.externalReferences, options, 'reference')
345345
}
346346
: undefined
347-
const components: SimpleXml.Element | undefined = data.components.size > 0
347+
const properties: SimpleXml.Element | undefined = spec.supportsProperties(data) && data.properties.size > 0
348348
? {
349349
type: 'element',
350-
name: 'components',
351-
children: this.normalizeRepository(data.components, options, 'component')
350+
name: 'properties',
351+
children: this._factory.makeForProperty().normalizeRepository(data.properties, options, 'property')
352352
}
353353
: undefined
354-
const properties: SimpleXml.Element | undefined = data.properties.size > 0
354+
const components: SimpleXml.Element | undefined = data.components.size > 0
355355
? {
356356
type: 'element',
357-
name: 'properties',
358-
children: this._factory.makeForProperty().normalizeRepository(data.properties, options, 'property')
357+
name: 'components',
358+
children: this.normalizeRepository(data.components, options, 'component')
359359
}
360360
: undefined
361361
return {
@@ -381,8 +381,8 @@ export class ComponentNormalizer extends Base {
381381
makeOptionalTextElement(data.purl, 'purl'),
382382
swid,
383383
extRefs,
384-
components,
385-
properties
384+
properties,
385+
components
386386
].filter(isNotUndefined)
387387
}
388388
}

src/spec.ts

+28-22
Original file line numberDiff line numberDiff line change
@@ -37,28 +37,21 @@ export class UnsupportedFormatError extends Error {
3737
}
3838

3939
export interface Protocol {
40-
readonly version: Version
41-
40+
version: Version
4241
supportsFormat: (f: Format | any) => boolean
43-
4442
supportsComponentType: (ct: ComponentType | any) => boolean
45-
4643
supportsHashAlgorithm: (ha: HashAlgorithm | any) => boolean
47-
4844
supportsHashValue: (hv: HashContent | any) => boolean
49-
5045
supportsExternalReferenceType: (ert: ExternalReferenceType | any) => boolean
51-
52-
readonly supportsDependencyGraph: boolean
53-
54-
readonly supportsToolReferences: boolean
55-
56-
readonly requiresComponentVersion: boolean
46+
supportsDependencyGraph: boolean
47+
supportsToolReferences: boolean
48+
requiresComponentVersion: boolean
49+
supportsProperties: (model: any) => boolean
5750
}
5851

5952
/**
60-
* @internal This class was never intended to be public,
61-
* but it is a helper to get the exact spec-versions implemented according to {@see Protocol}.
53+
* @internal This class was never intended to be public, but
54+
* it is a helper to get the exact spec-versions implemented according to {@see Protocol}.
6255
*/
6356
class Spec implements Protocol {
6457
readonly #version: Version
@@ -70,6 +63,7 @@ class Spec implements Protocol {
7063
readonly #supportsDependencyGraph: boolean
7164
readonly #supportsToolReferences: boolean
7265
readonly #requiresComponentVersion: boolean
66+
readonly #supportsProperties: boolean
7367

7468
constructor (
7569
version: Version,
@@ -80,7 +74,8 @@ class Spec implements Protocol {
8074
externalReferenceTypes: Iterable<ExternalReferenceType>,
8175
supportsDependencyGraph: boolean,
8276
supportsToolReferences: boolean,
83-
requiresComponentVersion: boolean
77+
requiresComponentVersion: boolean,
78+
supportsProperties: boolean
8479
) {
8580
this.#version = version
8681
this.#formats = new Set(formats)
@@ -91,6 +86,7 @@ class Spec implements Protocol {
9186
this.#supportsDependencyGraph = supportsDependencyGraph
9287
this.#supportsToolReferences = supportsToolReferences
9388
this.#requiresComponentVersion = requiresComponentVersion
89+
this.#supportsProperties = supportsProperties
9490
}
9591

9692
get version (): Version {
@@ -129,6 +125,11 @@ class Spec implements Protocol {
129125
get requiresComponentVersion (): boolean {
130126
return this.#requiresComponentVersion
131127
}
128+
129+
supportsProperties (): boolean {
130+
// currently a global allow/deny -- might work based on input, in the future
131+
return this.#supportsProperties
132+
}
132133
}
133134

134135
/** Specification v1.2 */
@@ -182,7 +183,8 @@ export const Spec1dot2: Readonly<Protocol> = Object.freeze(new Spec(
182183
],
183184
true,
184185
false,
185-
true
186+
true,
187+
false
186188
))
187189

188190
/** Specification v1.3 */
@@ -236,6 +238,7 @@ export const Spec1dot3: Readonly<Protocol> = Object.freeze(new Spec(
236238
],
237239
true,
238240
false,
241+
true,
239242
true
240243
))
241244

@@ -291,11 +294,14 @@ export const Spec1dot4: Readonly<Protocol> = Object.freeze(new Spec(
291294
],
292295
true,
293296
true,
294-
false
297+
false,
298+
true
295299
))
296300

297-
export const SpecVersionDict = Object.freeze(Object.fromEntries([
298-
[Version.v1dot2, Spec1dot2],
299-
[Version.v1dot3, Spec1dot3],
300-
[Version.v1dot4, Spec1dot4]
301-
]) as { [key in Version]?: Readonly<Protocol> })
301+
export const SpecVersionDict: { readonly [key in Version]?: Readonly<Protocol> } = Object.freeze(
302+
Object.fromEntries([
303+
[Version.v1dot2, Spec1dot2],
304+
[Version.v1dot3, Spec1dot3],
305+
[Version.v1dot4, Spec1dot4]
306+
])
307+
)

tests/_data/normalizeResults/json_sortedLists_spec1.2.json

+1-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/normalizeResults/xml_sortedLists_spec1.2.json

-30
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/serializeResults/json_complex_spec1.2.json.bin

+1-15
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/_data/serializeResults/xml_complex_spec1.2.xml.bin

-5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)