Skip to content

Commit

Permalink
Expand valid targets of httpPayload
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kstich committed Jul 21, 2023
1 parent c419b33 commit 22998ef
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 19 deletions.
12 changes: 4 additions & 8 deletions docs/source-1.0/spec/core/http-traits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <structure>`, :ref:`union <union>`, :ref:`list <list>`,
:ref:`set <set>`, :ref:`map <map>`, or document type is targeted,
the shape value is serialized as a :ref:`protocol-specific <protocolDefinition-trait>`
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
Expand Down
13 changes: 4 additions & 9 deletions docs/source-2.0/spec/http-bindings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 <structure>`, :ref:`union <union>`, :ref:`list <list>`,
:ref:`map <map>`, or document type is targeted, the shape value is serialized
as a :ref:`protocol-specific <protocolDefinition-trait>` 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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"}]
Expand Down

0 comments on commit 22998ef

Please sign in to comment.