Skip to content

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

@david-perez

Description

@david-perez

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),

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Relationships

None yet

Development

No branches or pull requests

Issue actions