diff --git a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceIndex.java b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceIndex.java index 882bf90c985..cfb7d4865c3 100644 --- a/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceIndex.java +++ b/smithy-aws-cloudformation-traits/src/main/java/software/amazon/smithy/aws/cloudformation/traits/CfnResourceIndex.java @@ -149,8 +149,7 @@ public CfnResourceIndex(Model model) { // These shapes should be present given the @idRef failWhenMissing // setting, but gracefully handle if they're not. model.getShape(additionalSchema) - .map(Shape::asStructureShape) - .map(Optional::get) + .flatMap(Shape::asStructureShape) .ifPresent(shape -> { addAdditionalIdentifiers(builder, computeResourceAdditionalIdentifiers(shape)); updatePropertyMutabilities(builder, model, resourceId, null, shape, @@ -287,7 +286,7 @@ private Function getCfnResourcePropert Function, Set> updater ) { return definition -> { - CfnResourceProperty.Builder builder = definition.toBuilder().addShapeId(member.getId()); + CfnResourceProperty.Builder builder = definition.toBuilder().addShapeId(member.getId()); if (explicitMutability.isEmpty()) { // Update the existing mutabilities. diff --git a/smithy-aws-cloudformation-traits/src/test/resources/software/amazon/smithy/aws/cloudformation/traits/errorfiles/invalid-additional-schemas-shape.errors b/smithy-aws-cloudformation-traits/src/test/resources/software/amazon/smithy/aws/cloudformation/traits/errorfiles/invalid-additional-schemas-shape.errors new file mode 100644 index 00000000000..0d7f38476a7 --- /dev/null +++ b/smithy-aws-cloudformation-traits/src/test/resources/software/amazon/smithy/aws/cloudformation/traits/errorfiles/invalid-additional-schemas-shape.errors @@ -0,0 +1,3 @@ +[ERROR] smithy.example#InvalidAdditionalSchemasShapeResource: Error validating trait `aws.cloudformation#cfnResource`.additionalSchemas.0: Shape ID `smithy.example#ListShape` does not match selector `structure` | TraitValue +[NOTE] smithy.example#ListShape: The list shape is not connected to from any service shape. | UnreferencedShape +[WARNING] smithy.example#InvalidAdditionalSchemasShapeResource: This shape applies a trait that is unstable: aws.cloudformation#cfnResource | UnstableTrait diff --git a/smithy-aws-cloudformation-traits/src/test/resources/software/amazon/smithy/aws/cloudformation/traits/errorfiles/invalid-additional-schemas-shape.smithy b/smithy-aws-cloudformation-traits/src/test/resources/software/amazon/smithy/aws/cloudformation/traits/errorfiles/invalid-additional-schemas-shape.smithy new file mode 100644 index 00000000000..8d075f278de --- /dev/null +++ b/smithy-aws-cloudformation-traits/src/test/resources/software/amazon/smithy/aws/cloudformation/traits/errorfiles/invalid-additional-schemas-shape.smithy @@ -0,0 +1,58 @@ +$version: "2.0" + +namespace smithy.example + +use aws.cloudformation#cfnResource + +service InvalidAdditionalSchemasShape { + version: "2020-07-02", + resources: [ + InvalidAdditionalSchemasShapeResource, + ], +} + +@cfnResource( + additionalSchemas: [ListShape] +) +resource InvalidAdditionalSchemasShapeResource { + identifiers: { + fooId: String, + }, + create: CreateInvalidAdditionalSchemasShapeResource, + read: GetInvalidAdditionalSchemasShapeResource, +} + +list ListShape { + member: String +} + +operation CreateInvalidAdditionalSchemasShapeResource { + input: CreateInvalidAdditionalSchemasShapeResourceRequest, + output: CreateInvalidAdditionalSchemasShapeResourceResponse +} + +@input +structure CreateInvalidAdditionalSchemasShapeResourceRequest { + bar: String, +} + +@output +structure CreateInvalidAdditionalSchemasShapeResourceResponse {} + +@readonly +operation GetInvalidAdditionalSchemasShapeResource { + input: GetInvalidAdditionalSchemasShapeResourceRequest, + output: GetInvalidAdditionalSchemasShapeResourceResponse, +} + +@input +structure GetInvalidAdditionalSchemasShapeResourceRequest { + @required + fooId: String, +} + +@output +structure GetInvalidAdditionalSchemasShapeResourceResponse { + bar: String, +} +