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

Refactor asValidationExceptionField Property #3717

Open
drganjoo opened this issue Jun 26, 2024 · 0 comments
Open

Refactor asValidationExceptionField Property #3717

drganjoo opened this issue Jun 26, 2024 · 0 comments

Comments

@drganjoo
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant