-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: route53 custom error unmarshalling (#961)
- Loading branch information
Showing
4 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
.../kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegration.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package aws.sdk.kotlin.codegen.customization.route53 | ||
|
||
import aws.sdk.kotlin.codegen.protocols.core.AwsHttpBindingProtocolGenerator | ||
import aws.sdk.kotlin.codegen.sdkId | ||
import software.amazon.smithy.kotlin.codegen.KotlinSettings | ||
import software.amazon.smithy.kotlin.codegen.core.withBlock | ||
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration | ||
import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding | ||
import software.amazon.smithy.kotlin.codegen.model.expectShape | ||
import software.amazon.smithy.model.Model | ||
import software.amazon.smithy.model.shapes.ServiceShape | ||
|
||
class ChangeResourceRecordSetsUnmarshallingIntegration : KotlinIntegration { | ||
override val sectionWriters: List<SectionWriterBinding> = listOf( | ||
SectionWriterBinding(AwsHttpBindingProtocolGenerator.ProtocolErrorDeserialization) { writer, _ -> | ||
writer.withBlock("payload?.let {", "}\n") { | ||
withBlock("aws.sdk.kotlin.services.route53.internal.parseRestXmlInvalidChangeBatchResponse(payload)?.let {", "}") { | ||
write("setAseErrorMetadata(it.exception, wrappedResponse, it.errorDetails)") | ||
write("throw it.exception") | ||
} | ||
} | ||
}, | ||
) | ||
|
||
override fun enabledForService(model: Model, settings: KotlinSettings) = | ||
model.expectShape<ServiceShape>(settings.service).sdkId.equals("route 53", ignoreCase = true) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...lin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegrationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package aws.sdk.kotlin.codegen.customization.route53 | ||
|
||
import org.junit.jupiter.api.Test | ||
import software.amazon.smithy.kotlin.codegen.test.defaultSettings | ||
import software.amazon.smithy.kotlin.codegen.test.prependNamespaceAndService | ||
import software.amazon.smithy.kotlin.codegen.test.toSmithyModel | ||
import software.amazon.smithy.model.Model | ||
import kotlin.test.assertFalse | ||
import kotlin.test.assertTrue | ||
|
||
class ChangeResourceRecordSetsUnmarshallingIntegrationTest { | ||
@Test | ||
fun nonRoute53ModelIntegration() { | ||
val model = sampleModel("not route 53") | ||
val isEnabledForModel = ChangeResourceRecordSetsUnmarshallingIntegration().enabledForService(model, model.defaultSettings()) | ||
assertFalse(isEnabledForModel) | ||
} | ||
|
||
@Test | ||
fun route53ModelIntegration() { | ||
val model = sampleModel("route 53") | ||
val isEnabledForModel = ChangeResourceRecordSetsUnmarshallingIntegration().enabledForService(model, model.defaultSettings()) | ||
assertTrue(isEnabledForModel) | ||
} | ||
} | ||
|
||
private fun sampleModel(serviceName: String): Model = | ||
""" | ||
@http(method: "PUT", uri: "/foo") | ||
operation Foo { } | ||
@http(method: "POST", uri: "/bar") | ||
operation Bar { } | ||
""" | ||
.prependNamespaceAndService(operations = listOf("Foo", "Bar"), serviceName = serviceName) | ||
.toSmithyModel() |