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

Handle null values when deserializing series and structs for command expansion #1347

Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,10 @@ function convertType(value: any, schema: Schema): any {
case SchemaTypes.String:
return value;
case SchemaTypes.Series:
return value.map((value: any) => convertType(value, schema.items));
return value == null ? null : value.map((value: any) => convertType(value, schema.items));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would returning an empty array [] be better than returning null? This would show an absent collection while preserving the series structure.

case SchemaTypes.Struct:
const struct: { [attributeName: string]: any } = {};
if (value == null) {return null;}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the series but returning an empty {}

for (const [attributeKey, attributeSchema] of Object.entries(schema.items)) {
struct[attributeKey] = convertType(value[attributeKey], attributeSchema);
}
Expand Down
Loading