You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When generating an HTTP request test case, we code-generate an operation handler that returns "dummy" operation output, just so the test compiles. We do so very naively by filling out the operation output struct's fields with dummy data in Instantiator:
As the docs warn, these dummy values do not honor any modeled constraint traits.
This can make a test fail when building the operation output. For example, the RpcV2CborServerPopulatesDefaultsWhenMissingInRequestBody request test case generates:
let expected = crate::input::OperationWithDefaultsInput{defaults:::std::option::Option::Some(crate::model::Defaults{default_string:"hi".to_owned(),default_boolean:true,default_list:vec![],// <snip>default_enum:"FOO".parse::<crate::model::TestEnum>().expect("static value validated to member"),// <snip>}),// <snip>};
Which fails with:
thread 'operation::operation_with_defaults_test::rpc_v2_cbor_server_populates_defaults_when_missing_in_request_body_request' panicked at rpcv2Cbor/rust-server-codegen/src/operation.rs:468:30:
static value validated to member: ConstraintViolation("")
Instead of resorting to these dummy naive values, we should use any modeled default values. It might happen that there are no defaults for a @required shape, in which case we'd have to code for generating a dummy value that honors the modeled constraint traits, but since doing that might require some effort, we can punt on that for the time being.
The text was updated successfully, but these errors were encountered:
When generating an HTTP request test case, we code-generate an operation handler that returns "dummy" operation output, just so the test compiles. We do so very naively by filling out the operation output struct's fields with dummy data in
Instantiator
:smithy-rs/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt
Lines 448 to 471 in 17545f6
As the docs warn, these dummy values do not honor any modeled constraint traits.
This can make a test fail when building the operation output. For example, the
RpcV2CborServerPopulatesDefaultsWhenMissingInRequestBody
request test case generates:Which fails with:
Indeed,
""
is not a valid value for theTestEnum
shape.Instead of resorting to these dummy naive values, we should use any modeled default values. It might happen that there are no defaults for a
@required
shape, in which case we'd have to code for generating a dummy value that honors the modeled constraint traits, but since doing that might require some effort, we can punt on that for the time being.The text was updated successfully, but these errors were encountered: