-
Notifications
You must be signed in to change notification settings - Fork 26
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
misc: add Accept
header to all RpcV2Cbor requests
#1170
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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,5 @@ | ||
{ | ||
"id": "2daf7e93-a9e4-4c6b-9c0c-b083a1864c09", | ||
"type": "misc", | ||
"description": "Add `Accept` header to all RpcV2Cbor requests" | ||
} |
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
101 changes: 101 additions & 0 deletions
101
...egen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/RpcV2CborTest.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,101 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package software.amazon.smithy.kotlin.codegen.aws.protocols | ||
|
||
import software.amazon.smithy.kotlin.codegen.test.* | ||
import kotlin.test.Test | ||
|
||
class RpcV2CborTest { | ||
val model = """ | ||
${"$"}version: "2" | ||
|
||
namespace com.test | ||
|
||
use smithy.protocols#rpcv2Cbor | ||
use aws.api#service | ||
|
||
@rpcv2Cbor | ||
@service(sdkId: "CborExample") | ||
service CborExample { | ||
version: "1.0.0", | ||
operations: [GetFoo, GetFooStreaming] | ||
} | ||
|
||
@http(method: "POST", uri: "/foo") | ||
operation GetFoo {} | ||
|
||
@http(method: "POST", uri: "/foo-streaming") | ||
operation GetFooStreaming { | ||
input := {} | ||
output := { | ||
events: FooEvents | ||
} | ||
} | ||
|
||
// Model taken from https://smithy.io/2.0/spec/streaming.html#event-streams | ||
@streaming | ||
union FooEvents { | ||
up: Movement | ||
down: Movement | ||
left: Movement | ||
right: Movement | ||
throttlingError: ThrottlingError | ||
} | ||
|
||
structure Movement { | ||
velocity: Float | ||
} | ||
|
||
@error("client") | ||
@retryable(throttling: true) | ||
structure ThrottlingError {} | ||
""".toSmithyModel() | ||
|
||
@Test | ||
fun testStandardAcceptHeader() { | ||
val ctx = model.newTestContext("CborExample") | ||
|
||
val generator = RpcV2Cbor() | ||
generator.generateProtocolClient(ctx.generationCtx) | ||
|
||
ctx.generationCtx.delegator.finalize() | ||
ctx.generationCtx.delegator.flushWriters() | ||
|
||
val actual = ctx.manifest.expectFileString("/src/main/kotlin/com/test/DefaultTestClient.kt") | ||
val getFooMethod = actual.lines(" override suspend fun getFoo(input: GetFooRequest): GetFooResponse {", " }") | ||
|
||
val expectedHeaderMutation = """ | ||
op.install( | ||
MutateHeaders().apply { | ||
append("Accept", "application/cbor") | ||
} | ||
) | ||
""".replaceIndent(" ") | ||
getFooMethod.shouldContainOnlyOnceWithDiff(expectedHeaderMutation) | ||
} | ||
|
||
@Test | ||
fun testEventStreamAcceptHeader() { | ||
val ctx = model.newTestContext("CborExample") | ||
|
||
val generator = RpcV2Cbor() | ||
generator.generateProtocolClient(ctx.generationCtx) | ||
|
||
ctx.generationCtx.delegator.finalize() | ||
ctx.generationCtx.delegator.flushWriters() | ||
|
||
val actual = ctx.manifest.expectFileString("/src/main/kotlin/com/test/DefaultTestClient.kt") | ||
val getFooMethod = actual.lines(" override suspend fun <T> getFooStreaming(input: GetFooStreamingRequest, block: suspend (GetFooStreamingResponse) -> T): T {", " }") | ||
|
||
val expectedHeaderMutation = """ | ||
op.install( | ||
MutateHeaders().apply { | ||
append("Accept", "application/vnd.amazon.eventstream") | ||
} | ||
) | ||
""".replaceIndent(" ") | ||
getFooMethod.shouldContainOnlyOnceWithDiff(expectedHeaderMutation) | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small nit, feel free to ignore it: This looks like it should be
"GET"
instead of"POST"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same thing for the
GetFooStreaming
operationThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we make it a GET request Smithy fails with some "DANGER" level validations about sending bodies with GET. Setting up POST operations is simpler and the distinction is not important to the test