Error out for non-escaped special chars in `@pattern`s (#2752)
## Motivation and Context Closes https://github.com/awslabs/smithy-rs/issues/2508 ## Testing Modify `codegen-core/common-test-models/pokemon.smithy`: ```diff diff --git a/codegen-core/common-test-models/pokemon.smithy b/codegen-core/common-test-models/pokemon.smithy index 014ee61c4..2dd37046e 100644 --- a/codegen-core/common-test-models/pokemon.smithy +++ b/codegen-core/common-test-models/pokemon.smithy @@ -59,9 +59,12 @@ structure GetStorageInput { passcode: String, } +@pattern("[.\\n\r]+") +string Species + /// A list of Pokémon species. list SpeciesCollection { - member: String + member: Species } /// Contents of the Pokémon storage. ``` Try to codegen example service and see the error: ```bash $ cd examples $ make codegen ... [ERROR] com.aws.example#Species: Non-escaped special characters used inside `@pattern`. You must escape them: `@pattern("[.\\n\\r]+")`. See https://github.com/awslabs/smithy-rs/issues/2508 for more details. | PatternTraitEscapedSpecialChars /smithy-rs/codegen-server-test/../codegen-core/common-test-models/pokemon.smithy:62:1 ``` (For some reason validation errors reported by plugins get formatted by [LineValidationEventFormatter](https://github.com/awslabs/smithy/blob/aca7df7daf31a0e71aebfeb2e72aee06ff707568/smithy-model/src/main/java/software/amazon/smithy/model/validation/LineValidationEventFormatter.java) but errors reported by smithy-cli formatted by [PrettyAnsiValidationFormatter](https://github.com/awslabs/smithy/blob/aca7df7daf31a0e71aebfeb2e72aee06ff707568/smithy-cli/src/main/java/software/amazon/smithy/cli/commands/PrettyAnsiValidationFormatter.java). Might be a bug in smithy-cli) Replace pattern with `@pattern("[.\\n\\r]+")` and observe that error is gone: ```bash $ make codegen ``` ## Checklist <!--- If a checkbox below is not applicable, then please DELETE it rather than leaving it unchecked --> - [ ] I have updated `CHANGELOG.next.toml` if I made changes to the smithy-rs codegen or runtime crates - [ ] I have updated `CHANGELOG.next.toml` if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
Loading
Please register or sign in to comment