From 22998effb64b21e3162cb6fcbd1f92d9d8a5ccb6 Mon Sep 17 00:00:00 2001 From: kstich Date: Fri, 21 Jul 2023 09:04:41 -0700 Subject: [PATCH] Expand valid targets of httpPayload This commit updates the httpPayload trait to allow targeting a structure member that targets any type. Documentation is updated to clarify how the values of other types are serialized. AWS protocol support for new types of httpPayload marked member targets is unchanged. --- docs/source-1.0/spec/core/http-traits.rst | 12 +++----- docs/source-2.0/spec/http-bindings.rst | 13 +++----- ...o-not-support-list-set-map-payloads.errors | 3 ++ ...o-not-support-list-set-map-payloads.smithy | 30 ++++++++++++++++++- .../amazon/smithy/model/loader/prelude.smithy | 2 +- 5 files changed, 41 insertions(+), 19 deletions(-) diff --git a/docs/source-1.0/spec/core/http-traits.rst b/docs/source-1.0/spec/core/http-traits.rst index b6ae367a1d3..5a40d2c57f3 100644 --- a/docs/source-1.0/spec/core/http-traits.rst +++ b/docs/source-1.0/spec/core/http-traits.rst @@ -707,13 +707,9 @@ the body of the response. Summary Binds a single structure member to the body of an HTTP message. Trait selector - .. code-block:: none - - structure > :test(member > :test(string, blob, structure, union, document, list, set, map)) + ``structure > member`` - The ``httpPayload`` trait can be applied to ``structure`` members that - target a ``string``, ``blob``, ``structure``, ``union``, ``document``, - ``set``, ``map``, or ``list``. + *Any structure member* Value type Annotation trait. Conflicts with @@ -775,12 +771,12 @@ or :ref:`httpPrefixHeaders-trait`. .. rubric:: Serialization rules -#. When a string or blob member is referenced, the raw value is serialized - as the body of the message. #. When a :ref:`structure `, :ref:`union `, :ref:`list `, :ref:`set `, :ref:`map `, or document type is targeted, the shape value is serialized as a :ref:`protocol-specific ` document that is sent as the body of the message. +#. When any other type of member is referenced, the raw value is serialized as + the body of the message. .. smithy-trait:: smithy.api#httpPrefixHeaders diff --git a/docs/source-2.0/spec/http-bindings.rst b/docs/source-2.0/spec/http-bindings.rst index aa8ce2f2d0f..18e1bf30375 100644 --- a/docs/source-2.0/spec/http-bindings.rst +++ b/docs/source-2.0/spec/http-bindings.rst @@ -709,14 +709,9 @@ the body of the response. Summary Binds a single structure member to the body of an HTTP message. Trait selector - .. code-block:: none - - structure > :test(member > :test(string, blob, structure, union, document, list, map)) - - The ``httpPayload`` trait can be applied to ``structure`` members that - target a ``string``, ``blob``, ``structure``, ``union``, ``document``, - ``map``, or ``list``. + ``structure > member`` + *Any structure member* Value type Annotation trait. Conflicts with @@ -779,12 +774,12 @@ or :ref:`httpPrefixHeaders-trait`. .. rubric:: Serialization rules -#. When a string or blob member is referenced, the raw value is serialized - as the body of the message. #. When a :ref:`structure `, :ref:`union `, :ref:`list `, :ref:`map `, or document type is targeted, the shape value is serialized as a :ref:`protocol-specific ` document that is sent as the body of the message. +#. When any other type of member is referenced, the raw value is serialized as + the body of the message. .. smithy-trait:: smithy.api#httpPrefixHeaders diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/protocols/aws-protocols-do-not-support-list-set-map-payloads.errors b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/protocols/aws-protocols-do-not-support-list-set-map-payloads.errors index 7342a67c196..f581a8f9105 100644 --- a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/protocols/aws-protocols-do-not-support-list-set-map-payloads.errors +++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/protocols/aws-protocols-do-not-support-list-set-map-payloads.errors @@ -1,3 +1,6 @@ [ERROR] smithy.example#InvalidBindingOperationInput$listBinding: AWS Protocols only support binding the following shape types to the payload: string, blob, structure, union, and document | ProtocolHttpPayload [ERROR] smithy.example#InvalidBindingOperationOutput$mapBinding: AWS Protocols only support binding the following shape types to the payload: string, blob, structure, union, and document | ProtocolHttpPayload [ERROR] smithy.example#InvalidBindingError$setBinding: AWS Protocols only support binding the following shape types to the payload: string, blob, structure, union, and document | ProtocolHttpPayload +[ERROR] smithy.example#InvalidSimpleBindingOperationInput$booleanBinding: AWS Protocols only support binding the following shape types to the payload: string, blob, structure, union, and document | ProtocolHttpPayload +[ERROR] smithy.example#InvalidSimpleBindingOperationOutput$integerBinding: AWS Protocols only support binding the following shape types to the payload: string, blob, structure, union, and document | ProtocolHttpPayload +[ERROR] smithy.example#InvalidSimpleBindingError$doubleBinding: AWS Protocols only support binding the following shape types to the payload: string, blob, structure, union, and document | ProtocolHttpPayload diff --git a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/protocols/aws-protocols-do-not-support-list-set-map-payloads.smithy b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/protocols/aws-protocols-do-not-support-list-set-map-payloads.smithy index bc6dc913b8e..0659896e205 100644 --- a/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/protocols/aws-protocols-do-not-support-list-set-map-payloads.smithy +++ b/smithy-aws-traits/src/test/resources/software/amazon/smithy/aws/traits/errorfiles/protocols/aws-protocols-do-not-support-list-set-map-payloads.smithy @@ -13,7 +13,10 @@ use smithy.api#httpPayload @restJson1 service InvalidExample { version: "2020-12-29", - operations: [InvalidBindingOperation], + operations: [ + InvalidBindingOperation, + InvalidSimpleBindingOperation + ], } @http(method: "POST", uri: "/invalid-payload") @@ -41,6 +44,31 @@ structure InvalidBindingError { setBinding: StringSet } +@http(method: "POST", uri: "/invalid-simple-payload") +operation InvalidSimpleBindingOperation { + input: InvalidSimpleBindingOperationInput, + output: InvalidSimpleBindingOperationOutput, + errors: [InvalidSimpleBindingError], +} + +@input +structure InvalidSimpleBindingOperationInput { + @httpPayload + booleanBinding: Boolean, +} + +@output +structure InvalidSimpleBindingOperationOutput { + @httpPayload + integerBinding: Integer, +} + +@error("client") +structure InvalidSimpleBindingError { + @httpPayload + doubleBinding: Double +} + list StringList { member: String } diff --git a/smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude.smithy b/smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude.smithy index 17dfc9e46f7..2fc4b2c4274 100644 --- a/smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude.smithy +++ b/smithy-model/src/main/resources/software/amazon/smithy/model/loader/prelude.smithy @@ -832,7 +832,7 @@ string httpPrefixHeaders /// Binds a single structure member to the body of an HTTP request. @trait( - selector: "structure > :test(member > :test(string, blob, structure, union, document, list, map))", + selector: "structure > member", conflicts: [httpLabel, httpQuery, httpHeader, httpPrefixHeaders, httpResponseCode, httpQueryParams], structurallyExclusive: "member", breakingChanges: [{change: "presence"}]