generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 220
Add validation and codegen for custom validation exception traits #4317
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
Open
jasgin
wants to merge
53
commits into
smithy-lang:main
Choose a base branch
from
jasgin:custom-validation-exception
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 52 commits
Commits
Show all changes
53 commits
Select commit
Hold shift + click to select a range
6baed18
Add `ValidationException` and `ValidationMessage` codegen server traits
jasgin dedfb07
Add `CustomValidationExceptionValidator`
jasgin 1bec408
Add tests for `CustomValidationExceptionValidator`
jasgin d11f574
Add remaining custom validation exception traits
jasgin a625749
Add custom validation exception to constrained input validation
jasgin 33e618a
Add tests for custom validation exception in constrained input valida…
jasgin 7e45bd9
Add parts of codegen for custom validation exception
jasgin 2704437
Figure out custom or default in shared generator
jasgin b56cdce
Add validation to ensure member with @validationMessage targets String
jasgin 011135a
Add validation for ensuring multiple ValidationExceptions are not inc…
jasgin 7410844
Add validation for ensuring multiple custom ValidationExceptions cann…
jasgin 4867eaf
Fix default constructibility validation
jasgin 3d365d9
Fix custom validation exception codegen
jasgin 8e5928d
Add customValidationFieldMessage handling
jasgin 4d7f2db
Reduce code duplication
jasgin db56b5c
Add additional field handling
jasgin 06106e4
Fix module to use custom shape serialization
jasgin 3b540c2
Add field handling for custom validation field
jasgin 03c6b3c
Clean up gradle for codegen server traits
jasgin b2dac07
Add copyright label to top of files
jasgin 52360aa
Remove unrelated formatting
jasgin fc282f5
Clean up validation function
jasgin ba25b69
Add validation to detect default ValidationException when custom one …
jasgin e284704
Factor out default field assignment logic
jasgin cf07b8c
Add handling for fields being required/optional
jasgin ca64ff6
Add e2e integration test for custom validation exceptions
jasgin d6080d7
Fix ValidationExceptionReason usage
jasgin 392da87
Consolidate codegen-server-traits into codegen-server
jasgin 831fda7
Add docs on why we need default constructibility requirement
jasgin fed9ceb
Update visibility modifiers of custom validation finder methods to be…
jasgin 35cb846
Refactor names to avoid variable shadowing
jasgin 5abc4ae
Remove custom formatting
jasgin a46e2b3
Update validationException custom trait documentation
jasgin 1e5d794
Update validation error detected message to avoid confusion
jasgin e1a05e6
Add implicit validation exception message field support
jasgin 9aaad1f
Remove redundant service errors check
jasgin fbe764a
Remove comment documenting completed work
jasgin 72f6cb1
Elaborate on documentation
jasgin c4e722c
Fix comments for updated ValidationException constraint
jasgin 4278d54
Add changelog
jasgin 124a53c
Fix order of CustomValidationExceptionDecorator to take precendence o…
jasgin 7584771
Apply idiomatic kotlin suggestions
jasgin 4646e8f
Refactor decorator code
jasgin 97ac178
update structure for existing traits
jasgin b3d7306
update changelog
jasgin be18581
Fix minor issues
jasgin ccf52ee
Rename to UserProvided instead of Custom
jasgin abd7355
Add validation exception docs and incorporate into error messages
jasgin 0b2ecaf
Remove redundant :W's
jasgin ef0413a
Refactor templating to be easier to follow
jasgin a79e7d5
Add prelude scope and codegen ctx for runtime and common templating
jasgin de18e9b
Add compilation tests for reqiured and optional fields
jasgin e9481e1
Use listOfNotNull to exclude validationField when not present
jasgin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
applies_to: ["server"] | ||
authors: ["jasgin"] | ||
references: ["smithy-rs#4317"] | ||
breaking: false | ||
new_feature: true | ||
bug_fix: false | ||
--- | ||
Adds validators and codegen support for the custom traits custom traits `@validationException`, `@validationMessage`, | ||
`@validationFieldList`, `@validationFieldName`, and `@validationFieldMessage` for defining a custom validation exception | ||
to use instead of `smithy.framework#ValidationException`. |
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
70 changes: 70 additions & 0 deletions
70
codegen-server-test/custom-test-models/custom-validation-exception.smithy
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
$version: "2.0" | ||
|
||
namespace com.aws.example | ||
|
||
use aws.protocols#restJson1 | ||
use smithy.rust.codegen.traits#validationException | ||
use smithy.rust.codegen.traits#validationFieldList | ||
use smithy.rust.codegen.traits#validationFieldMessage | ||
use smithy.rust.codegen.traits#validationFieldName | ||
use smithy.rust.codegen.traits#validationMessage | ||
|
||
@restJson1 | ||
service CustomValidationExample { | ||
version: "1.0.0" | ||
operations: [ | ||
TestOperation | ||
] | ||
errors: [ | ||
MyCustomValidationException | ||
] | ||
} | ||
|
||
@http(method: "POST", uri: "/test") | ||
operation TestOperation { | ||
input: TestInput | ||
} | ||
|
||
structure TestInput { | ||
@required | ||
@length(min: 1, max: 10) | ||
name: String | ||
|
||
@range(min: 1, max: 100) | ||
age: Integer | ||
} | ||
|
||
@error("client") | ||
@httpError(400) | ||
@validationException | ||
structure MyCustomValidationException { | ||
@required | ||
@validationMessage | ||
customMessage: String | ||
|
||
@required | ||
@default("testReason1") | ||
reason: ValidationExceptionReason | ||
|
||
@validationFieldList | ||
customFieldList: CustomValidationFieldList | ||
} | ||
|
||
enum ValidationExceptionReason { | ||
jasgin marked this conversation as resolved.
Show resolved
Hide resolved
|
||
TEST_REASON_0 = "testReason0" | ||
TEST_REASON_1 = "testReason1" | ||
} | ||
|
||
structure CustomValidationField { | ||
@required | ||
@validationFieldName | ||
customFieldName: String | ||
|
||
@required | ||
@validationFieldMessage | ||
customFieldMessage: String | ||
} | ||
|
||
list CustomValidationFieldList { | ||
member: CustomValidationField | ||
} |
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.