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

Ignore unknown JSON fields in Connect unary responses #674

Merged
merged 4 commits into from
Jun 14, 2023

Conversation

smaye81
Copy link
Member

@smaye81 smaye81 commented Jun 13, 2023

This ignores unknown fields by default if the format is JSON when parsing a response. This was put into place in #642, but this is actually a special case that doesn't follow the code path in #642 and must be handled separately.

@smaye81 smaye81 requested a review from timostamm June 13, 2023 17:51
Comment on lines 208 to 210
if (options.jsonOptions) {
options.jsonOptions.ignoreUnknownFields ??= true;
}
Copy link
Member

Choose a reason for hiding this comment

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

This code block does not run if no jsonOptions are given, and unknown fields will not be ignored.

@timostamm
Copy link
Member

We should avoid duplicating the logic to change the settings. Let's add a function instead:

export function getJsonOptions(options: Partial<JsonReadOptions & JsonWriteOptions> | undefined) {
  const o = {...options};
  o.ignoreUnknownFields ??= true;
  return o;
}

And use that in serialization.ts, and in connect-transport.ts.

Copy link
Member

@timostamm timostamm left a comment

Choose a reason for hiding this comment

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

Just one suggestion for the JSDoc.

packages/connect/src/protocol/serialization.ts Outdated Show resolved Hide resolved
@timostamm timostamm changed the title Ignore unknown fields for unary JSON format Ignore unknown JSON fields in Connect unary responses Jun 14, 2023
smaye81 and others added 2 commits June 14, 2023 10:09
Co-authored-by: Timo Stamm <ts@timostamm.de>
@smaye81 smaye81 merged commit 4c67955 into main Jun 14, 2023
@smaye81 smaye81 deleted the sayers/special_case_json branch June 14, 2023 14:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants