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

Allow 'null' variants in unions #3481

Merged
merged 2 commits into from
Mar 15, 2024
Merged

Allow 'null' variants in unions #3481

merged 2 commits into from
Mar 15, 2024

Conversation

rcoh
Copy link
Collaborator

@rcoh rcoh commented Mar 12, 2024

Motivation and Context

Description

Update the JSON parser generator to allow for null to be set in unions. Servers can send unions like this:

{
  "AmazonElasticsearchParameters": null,
  "AmazonOpenSearchParameters": null,
  "AppFlowParameters": null,
  "AthenaParameters": null,
  "AuroraParameters": null,
  "AuroraPostgreSqlParameters": null,
  "AwsIotAnalyticsParameters": null,
  "BigQueryParameters": null,
  "DatabricksParameters": null,
  "Db2Parameters": null,
  "DenodoParameters": null,
  "DocumentDBParameters": null,
  "DremioParameters": null,
  "ExasolParameters": null,
  "GoogleAnalyticsParameters": null,
  "JiraParameters": null,
  "MariaDbParameters": null,
  "MongoAtlasParameters": null,
  "MongoDBParameters": null,
  "MySqlParameters": null,
  "OracleParameters": null,
  "PostgreSqlParameters": null,
  "PrestoParameters": null,
  "RdsParameters": null,
  "RedshiftParameters": null,
  "S3Parameters": {
    "IsUploaded": false,
    "ManifestFileLocation": {
      "Bucket": "deided-bucket.prod.us-east-1",
      "Key": "sales/manifest.json"
    },
    "RoleArn": null
  },
  "SalesforceParameters": null,
  "SapHanaParameters": null,
  "ServiceNowParameters": null,
  "SnowflakeParameters": null,
  "SparkParameters": null,
  "SqlServerParameters": null,
  "StarburstParameters": null,
  "TeradataParameters": null,
  "TrinoParameters": null,
  "TwitterParameters": null
}

This caused our parser to fail.

Testing

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.

Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

rustTemplate(
"""
if let #{Some}(#{Ok}(#{Token}::ValueNull { .. })) = tokens.peek() {
#{skip_value}(tokens)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Calling skip_value seems excessive if you already know it's null. Should just be able to pop it after.

Copy link
Contributor

@ysaito1001 ysaito1001 left a comment

Choose a reason for hiding this comment

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

the approach looks good, only a server test needs to be updated.

@rcoh rcoh force-pushed the null-value-variants-unions branch from e818699 to 2e0e037 Compare March 15, 2024 21:59
Copy link

A new generated diff is ready to view.

A new doc preview is ready to view.

@rcoh rcoh enabled auto-merge March 15, 2024 22:29
@rcoh rcoh added this pull request to the merge queue Mar 15, 2024
Merged via the queue into main with commit 23cdff1 Mar 15, 2024
41 checks passed
@rcoh rcoh deleted the null-value-variants-unions branch March 15, 2024 23:02
david-perez added a commit to david-perez/smithy that referenced this pull request May 24, 2024
Once we're inside of a `{}` JSON object, a known union variant must be
provided. Servers must not accept `{}` as "the union shape was not set"
when the union shape is optional (which was the behavior in smithy-rs
prior to smithy-lang/smithy-rs#3481).

This commit adds a protocol test to pin this behavior.
mtdowling pushed a commit to smithy-lang/smithy that referenced this pull request May 24, 2024
Once we're inside of a `{}` JSON object, a known union variant must be
provided. Servers must not accept `{}` as "the union shape was not set"
when the union shape is optional (which was the behavior in smithy-rs
prior to smithy-lang/smithy-rs#3481).

This commit adds a protocol test to pin this behavior.
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.

3 participants