diff --git a/.github/workflows/test_models_rust_tests.yml b/.github/workflows/test_models_rust_tests.yml index dcf06d521..7ab616a58 100644 --- a/.github/workflows/test_models_rust_tests.yml +++ b/.github/workflows/test_models_rust_tests.yml @@ -59,7 +59,7 @@ jobs: - name: Set up Rust uses: actions-rust-lang/setup-rust-toolchain@v1 with: - toolchain: "1.80.0" + toolchain: "1.81.0" rustflags: "" components: rustfmt diff --git a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithyrust/generator/RustLibraryShimGenerator.java b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithyrust/generator/RustLibraryShimGenerator.java index 93ebbaea8..a3ba3ee71 100644 --- a/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithyrust/generator/RustLibraryShimGenerator.java +++ b/codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/smithyrust/generator/RustLibraryShimGenerator.java @@ -1049,45 +1049,65 @@ private String generateValidationFunction( ); } } else if (shape instanceof StructureShape structureShape) { - var isPositionalOutput = - (operation == null || - operation.getOutputShape().equals(shape.getId())) && - structureShape.hasTrait(PositionalTrait.class); - for (final var memberShape : structureShape.getAllMembers().values()) { - final var memberVariables = structureMemberVariables(memberShape); - memberVariables.put( - "memberValidationFunctionName", - shapeValidationFunctionName(null, null, memberShape) + // If this is a response shape for an AWS SDK, + // make validation a no-op for now. + // This is because the SDKs will produce values that violate constraints, + // such as a `Some({})` on an optional map with @length(min: 1). + // This could be considered an SDK bug since information is lost, + // SDKs are also not supposed to validate constraints + // which makes it harder to argue it should be fixed. + // See https://github.com/smithy-lang/smithy-dafny/issues/751 + var generator = mergedGenerator.generatorForShape(shape); + if ( + generator instanceof RustAwsSdkShimGenerator && + operationIndex.isOutputStructure(shape) + ) { + validationBlocks.add( + "// Validation intentionally suppressed for AWS SDK response structures" ); - - if (isPositionalOutput) { - validationBlocks.add( - evalTemplate( - "$memberValidationFunctionName:L(&Some(input.clone()))?;", - memberVariables - ) - ); - } else if ( - mergedGenerator - .generatorForShape(structureShape) - .isRustFieldRequired(structureShape, memberShape) && - // TODO: This may be more correct than the current isRustFieldRequired in general - !(operationIndex.isOutputStructure(structureShape) && - model.expectShape(memberShape.getTarget()).isListShape()) - ) { - validationBlocks.add( - evalTemplate( - "$memberValidationFunctionName:L(&Some(input.$fieldName:L.clone()))?;", - memberVariables - ) - ); - } else { - validationBlocks.add( - evalTemplate( - "$memberValidationFunctionName:L(&input.$fieldName:L)?;", - memberVariables - ) + } else { + var isPositionalOutput = + (operation == null || + operation.getOutputShape().equals(shape.getId())) && + structureShape.hasTrait(PositionalTrait.class); + for (final var memberShape : structureShape + .getAllMembers() + .values()) { + final var memberVariables = structureMemberVariables(memberShape); + memberVariables.put( + "memberValidationFunctionName", + shapeValidationFunctionName(null, null, memberShape) ); + + if (isPositionalOutput) { + validationBlocks.add( + evalTemplate( + "$memberValidationFunctionName:L(&Some(input.clone()))?;", + memberVariables + ) + ); + } else if ( + mergedGenerator + .generatorForShape(structureShape) + .isRustFieldRequired(structureShape, memberShape) && + // TODO: This may be more correct than the current isRustFieldRequired in general + !(operationIndex.isOutputStructure(structureShape) && + model.expectShape(memberShape.getTarget()).isListShape()) + ) { + validationBlocks.add( + evalTemplate( + "$memberValidationFunctionName:L(&Some(input.$fieldName:L.clone()))?;", + memberVariables + ) + ); + } else { + validationBlocks.add( + evalTemplate( + "$memberValidationFunctionName:L(&input.$fieldName:L)?;", + memberVariables + ) + ); + } } } } else if (shape instanceof UnionShape unionShape) {