From f63980cda330c2d76384d465692110f04d517092 Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Thu, 16 Nov 2023 10:50:53 -0500 Subject: [PATCH 1/2] Fix AwsQuery target serialization (#3210) ## Motivation and Context - aws-sdk-rust#957 ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._ --- CHANGELOG.next.toml | 8 +++- buildSrc/src/main/kotlin/CodegenTestCommon.kt | 17 ++++++--- codegen-client-test/build.gradle.kts | 9 ++++- .../aws-json-query-compat.smithy | 38 +++++++++++++++++++ .../smithy/protocols/AwsQueryCompatible.kt | 3 ++ 5 files changed, 67 insertions(+), 8 deletions(-) create mode 100644 codegen-core/common-test-models/aws-json-query-compat.smithy diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index fc4c4c2578..3d55ebc164 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -9,4 +9,10 @@ # message = "Fix typos in module documentation for generated crates" # references = ["smithy-rs#920"] # meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"} -# author = "rcoh" \ No newline at end of file +# author = "rcoh" + +[[aws-sdk-rust]] +message = "Fix broken serialization for SQS" +references = ["smithy-rs#3210", "aws-sdk-rust#957"] +meta = { "breaking" = false, "tada" = false, "bug" = false } +author = "rcoh" diff --git a/buildSrc/src/main/kotlin/CodegenTestCommon.kt b/buildSrc/src/main/kotlin/CodegenTestCommon.kt index 12b3a543c1..3a7008f897 100644 --- a/buildSrc/src/main/kotlin/CodegenTestCommon.kt +++ b/buildSrc/src/main/kotlin/CodegenTestCommon.kt @@ -90,9 +90,11 @@ private fun codegenTests(properties: PropertyRetriever, allTests: List { AllCargoCommands } require(ret.isNotEmpty()) { - "None of the provided cargo commands (`$cargoCommandsOverride`) are valid cargo commands (`${AllCargoCommands.map { - it.toString - }}`)" + "None of the provided cargo commands (`$cargoCommandsOverride`) are valid cargo commands (`${ + AllCargoCommands.map { + it.toString + } + }`)" } return ret } @@ -137,6 +141,7 @@ fun Project.registerGenerateSmithyBuildTask( this.tasks.register("generateSmithyBuild") { description = "generate smithy-build.json" outputs.file(project.projectDir.resolve("smithy-build.json")) + // NOTE: This is not working. allCodegenTests.flatMap { it.imports }.forEach { inputs.file(project.projectDir.resolve(it)) } doFirst { diff --git a/codegen-client-test/build.gradle.kts b/codegen-client-test/build.gradle.kts index ae84542a3e..606d868ccf 100644 --- a/codegen-client-test/build.gradle.kts +++ b/codegen-client-test/build.gradle.kts @@ -73,7 +73,11 @@ val allCodegenTests = listOf( ClientTest("aws.protocoltests.restxml#RestXml", "rest_xml", addMessageToErrors = false), ClientTest("aws.protocoltests.query#AwsQuery", "aws_query", addMessageToErrors = false), ClientTest("aws.protocoltests.ec2#AwsEc2", "ec2_query", addMessageToErrors = false), - ClientTest("aws.protocoltests.restxml.xmlns#RestXmlWithNamespace", "rest_xml_namespace", addMessageToErrors = false), + ClientTest( + "aws.protocoltests.restxml.xmlns#RestXmlWithNamespace", + "rest_xml_namespace", + addMessageToErrors = false, + ), ClientTest("aws.protocoltests.restxml#RestXmlExtras", "rest_xml_extras", addMessageToErrors = false), ClientTest( "aws.protocoltests.restxmlunwrapped#RestXmlExtrasUnwrappedErrors", @@ -108,7 +112,10 @@ val allCodegenTests = listOf( "pokemon-service-awsjson-client", dependsOn = listOf("pokemon-awsjson.smithy", "pokemon-common.smithy"), ), + ClientTest("aws.protocoltests.misc#QueryCompatService", "query-compat-test", dependsOn = listOf("aws-json-query-compat.smithy")), ).map(ClientTest::toCodegenTest) +// use this line to run just one test +// .filter { it.module == "query-compat-test" } project.registerGenerateSmithyBuildTask(rootProject, pluginName, allCodegenTests) project.registerGenerateCargoWorkspaceTask(rootProject, pluginName, allCodegenTests, workingDirUnderBuildDir) diff --git a/codegen-core/common-test-models/aws-json-query-compat.smithy b/codegen-core/common-test-models/aws-json-query-compat.smithy new file mode 100644 index 0000000000..4a98f70906 --- /dev/null +++ b/codegen-core/common-test-models/aws-json-query-compat.smithy @@ -0,0 +1,38 @@ +$version: "1.0" + +namespace aws.protocoltests.misc + +use aws.protocols#awsQueryCompatible +use aws.protocols#awsJson1_0 +use aws.protocols#awsQueryError +use smithy.test#httpRequestTests +@awsQueryCompatible +@awsJson1_0 +service QueryCompatService { + operations: [ + Operation + ] +} + +@httpRequestTests([{ + id: "BasicQueryCompatTest" + protocol: awsJson1_0, + method: "POST", + uri: "https://foo.com", + body: "{\"message\":\"hello!\"}", + bodyMedaType: "application/json", + params: { + message: "hello!" + }, + headers: { "x-amz-target": "QueryCompatService.Operation"} + + } +]) +operation Operation { + input: OperationInputOutput + output: OperationInputOutput +} + +structure OperationInputOutput { + message: String +} diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQueryCompatible.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQueryCompatible.kt index b37a0b5725..61861a369a 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQueryCompatible.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQueryCompatible.kt @@ -92,4 +92,7 @@ class AwsQueryCompatible( override fun parseEventStreamErrorMetadata(operationShape: OperationShape): RuntimeType = awsJson.parseEventStreamErrorMetadata(operationShape) + + override fun additionalRequestHeaders(operationShape: OperationShape): List> = + listOf("x-amz-target" to "${codegenContext.serviceShape.id.name}.${operationShape.id.name}") } From 2415f0f3a9a6a05aae615215ffe6f22443ee384d Mon Sep 17 00:00:00 2001 From: ysaito1001 Date: Thu, 16 Nov 2023 15:05:35 -0600 Subject: [PATCH 2/2] Update URI in `aws-json-query-compat.smithy` to pass the failed test --- codegen-core/common-test-models/aws-json-query-compat.smithy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-core/common-test-models/aws-json-query-compat.smithy b/codegen-core/common-test-models/aws-json-query-compat.smithy index 4a98f70906..b3e1cf0375 100644 --- a/codegen-core/common-test-models/aws-json-query-compat.smithy +++ b/codegen-core/common-test-models/aws-json-query-compat.smithy @@ -18,7 +18,7 @@ service QueryCompatService { id: "BasicQueryCompatTest" protocol: awsJson1_0, method: "POST", - uri: "https://foo.com", + uri: "/", body: "{\"message\":\"hello!\"}", bodyMedaType: "application/json", params: {