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

smithy 1.8 upgrade & awsQueryError support (#533)

Upgrade Smithy to 1.8. Smithy 1.8 introduces the awsQueryError trait which customizes error codes for awsQuery.
parent a02f7afc
Loading
Loading
Loading
Loading
+18 −9
Original line number Diff line number Diff line
@@ -5,9 +5,11 @@

package software.amazon.smithy.rust.codegen.smithy.protocols

import software.amazon.smithy.aws.traits.protocols.AwsQueryErrorTrait
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.pattern.UriPattern
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.ToShapeId
import software.amazon.smithy.model.traits.HttpTrait
import software.amazon.smithy.model.traits.TimestampFormatTrait
import software.amazon.smithy.rust.codegen.rustlang.CargoDependency
@@ -24,6 +26,7 @@ import software.amazon.smithy.rust.codegen.smithy.protocols.serialize.AwsQuerySe
import software.amazon.smithy.rust.codegen.smithy.protocols.serialize.StructuredDataSerializerGenerator
import software.amazon.smithy.rust.codegen.smithy.transformers.OperationNormalizer
import software.amazon.smithy.rust.codegen.smithy.transformers.RemoveEventStreamOperations
import software.amazon.smithy.rust.codegen.util.getTrait

class AwsQueryFactory : ProtocolGeneratorFactory<HttpBoundProtocolGenerator> {
    override fun buildProtocolGenerator(protocolConfig: ProtocolConfig): HttpBoundProtocolGenerator =
@@ -43,18 +46,24 @@ class AwsQueryFactory : ProtocolGeneratorFactory<HttpBoundProtocolGenerator> {
    }
}

class AwsQueryProtocol(private val protocolConfig: ProtocolConfig) : Protocol {
    private val runtimeConfig = protocolConfig.runtimeConfig
    private val awsQueryErrors: RuntimeType = RuntimeType.wrappedXmlErrors(runtimeConfig)
    override val httpBindingResolver: HttpBindingResolver = StaticHttpBindingResolver(
        protocolConfig.model,
        HttpTrait.builder()
private val awsQueryHttpTrait = HttpTrait.builder()
    .code(200)
    .method("POST")
    .uri(UriPattern.parse("/"))
            .build(),
        "application/x-www-form-urlencoded"
    )
    .build()

class AwsQueryBindingResolver(private val model: Model) :
    StaticHttpBindingResolver(model, awsQueryHttpTrait, "application/x-www-form-urlencoded") {
    override fun errorCode(errorShape: ToShapeId): String {
        val error = model.expectShape(errorShape.toShapeId())
        return error.getTrait<AwsQueryErrorTrait>()?.code ?: errorShape.toShapeId().name
    }
}

class AwsQueryProtocol(private val protocolConfig: ProtocolConfig) : Protocol {
    private val runtimeConfig = protocolConfig.runtimeConfig
    private val awsQueryErrors: RuntimeType = RuntimeType.wrappedXmlErrors(runtimeConfig)
    override val httpBindingResolver: HttpBindingResolver = AwsQueryBindingResolver(protocolConfig.model)

    override val defaultTimestampFormat: TimestampFormatTrait.Format = TimestampFormatTrait.Format.DATE_TIME

+3 −1
Original line number Diff line number Diff line
@@ -53,6 +53,8 @@ interface HttpBindingResolver {
     */
    fun errorResponseBindings(errorShape: ToShapeId): List<HttpBindingDescriptor>

    fun errorCode(errorShape: ToShapeId): String = errorShape.toShapeId().name

    /**
     * Returns a list of member shapes bound to a given request [location] for a given [operationShape]
     */
@@ -122,7 +124,7 @@ class HttpTraitHttpBindingResolver(
 * Takes an [HttpTrait] value and content type, and provides bindings based on those.
 * All members will end up being document members.
 */
class StaticHttpBindingResolver(
open class StaticHttpBindingResolver(
    private val model: Model,
    private val httpTrait: HttpTrait,
    private val requestContentType: String,
+1 −1
Original line number Diff line number Diff line
@@ -296,7 +296,7 @@ class HttpBoundProtocolGenerator(
                            val errorShape = model.expectShape(error, StructureShape::class.java)
                            val variantName = symbolProvider.toSymbol(model.expectShape(error)).name
                            withBlock(
                                "${error.name.dq()} => #1T { meta: generic, kind: #1TKind::$variantName({",
                                "${httpBindingResolver.errorCode(errorShape).dq()} => #1T { meta: generic, kind: #1TKind::$variantName({",
                                "})},",
                                errorSymbol
                            ) {
+1 −1
Original line number Diff line number Diff line
@@ -6,7 +6,7 @@
kotlin.code.style=official

# codegen
smithyVersion=1.7.2
smithyVersion=1.8.0

# kotlin
kotlinVersion=1.4.21