diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/HttpProtocolGenerator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/HttpProtocolGenerator.kt index 053ac3a07..ebd566d9d 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/HttpProtocolGenerator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/HttpProtocolGenerator.kt @@ -10,7 +10,6 @@ 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.traits.EndpointTrait import software.amazon.smithy.rust.codegen.rustlang.Derives import software.amazon.smithy.rust.codegen.rustlang.RustWriter import software.amazon.smithy.rust.codegen.rustlang.documentShape @@ -51,9 +50,9 @@ abstract class HttpProtocolGenerator( private val symbolProvider = protocolConfig.symbolProvider private val model = protocolConfig.model fun renderOperation(operationWriter: RustWriter, inputWriter: RustWriter, operationShape: OperationShape, customizations: List) { - if (operationShape.hasTrait(EndpointTrait::class.java)) { + /* if (operationShape.hasTrait(EndpointTrait::class.java)) { TODO("https://github.com/awslabs/smithy-rs/issues/197") - } + } */ val inputShape = operationShape.inputShape(model) val inputSymbol = symbolProvider.toSymbol(inputShape) val builderGenerator = OperationInputBuilderGenerator(model, symbolProvider, operationShape, protocolConfig.moduleName, customizations) diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/HttpProtocolTestGenerator.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/HttpProtocolTestGenerator.kt index 21aee1902..79c575da9 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/HttpProtocolTestGenerator.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/generators/HttpProtocolTestGenerator.kt @@ -10,6 +10,7 @@ import software.amazon.smithy.model.knowledge.OperationIndex import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.ErrorTrait +import software.amazon.smithy.protocoltests.traits.AppliesTo import software.amazon.smithy.protocoltests.traits.HttpMessageTestCase import software.amazon.smithy.protocoltests.traits.HttpRequestTestCase import software.amazon.smithy.protocoltests.traits.HttpRequestTestsTrait @@ -66,9 +67,9 @@ class HttpProtocolTestGenerator( fun render() { val requestTests = operationShape.getTrait(HttpRequestTestsTrait::class.java) - .orNull()?.testCases.orEmpty().map { TestCase.RequestTest(it) } + .orNull()?.getTestCasesFor(AppliesTo.CLIENT).orEmpty().map { TestCase.RequestTest(it) } val responseTests = operationShape.getTrait(HttpResponseTestsTrait::class.java) - .orNull()?.testCases.orEmpty().map { TestCase.ResponseTest(it, outputShape) } + .orNull()?.getTestCasesFor(AppliesTo.CLIENT).orEmpty().map { TestCase.ResponseTest(it, outputShape) } val errorTests = operationIndex.getErrors(operationShape).flatMap { error -> val testCases = error.getTrait(HttpResponseTestsTrait::class.java).orNull()?.testCases.orEmpty() @@ -159,6 +160,9 @@ class HttpProtocolTestGenerator( assert_eq!(http_request.uri().path(), ${uri.dq()}); """ ) + resolvedHost.orNull()?.also { host -> + rust("""assert_eq!(http_request.uri().host().expect("host should be set"), ${host.dq()});""") + } } checkQueryParams(this, httpRequestTestCase.queryParams) checkForbidQueryParams(this, httpRequestTestCase.forbidQueryParams) @@ -167,7 +171,10 @@ class HttpProtocolTestGenerator( checkForbidHeaders(this, httpRequestTestCase.forbidHeaders) checkRequiredHeaders(this, httpRequestTestCase.requireHeaders) if (protocolSupport.requestBodySerialization) { - checkBody(this, httpRequestTestCase.body.orElse(""), httpRequestTestCase.bodyMediaType.orElse(null)) + // "If no request body is defined, then no assertions are made about the body of the message." + httpRequestTestCase.body.orNull()?.let { body -> + checkBody(this, body, httpRequestTestCase.bodyMediaType.orNull()) + } } // Explicitly warn if the test case defined parameters that we aren't doing anything with @@ -362,7 +369,17 @@ class HttpProtocolTestGenerator( ), // Document deserialization: - FailingTest(AwsJson11, "PutAndGetInlineDocumentsInput", Action.Response) + FailingTest(AwsJson11, "PutAndGetInlineDocumentsInput", Action.Response), + + // Endpoint trait https://github.com/awslabs/smithy-rs/issues/197 + // This will also require running operations through the endpoint middleware (or moving endpoint middleware + // into operation construction + FailingTest(JsonRpc10, "AwsJson10EndpointTrait", Action.Request), + FailingTest(JsonRpc10, "AwsJson10EndpointTraitWithHostLabel", Action.Request), + FailingTest(AwsJson11, "AwsJson11EndpointTrait", Action.Request), + FailingTest(AwsJson11, "AwsJson11EndpointTraitWithHostLabel", Action.Request), + FailingTest(RestJson, "RestJsonEndpointTrait", Action.Request), + FailingTest(RestJson, "RestJsonEndpointTraitWithHostLabel", Action.Request) ) private val RunOnly: Set? = null diff --git a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/AwsJson10.kt b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/AwsJson10.kt index 70b7dcf53..b855dc1a5 100644 --- a/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/AwsJson10.kt +++ b/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/AwsJson10.kt @@ -181,7 +181,7 @@ class BasicAwsJsonGenerator( override fun toBodyImpl(implBlockWriter: RustWriter, inputShape: StructureShape, inputBody: StructureShape?) { if (inputBody == null) { bodyBuilderFun(implBlockWriter) { - write("vec![]") + write("\"{}\".to_string().into()") } return } diff --git a/gradle.properties b/gradle.properties index b3b3b69ea..c1a81f76c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,7 +6,7 @@ kotlin.code.style=official # codegen -smithyVersion=1.5.0 +smithyVersion=1.6.1 # kotlin kotlinVersion=1.4.21 diff --git a/rust-runtime/protocol-test-helpers/src/lib.rs b/rust-runtime/protocol-test-helpers/src/lib.rs index 93ecc024b..059585933 100644 --- a/rust-runtime/protocol-test-helpers/src/lib.rs +++ b/rust-runtime/protocol-test-helpers/src/lib.rs @@ -30,7 +30,7 @@ pub enum ProtocolTestFailure { MissingHeader { expected: String }, #[error("Header `{forbidden}` was forbidden but found: `{found}`")] ForbiddenHeader { forbidden: String, found: String }, - #[error("body did not match. Hint:\n{hint}")] + #[error("body did not match. Hint:\n{hint}. Expected:\n `{expected}`\n Actual: \n`{found}")] BodyDidNotMatch { expected: String, found: String,