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

Nested server structure member shapes targeting simple shapes with @default don't work #2343

Closed
david-perez opened this issue Feb 10, 2023 · 1 comment · Fixed by #2352
Closed
Assignees
Labels
bug Something isn't working constraint-traits high-priority High priority issue server Rust server SDK
Milestone

Comments

@david-perez
Copy link
Contributor

david-perez commented Feb 10, 2023

Minimal reproducer:

$version: "1.0"

namespace com.amazonaws.simple

use aws.protocols#restJson1
use smithy.framework#ValidationException

@restJson1
service SimpleService {
    operations: [
        Operation
    ]
}

@http(uri: "/operation", method: "POST")
operation Operation {
    //input: KeyModesOfUse // This works fine.
    input: OperationInput
    errors: [ValidationException]
}

structure OperationInput {
    @required
    KeyModesOfUse: KeyModesOfUse
}

structure KeyModesOfUse {
    Encrypt: PrimitiveBoolean
}

The issue is largely within these functions:

https://github.com/awslabs/smithy-rs/blob/bf678fd7d28762e7add375f8485bd7f307b8e317/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerBuilderConstraintViolations.kt#L86-L94

https://github.com/awslabs/smithy-rs/blob/bf678fd7d28762e7add375f8485bd7f307b8e317/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/Constraints.kt#L80-L95

Using the example above:

https://github.com/awslabs/smithy-rs/blob/bf678fd7d28762e7add375f8485bd7f307b8e317/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/Constraints.kt#L86-L86

  • However, when rendering the constraint violations for the KeyModesOfUse structure, the member is not detected as constrained: there is no arm in isDirectlyConstrained that matches the shape's type (the BooleanShape Java class), so we go through the else branch.

So this results in the constraint violation for OperationInput containing a member pointing to the constraint violation for KeyModesOfUse, but the latter is never rendered!

error[E0412]: cannot find type `ConstraintViolation` in module `crate::model::key_modes_of_use`
  --> simple/rust-server-codegen/src/input.rs:27:55
   |
27 |         KeyModesOfUse(crate::model::key_modes_of_use::ConstraintViolation),
   |                                                       ^^^^^^^^^^^^^^^^^^^ not found in `crate::model::key_modes_of_use`
   |
help: consider importing one of these items
   |
19 |     use crate::error::validation_exception::ConstraintViolation;
   |
19 |     use crate::model::validation_exception_field::ConstraintViolation;
   |
help: if you import `ConstraintViolation`, refer to it directly
   |
27 -         KeyModesOfUse(crate::model::key_modes_of_use::ConstraintViolation),
27 +         KeyModesOfUse(ConstraintViolation),
@david-perez
Copy link
Contributor Author

The issue is misleading in describing what should happen to make the generation correct. To clarify:

  1. OperationInput should be detected as constrained because its member is @required.
  2. KeyModesOfUse should not be detected as constrained because no member is constrained, and hence:
    1. crate::model::key_modes_of_use::ConstraintViolation should not be rendered.

And currently, (1) is happening, (2.i) is happening, but (2) isn't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working constraint-traits high-priority High priority issue server Rust server SDK
Projects
None yet
2 participants