Skip to content

Commit

Permalink
Add x-amzn-query-mode customization
Browse files Browse the repository at this point in the history
  • Loading branch information
lauzadis committed Oct 30, 2024
1 parent 68d1386 commit fb88223
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changes/20e287a5-cee0-4a5f-9d08-4022dcdee843.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "20e287a5-cee0-4a5f-9d08-4022dcdee843",
"type": "misc",
"description": "Send x-amzn-query-mode=true for services with query-compatible trait"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package aws.sdk.kotlin.codegen.customization

import software.amazon.smithy.aws.traits.protocols.AwsQueryCompatibleTrait
import software.amazon.smithy.kotlin.codegen.KotlinSettings
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration
import software.amazon.smithy.kotlin.codegen.model.hasTrait
import software.amazon.smithy.kotlin.codegen.rendering.protocol.MutateHeadersMiddleware
import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator
import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolMiddleware
import software.amazon.smithy.model.Model

/**
* Send an extra `x-amzn-query-mode` header with a value of `true` for services which have the [AwsQueryCompatibleTrait] applied.
*/
class AwsQueryModeCustomization : KotlinIntegration {
override fun enabledForService(model: Model, settings: KotlinSettings): Boolean =
model
.getShape(settings.service)
.get()
.hasTrait<AwsQueryCompatibleTrait>()

override fun customizeMiddleware(ctx: ProtocolGenerator.GenerationContext, resolved: List<ProtocolMiddleware>): List<ProtocolMiddleware> =
resolved + MutateHeadersMiddleware(extraHeaders = mapOf("x-amzn-query-mode" to "true"))
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ aws.sdk.kotlin.codegen.customization.s3.express.S3ExpressIntegration
aws.sdk.kotlin.codegen.customization.s3.S3ExpiresIntegration
aws.sdk.kotlin.codegen.BusinessMetricsIntegration
aws.sdk.kotlin.codegen.smoketests.SmokeTestsDenyListIntegration
aws.sdk.kotlin.codegen.customization.AwsQueryModeCustomization

0 comments on commit fb88223

Please sign in to comment.