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

Document precedence for constraint traits #784

Merged
merged 1 commit into from
Apr 29, 2021
Merged
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
56 changes: 56 additions & 0 deletions docs/source/1.0/spec/core/constraint-traits.rst
Original file line number Diff line number Diff line change
Expand Up @@ -616,5 +616,61 @@ Value type
}
}

.. _precedence:

----------------
Trait precedence
----------------

Some constraints can be applied to shapes as well as structure members. If a
constraint of the same type is applied to a structure member and the shape
that the member targets, the trait applied to the member takes precedence.

In the below example, the ``range`` trait applied to ``numberOfItems``
takes precedence over the one applied to ``PositiveInteger``. The resolved
minimum will be ``7``, and the maximum ``12``.

.. tabs::

.. code-tab:: smithy

structure ShoppingCart {
@range(min: 7, max:12)
numberOfItems: PositiveInteger
}

@range(min: 1)
integer PositiveInteger

.. code-tab:: json

{
"smithy": "1.0",
"shapes": {
"smithy.example#MyStructure": {
"type": "structure",
"members": {
"foo": {
"target": "smithy.example#PositiveInteger",
"traits": {
"smithy.api#range": {
"min": 7,
"max": 12
}
}
}
}
},
"smithy.example#PositiveInteger": {
"type": "integer",
"traits": {
"smithy.api#range": {
"min": 1
}
}
}
}
}

.. _ECMA 262 regular expression dialect: https://www.ecma-international.org/ecma-262/8.0/index.html#sec-patterns
.. _CommonMark: https://spec.commonmark.org/