Contract traits¶
Contract traits are used to further constrain the valid values and behaviors of a model. Like constraint traits, contract traits are for validation only and SHOULD NOT impact the types signatures of generated code.
Contract trait enforcement¶
Contract traits provide structured documentation of implicit API constraints, and are useful for generating tests or applying static analysis to client or service code.
Contract traits SHOULD NOT be directly enforced by default when serializing or deserializing. These traits often express contracts using higher-level constructs and simpler but less efficient expressions. Services will usually check these contracts outside of service frameworks in more efficient ways.
conditions trait¶
- Summary
Restricts shape values to those which satisfy the given JMESPath expressions.
- Trait selector
:not(:test(service, operation, resource))Any shape other than services, operations, and resources
- Value type
map
The conditions trait is a map from condition names to Condition structures that contain
the following members:
Property |
Type |
Description |
|---|---|---|
expression |
|
Required. JMESPath expression that must evaluate to true. |
documentation |
|
Required. Documentation about the condition defined using CommonMark. |
See the JMESPath data model for details on how Smithy types are mapped to JMESPath types.
@conditions({
StartBeforeEnd: {
description: "The start time must be strictly less than the end time",
expression: "start < end"
}
})
structure FetchLogsInput {
@required
start: Timestamp
@required
end: Timestamp
}
@conditions({
NoKeywords: {
description: "The name cannot contain either 'id' or 'name', as these are reserved keywords"
expression: "!contains(@, 'id') && !contains(@, 'name')"
}
})
string Name