-
Notifications
You must be signed in to change notification settings - Fork 195
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
rust-server-codegen
: add support for @httpPayload
in requests
#1060
Conversation
This commit adds support for the `httpPayload` Smithy trait when applied to operation input members (request deserialization). The code to deserialize HTTP-bound data from HTTP responses in `ResponseBindingGenerator.kt` has been moved into a common class, `HttpBindingGenerator.kt`, since it's useful for both clients and servers in deserializing data from HTTP requests and responses, respectively.
A new doc preview is ready to view. |
A new generated diff 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.
Minor comments. LGTM.
val docShapeHandler: RustWriter.(String) -> Unit = { body -> | ||
rust( | ||
"#T($body)", | ||
structuredDataParser.documentParser(operationShape), | ||
) | ||
} | ||
val structureShapeHandler: RustWriter.(String) -> Unit = { body -> | ||
rust("#T($body)", structuredDataParser.payloadParser(binding.member)) | ||
} |
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.
Out of curiosity, do you really need to explicitly set the types here? We don't really do it anywhere..
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.
You mean the type of the function RustWriter.(String) -> Unit
? Type inference fails if I omit the signature.
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.
Yep, that's what I meant. Thanks for thee clarification.
...n/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpProtocolGenerator.kt
Outdated
Show resolved
Hide resolved
/** | ||
* This class generates Rust functions that deserialize data from an HTTP message. | ||
* They are useful for *both*: | ||
* - servers (that deserialize HTTP requests); and |
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.
* - servers (that deserialize HTTP requests); and | |
* - servers (that deserialize HTTP requests). |
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.
All these are sentences split across bullet points. The style is:
* item 1,
* item 2,
* ...
* item n-1; and
* item n.
where and
can of course be any other grammatical conjunction.
Or:
* item 1,
* item 2,
* ...
* item n-1; and
* item n
if the sentence continues past the bullet points and ends in the next line.
I don't think there's an agreed upon standard, but some formal / technical writing does use this style.
I don't have strong opinions on this, I just try to be consistent.
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.
I have no strong opinions as well. It just feels weird to me, but not a blocker. Same for the rest below.
/** | ||
* The type of HTTP message from which we are deserializing the HTTP-bound data. | ||
* We are either: | ||
* - deserializing data from an HTTP request (we are a server); or |
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.
* - deserializing data from an HTTP request (we are a server); or | |
* - deserializing data from an HTTP request (we are a server). |
* For deserialization logic that is wholly different among clients and servers, use the classes: | ||
* - [ServerRequestBindingGenerator] from the `codegen-server` project for servers; and | ||
* - [ResponseBindingGenerator] from this project for clients |
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.
* For deserialization logic that is wholly different among clients and servers, use the classes: | |
* - [ServerRequestBindingGenerator] from the `codegen-server` project for servers; and | |
* - [ResponseBindingGenerator] from this project for clients | |
* For deserialization logic that is wholly different among clients and servers, use the classes: | |
* - [ServerRequestBindingGenerator] from the `codegen-server` project for servers. | |
* - [ResponseBindingGenerator] from this project for clients. |
* Generate a function to deserialize [binding] from HTTP headers | ||
* | ||
* The name of the resulting function is returned as a String |
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.
* Generate a function to deserialize [binding] from HTTP headers | |
* | |
* The name of the resulting function is returned as a String | |
* Generates a function to deserialize [binding] from HTTP headers. | |
* | |
* The name of the resulting function is returned as a String. |
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.
I moved ResponseBindingGenerator.kt
to HttpBindingGenerator.kt
; all the existing comments use the imperative. I'll add the full stops though.
// of an empty instance of the response type. | ||
withBlock("(!body.is_empty()).then(||{", "}).transpose()") { | ||
when (targetShape) { | ||
// TODO What if targetShape is set/map/list ? |
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 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.
Ah, was reading the code and forgot to test that.
Turns out that if you try to target a set/map/list, you get:
ERROR: com.amazonaws.simple#HealthcheckInputRequest$payload (ProtocolHttpPayload)
@ /local/home/davidpz/workplace/smithy-ws/src/SmithyRsSource/codegen-server-test/model/simple.smithy
|
36 | payload: StringList
| ^
= AWS Protocols do not support applying the httpPayload trait to members that target sets, lists, or maps.
Which I didn't know, but it's called out in the protocol e.g. restJson1. We only offer support for AWS protocols:
Projection simple failed: software.amazon.smithy.codegen.core.CodegenException: No matching protocol ? service offers: []. We offer: [aws.protocols#awsJson1_0, aws.protocols#awsJson1_1, aws.protocols#awsQuery, aws.protocols#ec2Query, aws.protocols#restJson1, aws.protocols#restXml]
So I'll just leave a comment documenting this fact.
A new doc preview is ready to view. |
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.
LGTM
A new generated diff is ready to view. |
A new doc preview is ready to view. |
A new generated diff is ready to view.
|
A new doc preview is ready to view. |
A new generated diff 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.
httpbinding refactoring lgtm
Hi @david-perez |
@guymguym Ah yes, the logic for setting headers that you copied over in your PR should be moved to the class I also need to set headers in responses, to resolve #1071 and #1075, so I'll merge this PR and work on moving header-setting to |
A new doc preview is ready to view. |
A new generated diff is ready to view.
|
This commit adds support for the
httpPayload
Smithy trait when appliedto operation input members (request deserialization).
The code to deserialize HTTP-bound data from HTTP responses in
ResponseBindingGenerator.kt
has been moved into a common class,HttpBindingGenerator.kt
, since it's useful for both clients andservers in deserializing data from HTTP requests and responses,
respectively.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.