Loading codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/CborSerializerGenerator.kt +0 −1 Original line number Diff line number Diff line Loading @@ -240,7 +240,6 @@ class CborSerializerGenerator( } val httpDocumentMembers = httpBindingResolver.requestMembers(operationShape, HttpLocation.DOCUMENT) val inputShape = operationShape.inputShape(model) return protocolFunctions.serializeFn(operationShape, fnNameSuffix = "input") { fnName -> rustBlockTemplate( Loading codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt +1 −1 Original line number Diff line number Diff line Loading @@ -209,7 +209,7 @@ open class ServerCodegenVisitor( .let { AttachValidationExceptionToConstrainedOperationInputs.transform(it, settings) } // Tag aggregate shapes reachable from operation input .let(ShapesReachableFromOperationInputTagger::transform) // Remove traits that are not supported by the chosen protocol // Remove traits that are not supported by the chosen protocol. .let { ServerProtocolBasedTransformationFactory.transform(it, settings) } // Normalize event stream operations .let(EventStreamNormalizer::transform) Loading codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/BeforeSerializingMemberCborCustomization.kt +7 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,13 @@ import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.Value import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.server.smithy.workingWithPublicConstrainedWrapperTupleType /** * Constrained shapes are wrapped in a Rust tuple struct that implements all necessary checks. However, * for serialization purposes, the inner type of the constrained shape is used for serialization. * * The `BeforeSerializingMemberCborCustomization` class generates a reference to the inner type when the shape being * code-generated is constrained and the `publicConstrainedTypes` codegen flag is set. */ class BeforeSerializingMemberCborCustomization(private val codegenContext: ServerCodegenContext) : CborSerializerCustomization() { override fun section(section: CborSerializerSection): Writable = when (section) { Loading codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ConstraintsTest.kt +13 −5 Original line number Diff line number Diff line Loading @@ -38,17 +38,25 @@ enum class ModelProtocol(val trait: AbstractTrait) { Rpcv2Cbor(Rpcv2CborTrait.builder().build()), } fun loadSmithyConstraintsModelForProtocol(modelProtocol: ModelProtocol): Pair<ShapeId, Model> { val (serviceShapeId, model) = loadSmithyConstraintsModel() return Pair(serviceShapeId, model.replaceProtocolTrait(serviceShapeId, modelProtocol)) /** * Returns the Smithy constraints model from the common repository, with the specified protocol * applied to the service. */ fun loadSmithyConstraintsModelForProtocol(modelProtocol: ModelProtocol): Pair<Model, ShapeId> { val (model, serviceShapeId) = loadSmithyConstraintsModel() return Pair(model.replaceProtocolTrait(serviceShapeId, modelProtocol), serviceShapeId) } fun loadSmithyConstraintsModel(): Pair<ShapeId, Model> { /** * Loads the Smithy constraints model defined in the common repository and returns the model along with * the service shape defined in it. */ fun loadSmithyConstraintsModel(): Pair<Model, ShapeId> { val filePath = "../codegen-core/common-test-models/constraints.smithy" val serviceShapeId = ShapeId.from("com.amazonaws.constraints#ConstraintsService") val model = File(filePath).readText().asSmithyModel() return Pair(serviceShapeId, model) return Pair(model, serviceShapeId) } /** Loading codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/CborConstraintsIntegrationTest.kt +1 −3 Original line number Diff line number Diff line 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, model) = loadSmithyConstraintsModelForProtocol(ModelProtocol.Rpcv2Cbor) val (model, serviceShape) = loadSmithyConstraintsModelForProtocol(ModelProtocol.Rpcv2Cbor) // The test should compile; no further testing is required. serverIntegrationTest( model, Loading codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/CborParserGenerator.kt +4 −4 File changed.Contains only whitespace changes. Show changes Loading
codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/CborSerializerGenerator.kt +0 −1 Original line number Diff line number Diff line Loading @@ -240,7 +240,6 @@ class CborSerializerGenerator( } val httpDocumentMembers = httpBindingResolver.requestMembers(operationShape, HttpLocation.DOCUMENT) val inputShape = operationShape.inputShape(model) return protocolFunctions.serializeFn(operationShape, fnNameSuffix = "input") { fnName -> rustBlockTemplate( Loading
codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt +1 −1 Original line number Diff line number Diff line Loading @@ -209,7 +209,7 @@ open class ServerCodegenVisitor( .let { AttachValidationExceptionToConstrainedOperationInputs.transform(it, settings) } // Tag aggregate shapes reachable from operation input .let(ShapesReachableFromOperationInputTagger::transform) // Remove traits that are not supported by the chosen protocol // Remove traits that are not supported by the chosen protocol. .let { ServerProtocolBasedTransformationFactory.transform(it, settings) } // Normalize event stream operations .let(EventStreamNormalizer::transform) Loading
codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/BeforeSerializingMemberCborCustomization.kt +7 −0 Original line number Diff line number Diff line Loading @@ -13,6 +13,13 @@ import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.Value import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.server.smithy.workingWithPublicConstrainedWrapperTupleType /** * Constrained shapes are wrapped in a Rust tuple struct that implements all necessary checks. However, * for serialization purposes, the inner type of the constrained shape is used for serialization. * * The `BeforeSerializingMemberCborCustomization` class generates a reference to the inner type when the shape being * code-generated is constrained and the `publicConstrainedTypes` codegen flag is set. */ class BeforeSerializingMemberCborCustomization(private val codegenContext: ServerCodegenContext) : CborSerializerCustomization() { override fun section(section: CborSerializerSection): Writable = when (section) { Loading
codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ConstraintsTest.kt +13 −5 Original line number Diff line number Diff line Loading @@ -38,17 +38,25 @@ enum class ModelProtocol(val trait: AbstractTrait) { Rpcv2Cbor(Rpcv2CborTrait.builder().build()), } fun loadSmithyConstraintsModelForProtocol(modelProtocol: ModelProtocol): Pair<ShapeId, Model> { val (serviceShapeId, model) = loadSmithyConstraintsModel() return Pair(serviceShapeId, model.replaceProtocolTrait(serviceShapeId, modelProtocol)) /** * Returns the Smithy constraints model from the common repository, with the specified protocol * applied to the service. */ fun loadSmithyConstraintsModelForProtocol(modelProtocol: ModelProtocol): Pair<Model, ShapeId> { val (model, serviceShapeId) = loadSmithyConstraintsModel() return Pair(model.replaceProtocolTrait(serviceShapeId, modelProtocol), serviceShapeId) } fun loadSmithyConstraintsModel(): Pair<ShapeId, Model> { /** * Loads the Smithy constraints model defined in the common repository and returns the model along with * the service shape defined in it. */ fun loadSmithyConstraintsModel(): Pair<Model, ShapeId> { val filePath = "../codegen-core/common-test-models/constraints.smithy" val serviceShapeId = ShapeId.from("com.amazonaws.constraints#ConstraintsService") val model = File(filePath).readText().asSmithyModel() return Pair(serviceShapeId, model) return Pair(model, serviceShapeId) } /** Loading
codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/CborConstraintsIntegrationTest.kt +1 −3 Original line number Diff line number Diff line 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, model) = loadSmithyConstraintsModelForProtocol(ModelProtocol.Rpcv2Cbor) val (model, serviceShape) = loadSmithyConstraintsModelForProtocol(ModelProtocol.Rpcv2Cbor) // The test should compile; no further testing is required. serverIntegrationTest( model, Loading
codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/CborParserGenerator.kt +4 −4 File changed.Contains only whitespace changes. Show changes