-
Notifications
You must be signed in to change notification settings - Fork 187
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
Re-export runtime types in server generated crates #1909
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6cd280d
Re-export runtime types in server generated crates
82marbag ce16cd3
Add copyright header
82marbag 8a5e367
Remove doc hidden
82marbag fe6cf23
Update re-exports
82marbag c30843c
Update re-exports
82marbag 2cc66c2
Merge branch 'main' into 1506
82marbag b85ad60
Update to main
82marbag b30671d
LambdaHandler feature activate
82marbag cc0f5f2
Merge branch 'main' into 1506
82marbag 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
61 changes: 61 additions & 0 deletions
61
...azon/smithy/rust/codegen/server/smithy/generators/ServerRuntimeTypesReExportsGenerator.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,61 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package software.amazon.smithy.rust.codegen.server.smithy.generators | ||
|
||
import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter | ||
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate | ||
import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext | ||
import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency | ||
import software.amazon.smithy.rust.codegen.server.smithy.ServerRuntimeType | ||
|
||
class ServerRuntimeTypesReExportsGenerator( | ||
codegenContext: CodegenContext, | ||
) { | ||
private val runtimeConfig = codegenContext.runtimeConfig | ||
private val codegenScope = arrayOf( | ||
"Router" to ServerRuntimeType.router(runtimeConfig), | ||
"SmithyHttpServer" to ServerCargoDependency.smithyHttpServer(runtimeConfig).toType(), | ||
) | ||
|
||
fun render(writer: RustWriter) { | ||
writer.rustTemplate( | ||
""" | ||
pub mod body { | ||
pub use #{SmithyHttpServer}::body::BoxBody; | ||
} | ||
pub mod operation { | ||
pub use #{SmithyHttpServer}::operation::OperationShape; | ||
pub use #{SmithyHttpServer}::operation::Operation; | ||
} | ||
pub mod plugin { | ||
pub use #{SmithyHttpServer}::plugin::Plugin; | ||
pub use #{SmithyHttpServer}::plugin::PluginPipeline; | ||
pub use #{SmithyHttpServer}::plugin::PluginStack; | ||
} | ||
pub mod request { | ||
pub use #{SmithyHttpServer}::request::FromParts; | ||
} | ||
pub mod response { | ||
pub use #{SmithyHttpServer}::response::IntoResponse; | ||
} | ||
pub mod routing { | ||
pub use #{SmithyHttpServer}::routing::IntoMakeService; | ||
pub use #{SmithyHttpServer}::routing::IntoMakeServiceWithConnectInfo; | ||
pub use #{SmithyHttpServer}::routing::Router; | ||
|
||
##[cfg(feature = "aws-lambda")] | ||
pub use #{SmithyHttpServer}::routing::LambdaHandler; | ||
} | ||
|
||
pub use #{SmithyHttpServer}::instrumentation; | ||
pub use #{SmithyHttpServer}::proto; | ||
|
||
pub use #{SmithyHttpServer}::Extension; | ||
""", | ||
*codegenScope, | ||
) | ||
} | ||
} |
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
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.
Alternatively here we could
Which would allow us to preserve the root crate docs but would mean that we re-export everything from the
aws-smithy-http-server
crate.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.
The conclusion of a discussion about this was: no, we don't want to do a blanket re-export for now. But we should ensure we preserve the layout between codegen items and
aws-smithy-http-server
items so that if we reconsider it will be a non-breaking change.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.
Isn't
server
a confusing name? What about calling the moduleaws_smithy_http_server
to better signal where we are re-exporting from? Not a blocker TBH.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.
If we want to hide where re-exports are from and allow us to re-export also from other runtime crates possibly, probably we shouldn't signal the name of the crate
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.
It feels like
server
is clear from context and it buys us a bit of flexibility, as @82marbag was saying.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.
Allright! Thanks for the comments.