Commit 763d5987 authored by Fahad Zubair's avatar Fahad Zubair
Browse files

Fix formatting and comments

parent f2c11b87
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -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(
+1 −1
Original line number Diff line number Diff line
@@ -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)
+7 −0
Original line number Diff line number Diff line
@@ -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) {
+13 −5
Original line number Diff line number Diff line
@@ -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)
}

/**
+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,
+4 −4

File changed.

Contains only whitespace changes.

Loading