Skip to content
Snippets Groups Projects
Commit f2c11b87 authored by Fahad Zubair's avatar Fahad Zubair
Browse files

Merge remote-tracking branch 'cbor-fixe/fahadzub/cbor-constraint' into fahadzub/cbor-constraint

parents 5bb92b13 6afc8bf2
Branches
Tags
No related merge requests found
...@@ -2,6 +2,7 @@ package software.amazon.smithy.rust.codegen.server.smithy.transformers ...@@ -2,6 +2,7 @@ package software.amazon.smithy.rust.codegen.server.smithy.transformers
import software.amazon.smithy.model.Model import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.AbstractShapeBuilder 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.MemberShape
import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.Shape
...@@ -9,6 +10,7 @@ import software.amazon.smithy.model.shapes.ShapeId ...@@ -9,6 +10,7 @@ import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.traits.HttpLabelTrait import software.amazon.smithy.model.traits.HttpLabelTrait
import software.amazon.smithy.model.traits.HttpPayloadTrait import software.amazon.smithy.model.traits.HttpPayloadTrait
import software.amazon.smithy.model.traits.HttpTrait 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.model.transform.ModelTransformer
import software.amazon.smithy.protocol.traits.Rpcv2CborTrait import software.amazon.smithy.protocol.traits.Rpcv2CborTrait
import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait
...@@ -17,8 +19,8 @@ import software.amazon.smithy.utils.SmithyBuilder ...@@ -17,8 +19,8 @@ import software.amazon.smithy.utils.SmithyBuilder
import software.amazon.smithy.utils.ToSmithyBuilder import software.amazon.smithy.utils.ToSmithyBuilder
/** /**
* Each protocol may not support all of the features that Smithy allows. For instance, most * Each protocol may not support all of the features that Smithy allows. For instance, `rpcv2Cbor`
* RPC protocols do not support HTTP bindings. `ServerProtocolBasedTransformationFactory` is a factory * 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 that transforms the model and removes specific traits based on the protocol being instantiated.
*/ */
object ServerProtocolBasedTransformationFactory { object ServerProtocolBasedTransformationFactory {
...@@ -31,6 +33,10 @@ object ServerProtocolBasedTransformationFactory { ...@@ -31,6 +33,10 @@ object ServerProtocolBasedTransformationFactory {
return model 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 -> return ModelTransformer.create().mapShapes(model) { shape ->
when (shape) { when (shape) {
is OperationShape -> shape.removeTraitIfPresent(HttpTrait.ID) is OperationShape -> shape.removeTraitIfPresent(HttpTrait.ID)
...@@ -39,7 +45,9 @@ object ServerProtocolBasedTransformationFactory { ...@@ -39,7 +45,9 @@ object ServerProtocolBasedTransformationFactory {
.removeTraitIfPresent(HttpLabelTrait.ID) .removeTraitIfPresent(HttpLabelTrait.ID)
.removeTraitIfPresent(HttpPayloadTrait.ID) .removeTraitIfPresent(HttpPayloadTrait.ID)
} }
is BlobShape -> {
shape.removeTraitIfPresent(StreamingTrait.ID)
}
else -> shape else -> shape
} }
} }
......
...@@ -12,15 +12,7 @@ import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverIntegrat ...@@ -12,15 +12,7 @@ import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverIntegrat
class CborConstraintsIntegrationTest { class CborConstraintsIntegrationTest {
@Test @Test
fun `ensure CBOR implementation works for all constraint types`() { fun `ensure CBOR implementation works for all constraint types`() {
val (serviceShape, constraintModel) = loadSmithyConstraintsModelForProtocol(ModelProtocol.Rpcv2Cbor) val (serviceShape, model) = 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)
// The test should compile; no further testing is required. // The test should compile; no further testing is required.
serverIntegrationTest( serverIntegrationTest(
model, model,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment