Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add docs for inline io and mixins #1057

Merged
merged 5 commits into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion designs/mixins.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ The members and traits applied to members of a mixin are copied onto the target
shape. It is sometimes necessary to provide a more specific trait value for a
copied member or to add traits only to a specific copy of a member. Traits can
be added on to these members like any other member. Additionally, Traits can be
applied to these members in the JSON AST using the `apply` type and in the
applied to these members in the JSON AST using the `apply` type and in the
Smithy IDL using `apply` statements.

> Note: Traits applied to shapes supersede any traits inherited from mixins.
Expand Down
186 changes: 171 additions & 15 deletions docs/source/1.0/spec/core/idl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,26 @@ The Smithy IDL is defined by the following ABNF:
:/ `service_statement`
:/ `operation_statement`
:/ `resource_statement`
simple_shape_statement :`simple_type_name` `ws` `identifier`
mixins :`sp` "with" `ws` "[" 1*(`ws` `shape_id`) `ws` "]"
simple_shape_statement :`simple_type_name` `ws` `identifier` [`mixins`]
simple_type_name :"blob" / "boolean" / "document" / "string"
:/ "byte" / "short" / "integer" / "long"
:/ "float" / "double" / "bigInteger"
:/ "bigDecimal" / "timestamp"
shape_members :"{" `ws` *(`shape_member_kvp` `ws`) "}"
shape_member_kvp :`trait_statements` `identifier` `ws` ":" `ws` `shape_id`
list_statement :"list" `ws` `identifier` `ws` `shape_members`
set_statement :"set" `ws` `identifier` `ws` `shape_members`
map_statement :"map" `ws` `identifier` `ws` `shape_members`
structure_statement :"structure" `ws` `identifier` `ws` `shape_members`
union_statement :"union" `ws` `identifier` `ws` `shape_members`
service_statement :"service" `ws` `identifier` `ws` `node_object`
operation_statement :"operation" `ws` `identifier` `ws` `node_object`
resource_statement :"resource" `ws` `identifier` `ws` `node_object`
list_statement :"list" `ws` `identifier` [`mixins`] `ws` `shape_members`
set_statement :"set" `ws` `identifier` [`mixins`] `ws` `shape_members`
map_statement :"map" `ws` `identifier` [`mixins`] `ws` `shape_members`
structure_statement :"structure" `ws` `identifier` [`mixins`] `ws` `shape_members`
union_statement :"union" `ws` `identifier` [`mixins`] `ws` `shape_members`
service_statement :"service" `ws` `identifier` [`mixins`] `ws` `node_object`
operation_statement :"operation" `ws` `identifier` [`mixins`] `ws` `inlineable_properties`
inlineable_properties :"{" *(`inlineable_property` `ws`) `ws` "}"
inlineable_property :`node_object_kvp` / `inline_structure`
inline_structure :`node_object_key` `ws` ":=" `ws` `inline_structure_value`
inline_structure_value :`trait_statements` [`mixins` ws] shape_members
resource_statement :"resource" `ws` `identifier` [`mixins`] `ws` `node_object`

.. rubric:: Traits

Expand Down Expand Up @@ -250,11 +255,30 @@ The :token:`control section <smithy:control_section>` of a model contains
:token:`control statements <smithy:control_statement>` that apply parser directives
to a *specific IDL file*. Because control statements influence parsing, they
MUST appear at the beginning of a file before any other statements and have
no effect on the :ref:`semantic model <semantic-model>`
no effect on the :ref:`semantic model <semantic-model>` The following control
statements are currently supported:

The :ref:`version <smithy-version>` statement is currently the only control
statement defined in the Smithy IDL. Implementations MUST ignore unknown
control statements.
.. list-table::
:header-rows: 1
:widths: 10 10 80

* - Name
- Type
- Description
* - version
- string
- Defines the :ref:`version <smithy-version>` of the Smithy IDL used in
the model file.
* - operationInputSuffix
- string
- Defines the suffix used when generating names for
:ref:`inline operation input <idl-inline-input-output>`.
* - operationOutputSuffix
- string
- Defines the suffix used when generating names for
:ref:`inline operation output <idl-inline-input-output>`.

Implementations MUST ignore unknown control statements.


.. _smithy-version:
Expand Down Expand Up @@ -1100,8 +1124,8 @@ Operation shape
---------------

An operation shape is defined using an :token:`smithy:operation_statement` and the
provided :token:`smithy:node_object` supports the same properties defined in the
:ref:`operation specification <operation>`.
provided :token:`smithy:inlineable_properties` supports the same properties defined
in the :ref:`operation specification <operation>`.

The following example defines an operation shape that accepts an input
structure named ``Input``, returns an output structure named ``Output``, and
Expand Down Expand Up @@ -1146,6 +1170,109 @@ can potentially return the ``Unavailable`` or ``BadRequest``
}


.. _idl-inline-input-output:

Inline input / output shapes
++++++++++++++++++++++++++++

The input and output properties of operations can be defined using a more
succinct, inline syntax.

A structure defined using inline syntax is automatically marked with the
:ref:`input-trait` for inputs and the :ref:`output-trait` for outputs.

A structure defined using inline syntax is given a generated shape name. For
inputs, the generated name is the name of the operation shape with the suffix
``Input`` added. For outputs, the generated name is the name of the operation
shape with the ``Output`` suffix added.

For example, the following model:

.. code-block:: smithy

operation GetUser {
// The generated shape name is GetUserInput
input := {
userId: String
}

// The generated shape name is GetUserOutput
output := {
username: String
userId: String
}
}

Is equivalent to:

.. code-block:: smithy

operation GetUser {
input: GetUserInput
output: GetUserOutput
}

@input
structure GetUserInput {
userId: String
}

@output
structure GetUserOutput {
username: String
userId: String
}

Traits and mixins can be applied to the inline structure:

.. code-block:: smithy

@mixin
structure BaseUser {
userId: String
}

operation GetUser {
input := @references([{resource: User}]) {
userId: String
}

output := with [BaseUser] {
username: String
}
}

operation PutUser {
input :=
@references([{resource: User}])
with [BaseUser] {}
}

The suffixes for the generated names can be customized using the
``operationInputSuffix`` and ``operationOutputSuffix`` control statements.
JordonPhillips marked this conversation as resolved.
Show resolved Hide resolved

.. code-block:: smithy

$version: "2.0"
$operationInputSuffix: "Request"
$operationInputSuffix: "Response"

namespace smithy.example

operation GetUser {
// The generated shape name is GetUserRequest
input := {
userId: String
}

// The generated shape name is GetUserResponse
output := {
username: String
userId: String
}
}


.. _idl-resource:

Resource shape
Expand Down Expand Up @@ -1191,6 +1318,35 @@ and defines a :ref:`read <read-lifecycle>` operation:
}


.. _idl-mixins:

Mixins
------

:ref:`Mixins <mixins>` can be added to a shape using the optional
:token:`smithy:mixins` clause of a shape definition.

For example:

.. code-block:: smithy

@mixin
structure BaseUser {
userId: String
}

structure UserDetails with [BaseUser] {
username: String
}

@mixin
@sensitive
string SensitiveString

@pattern("^[a-zA-Z\.]*$")
string SensitiveText with [SensitiveString]


.. _documentation-comment:

Documentation comment
Expand Down
44 changes: 44 additions & 0 deletions docs/source/1.0/spec/core/json-ast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,50 @@ The following example defines an operation, its input, output, and errors:
}


.. ast-mixins:

------
Mixins
------

All shapes in the ``shapes`` map can contain a ``mixins`` property that
defines the :ref:`mixins` that are added to the shape. ``mixins`` is an
array of :ref:`shape references <ast-shape-reference>` that target shapes
marked with the :ref:`mixin trait <mixin-trait>`.

.. code-block:: json

{
"smithy": "2.0",
"shapes": {
"smithy.example#BaseUser": {
"type": "structure",
"members": {
"userId": {
"target": "smithy.api#String"
}
},
"traits": {
"smithy.api#mixin": {}
}
},
"smithy.example#UserDetails": {
"type": "structure",
"members": {
"username": {
"target": "smithy.api#String"
}
},
"mixins": [
{
"target": "smithy.example#BaseUser"
}
]
}
}
}


.. _ast-apply:

--------------
Expand Down
Loading