Skip to content

Conversation

jasgin
Copy link
Contributor

@jasgin jasgin commented Sep 29, 2025

Motivation and Context

Adds ability to define custom validation exceptions per RFC:

Description

Adds ability to use the following traits:

  • @validationException
  • @validationMessage
  • @validationFieldList
  • @validationFieldName
  • @validationFieldMessage

to define a custom validation exception for a service or operation.

Updated Smithy validation ensures:

  • The custom validation exception shape also has @error trait
  • The custom validation exception shape has exactly one member with the @validationMessage trait
  • Default constructibility if it contains constrained shapes
  • At most one custom validation exception is defined
  • smithy.framework#ValidationException is not used in an operation or service is a custom validation exception is defined
  • Operations with constrained input have exactly one of the default validation exception or a custom validation exception attached to their errors.

Testing

  • For unit testing, the following were added/updated:
    • codegen-server-traits/src/test/kotlin/software/amazon/smithy/rust/codegen/server/traits/ValidationExceptionTraitTest.kt
    • codegen-server-traits/src/test/kotlin/software/amazon/smithy/rust/codegen/server/traits/ValidationMessageTraitTest.kt
    • codegen-server-traits/src/test/kotlin/software/amazon/smithy/rust/codegen/server/traits/ValidationFieldListTraitTest.kt
    • codegen-server-traits/src/test/kotlin/software/amazon/smithy/rust/codegen/server/traits/ValidationFieldNameTraitTest.kt
    • codegen-server-traits/src/test/kotlin/software/amazon/smithy/rust/codegen/server/traits/ValidationFieldMessageTraitTest.kt
    • codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ValidateUnsupportedConstraintsAreNotUsedTest.kt
    • codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/CustomValidationExceptionDecoratorTest.kt
    • codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/validators/CustomValidationExceptionValidatorTest.kt
  • For integration testing
    • serverIntegrationTests in codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/CustomValidationExceptionDecoratorTest.kt
  • For e2e integration testing
    • codegen-server-test/custom-test-models/custom-validation-exception.smithy
    • codegen-server-test/build.gradle.kts
  • For regression testing
    • The existing e2e integration tests in codegen-server-tests use common models in codegen-core/common-test-models, which use the default smithy.framework#ValidationException

Ran with export RUSTFLAGS="-D warnings -A clippy::redundant_closure -A non_local_definitions" until fixed in server runtime crates. See #4122.

Checklist

  • For changes to the smithy-rs codegen or runtime crates, I have created a changelog entry Markdown file in the .changelog directory, specifying "client," "server," or both in the applies_to key.
  • For changes to the AWS SDK, generated SDK code, or SDK runtime crates, I have created a changelog entry Markdown file in the .changelog directory, specifying "aws-sdk-rust" in the applies_to key.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jasgin jasgin force-pushed the custom-validation-exception branch 4 times, most recently from 0812440 to 5789de4 Compare September 29, 2025 19:32
@jasgin jasgin requested a review from drganjoo September 30, 2025 17:31
@jasgin jasgin force-pushed the custom-validation-exception branch 2 times, most recently from 0d79bd7 to 3f8e8b5 Compare September 30, 2025 20:35
@jasgin jasgin requested a review from rcoh September 30, 2025 20:39
@jasgin jasgin marked this pull request as ready for review September 30, 2025 20:39
@jasgin jasgin requested review from a team as code owners September 30, 2025 20:39
rcoh pushed a commit that referenced this pull request Oct 3, 2025
#4321)

## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here -->

Extension of #4317.

This PR will add the traits and the
#4317 will be used to add
the validation and codegen.

Deferring moving existing traits to this new package to another PR to
avoid clashing refactors with features.

## Description
<!--- Describe your changes in detail -->

## Testing
<!--- Please describe in detail how you tested your changes -->
<!--- Include details of your testing environment, and the tests you ran
to -->
<!--- see how your change affects other areas of the code, etc. -->

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] For changes to the smithy-rs codegen or runtime crates, I have
created a changelog entry Markdown file in the `.changelog` directory,
specifying "client," "server," or both in the `applies_to` key.
- [x] For changes to the AWS SDK, generated SDK code, or SDK runtime
crates, I have created a changelog entry Markdown file in the
`.changelog` directory, specifying "aws-sdk-rust" in the `applies_to`
key.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
@jasgin jasgin force-pushed the custom-validation-exception branch from 3f8e8b5 to 234f108 Compare October 6, 2025 13:40
@jasgin jasgin changed the title Add custom validation exception Add validation and codegen for custom validation exception traits Oct 6, 2025
@jasgin jasgin force-pushed the custom-validation-exception branch from 301ac0c to ff62652 Compare October 6, 2025 16:25
@rcoh rcoh force-pushed the custom-validation-exception branch from ff62652 to bf14a00 Compare October 8, 2025 17:14
Copy link
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can decide if we want another pass on the codegen stuff. otherwise looks fine

@jasgin jasgin force-pushed the custom-validation-exception branch 2 times, most recently from 84c49f5 to d9c39b1 Compare October 13, 2025 15:32
@jasgin jasgin requested a review from rcoh October 13, 2025 17:10
@jasgin jasgin force-pushed the custom-validation-exception branch from d9c39b1 to 9b5299c Compare October 13, 2025 17:15
@jasgin jasgin force-pushed the custom-validation-exception branch from bcd5045 to e58ce74 Compare October 14, 2025 15:48
@jasgin jasgin force-pushed the custom-validation-exception branch from e58ce74 to de18e9b Compare October 14, 2025 15:49
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

Successfully merging this pull request may close these issues.

3 participants