Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle the case when additionSchema targets an invalid shape #1708

Merged
merged 2 commits into from
Apr 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}