Interface Trait
-
- All Superinterfaces:
FromSourceLocation,ToNode,ToShapeId
- All Known Implementing Classes:
AbstractTrait,ActionPermissionDescriptionTrait,AnnotationTrait,ApiKeySourceTrait,ArnReferenceTrait,ArnTrait,AuthDefinitionTrait,AuthorizersTrait,AuthorizerTrait,AuthTrait,AwsJson1_0Trait,AwsJson1_1Trait,AwsProtocolTrait,AwsQueryTrait,BoxTrait,CfnAdditionalIdentifierTrait,CfnExcludePropertyTrait,CfnMutabilityTrait,CfnNameTrait,CfnResourceTrait,ClientDiscoveredEndpointTrait,ClientEndpointDiscoveryIdTrait,ClientEndpointDiscoveryTrait,CognitoUserPoolsTrait,ConditionKeysTrait,ControlPlaneTrait,CorsTrait,DataPlaneTrait,DataTrait,DefineConditionKeysTrait,DeprecatedTrait,DisableConditionKeyInferenceTrait,DocumentationTrait,DynamicTrait,Ec2QueryNameTrait,Ec2QueryTrait,EndpointTrait,EnumTrait,ErrorTrait,EventHeaderTrait,EventPayloadTrait,ExamplesTrait,ExternalDocumentationTrait,HostLabelTrait,HttpApiKeyAuthTrait,HttpBasicAuthTrait,HttpBearerAuthTrait,HttpChecksumRequiredTrait,HttpDigestAuthTrait,HttpErrorTrait,HttpHeaderTrait,HttpLabelTrait,HttpPayloadTrait,HttpPrefixHeadersTrait,HttpQueryTrait,HttpRequestTestsTrait,HttpResponseCodeTrait,HttpResponseTestsTrait,HttpTrait,IdempotencyTokenTrait,IdempotentTrait,IdRefTrait,IntegrationTrait,InternalTrait,JsonNameTrait,LengthTrait,MediaTypeTrait,MockIntegrationTrait,MqttJsonTrait,NoReplaceTrait,OptionalAuthTrait,PaginatedTrait,PatternTrait,PrivateTrait,ProtocolDefinitionTrait,PublishTrait,RangeTrait,ReadonlyTrait,ReferencesTrait,RequestValidatorTrait,RequiredActionsTrait,RequiredTrait,RequiresLengthTrait,ResourceIdentifierTrait,RestJson1Trait,RestXmlTrait,RetryableTrait,SensitiveTrait,ServiceTrait,SigV4Trait,SinceTrait,SparseTrait,StreamingTrait,StringListTrait,StringTrait,SubscribeTrait,SuppressTrait,TagsTrait,TimestampFormatTrait,TitleTrait,TopicLabelTrait,TraitDefinition,UniqueItemsTrait,UnsignedPayloadTrait,UnstableTrait,WaitableTrait,XmlAttributeTrait,XmlFlattenedTrait,XmlNamespaceTrait,XmlNameTrait
public interface Trait extends FromSourceLocation, ToNode, ToShapeId
Traits provide additional context and semantics to shapes.A trait complements a
Shapeby providing additional information to help correctly interpret any specific representation of it or to add information about constraints on the logical structure of theShape. For example, oneTraitobject might reflect details about how aShapeis bound to JSON while another might reflect details about how that sameShapeis bound to Ion.Traits are discovered through Java SPI using the
TraitServiceinterface. All traits that are defined in a Smithy MUST provide a TraitService in order for the concrete trait type to be created for the trait in code. Otherwise, the trait is created as aDynamicTrait.Traits may perform as much validation in their constructor; any exception thrown while creating a trait when assembling a model will automatically include the name of the trait in the thrown exception message. Any validation that requires more context than is provided to the trait constructor should be performed by implementing a
Validatorclass for the trait that is automatically registered each time the model is validated by implementing theValidatorinterface and registering the validator through SPI.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description static <S extends Shape,T extends Trait>
java.util.stream.Stream<Pair<S,T>>flatMapStream(S shape, java.lang.Class<T> traitClass)Used in a stream flatMapStream to return aStreamwith aPairof Shape and Trait if the trait is present on the given shape.static java.lang.StringgetIdiomaticTraitName(java.lang.String traitName)Gets the idiomatic name of a prelude trait by stripping off the smithy.api# prefix.static java.lang.StringgetIdiomaticTraitName(ToShapeId id)Gets the idiomatic name of a prelude trait by stripping off the smithy.api# prefix.static java.lang.StringmakeAbsoluteName(java.lang.String traitName)Makes the given trait name absolute if it is relative.static java.lang.StringmakeAbsoluteName(java.lang.String traitName, java.lang.String defaultNamespace)Makes the given trait name absolute if it is relative.ShapeIdtoShapeId()Gets the shape ID of the trait.-
Methods inherited from interface software.amazon.smithy.model.FromSourceLocation
getSourceLocation
-
-
-
-
Method Detail
-
toShapeId
ShapeId toShapeId()
Gets the shape ID of the trait.
-
flatMapStream
static <S extends Shape,T extends Trait> java.util.stream.Stream<Pair<S,T>> flatMapStream(S shape, java.lang.Class<T> traitClass)
Used in a stream flatMapStream to return aStreamwith aPairof Shape and Trait if the trait is present on the given shape.- Type Parameters:
S- ShapeT- Trait- Parameters:
shape- Shape to query for the trait.traitClass- Trait to retrieve.- Returns:
- Returns the Stream of the found trait or an empty stream.
-
getIdiomaticTraitName
static java.lang.String getIdiomaticTraitName(java.lang.String traitName)
Gets the idiomatic name of a prelude trait by stripping off the smithy.api# prefix. This is used in various error messages.- Parameters:
traitName- Trait name to make idiomatic.- Returns:
- Returns the idiomatic trait name.
-
getIdiomaticTraitName
static java.lang.String getIdiomaticTraitName(ToShapeId id)
Gets the idiomatic name of a prelude trait by stripping off the smithy.api# prefix. This is used in various error messages.- Parameters:
id- Trait name to make idiomatic.- Returns:
- Returns the idiomatic trait name.
-
makeAbsoluteName
static java.lang.String makeAbsoluteName(java.lang.String traitName)
Makes the given trait name absolute if it is relative.The namespace used to resolve with the trait name is the prelude namespace, smithy.api.
- Parameters:
traitName- Trait name to make absolute.- Returns:
- Returns the absolute trait name.
-
makeAbsoluteName
static java.lang.String makeAbsoluteName(java.lang.String traitName, java.lang.String defaultNamespace)Makes the given trait name absolute if it is relative.- Parameters:
traitName- Trait name to make absolute.defaultNamespace- Namespace to use if the name is relative.- Returns:
- Returns the absolute trait name.
-
-