Unverified Commit c0fa7f0b authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Upgrade to Smithy 1.12 (#812)



* Upgrade to Smithy 1.12

* update changelog

* Add protocol test

* Remove S3 customization: S3 content length fixed upstream

* Delete unuse S3 customization

Co-authored-by: default avatarZelda Hessler <zelda.hessler@pm.me>
parent 2757fcbb
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -3,6 +3,9 @@ vNext (Month Day, Year)
**Breaking Changes**
- `<operation>.make_operation(&config)` is now an `async` function for all operations. Code should be updated to call `.await`. This will only impact users using the low-level API. (smithy-rs#797)

**New this week**
- Upgrade to Smithy 1.12

v0.27 (October 20th, 2021)
==========================

+0 −19
Original line number Diff line number Diff line
@@ -6,12 +6,8 @@
package software.amazon.smithy.rustsdk.customize.s3

import software.amazon.smithy.aws.traits.protocols.RestXmlTrait
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.IntegerShape
import software.amazon.smithy.model.shapes.LongShape
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.transform.ModelTransformer
import software.amazon.smithy.rust.codegen.rustlang.CargoDependency
import software.amazon.smithy.rust.codegen.rustlang.RustModule
import software.amazon.smithy.rust.codegen.rustlang.Writable
@@ -110,18 +106,3 @@ class S3PubUse : LibRsCustomization() {
        else -> emptySection
    }
}

/** `com.amazonaws.s3#Size` is modeled as `integer`, which is too small for file sizes */
class S3CorrectSizeIntegerType {
    companion object {
        val SIZE_SHAPE_ID = ShapeId.from("com.amazonaws.s3#Size")
    }

    fun transform(model: Model): Model = ModelTransformer.create().mapShapes(model) { shape ->
        if (shape is IntegerShape && shape.id == SIZE_SHAPE_ID) {
            LongShape.builder().id(shape.id).source(shape.sourceLocation).traits(shape.allTraits.values).build()
        } else {
            shape
        }
    }
}
+0 −47
Original line number Diff line number Diff line
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0.
 */

package software.amazon.smithy.rustsdk.customize.s3

import io.kotest.matchers.shouldBe
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.Test
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.rust.codegen.testutil.asSmithyModel

class S3DecoratorTest {
    @Nested
    inner class S3CorrectSizeIntegerTypeTest {
        // TODO: Re-enable test below once https://github.com/awslabs/smithy/pull/900 is merged and
        // the latest Smithy is pulled in.
        @Disabled
        @Test
        fun `it should make Size a Long`() {
            val model = """
                namespace com.amazonaws.s3

                // The actual model doesn't have traits, but make sure we copy them to stay future-proof
                @range(min: 0)
                integer Size

                structure Object {
                    size: Size,
                }
            """.asSmithyModel()

            // Precondition: make sure the test model is correct
            val oldSize = model.expectShape(S3CorrectSizeIntegerType.SIZE_SHAPE_ID)

            val transformed = S3CorrectSizeIntegerType().transform(model)
            val newSize = transformed.expectShape(S3CorrectSizeIntegerType.SIZE_SHAPE_ID)
            newSize.isLongShape shouldBe true
            newSize.allTraits shouldBe oldSize.allTraits
            newSize.sourceLocation shouldBe oldSize.sourceLocation

            transformed.expectShape(ShapeId.from("com.amazonaws.s3#Object")).members().first().isLongShape shouldBe true
        }
    }
}
+0 −12
Original line number Diff line number Diff line
@@ -28,16 +28,6 @@ def discover_new_models(aws_models_repo, known_models):
            new_models.append(model)
    return new_models

# HACK: Modify the S3 model directly to change the type of `Size` until Smithy
# allows this transformation directly (https://github.com/awslabs/smithy/pull/900).
def hack_s3_model(model_path):
    result = subprocess.run(["jq", "-M", ".shapes[\"com.amazonaws.s3#Size\"].type = \"long\"", str(model_path)], capture_output = True, check = True)
    hacked = result.stdout.decode("utf-8")
    with open(model_path, "w") as file:
        file.write(hacked)
        if not hacked.endswith("\n"):
            file.write("\n")

def copy_model(source_path, model_path, model_name):
    dest_path = Path("aws-models") / model_path
    source = source_path.read_text()
@@ -46,8 +36,6 @@ def copy_model(source_path, model_path, model_name):
        file.write(source)
        if not source.endswith("\n"):
            file.write("\n")
    if model_name == "s3":
        hack_s3_model(dest_path)

def copy_known_models(aws_models_repo):
    known_models = set()
+3 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ import software.amazon.smithy.model.shapes.StringShape
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.model.shapes.UnionShape
import software.amazon.smithy.model.traits.EnumTrait
import software.amazon.smithy.model.transform.ModelTransformer
import software.amazon.smithy.rust.codegen.rustlang.RustMetadata
import software.amazon.smithy.rust.codegen.rustlang.RustModule
import software.amazon.smithy.rust.codegen.rustlang.RustWriter
@@ -130,6 +131,8 @@ class CodegenVisitor(context: PluginContext, private val codegenDecorator: RustC
     */
    private fun baselineTransform(model: Model) =
        model
            // Add errors attached at the service level to the models
            .let { ModelTransformer.create().copyServiceErrorsToOperations(it, settings.getService(it)) }
            // Add `Box<T>` to recursive shapes as necessary
            .let(RecursiveShapeBoxer::transform)
            // Normalize the `message` field on errors when enabled in settings (default: true)
Loading