You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The data class TraitInfo holds information for generating Rust code for a constraint trait.
It has a property asValidationExceptionField, which should not be included in this class because ValidationExceptionField is a member of smithy.framework#ValidationException and is not accessible when it is not referenced in the model, which is the case when implementing custom validation code. Moreover, the name asValidationExceptionField is misleading, as it refers only to a specific case of validation exceptions and does not make sense when using custom validations.
Implementers can define their own ValidationExceptionConversionGenerator, but they must duplicate code for generating the matching enum variant arm that represents the particular constraint trait. For example, for a LengthTrait applied to a String, a Rust ConstraintTrait enum variant is generated as Length(usize). Currently, asValidationExceptionField refers to the same variant using Self::Length(length) => ..., and the SmithyValidationExceptionConversionGenerator uses this to generate appropriate code. However, custom validation code cannot use asValidationExceptionField and must duplicate the code for generating the Self::Length(length) => ... matching arm in its implementation.
The asValidationExceptionField property should be refactored to be agnostic of the ValidationException used in the code generator. Any custom validation exception generator should be able to gather information from TraitInfo about what Rust code needs to be generated for matching the particular enum variant arm. It can then generate code to set the appropriate validation exception Rust structure.
The text was updated successfully, but these errors were encountered:
The data class
TraitInfo
holds information for generating Rust code for a constraint trait.It has a property
asValidationExceptionField
, which should not be included in this class becauseValidationExceptionField
is a member of smithy.framework#ValidationException and is not accessible when it is not referenced in the model, which is the case when implementing custom validation code. Moreover, the nameasValidationExceptionField
is misleading, as it refers only to a specific case of validation exceptions and does not make sense when using custom validations.Implementers can define their own
ValidationExceptionConversionGenerator
, but they must duplicate code for generating the matching enum variant arm that represents the particular constraint trait. For example, for aLengthTrait
applied to aString
, a RustConstraintTrait
enum variant is generated asLength(usize)
. Currently,asValidationExceptionField
refers to the same variant usingSelf::Length(length) => ...
, and theSmithyValidationExceptionConversionGenerator
uses this to generate appropriate code. However, custom validation code cannot useasValidationExceptionField
and must duplicate the code for generating theSelf::Length(length) => ...
matching arm in its implementation.The
asValidationExceptionField
property should be refactored to be agnostic of theValidationException
used in the code generator. Any custom validation exception generator should be able to gather information fromTraitInfo
about what Rust code needs to be generated for matching the particular enum variant arm. It can then generate code to set the appropriate validation exception Rust structure.The text was updated successfully, but these errors were encountered: