Skip to content

Commit

Permalink
Gracefully handle the case when additionSchema targets an invalid sha…
Browse files Browse the repository at this point in the history
…pe (#1708)
  • Loading branch information
sugmanue authored Apr 1, 2023
1 parent cc38108 commit 2378099
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -287,7 +286,7 @@ private Function<CfnResourceProperty, CfnResourceProperty> getCfnResourcePropert
Function<Set<Mutability>, Set<Mutability>> 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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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,
}

0 comments on commit 2378099

Please sign in to comment.