Skip to content

Commit fb88223

Browse files
committed
Add x-amzn-query-mode customization
1 parent 68d1386 commit fb88223

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"id": "20e287a5-cee0-4a5f-9d08-4022dcdee843",
3+
"type": "misc",
4+
"description": "Send x-amzn-query-mode=true for services with query-compatible trait"
5+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
package aws.sdk.kotlin.codegen.customization
6+
7+
import software.amazon.smithy.aws.traits.protocols.AwsQueryCompatibleTrait
8+
import software.amazon.smithy.kotlin.codegen.KotlinSettings
9+
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration
10+
import software.amazon.smithy.kotlin.codegen.model.hasTrait
11+
import software.amazon.smithy.kotlin.codegen.rendering.protocol.MutateHeadersMiddleware
12+
import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator
13+
import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolMiddleware
14+
import software.amazon.smithy.model.Model
15+
16+
/**
17+
* Send an extra `x-amzn-query-mode` header with a value of `true` for services which have the [AwsQueryCompatibleTrait] applied.
18+
*/
19+
class AwsQueryModeCustomization : KotlinIntegration {
20+
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean =
21+
model
22+
.getShape(settings.service)
23+
.get()
24+
.hasTrait<AwsQueryCompatibleTrait>()
25+
26+
override fun customizeMiddleware(ctx: ProtocolGenerator.GenerationContext, resolved: List<ProtocolMiddleware>): List<ProtocolMiddleware> =
27+
resolved + MutateHeadersMiddleware(extraHeaders = mapOf("x-amzn-query-mode" to "true"))
28+
}

codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ aws.sdk.kotlin.codegen.customization.s3.express.S3ExpressIntegration
4343
aws.sdk.kotlin.codegen.customization.s3.S3ExpiresIntegration
4444
aws.sdk.kotlin.codegen.BusinessMetricsIntegration
4545
aws.sdk.kotlin.codegen.smoketests.SmokeTestsDenyListIntegration
46+
aws.sdk.kotlin.codegen.customization.AwsQueryModeCustomization

0 commit comments

Comments
 (0)