Loading codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/transformers/ServerProtocolBasedTransformationFactory.kt +11 −3 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading @@ -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 { Loading @@ -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) Loading @@ -39,7 +45,9 @@ object ServerProtocolBasedTransformationFactory { .removeTraitIfPresent(HttpLabelTrait.ID) .removeTraitIfPresent(HttpPayloadTrait.ID) } is BlobShape -> { shape.removeTraitIfPresent(StreamingTrait.ID) } else -> shape } } Loading codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/CborConstraintsIntegrationTest.kt +1 −9 Original line number Diff line number Diff line Loading @@ -12,15 +12,7 @@ import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverIntegrat 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, Loading Loading
codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/transformers/ServerProtocolBasedTransformationFactory.kt +11 −3 Original line number Diff line number Diff line Loading @@ -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 Loading @@ -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 Loading @@ -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 { Loading @@ -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) Loading @@ -39,7 +45,9 @@ object ServerProtocolBasedTransformationFactory { .removeTraitIfPresent(HttpLabelTrait.ID) .removeTraitIfPresent(HttpPayloadTrait.ID) } is BlobShape -> { shape.removeTraitIfPresent(StreamingTrait.ID) } else -> shape } } Loading
codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/CborConstraintsIntegrationTest.kt +1 −9 Original line number Diff line number Diff line Loading @@ -12,15 +12,7 @@ import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverIntegrat 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, Loading