Add validation and codegen for custom validation exception traits#4317
Merged
aws-sdk-rust-ci merged 72 commits intosmithy-lang:mainfrom Oct 23, 2025
Merged
Add validation and codegen for custom validation exception traits#4317aws-sdk-rust-ci merged 72 commits intosmithy-lang:mainfrom
aws-sdk-rust-ci merged 72 commits intosmithy-lang:mainfrom
Conversation
0812440 to
5789de4
Compare
drganjoo
reviewed
Sep 30, 2025
codegen-server-test/custom-test-models/custom-validation-exception.smithy
Show resolved
Hide resolved
...re/amazon/smithy/rust/codegen/server/smithy/validators/CustomValidationExceptionValidator.kt
Outdated
Show resolved
Hide resolved
...smithy/rust/codegen/server/smithy/customizations/UserProvidedValidationExceptionDecorator.kt
Show resolved
Hide resolved
...mazon/smithy/rust/codegen/server/smithy/customizations/CustomValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
...n/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ValidateUnsupportedConstraints.kt
Outdated
Show resolved
Hide resolved
codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/Constraints.kt
Outdated
Show resolved
Hide resolved
codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/Constraints.kt
Outdated
Show resolved
Hide resolved
codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/Constraints.kt
Outdated
Show resolved
Hide resolved
...n/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ValidateUnsupportedConstraints.kt
Outdated
Show resolved
Hide resolved
rcoh
reviewed
Sep 30, 2025
...mazon/smithy/rust/codegen/server/smithy/customizations/CustomValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
...mazon/smithy/rust/codegen/server/smithy/customizations/CustomValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
.../kotlin/software/amazon/smithy/rust/codegen/server/smithy/traits/ValidationFieldNameTrait.kt
Show resolved
Hide resolved
...mazon/smithy/rust/codegen/server/smithy/customizations/CustomValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
...mazon/smithy/rust/codegen/server/smithy/customizations/CustomValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
...mazon/smithy/rust/codegen/server/smithy/customizations/CustomValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
...mazon/smithy/rust/codegen/server/smithy/customizations/CustomValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
...mazon/smithy/rust/codegen/server/smithy/customizations/CustomValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
0d79bd7 to
3f8e8b5
Compare
2 tasks
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._
3f8e8b5 to
234f108
Compare
rcoh
reviewed
Oct 6, 2025
.../kotlin/software/amazon/smithy/rust/codegen/server/smithy/traits/ValidationExceptionTrait.kt
Outdated
Show resolved
Hide resolved
301ac0c to
ff62652
Compare
ff62652 to
bf14a00
Compare
rcoh
reviewed
Oct 8, 2025
Collaborator
rcoh
left a comment
There was a problem hiding this comment.
we can decide if we want another pass on the codegen stuff. otherwise looks fine
...smithy/rust/codegen/server/smithy/customizations/UserProvidedValidationExceptionDecorator.kt
Show resolved
Hide resolved
...mazon/smithy/rust/codegen/server/smithy/customizations/CustomValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
...smithy/rust/codegen/server/smithy/customizations/UserProvidedValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
...smithy/rust/codegen/server/smithy/customizations/UserProvidedValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
...smithy/rust/codegen/server/smithy/customizations/UserProvidedValidationExceptionDecorator.kt
Show resolved
Hide resolved
...mazon/smithy/rust/codegen/server/smithy/customizations/CustomValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
...smithy/rust/codegen/server/smithy/customizations/UserProvidedValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
...smithy/rust/codegen/server/smithy/customizations/UserProvidedValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
rcoh
reviewed
Oct 8, 2025
...erver/src/main/resources/META-INF/services/software.amazon.smithy.model.validation.Validator
Outdated
Show resolved
Hide resolved
rcoh
reviewed
Oct 8, 2025
...smithy/rust/codegen/server/smithy/customizations/UserProvidedValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
rcoh
reviewed
Oct 8, 2025
...hy/rust/codegen/server/smithy/customizations/UserProvidedValidationExceptionDecoratorTest.kt
Show resolved
Hide resolved
rcoh
reviewed
Oct 8, 2025
...n/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ValidateUnsupportedConstraints.kt
Outdated
Show resolved
Hide resolved
rcoh
reviewed
Oct 8, 2025
...hy/rust/codegen/server/smithy/customizations/UserProvidedValidationExceptionDecoratorTest.kt
Show resolved
Hide resolved
84c49f5 to
d9c39b1
Compare
d9c39b1 to
9b5299c
Compare
…dationExceptionTrait
Contributor
|
This prevents unused custom validation exceptions in the Smithy model. For example, this model: use smithy.framework#ValidationException
use smithy.rust.codegen.traits#validationException
@title("Sample Service")
service BurgerService {
version: "2024-03-18"
operations: [
EatBurger,
]
}
@http(uri: "/eat/{name}", method: "POST")
operation EatBurger {
input := @sensitive {
@required
@httpLabel
name: String
@required
@httpHeader("size")
size: String
}
output := {
@required
value: Integer
}
errors: [
ValidationException
]
}
@validationException
@error("client")
structure BurgerValidationException {
message: String
}
```
generates this error:
```bash
Caused by: ValidationResult(shouldAbort=true, messages=[LogMessage(level=SEVERE, message=Operation com.test#StreamBurgerOrders uses the default ValidationException, but a custom validation exception is defined.
Remove ValidationException from the operation's errors and use the custom validation exception instead.
For documentation, see https://smithy-lang.github.io/smithy-rs/design/server/validation_exceptions.html), LogMessage(level=SEVERE, message=Operation com.test#EatBurger uses the default ValidationException, but a custom validation exception is defined.
Remove ValidationException from the operation's errors and use the custom validation exception instead.
For documentation, see https://smithy-lang.github.io/smithy-rs/design/server/validation_exceptions.html)])
at software.amazon.smithy.rust.codegen.server.smithy.ValidateUnsupportedConstraintsKt.validateModelHasAtMostOneValidationException(ValidateUnsupportedConstraints.kt:354)
at software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenVisitor.execute(ServerCodegenVisitor.kt:241)
... 16 more
|
drganjoo
reviewed
Oct 16, 2025
6c84ffa to
54f4e95
Compare
drganjoo
reviewed
Oct 17, 2025
...smithy/rust/codegen/server/smithy/customizations/UserProvidedValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
...smithy/rust/codegen/server/smithy/customizations/UserProvidedValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
...smithy/rust/codegen/server/smithy/customizations/UserProvidedValidationExceptionDecorator.kt
Outdated
Show resolved
Hide resolved
…chable from operation input
818bc20 to
08d142f
Compare
drganjoo
approved these changes
Oct 21, 2025
ysaito1001
approved these changes
Oct 21, 2025
Contributor
ysaito1001
left a comment
There was a problem hiding this comment.
Only reviewed codegen-core, codegen-traits.
vcjana
pushed a commit
that referenced
this pull request
Oct 27, 2025
) ## 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 --> Adds ability to define custom validation exceptions per RFC: - https://github.com/smithy-lang/smithy-rs/blob/custom-validation-rfc/design/src/rfcs/rfc0047_custom_validation.md ## Description <!--- Describe your changes in detail --> 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 <!--- 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. --> - 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 <!--- 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._
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation and Context
Adds ability to define custom validation exceptions per RFC:
Description
Adds ability to use the following traits:
to define a custom validation exception for a service or operation.
Updated Smithy validation ensures:
smithy.framework#ValidationExceptionis not used in an operation or service is a custom validation exception is definedTesting
codegen-server-traits/src/test/kotlin/software/amazon/smithy/rust/codegen/server/traits/ValidationExceptionTraitTest.ktcodegen-server-traits/src/test/kotlin/software/amazon/smithy/rust/codegen/server/traits/ValidationMessageTraitTest.ktcodegen-server-traits/src/test/kotlin/software/amazon/smithy/rust/codegen/server/traits/ValidationFieldListTraitTest.ktcodegen-server-traits/src/test/kotlin/software/amazon/smithy/rust/codegen/server/traits/ValidationFieldNameTraitTest.ktcodegen-server-traits/src/test/kotlin/software/amazon/smithy/rust/codegen/server/traits/ValidationFieldMessageTraitTest.ktcodegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ValidateUnsupportedConstraintsAreNotUsedTest.ktcodegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/CustomValidationExceptionDecoratorTest.ktcodegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/validators/CustomValidationExceptionValidatorTest.ktcodegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/CustomValidationExceptionDecoratorTest.ktcodegen-server-test/custom-test-models/custom-validation-exception.smithycodegen-server-test/build.gradle.ktscodegen-server-testsuse common models incodegen-core/common-test-models, which use the defaultsmithy.framework#ValidationExceptionRan with
export RUSTFLAGS="-D warnings -A clippy::redundant_closure -A non_local_definitions"until fixed in server runtime crates. See #4122.Checklist
.changelogdirectory, specifying "client," "server," or both in theapplies_tokey..changelogdirectory, specifying "aws-sdk-rust" in theapplies_tokey.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.