Repository: smithy-lang/smithy
Pull request #2579 (2025-04-07 16:43:20)

Complete AWS query compatibility for RPC v2 CBOR
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.



Patch:
diff --git a/docs/source-2.0/aws/protocols/aws-query-protocol.rst b/docs/source-2.0/aws/protocols/aws-query-protocol.rst
index b91703442..526ab0820 100644
--- a/docs/source-2.0/aws/protocols/aws-query-protocol.rst
+++ b/docs/source-2.0/aws/protocols/aws-query-protocol.rst
@@ -562,7 +562,7 @@ Summary
     :ref:`awsQueryError <aws.protocols#awsQueryError-trait>`, and ``Fault`` is
     one of ``Sender`` or ``Receiver``.
 Trait selector
-    ``service [trait|awsJson1_0]``
+    ``service :test([trait|aws.protocols#awsJson1_0], [trait|smithy.protocols#rpcv2Cbor])``
 Value type
     Annotation trait
 
diff --git a/smithy-aws-traits/build.gradle.kts b/smithy-aws-traits/build.gradle.kts
index a4ae351aa..97ace4626 100644
--- a/smithy-aws-traits/build.gradle.kts
+++ b/smithy-aws-traits/build.gradle.kts
@@ -14,4 +14,5 @@ extra["moduleName"] = "software.amazon.smithy.aws.traits"
 dependencies {
     api(project(":smithy-diff"))
     api(project(":smithy-model"))
+    api(project(":smithy-protocol-traits"))
 }
diff --git a/smithy-aws-traits/src/main/resources/META-INF/smithy/aws.protocols.smithy b/smithy-aws-traits/src/main/resources/META-INF/smithy/aws.protocols.smithy
index 16fbbfb2b..311eb9779 100644
--- a/smithy-aws-traits/src/main/resources/META-INF/smithy/aws.protocols.smithy
+++ b/smithy-aws-traits/src/main/resources/META-INF/smithy/aws.protocols.smithy
@@ -86,8 +86,9 @@ structure awsQueryError {
     httpResponseCode: Integer
 }
 
-/// Enable backward compatibility when migrating from awsQuery to awsJson protocol
-@trait(selector: "service [trait|aws.protocols#awsJson1_0]")
+/// Enable backward compatibility when migrating from awsQuery to the awsJson
+/// protocol or Smithy RPC v2 CBOR.
+@trait(selector: "service :test([trait|aws.protocols#awsJson1_0], [trait|smithy.protocols#rpcv2Cbor])")
 structure awsQueryCompatible {}
 
 /// An RPC-based protocol that sends 'POST' requests in the body as Amazon EC2


Test patch:
diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/aws-query-compatible.smithy b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/aws-query-compatible.smithy
index a748c687e..25b682874 100644
--- a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/aws-query-compatible.smithy
+++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/aws-query-compatible.smithy
@@ -5,6 +5,7 @@ namespace smithy.example
 use aws.protocols#awsQueryCompatible
 use aws.protocols#awsQueryError
 use aws.protocols#awsJson1_0
+use smithy.protocols#rpcv2Cbor
 
 @awsQueryCompatible
 @awsJson1_0
@@ -21,3 +22,10 @@ service MyService {
 structure InvalidThingException {
     message: String
 }
+
+@awsQueryCompatible
+@rpcv2Cbor
+service MyService2 {
+    version: "2020-02-05",
+    errors: [InvalidThingException]
+}
diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/protocols/aws-query-compatible-does-not-support-non-aws-json.errors b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/protocols/aws-query-compatible-does-not-support-non-aws-json.errors
index af5c295f0..c2bd3a1f9 100644
--- a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/protocols/aws-query-compatible-does-not-support-non-aws-json.errors
+++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/protocols/aws-query-compatible-does-not-support-non-aws-json.errors
@@ -1,2 +1,2 @@
 [WARNING] smithy.example#MyService: This shape applies a trait that is deprecated: aws.protocols#awsQuery | DeprecatedTrait
-[ERROR] smithy.example#MyService: Trait `aws.protocols#awsQueryCompatible` cannot be applied to `smithy.example#MyService`. This trait may only be applied to shapes that match the following selector: service [trait|aws.protocols#awsJson1_0] | TraitTarget
+[ERROR] smithy.example#MyService: Trait `aws.protocols#awsQueryCompatible` cannot be applied to `smithy.example#MyService`. This trait may only be applied to shapes that match the following selector: service :test([trait|aws.protocols#awsJson1_0], [trait|smithy.protocols#rpcv2Cbor]) | TraitTarget