-
Notifications
You must be signed in to change notification settings - Fork 196
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
Add server RPC v2 CBOR support #2544
Conversation
24d2614
to
b9016ae
Compare
Squashed all commits rebased on top of current |
This fixes two bugs: 1. `Content-Type` header checking was succeeding when no `Content-Type` header was present but one was expected. 2. When a shape was @httpPayload`-bound, `Content-Type` header checking occurred even when no payload was being sent. In this case it is not necessary to check the header, since there is no content. Code has been refactored and cleaned up. The crux of the logic is now easier to understand, and contained in `content_type_header_classifier`.
…test model; but switching to refactoring protocol test generation now
A new generated diff is ready to view.
A new doc preview is ready to view. |
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.
Reviewed all but codegen-server-test
, codegen/server
, and aws-smithy-http-server
. Thank you for @jjant for this awesome work!
* appear when serializing both. | ||
* | ||
* Strictly speaking, the spec says we should only add `__type` when serializing an operation error response, but | ||
* there shouldn't™️ be any harm in always including it, which simplifies the code generator. |
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.
* there shouldn't™️ be any harm in always including it, which simplifies the code generator. | |
* there shouldn't be any harm in always including it, which simplifies the code generator. |
...e/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt
Show resolved
Hide resolved
...-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RpcV2Cbor.kt
Show resolved
Hide resolved
...otlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/ReturnSymbolToParse.kt
Outdated
Show resolved
Hide resolved
...ftware/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt
Show resolved
Hide resolved
...ftware/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/CborSerializerGenerator.kt
Show resolved
Hide resolved
...ftware/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/CborSerializerGenerator.kt
Outdated
Show resolved
Hide resolved
...otlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/CborParserGenerator.kt
Outdated
Show resolved
Hide resolved
...otlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/CborParserGenerator.kt
Outdated
Show resolved
Hide resolved
...otlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/CborParserGenerator.kt
Outdated
Show resolved
Hide resolved
A new generated diff is ready to view.
A new doc preview is ready to view. |
...ftware/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/CborSerializerGenerator.kt
Outdated
Show resolved
Hide resolved
...ftware/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/CborSerializerGenerator.kt
Outdated
Show resolved
Hide resolved
...ftware/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/CborSerializerGenerator.kt
Outdated
Show resolved
Hide resolved
...ftware/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt
Outdated
Show resolved
Hide resolved
writable { | ||
// We're only interested in _structure_ member shapes that can reach constrained shapes. | ||
if ( | ||
codegenContext.model.expectShape(section.shape.container) is StructureShape && |
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.
Yes, a Smithy shape is constrained, but somewhere in the codebase, we've already generated a Rust symbol that represents this fact. MaybeConstrained
is a Rust type/symbol, not directly related to Smithy. My point is, we have 108 instances where we check if a Smithy shape is constrained. Instead, why don't we query the symbol provider or the symbol itself to determine if it supports the MaybeConstrained
Rust type and if we need to issue a v.into()
to convert to MaybeConstrained
, rather than checking that a Shape's target can reach a constrained shape, and assuming we've generated a MaybeConstrained
for that shape?
...ftware/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/CborSerializerGenerator.kt
Outdated
Show resolved
Hide resolved
A new generated diff is ready to view.
A new doc preview is ready to view. |
## Motivation and Context Follow-up on #2544 to add client-side support for the protocol ## Description The client implementation mainly focuses on a sub-section [Requests](https://smithy.io/2.0/additional-specs/protocols/smithy-rpc-v2.html#requests) in the spec. To that end, this PR addresses `TODO` for the client to fill in the blanks and includes additional adjustments/refactoring to pass client protocol tests. ## Testing - Existing tests in CI - Upstream protocol test `rpcv2Cbor` - Our handwritten protocol test `rpcv2Cbor-extras.smithy` ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
RPC v2 CBOR is a new protocol that
is being addedhas recently been added to the Smithyspecification.
(I'll add more details here as the patchset evolves)
Credit goes to @jjant for initial implementation of the router, which I built on top of from his
jjant/smithy-rpc-v2-exploration
branch.Tracking issue: #3573.
Caveats
TODO
s are currently exhaustively sprinkled throughout the patch documenting what remains to be done. Most of these need to be addressed before this can be merged in; some can be punted on to not make this PR bigger.However, I'd like to call out the major caveats and blockers here. I'll keep updating this list as the patchset evolves.
smithy-rpc-v2
branch. The following are prerrequisites for this PR to be merged; until they are done CI on this PR will fail:Protocol tests for the protocol do not currently exist in Smithy. Until those get written, this PR resorts to Rust unit tests and integration tests that useserde
to round-trip messages and compareserde
's encoders and decoders with ours for correctness.smithy-protocol-tests
directory in Smithy.serde_cbor
round-trip tests for defense in depth.[ ] Smithydocument
shapes are not supported. RPC v2's specification currently doesn't indicate how to implement them.Prerequisite PRs
This section lists prerequisite PRs and issues that would make the diff for this one lighter or easier to understand. It's preferable that these PRs be merged prior to this one; some are hard prerequisites. They mostly relate to parts of the codebase I've had to touch or
pilferinspect in this PR where I've made necessary changes, refactors and "drive-by improvements" that are mostly unrelated, although some directly unlock things I've needed in this patchset. It makes sense to pull them out to ease reviewability and make this patch more semantically self-contained.ignoreUnsupportedConstraintTraits
from integration test models #2516RuntimeError
andRequestRejection
by protocol #2517aws_smithy_types::primitive::Parse
in the server #2528Protocol
sstructuredDataParser
,structuredDataSerializer
#2536RestRequestSpecGenerator
intocodegen-server
#2537Content-Type
header in all server protocols #2531#[allow(unused_variables)]
in JSON serializers when structure has no members #2538ignoreUnsupportedConstraintTraits
has no effect #2539RUSTFLAGS
environment variable when invoking Cargo commands via Gradle tasks #3678Content-Type
header checking in servers #3690@httpPayload
#3752Testing
RPC v2 has still not been added to the Smithy specification. It is currently being worked on over in the
smithy-rpc-v2
branch.This can only be tested locally following these steps:
1. Clone the Smithy repository and checkout thesmithy-rpc-v2
branch.2. Inside your local checkout of smithy-rs pointing to this PR's branch, make sure you've added
mavenLocal()
as a repository in thebuild.gradle.kts
files. Example.4. Inside your local checkout of Smithy's
smithy-rpc-v2
branch:1. Set
VERSION
to the current Smithy version used in smithy-rs (1.28.1 as of writing, but check here).2. Run
./gradlew clean build pTML
.6.1. In your local checkout of the smithy-rs'ssmithy-rpc-v2
branch, run./gradlew codegen-server-test:build -P modules='rpcv2Cbor'
.You can troubleshoot whether you have Smithy correctly set up locally by inspecting~/.m2/repository/software/amazon/smithy/smithy-protocols-traits
.Checklist
CHANGELOG.next.toml
if I made changes to the smithy-rs codegen or runtime cratesBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.