Skip to content

Commit

Permalink
Smithy 1.9/1.10 Upgrade (#618)
Browse files Browse the repository at this point in the history
* smithy 1.9.1 upgrade & primitive encode/decode

This upgrades to Smithy 1.10, but the major change is a complete overhaul of how primitives are formatted and parsed. Primitive serialization was migrated and unified into Smithy Types with the end requirement of dealing with special float serialization semantics.

* Switch to Smithy Core S3 Customization Trait

Smithy 1.9.1 brings S3UnwrappedXmlOutput as a vended trait. This commit pulls in the new model & uses that trait.

* Fix clippy warnings

* Fix doc links

* fix kotlin formatting

* Fix s3 customization to use the operation shape

* Ensure that numbers in string don't parse as numbers

* remove unused itoa

* Apply suggestions from code review

Co-authored-by: John DiSanti <[email protected]>

* Fix tests, CR feedback

* rename parse to parse_smithy_primitive

* Fix some more clippy errors

* Update changelog

Co-authored-by: John DiSanti <[email protected]>
  • Loading branch information
rcoh and jdisanti authored Jul 30, 2021
1 parent 9fef09a commit f1a726c
Show file tree
Hide file tree
Showing 54 changed files with 708 additions and 229 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
**New This Week**
- :bug: Correctly encode HTTP Checksums using base64 instead of hex. Fixes aws-sdk-rust#164. (#615)
- (When complete) Add profile file provider for region (#594, #xyz)
- Overhaul serialization/deserialization of numeric/boolean types. This resolves issues around serialization of NaN/Infinity and should also reduce the number of allocations required during serialization. (#618)

## v0.18.1 (July 27th 2021)
* Remove timestreamwrite and timestreamquery from the generated services (#613)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@
package software.amazon.smithy.rustsdk.customize.s3

import software.amazon.smithy.aws.traits.protocols.RestXmlTrait
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.model.transform.ModelTransformer
import software.amazon.smithy.rust.codegen.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.rustlang.Writable
import software.amazon.smithy.rust.codegen.rustlang.asType
Expand All @@ -28,7 +24,6 @@ import software.amazon.smithy.rust.codegen.smithy.letIf
import software.amazon.smithy.rust.codegen.smithy.protocols.ProtocolMap
import software.amazon.smithy.rust.codegen.smithy.protocols.RestXml
import software.amazon.smithy.rust.codegen.smithy.protocols.RestXmlFactory
import software.amazon.smithy.rust.codegen.smithy.traits.S3UnwrappedXmlOutputTrait
import software.amazon.smithy.rustsdk.AwsRuntimeType

/**
Expand Down Expand Up @@ -59,20 +54,6 @@ class S3Decorator : RustCodegenDecorator {
it + S3PubUse()
}
}

override fun transformModel(service: ServiceShape, model: Model): Model {
return model.letIf(applies(service.id)) {
ModelTransformer.create().mapShapes(model) { shape ->
// Apply the S3UnwrappedXmlOutput customization to GetBucketLocation (more
// details on the S3UnwrappedXmlOutputTrait)
if (shape is StructureShape && shape.id == ShapeId.from("com.amazonaws.s3#GetBucketLocationOutput")) {
shape.toBuilder().addTrait(S3UnwrappedXmlOutputTrait()).build()
} else {
shape
}
}
}
}
}

class S3(protocolConfig: ProtocolConfig) : RestXml(protocolConfig) {
Expand Down
2 changes: 1 addition & 1 deletion aws/sdk/aws-models/accessanalyzer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4823,4 +4823,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion aws/sdk/aws-models/amp.json
Original file line number Diff line number Diff line change
Expand Up @@ -935,4 +935,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion aws/sdk/aws-models/appmesh.json
Original file line number Diff line number Diff line change
Expand Up @@ -8671,4 +8671,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion aws/sdk/aws-models/braket.json
Original file line number Diff line number Diff line change
Expand Up @@ -1404,4 +1404,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion aws/sdk/aws-models/codeguruprofiler.json
Original file line number Diff line number Diff line change
Expand Up @@ -3174,4 +3174,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion aws/sdk/aws-models/groundstation.json
Original file line number Diff line number Diff line change
Expand Up @@ -3544,4 +3544,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion aws/sdk/aws-models/location.json
Original file line number Diff line number Diff line change
Expand Up @@ -5937,4 +5937,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion aws/sdk/aws-models/mgn.json
Original file line number Diff line number Diff line change
Expand Up @@ -3944,4 +3944,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion aws/sdk/aws-models/mwaa.json
Original file line number Diff line number Diff line change
Expand Up @@ -1938,4 +1938,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion aws/sdk/aws-models/proton.json
Original file line number Diff line number Diff line change
Expand Up @@ -6482,4 +6482,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion aws/sdk/aws-models/rds-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1336,4 +1336,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion aws/sdk/aws-models/redshift-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -1423,4 +1423,4 @@
"type": "boolean"
}
}
}
}
1 change: 1 addition & 0 deletions aws/sdk/aws-models/s3.json
Original file line number Diff line number Diff line change
Expand Up @@ -4073,6 +4073,7 @@
"target": "com.amazonaws.s3#GetBucketLocationOutput"
},
"traits": {
"aws.customizations#s3UnwrappedXmlOutput": {},
"smithy.api#documentation": "<p>Returns the Region the bucket resides in. You set the bucket's Region using the\n <code>LocationConstraint</code> request parameter in a <code>CreateBucket</code>\n request. For more information, see <a href=\"https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html\">CreateBucket</a>.</p>\n\n <p> To use this implementation of the operation, you must be the bucket owner.</p>\n\n <p>The following operations are related to <code>GetBucketLocation</code>:</p>\n <ul>\n <li>\n <p>\n <a href=\"https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html\">GetObject</a>\n </p>\n </li>\n <li>\n <p>\n <a href=\"https://docs.aws.amazon.com/AmazonS3/latest/API/API_CreateBucket.html\">CreateBucket</a>\n </p>\n </li>\n </ul>",
"smithy.api#http": {
"method": "GET",
Expand Down
2 changes: 1 addition & 1 deletion aws/sdk/aws-models/ssm-incidents.json
Original file line number Diff line number Diff line change
Expand Up @@ -4041,4 +4041,4 @@
}
}
}
}
}
2 changes: 1 addition & 1 deletion aws/sdk/examples/batch/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ batch = { package = "aws-sdk-batch", path = "../../build/aws-sdk/batch" }
aws-types = { path = "../../build/aws-sdk/aws-types" }
tokio = { version = "1", features = ["full"] }
structopt = { version = "0.3", default-features = false }
tracing-subscriber = "0.2.18"
tracing-subscriber = "0.2.18"
2 changes: 1 addition & 1 deletion aws/sdk/examples/ebs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ tokio = { version = "1", features = ["full"]}
base64 = "0.13.0"
sha2 = "0.9.5"
structopt = { version = "0.3", default-features = false }
tracing-subscriber = "0.2.19"
tracing-subscriber = "0.2.19"
2 changes: 1 addition & 1 deletion aws/sdk/examples/kinesis/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ kinesis = { package = "aws-sdk-kinesis", path = "../../build/aws-sdk/kinesis" }
aws-types = { path = "../../build/aws-sdk/aws-types" }
tokio = { version = "1", features = ["full"] }
structopt = { version = "0.3", default-features = false }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }
2 changes: 1 addition & 1 deletion aws/sdk/examples/medialive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ medialive = { package = "aws-sdk-medialive", path = "../../build/aws-sdk/mediali
aws-types = { path = "../../build/aws-sdk/aws-types" }
tokio = { version = "1", features = ["full"] }
structopt = { version = "0.3", default-features = false }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }
2 changes: 1 addition & 1 deletion aws/sdk/examples/mediapackage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ mediapackage = { package = "aws-sdk-mediapackage", path = "../../build/aws-sdk/m
aws-types = { path = "../../build/aws-sdk/aws-types" }
tokio = { version = "1", features = ["full"] }
structopt = { version = "0.3", default-features = false }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }
1 change: 0 additions & 1 deletion aws/sdk/examples/polly/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,3 @@ aws-types = { path = "../../build/aws-sdk/aws-types" }
tokio = { version = "1", features = ["full"] }
structopt = { version = "0.3", default-features = false }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }

2 changes: 0 additions & 2 deletions aws/sdk/examples/qldb/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ aws-types = { path = "../../build/aws-sdk/aws-types" }
tokio = { version = "1", features = ["full"] }
structopt = { version = "0.3", default-features = false }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }


2 changes: 1 addition & 1 deletion aws/sdk/examples/qldb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ where:
If the environment variable is not set, defaults to **us-west-2**.
- __-v__ enables displaying additional information.

##
##
2 changes: 1 addition & 1 deletion aws/sdk/examples/rds/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ rds = {package = "aws-sdk-rds", path = "../../build/aws-sdk/rds"}
aws-types = { path = "../../build/aws-sdk/aws-types" }
tokio = {version = "1", features = ["full"]}
structopt = { version = "0.3", default-features = false }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }
2 changes: 1 addition & 1 deletion aws/sdk/examples/rdsdata/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ rdsdata = {package = "aws-sdk-rdsdata", path = "../../build/aws-sdk/rdsdata"}
aws-types = { path = "../../build/aws-sdk/aws-types" }
tokio = {version = "1", features = ["full"]}
structopt = { version = "0.3", default-features = false }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }
2 changes: 1 addition & 1 deletion aws/sdk/examples/sagemaker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ tokio = { version = "1", features = ["full"] }
env_logger = "0.8.2"
chrono = "0.4.19"
structopt = { version = "0.3", default-features = false }
tracing-subscriber = "0.2.18"
tracing-subscriber = "0.2.18"
1 change: 0 additions & 1 deletion aws/sdk/examples/secretsmanager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ tokio = { version = "1", features = ["full"]}

structopt = { version = "0.3", default-features = false }
tracing-subscriber = { version = "0.2.16", features = ["fmt"] }

2 changes: 1 addition & 1 deletion aws/sdk/examples/snowball/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ aws-sdk-snowball = { path = "../../build/aws-sdk/snowball" }
aws-types = { path = "../../build/aws-sdk/aws-types" }
tokio = { version = "1", features = ["full"] }
structopt = { version = "0.3", default-features = false }
tracing-subscriber = "0.2.18"
tracing-subscriber = "0.2.18"
2 changes: 1 addition & 1 deletion aws/sdk/examples/sqs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ edition = "2018"
[dependencies]
sqs = { package = "aws-sdk-sqs", path = "../../build/aws-sdk/sqs" }
tokio = { version = "1", features = ["full"] }
tracing-subscriber = "0.2.18"
tracing-subscriber = "0.2.18"
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,17 @@ package software.amazon.smithy.rust.codegen.rustlang
import software.amazon.smithy.rust.codegen.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.util.dq

/**
* Dereference [input]
*
* Clippy is upset about `*&`, so if [input] is already referenced, simply strip the leading '&'
*/
fun autoDeref(input: String) = if (input.startsWith("&")) {
input.removePrefix("&")
} else {
"*$input"
}

/**
* A hierarchy of types handled by Smithy codegen
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package software.amazon.smithy.rust.codegen.smithy.generators

import software.amazon.smithy.codegen.core.CodegenException
import software.amazon.smithy.model.knowledge.OperationIndex
import software.amazon.smithy.model.shapes.DoubleShape
import software.amazon.smithy.model.shapes.FloatShape
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.model.traits.ErrorTrait
Expand Down Expand Up @@ -306,7 +308,21 @@ class HttpProtocolTestGenerator(
);"""
)
} else {
rust("""assert_eq!(parsed.$memberName, expected_output.$memberName, "Unexpected value for `$memberName`");""")
when (protocolConfig.model.expectShape(member.target)) {
is DoubleShape, is FloatShape -> {
addUseImports(
RuntimeType.ProtocolTestHelper(protocolConfig.runtimeConfig, "FloatEquals").toSymbol()
)
rust(
"""
assert!(parsed.$memberName.float_equals(&expected_output.$memberName),
"Unexpected value for `$memberName` {:?} vs. {:?}", expected_output.$memberName, parsed.$memberName);
"""
)
}
else ->
rust("""assert_eq!(parsed.$memberName, expected_output.$memberName, "Unexpected value for `$memberName`");""")
}
}
}
}
Expand Down Expand Up @@ -428,7 +444,11 @@ class HttpProtocolTestGenerator(
private val RestXml = "aws.protocoltests.restxml#RestXml"
private val AwsQuery = "aws.protocoltests.query#AwsQuery"
private val Ec2Query = "aws.protocoltests.ec2#AwsEc2"
private val ExpectFail = setOf<FailingTest>()
private val ExpectFail = setOf<FailingTest>(
FailingTest(
service = RestJson, id = "RestJsonHostWithPath", action = Action.Request
)
)
private val RunOnly: Set<String>? = null

// These tests are not even attempted to be generated, either because they will not compile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,18 @@ class Instantiator(

// Simple Shapes
is StringShape -> renderString(writer, shape, arg as StringNode)
is NumberShape -> writer.write(arg.asNumberNode().get())
is NumberShape -> when (arg) {
is StringNode -> {
val numberSymbol = symbolProvider.toSymbol(shape)
// support Smithy custom values, such as Infinity
writer.rust(
"""<#T as #T>::parse_smithy_primitive(${arg.value.dq()}).expect("invalid string for number")""",
numberSymbol,
CargoDependency.SmithyTypes(runtimeConfig).asType().member("primitive::Parse")
)
}
is NumberNode -> writer.write(arg.value)
}
is BooleanShape -> writer.write(arg.asBooleanNode().get().toString())
is DocumentShape -> writer.rustBlock("") {
val smithyJson = CargoDependency.smithyJson(runtimeConfig).asType()
Expand Down
Loading

0 comments on commit f1a726c

Please sign in to comment.