Skip to content

Commit aaae9c2

Browse files
authored
datastreams: skip null array entries (#6090)
This aligns with the former implementation.
1 parent e8ac8bf commit aaae9c2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packages/dd-trace/src/datastreams/schemas/schema_builder.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ class OpenApiComponents {
9999
// This adds a single whitespace between entries without adding newlines.
100100
// This differs from JSON.stringify and is used to align with the output
101101
// in other platforms.
102+
// TODO: Add tests to verify this behavior. A couple of cases are not
103+
// covered by the existing tests.
102104
function toJSON (value) {
103105
// eslint-disable-next-line eslint-rules/eslint-safe-typeof-object
104106
if (typeof value === 'object') {
@@ -108,10 +110,12 @@ function toJSON (value) {
108110
if (Array.isArray(value)) {
109111
let result = '['
110112
for (let i = 0; i < value.length; i++) {
111-
if (i > 0) {
112-
result += ', '
113+
if (value[i] !== null) {
114+
if (i !== 0) {
115+
result += ', '
116+
}
117+
result += value[i] === undefined ? 'null' : toJSON(value[i])
113118
}
114-
result += value[i] == null ? 'null' : toJSON(value[i])
115119
}
116120
return `${result}]`
117121
}

0 commit comments

Comments
 (0)