-
Notifications
You must be signed in to change notification settings - Fork 90
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
fix(protocols): fix header serde, handle unset union payloads #1417
Conversation
b2e5153
to
4821895
Compare
4821895
to
89fedbc
Compare
Location.PAYLOAD, "data", binding.getMember(), target)); | ||
} | ||
); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
old:
const data: Record<string, any> | undefined = __expectUnion(await parseBody(output.body, context));
contents.nested = de_UnionPayload(data, context);
(does not handle empty output correctly)
new:
const data: Record<string, any> | undefined = await parseBody(output.body, context);
if (Object.keys(data ?? {}).length) {
contents.nested = __expectUnion(de_UnionPayload(data, context));
}
d757a15
to
d51fec8
Compare
* @param value - header string value. | ||
* @returns value split by commas that aren't in quotes. | ||
*/ | ||
export const splitHeader = (value: string): string[] => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This takes over .split(",")
on the deserialization side. Splitting by commas is not enough, because commas within quotes do not count as delimiters, and once split, the items wrapped by double quotes should have those quotes removed.
Behavior specified here: https://github.com/smithy-lang/smithy/blob/main/smithy-aws-protocol-tests/model/restJson1/http-headers.smithy#L229-L232
{
id: "RestJsonInputAndOutputWithQuotedStringHeaders",
documentation: "Tests responses with string list header bindings that require quoting",
protocol: restJson1,
code: 200,
headers: {
"X-StringList": "\"b,c\", \"\\\"def\\\"\", a"
},
params: {
headerStringList: ["b,c", "\"def\"", "a"]
}
}
""", header, value); | ||
} else { | ||
writer.write("expect(r.headers[$S]).toBe($S);", header, value); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I propose that we ignore comma delimiter spacing rather than changing the upstream Smithy test assertion or our and other language implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah this is a pain. Although wouldn't it be easier to just add a space here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be fine, so I pushed a commit to do so.
""", header, value); | ||
} else { | ||
writer.write("expect(r.headers[$S]).toBe($S);", header, value); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah this is a pain. Although wouldn't it be easier to just add a space here?
return values.map((v) => { | ||
v = v.trim(); | ||
const z = v.length; | ||
if (v[0] === `"` && v[z - 1] === `"`) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can v
be empty? What if there's sequential ,
, or ,
only separated by ws?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added more test cases to describe what happens, i.e. ,,
is 3 empty strings, and so is , ,
.
this is a set of changes revealed by re-enabling the skipped protocol tests in aws/aws-sdk-js-v3#6512