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 actual default value instead of 0/false #3252

Merged
merged 3 commits into from
Dec 15, 2023

Conversation

milesziemer
Copy link
Contributor

@milesziemer milesziemer commented Nov 24, 2023

Motivation and Context

Previously, there was logic used to ignore the default 0/false values for numbers/booleans when serializing members if they weren't boxed. This was to fix issues that occured when upstream models didn't properly box shapes that were meant to be optional, and for the most part worked because services would just fill in the default if it wasn't passed. However, with Smithy 2.0, models may have defaults != 0/false, but the codegenerator still ignores the zero value.

Description

This commit makes it so that the actual default value for the member is ignored for booleans and numbers, instead of just 0/false. It also updates serialization for http bindings so that headers and query parameters with 0/false values aren't ignored if they are optional parameters.

Testing

  • Generated AWS SDK and inspected diff. Only changes are not ignoring default value inside if let Some() = ... blocks, and ignoring default value instead of just 0 (only seems to effect nimble).
  • Added protocol tests for serializing 0/false in query params for restXml and restJson

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the smithy-rs codegen or runtime crates
  • I have updated CHANGELOG.next.toml if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@milesziemer milesziemer requested review from a team as code owners November 24, 2023 18:51
@milesziemer milesziemer mentioned this pull request Nov 25, 2023
4 tasks
@milesziemer
Copy link
Contributor Author

milesziemer commented Dec 12, 2023

Opened PR to add protocol tests in Smithy for this: smithy-lang/smithy#2070

Previously, there was logic used to ignore the default 0/false values
for numbers/booleans when serializing members if they weren't boxed.
This was to fix issues that occured when upstream models didn't
properly box shapes that were meant to be optional, and for the
most part worked because services would just fill in the default if
it wasn't passed. However, with Smithy 2.0, models may have defaults
!= 0/false, but the codegenerator still ignores the zero value.

This commit makes it so that the actual default value for the member
is ignored for booleans and numbers, instead of just 0/false. It
also updates serialization for http bindings so that headers and
query parameters with 0/false values aren't ignored if they are
optional parameters.
@milesziemer milesziemer force-pushed the expand-ifnotdefault branch 2 times, most recently from 6863ec9 to 279b3bd Compare December 15, 2023 14:45
Copy link
Collaborator

@jdisanti jdisanti left a comment

Choose a reason for hiding this comment

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

Looks great! Just some minor changelog changes.

CHANGELOG.next.toml Outdated Show resolved Hide resolved
CHANGELOG.next.toml Outdated Show resolved Hide resolved
CHANGELOG.next.toml Outdated Show resolved Hide resolved
CHANGELOG.next.toml Outdated Show resolved Hide resolved
@jdisanti jdisanti added this pull request to the merge queue Dec 15, 2023
Merged via the queue into smithy-lang:main with commit 345624e Dec 15, 2023
38 of 39 checks passed
milesziemer added a commit to smithy-lang/smithy that referenced this pull request Jan 24, 2024
Previously we didn't have protocol tests specifically for 0/false in query params, which allowed for situations like
smithy-lang/smithy-rs#3252 to occur.
hpmellema pushed a commit to hpmellema/smithy that referenced this pull request Jan 25, 2024
Previously we didn't have protocol tests specifically for 0/false in query params, which allowed for situations like
smithy-lang/smithy-rs#3252 to occur.
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