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

Transform to add a shape to an operation's errors #3802

Closed
david-perez opened this issue Aug 27, 2024 · 1 comment
Closed

Transform to add a shape to an operation's errors #3802

david-perez opened this issue Aug 27, 2024 · 1 comment
Labels
server Rust server SDK

Comments

@david-perez
Copy link
Contributor

It is somewhat common for smithy-rs server users to want to generate an SDK from an existing Smithy model and get:

[SEVERE] Operation com.amazon.service#Operation takes in input that is
constrained
(https://awslabs.github.io/smithy/2.0/spec/constraint-traits.html), and as
such can fail with a validation exception. You must model this behavior in
the operation shape in your model file.
```smithy
use smithy.framework#ValidationException

operation Operation {
    ...
    errors: [..., ValidationException] // <-- Add this.
}

To fix this and still have the framework honor validation, they'll have to create a new model, import the existing one, and re-define all the constrained operations' errors.

This can be a bit boilerplatey, and inconvenient when you don't own the model, so perhaps we should vend a transform that adds a given shape to an operation's list of errors.

@david-perez david-perez added the server Rust server SDK label Aug 27, 2024
github-merge-queue bot pushed a commit that referenced this issue Aug 29, 2024
…#3803)

The Server SDK requires the model to include
`aws.smithy.framework#ValidationException` in each operation that can
access a constrained member shape. This becomes problematic when
generating the server SDK for a model not owned by the team creating the
SDK, as they cannot easily modify the model.

This PR introduces a codegen flag,
`addValidationExceptionToConstrainedOperations`. When set in
`smithy-build-template.json`, this flag will automatically add
`ValidationException` to operations that require it but do not already
list it among their errors.

Closes Issue:
[3802](#3802)

Sample `smithy-build-template.json`
```
"plugins": {
            "rust-server-codegen": {
                "service": "ServiceToGenerateSDKFor",
                "module": "amzn-sample-server-sdk",
                "codegen": {
                    "addValidationExceptionToConstrainedOperations": true,
                }
            }
        }
```

---------

Co-authored-by: Fahad Zubair <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
server Rust server SDK
Projects
None yet
Development

No branches or pull requests

1 participant