diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/transformers/ServerProtocolBasedTransformationFactory.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/transformers/ServerProtocolBasedTransformationFactory.kt index 6c3357bf87a2ba5175e5749ff49f80f3cd138401..c38d8b623d310fbeb6fb71883b4a52aa13d0950e 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/transformers/ServerProtocolBasedTransformationFactory.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/transformers/ServerProtocolBasedTransformationFactory.kt @@ -2,6 +2,7 @@ package software.amazon.smithy.rust.codegen.server.smithy.transformers import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.AbstractShapeBuilder +import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.Shape @@ -9,6 +10,7 @@ import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.traits.HttpLabelTrait import software.amazon.smithy.model.traits.HttpPayloadTrait import software.amazon.smithy.model.traits.HttpTrait +import software.amazon.smithy.model.traits.StreamingTrait import software.amazon.smithy.model.transform.ModelTransformer import software.amazon.smithy.protocol.traits.Rpcv2CborTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait @@ -17,8 +19,8 @@ import software.amazon.smithy.utils.SmithyBuilder import software.amazon.smithy.utils.ToSmithyBuilder /** - * Each protocol may not support all of the features that Smithy allows. For instance, most - * RPC protocols do not support HTTP bindings. `ServerProtocolBasedTransformationFactory` is a factory + * Each protocol may not support all of the features that Smithy allows. For instance, `rpcv2Cbor` + * does not support HTTP bindings. `ServerProtocolBasedTransformationFactory` is a factory * object that transforms the model and removes specific traits based on the protocol being instantiated. */ object ServerProtocolBasedTransformationFactory { @@ -31,6 +33,10 @@ object ServerProtocolBasedTransformationFactory { return model } + // `rpcv2Cbor` does not support: + // 1. `@httpPayload` trait. + // 2. `@httpLabel` trait. + // 3. `@streaming` trait applied to a `Blob` (data streaming). return ModelTransformer.create().mapShapes(model) { shape -> when (shape) { is OperationShape -> shape.removeTraitIfPresent(HttpTrait.ID) @@ -39,6 +45,9 @@ object ServerProtocolBasedTransformationFactory { .removeTraitIfPresent(HttpLabelTrait.ID) .removeTraitIfPresent(HttpPayloadTrait.ID) } + is BlobShape -> { + shape.removeTraitIfPresent(StreamingTrait.ID) + } else -> shape } diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/CborConstraintsIntegrationTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/CborConstraintsIntegrationTest.kt index 60bf75d127e11c0f605ef78cedc70956bacb7045..242bcb398cde22368981c023bb76180034b38001 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/CborConstraintsIntegrationTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/CborConstraintsIntegrationTest.kt @@ -1,26 +1,16 @@ package software.amazon.smithy.rust.codegen.server.smithy.protocols.serialize import org.junit.jupiter.api.Test -import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.rust.codegen.core.testutil.IntegrationTestParams import software.amazon.smithy.rust.codegen.core.testutil.ServerAdditionalSettings import software.amazon.smithy.rust.codegen.server.smithy.ModelProtocol import software.amazon.smithy.rust.codegen.server.smithy.loadSmithyConstraintsModelForProtocol -import software.amazon.smithy.rust.codegen.server.smithy.removeOperations import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverIntegrationTest class CborConstraintsIntegrationTest { @Test fun `ensure CBOR implementation works for all constraint types`() { - val (serviceShape, constraintModel) = loadSmithyConstraintsModelForProtocol(ModelProtocol.Rpcv2Cbor) - // Event streaming operations are not supported by `Rpcv2Cbor` implementation. - // https://github.com/smithy-lang/smithy-rs/issues/3573 - val nonSupportedOperations = - listOf("StreamingBlobOperation") - .map { ShapeId.from("${serviceShape.namespace}#$it") } - val model = - constraintModel - .removeOperations(serviceShape, nonSupportedOperations) + val (serviceShape, model) = loadSmithyConstraintsModelForProtocol(ModelProtocol.Rpcv2Cbor) // The test should compile; no further testing is required. serverIntegrationTest( model,