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

Must set a member in unions #2241

Merged
merged 9 commits into from
Feb 2, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -493,6 +493,7 @@ class JsonParserGenerator(
"Shape" to returnSymbolToParse.symbol,
) {
rust("let mut variant = None;")
val checkValueSet = !shape.members().all { it.isTargetUnit() } && !codegenTarget.renderUnknownVariant()
rustBlock("match tokens.next().transpose()?") {
rustBlockTemplate(
"""
Expand Down Expand Up @@ -525,7 +526,7 @@ class JsonParserGenerator(
} else {
withBlock("Some(#T::$variantName(", "))", returnSymbolToParse.symbol) {
deserializeMember(member)
unwrapOrDefaultOrError(member)
unwrapOrDefaultOrError(member, checkValueSet)
}
}
}
Expand Down Expand Up @@ -563,8 +564,8 @@ class JsonParserGenerator(
rust("#T(tokens)?", nestedParser)
}

private fun RustWriter.unwrapOrDefaultOrError(member: MemberShape) {
if (symbolProvider.toSymbol(member).canUseDefault()) {
private fun RustWriter.unwrapOrDefaultOrError(member: MemberShape, checkValueSet: Boolean) {
if (symbolProvider.toSymbol(member).canUseDefault() && !checkValueSet) {
rust(".unwrap_or_default()")
} else {
rustTemplate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -939,8 +939,6 @@ class ServerProtocolTestGenerator(
FailingTest(RestJson, "RestJsonMalformedSetNullItem", TestType.MalformedRequest),
FailingTest(RestJson, "RestJsonMalformedSetDuplicateBlobs", TestType.MalformedRequest),

FailingTest(RestJson, "RestJsonMalformedUnionNoFieldsSet", TestType.MalformedRequest),

// Tests involving constraint traits, which are not yet fully implemented.
// See https://github.com/awslabs/smithy-rs/issues/1401.
FailingTest(RestJsonValidation, "RestJsonMalformedRangeFloat_case0", TestType.MalformedRequest),
Expand Down