From 911f2817b79e00527972fbb40058a98f5488ab1c Mon Sep 17 00:00:00 2001 From: 82marbag <69267416+82marbag@users.noreply.github.com> Date: Tue, 27 Sep 2022 04:11:08 -0400 Subject: [PATCH 01/57] Docs: generation of Pokemon service (#1652) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Docs: generation of Pokemon service This is an overview of the Pokémon service. It describes: * How a smithy-rs customer uses the vanilla SDK and writes their business logic * What the runtime is and how code is generated * The folder structure of the project Signed-off-by: Daniele Ahmed --- design/src/docs/code_generation.md | 100 ++++++++++++ design/src/docs/pokemon_service.md | 236 +++++++++++++++++++++++++++++ design/src/smithy/overview.md | 8 +- 3 files changed, 341 insertions(+), 3 deletions(-) create mode 100644 design/src/docs/code_generation.md create mode 100644 design/src/docs/pokemon_service.md diff --git a/design/src/docs/code_generation.md b/design/src/docs/code_generation.md new file mode 100644 index 00000000000..f0a8bd3793c --- /dev/null +++ b/design/src/docs/code_generation.md @@ -0,0 +1,100 @@ +## Generating common service code + +How a service is constructed and how to plug in new business logic is described in [Pokémon Service][1]. +This document introduces the project and how code is being generated. It is written for developers who want to start contributing to `smithy-rs`. + +### Folder structure + +The project is divided in: + +- `/codegen`: it contains shared code for both client and server, but only generates a client +- `/codegen-server`: server only. This project started with `codegen` to generate a client, but client and server share common code; that code lives in `codegen`, which `codegen-server` depends on +- `/aws`: the AWS Rust SDK, it deals with AWS services specifically. The folder structure reflects the project's, with the `rust-runtime` and the `codegen` +- `/rust-runtime`: the generated client and server crates may depend on crates in this folder. Crates here are not code generated. The only crate that is not published is `inlineable`, +which contains common functions used by other crates, [copied into][2] the source crate + +`/rust-runtime` crates ("runtime crates") are added to a crate's dependency only when used. If a model uses event streams, it will depend on [`aws-smithy-eventstream`][3]. + +### Generating code + +`smithy-rs`'s entry points are Smithy code-generation plugins, and is not a command. One entry point is in [RustCodegenPlugin::execute][4] and +inherits from `SmithyBuildPlugin` in [smithy-build][5]. Code generation is in Kotlin and shared common, non-Rust specific code with the [`smithy` Java repository][6]. They plug into the [Smithy gradle][7] plugin, which is a gradle plugin. + +The comment at the beginning of `execute` describes what a `Decorator` is and uses the following terms: + +- Context: contains the model being generated, projection and settings for the build +- Decorator: (also referred to as customizations) customizes how code is being generated. AWS services are required to sign with the SigV4 protocol, and [a decorator][8] adds Rust code to sign requests and responses. + Decorators are applied in reverse order of being added and have a priority order. +- Writer: creates files and adds content; it supports templating, using `#` for substitutions +- Location: the file where a symbol will be written to + +The only task of a `RustCodegenPlugin` is to construct a `CodegenVisitor` and call its [execute()][9] method. + +`CodegenVisitor::execute()` is given a `Context` and decorators, and calls a [CodegenVisitor][10]. + +CodegenVisitor, RustCodegenPlugin, and wherever there are different implementations between client and server, such as in generating error types, +have corresponding server versions. + +Objects used throughout code generation are: + +- Symbol: a node in a graph, an abstraction that represents the qualified name of a type; symbols reference and depend on other symbols, and have some common properties among languages (such as a namespace or a definition file). For Rust, we add properties to include more metadata about a symbol, such as its [type][11] +- [RustType][12]: `Option`, `HashMap`, ... along with their namespaces of origin such as `std::collections` +- [RuntimeType][13]: the information to locate a type, plus the crates it depends on +- [ShapeId][14]: an immutable object that identifies a `Shape` + +Useful conversions are: + +```kotlin +SymbolProvider.toSymbol(shape) +``` + +where `SymbolProvider` constructs symbols for shapes. Some symbols require to create other symbols and types; +[event streams][15] and [other streaming shapes][16] are an example. +Symbol providers are all [applied][17] in order; if a shape uses a reserved keyword in Rust, its name is converted to a new name by a [symbol provider][18], +and all other providers will work with this [new][19] symbol. + +```kotlin +Model.expectShape(shapeId) +``` + +Each model has a `shapeId` to `shape` map; this method returns the shape associated with this shapeId. + +Some objects implement a `transform` [method][20] that only change the input model, so that code generation will work on that new model. This is used to, for example, add a trait to a shape. + +`CodegenVisitor` is a `ShapeVisitor`. For all services in the input model, shapes are [converted into Rust][21]; +[here][22] is how a service is constructed, +[here][23] a structure and so on. + +Code generation flows from writer to files and entities are (mostly) generated only on a [need-by-need basis][24]. +The complete result is a [Rust crate][25], +in which all dependencies are written into their modules and `lib.rs` is generated ([here][26]). +`execute()` ends by running [cargo fmt][27], +to avoid having to format correctly Rust in `Writer`s and to be sure the generated code follows the styling rules. + +[1]: ./pokemon_service.md +[2]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/CargoDependency.kt#L95-L95 +[3]: https://docs.rs/aws-smithy-eventstream +[4]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RustCodegenPlugin.kt#L34 +[5]: https://github.com/awslabs/smithy/tree/main/smithy-build +[6]: https://github.com/awslabs/smithy +[7]: https://awslabs.github.io/smithy/1.0/guides/building-models/gradle-plugin.html +[8]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SigV4SigningDecorator.kt#L45 +[9]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenVisitor.kt#L115-L115 +[10]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenVisitor.kt#L44 +[11]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/SymbolVisitor.kt#L363-L363 +[12]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/RustTypes.kt#L25-L25 +[13]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RuntimeTypes.kt#L113-L113 +[14]: https://awslabs.github.io/smithy/1.0/spec/core/model.html#shape-id +[15]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/EventStreamSymbolProvider.kt#L65-L65 +[16]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/StreamingTraitSymbolProvider.kt#L26-L26 +[17]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/RustCodegenPlugin.kt#L62-L62 +[18]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/RustReservedWords.kt#L26-L26 +[19]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/EventStreamSymbolProvider.kt#L38-L38 +[20]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/transformers/OperationNormalizer.kt#L52-L52 +[21]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenVisitor.kt#L119-L119 +[22]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenVisitor.kt#L150-L150 +[23]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenVisitor.kt#L172-L172 +[24]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenDelegator.kt#L119-L126 +[25]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenDelegator.kt#L42-L42 +[26]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenDelegator.kt#L96-L107 +[27]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/CodegenVisitor.kt#L133-L133 diff --git a/design/src/docs/pokemon_service.md b/design/src/docs/pokemon_service.md new file mode 100644 index 00000000000..d1209696b6d --- /dev/null +++ b/design/src/docs/pokemon_service.md @@ -0,0 +1,236 @@ +## Code generating the Pokémon Service + +This is an overview of client and server of the Pokémon service. It introduces: + +- How a smithy-rs server customer uses the vanilla SDK and writes their business logic +- What the runtime is and how code is generated +- The folder structure of the project + +All the code shown and linked to is from the repository at this commit: [db48039065bec890ef387385773b37154b555b14][1] + +The Smithy model used to generate the code snippets is: [Pokémon][2] + +### Building the service + +The entry point of a service is [main.rs][3] + +The `PokemonService` service in the `pokemon.smithy` has these operations and resources: + +```smithy +resources: [PokemonSpecies, Storage], +operations: [GetServerStatistics, EmptyOperation, CapturePokemonOperation, HealthCheckOperation], +``` + +The entry app is constructed as: + +```rust +let app: Router = OperationRegistryBuilder::default() +``` + +`OperationRegistryBuilder` is a struct, generated [here][4], +used by service implementors to register, for each operation, the operation's implementation logic, input and output. + +```rust +pub struct OperationRegistry { + capture_pokemon_operation: Op0, + empty_operation: Op1, + get_pokemon_species: Op2, + get_server_statistics: Op3, + get_storage: Op4, + health_check_operation: Op5, + _phantom: std::marker::PhantomData<(B, In0, In1, In2, In3, In4, In5)>, +} +``` + +The builder is constructed by a `OperationRegistryBuilder`; if an operation is not passed to the builder, it will return an error. + +```rust +let app: Router = OperationRegistryBuilder::default() + .get_pokemon_species(get_pokemon_species) + .get_storage(get_storage) + .get_server_statistics(get_server_statistics) + .capture_pokemon_operation(capture_pokemon) + .empty_operation(empty_operation) + .health_check_operation(health_check_operation) + .build() + .expect("Unable to build operation registry") + .into(); +``` + +Each of these operations is a function that can take any of these signatures. + +1. If the operation is not fallible and does not share any state: + +```rust +pub async fn health_check_operation(_input: input::HealthCheckOperationInput) -> output::HealthCheckOperationOutput {...} +``` + +2. If the operation is fallible and does not share any state: + +```rust +pub async fn capture_pokemon( + mut input: input::CapturePokemonOperationInput, +) -> Result {...} +``` + +3. If the operation is not fallible and shares some state: + +```rust +pub async fn get_server_statistics( + _input: input::GetServerStatisticsInput, + state: Extension>, +) -> output::GetServerStatisticsOutput {...} +``` + +4. If the operation is fallible and shares some state: + +```rust +pub async fn get_storage( + input: input::GetStorageInput, + _state: Extension>, +) -> Result {...} +``` + +All of these are operations which implementors define; they are the business logic of the application. The rest is code generated. + +The `OperationRegistry` builds into a `Router` (`let app: Router = OperationRegistryBuilder...build().into()`). +The implementation is code generated [here][5]. + +```rust +impl + std::convert::From< + OperationRegistry, + > for aws_smithy_http_server::routing::Router +where + B: Send + 'static, + Op0: crate::server_operation_handler_trait::Handler< + B, + In0, + crate::input::CapturePokemonOperationInput, + >, + In0: 'static + Send, + ... for all Op, In +{ + fn from( + registry: OperationRegistry, + ) -> Self {...} +} +``` + +For each operation, it registers a route; the specifics depend on the [protocol][6]. +The PokemonService uses [restJson1][7] as its protocol, an operation like the `HealthCheckOperation` will be rendered as: + +```rust +let capture_pokemon_operation_request_spec = aws_smithy_http_server::routing::request_spec::RequestSpec::new( + http::Method::POST, + aws_smithy_http_server::routing::request_spec::UriSpec::new( + aws_smithy_http_server::routing::request_spec::PathAndQuerySpec::new( + aws_smithy_http_server::routing::request_spec::PathSpec::from_vector_unchecked(vec![ + aws_smithy_http_server::routing::request_spec::PathSegment::Literal(String::from("capture-pokemon-event")), + aws_smithy_http_server::routing::request_spec::PathSegment::Label, + ]), + aws_smithy_http_server::routing::request_spec::QuerySpec::from_vector_unchecked(vec![]))),); +``` + +because the URI is `/capture-pokemon-event/{region}`, with method `POST` and `region` a `Label` (then passed to the operation with its `CapturePokemonOperationInput` input struct). + +Finally, it creates a RestJSON `Router`, because that is the service's protocol. +You will have noticed, each operation is implemented as a `pub async fn`. Each operation is wrapped into an `OperationHandler`, generated [here][8]. +`OperationHandler` implements tower's `Service` [trait][9]. Implementing `Service` means that +the business logic is written as protocol-agnostic and clients request a service by calling into them, similar to an RPC call. + +```rust +aws_smithy_http_server::routing::Router::new_rest_json_router(vec![ + { + let svc = crate::server_operation_handler_trait::operation( + registry.capture_pokemon_operation, + ); +``` + +At this level, logging might be prohibited by the [`@sensitive`][10] trait. If there are no `@sensitive` shapes, the generated code looks like: + +```rust +let request_fmt = aws_smithy_http_server::logging::sensitivity::RequestFmt::new(); +let response_fmt = aws_smithy_http_server::logging::sensitivity::ResponseFmt::new(); +let svc = aws_smithy_http_server::logging::InstrumentOperation::new( + svc, + "capture_pokemon_operation", +) +.request_fmt(request_fmt) +.response_fmt(response_fmt); +``` + +Accessing the Pokédex is modeled as a restricted operation: a passcode is needed by the Pokémon trainer. +To not log the passcode, the code will be generated [here][11] as: + +```rust +let request_fmt = aws_smithy_http_server::logging::sensitivity::RequestFmt::new() + .header(|name: &http::header::HeaderName| { + #[allow(unused_variables)] + let name = name.as_str(); + let name_match = matches!(name, "passcode"); + let key_suffix = None; + let value = name_match; + aws_smithy_http_server::logging::sensitivity::headers::HeaderMarker { + value, + key_suffix, + } + }) + .label(|index: usize| matches!(index, 1)); +let response_fmt = aws_smithy_http_server::logging::sensitivity::ResponseFmt::new(); +``` + +Each route is a pair, [`BoxCloneService`][12] wrapping the service operation (the implementation) and +the information to consume the service operation. + +```rust +(tower::util::BoxCloneService::new(svc), capture_pokemon_operation_request_spec) +``` + +Now the `Router` is built. `Router` is not code generated, it instead lives in the [`aws-smithy-http-server`][13] crate. +We write Rust code in the runtime to: + +- Aid development of the project +- Have service-specific code that the majority of services share in the runtime + In Kotlin we generate code that is service-specific. + +A `Router` is a [`tower::Service`][9] that routes requests to the implemented services; hence it [implements][14] `Service` +like the other operations. + +The `Router` [implements][15] +the `tower::Layer` trait. Middleware are added as layers. The Pokémon example uses them: + +```rust +let shared_state = Arc::new(State::default()); +let app = app.layer( + ServiceBuilder::new() + .layer(TraceLayer::new_for_http()) + .layer(AddExtensionLayer::new(shared_state)), +); +``` + +The service is run by a [Hyper server][16]: + +```rust +hyper::Server::bind(&bind).serve(app.into_make_service()); +``` + +Generation of objects common to services, such as shapes, is described in [Code Generation][17]. + +[1]: https://github.com/awslabs/smithy-rs/tree/db48039065bec890ef387385773b37154b555b14 +[2]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen-server-test/model/pokemon.smithy +[3]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/main.rs#L34 +[4]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt#L1 +[5]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt#L285 +[6]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/protocols/Protocol.kt#L81 +[7]: https://awslabs.github.io/smithy/1.0/spec/aws/aws-restjson1-protocol.html +[8]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt#L30 +[9]: https://docs.rs/tower-service/latest/tower_service/trait.Service.html +[10]: https://awslabs.github.io/smithy/1.0/spec/core/documentation-traits.html#sensitive-trait +[11]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt#L58 +[12]: https://docs.rs/tower/latest/tower/util/struct.BoxCloneService.html +[13]: https://docs.rs/aws-smithy-http-server/latest/aws_smithy_http_server/ +[14]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/rust-runtime/aws-smithy-http-server/src/routing/mod.rs#L302 +[15]: https://github.com/awslabs/smithy-rs/blob/db48039065bec890ef387385773b37154b555b14/rust-runtime/aws-smithy-http-server/src/routing/mod.rs#L146 +[16]: https://docs.rs/hyper/latest/hyper/server/struct.Server.html +[17]: ./code_generation.md diff --git a/design/src/smithy/overview.md b/design/src/smithy/overview.md index e41d96a70c0..d7a8eee3d0e 100644 --- a/design/src/smithy/overview.md +++ b/design/src/smithy/overview.md @@ -7,8 +7,8 @@ Design documentation here covers both our implementation of Smithy Primitives (e Smithy introduces a few concepts that are defined here: 1. Shape: The core Smithy primitive. A smithy model is composed of nested shapes defining an API. -1. `Symbol`: A Representation of a type including namespaces & and any dependencies required to use a type. A shape can be converted into a symbol by a `SymbolVisitor`. A `SymbolVisitor` maps shapes to types in your programming language (e.g. Rust). In the Rust SDK, see [SymbolVisitor.kt](https://github.com/awslabs/smithy-rs/blob/c049a37f8cba5f9bec2e96c28db83e7efb2edc53/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/SymbolVisitor.kt). Symbol visitors are composable—many specific behaviors are mixed in via small & focused symbol providers, e.g. support for the streaming trait is mixed in separately. -2. `Writer`: Writers are code generation primitives that collect code prior to being written to a file. Writers enable language specific helpers to be added to simplify codegen for a given language. For example, `smithy-rs` adds `rustBlock` to [`RustWriter`](https://github.com/awslabs/smithy-rs/blob/908dec558e26bbae6fe4b7d9d1c221dd81699b59/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/RustWriter.kt) to create a "Rust block" of code. +2. `Symbol`: A Representation of a type including namespaces and any dependencies required to use a type. A shape can be converted into a symbol by a `SymbolVisitor`. A `SymbolVisitor` maps shapes to types in your programming language (e.g. Rust). In the Rust SDK, see [SymbolVisitor.kt](https://github.com/awslabs/smithy-rs/blob/c049a37f8cba5f9bec2e96c28db83e7efb2edc53/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/smithy/SymbolVisitor.kt). Symbol visitors are composable—many specific behaviors are mixed in via small & focused symbol providers, e.g. support for the streaming trait is mixed in separately. +3. `Writer`: Writers are code generation primitives that collect code prior to being written to a file. Writers enable language specific helpers to be added to simplify codegen for a given language. For example, `smithy-rs` adds `rustBlock` to [`RustWriter`](https://github.com/awslabs/smithy-rs/blob/908dec558e26bbae6fe4b7d9d1c221dd81699b59/codegen/src/main/kotlin/software/amazon/smithy/rust/codegen/rustlang/RustWriter.kt) to create a "Rust block" of code. ```kotlin writer.rustBlock("struct Model") { model.fields.forEach { @@ -24,4 +24,6 @@ Smithy introduces a few concepts that are defined here: } ``` -3. Generators: A Generator, e.g. `StructureGenerator`, `UnionGenerator` generates more complex Rust code from a Smithy model. Protocol generators pull these individual tools together to generate code for an entire service / protocol. +4. Generators: A Generator, e.g. `StructureGenerator`, `UnionGenerator` generates more complex Rust code from a Smithy model. Protocol generators pull these individual tools together to generate code for an entire service / protocol. + +A developer's view of code generation can be found in [this document](../docs/code_generation.md). From 5b7aa7b803c967570404f367c92b84be65c0c6cd Mon Sep 17 00:00:00 2001 From: david-perez Date: Tue, 27 Sep 2022 14:33:50 +0200 Subject: [PATCH 02/57] Move more things into `codegen-core` (#1762) This moves most things from `codegen-client` that should be in `codegen-core` into `codegen-core`. This is a continuation of the efforts started in #1697, #1730. --- .../smithy/rustsdk/AwsCodegenDecorator.kt | 3 +- .../smithy/rustsdk/AwsEndpointDecorator.kt | 107 ++++++----- .../rustsdk/AwsFluentClientDecorator.kt | 73 ++++---- .../smithy/rustsdk/AwsPresigningDecorator.kt | 93 +++++----- .../smithy/rustsdk/AwsReadmeDecorator.kt | 13 +- .../smithy/rustsdk/AwsRuntimeDependency.kt | 12 +- .../smithy/rustsdk/CrateLicenseDecorator.kt | 11 +- .../smithy/rustsdk/CredentialProviders.kt | 79 ++++---- .../rustsdk/HttpRequestChecksumDecorator.kt | 29 +-- .../rustsdk/HttpResponseChecksumDecorator.kt | 15 +- .../smithy/rustsdk/InlineAwsDependency.kt | 6 +- .../rustsdk/IntegrationTestDependencies.kt | 59 +++--- .../amazon/smithy/rustsdk/RegionDecorator.kt | 71 ++++---- .../rustsdk/RetryClassifierDecorator.kt | 21 +-- .../smithy/rustsdk/SdkConfigDecorator.kt | 21 +-- .../amazon/smithy/rustsdk/SdkSettings.kt | 2 +- .../smithy/rustsdk/ServiceConfigDecorator.kt | 13 +- .../smithy/rustsdk/SigV4SigningDecorator.kt | 37 ++-- .../smithy/rustsdk/UserAgentDecorator.kt | 29 +-- .../apigateway/ApiGatewayDecorator.kt | 23 +-- .../customize/auth/DisabledAuthDecorator.kt | 7 +- .../rustsdk/customize/ec2/Ec2Decorator.kt | 7 +- .../customize/glacier/AccountIdAutofill.kt | 10 +- .../customize/glacier/ApiVersionHeader.kt | 12 +- .../customize/glacier/GlacierDecorator.kt | 11 +- .../customize/glacier/TreeHashHeader.kt | 18 +- .../customize/route53/Route53Decorator.kt | 19 +- .../rustsdk/customize/s3/S3Decorator.kt | 48 ++--- .../rustsdk/customize/sts/STSDecorator.kt | 7 +- .../EndpointConfigCustomizationTest.kt | 17 +- .../rustsdk/RegionProviderConfigTest.kt | 2 +- .../amazon/smithy/rustsdk/TestUtil.kt | 4 +- codegen-client/build.gradle.kts | 2 - .../client/smithy/ClientCodegenContext.kt | 8 +- .../client/smithy/ClientRustSettings.kt | 4 + .../codegen/client/smithy/CodegenVisitor.kt | 40 +++-- .../smithy/EventStreamSymbolProvider.kt | 19 +- .../client/smithy/RustCodegenPlugin.kt | 9 +- .../client/smithy/ServerCodegenContext.kt | 8 +- .../client/smithy/ServerRustSettings.kt | 4 + .../smithy/StreamingTraitSymbolProvider.kt | 9 +- .../customizations/AllowLintsGenerator.kt | 8 +- .../customizations/ClientCustomizations.kt | 9 +- .../customizations/ClientDocsGenerator.kt | 21 +-- .../customizations/CrateVersionGenerator.kt | 27 +-- .../customizations/DocsRsMetadataDecorator.kt | 9 +- .../customizations/EndpointPrefixGenerator.kt | 22 +-- .../HttpChecksumRequiredGenerator.kt | 28 +-- .../HttpVersionListCustomization.kt | 24 +-- .../IdempotencyTokenGenerator.kt | 18 +- .../ResiliencyConfigCustomization.kt | 86 ++++----- .../SmithyTypesPubUseGenerator.kt | 44 ++--- .../NoOpEventStreamSigningDecorator.kt | 18 +- .../customize/RequiredCustomizations.kt | 14 +- .../smithy/customize/RustCodegenDecorator.kt | 51 +++--- .../EndpointTraitBindingGenerator.kt | 21 +-- .../generators/NestedAccessorGenerator.kt | 63 ++++--- .../smithy/generators/PaginatorGenerator.kt | 65 +++---- .../smithy/generators/ServiceGenerator.kt | 16 +- .../client/CustomizableOperationGenerator.kt | 30 ++-- .../generators/client/FluentClientCore.kt | 18 +- .../client/FluentClientDecorator.kt | 39 ++-- .../client/FluentClientGenerator.kt | 66 +++---- .../generators/client/FluentClientGenerics.kt | 20 +-- .../config/EventStreamSigningConfig.kt | 12 +- .../IdempotencyTokenProviderCustomization.kt | 10 +- .../config/ServiceConfigGenerator.kt | 20 +-- .../protocol/ClientProtocolGenerator.kt | 93 ++++++++++ .../generators/protocol/ProtocolGenerator.kt | 170 ------------------ .../protocol/ProtocolTestGenerator.kt | 94 +++++----- .../client/smithy/protocols/AwsJson.kt | 60 ++++--- .../client/smithy/protocols/AwsQuery.kt | 38 ++-- .../smithy/protocols/ClientProtocolLoader.kt | 33 ++++ .../client/smithy/protocols/Ec2Query.kt | 38 ++-- .../protocols/HttpBoundProtocolGenerator.kt | 92 +++++----- .../client/smithy/protocols/RestJson.kt | 37 ++-- .../client/smithy/protocols/RestXml.kt | 53 +++--- .../smithy/transformers/AddErrorMessage.kt | 5 +- .../rust/codegen/client/testutil/Rust.kt | 24 +-- .../testutil/TestConfigCustomization.kt | 8 +- .../codegen/client/testutil/TestHelpers.kt | 36 ++-- .../rust/codegen/client/SymbolBuilderTest.kt | 14 +- .../HttpVersionListGeneratorTest.kt | 23 +-- .../ResiliencyConfigCustomizationTest.kt | 4 +- .../SmithyTypesPubUseGeneratorTest.kt | 2 +- .../client/generators/EnumGeneratorTest.kt | 8 +- ...csGeneratorTest.kt => RustGenericsTest.kt} | 32 ++-- .../generators/StructureGeneratorTest.kt | 20 +-- .../client/generators/UnionGeneratorTest.kt | 6 +- .../http/RequestBindingGeneratorTest.kt | 18 +- .../http/ResponseBindingGeneratorTest.kt | 26 +-- .../client/rustlang/InlineDependencyTest.kt | 7 +- .../RustReservedWordSymbolProviderTest.kt | 7 +- .../codegen/client/rustlang/RustTypesTest.kt | 5 + .../codegen/client/rustlang/RustWriterTest.kt | 13 +- .../client/rustlang/UseDeclarationsTest.kt | 1 + .../codegen/client/rustlang/WritableTest.kt | 19 +- .../client/smithy/CodegenDelegatorTest.kt | 7 +- .../smithy/EventStreamSymbolProviderTest.kt | 8 +- .../codegen/client/smithy/RuntimeTypesTest.kt | 11 +- .../StreamingShapeSymbolProviderTest.kt | 4 +- .../smithy/generators/BuilderGeneratorTest.kt | 17 +- .../generators/CargoTomlGeneratorTest.kt | 4 +- .../generators/CombinedErrorGeneratorTest.kt | 6 +- .../generators/EndpointTraitBindingsTest.kt | 21 ++- .../smithy/generators/InstantiatorTest.kt | 15 +- .../config/ServiceConfigGeneratorTest.kt | 10 +- .../protocol/ProtocolTestGeneratorTest.kt | 81 +++++---- .../protocols/InlineFunctionNamerTest.kt | 2 + .../parse/AwsQueryParserGeneratorTest.kt | 9 +- .../parse/Ec2QueryParserGeneratorTest.kt | 9 +- .../parse/JsonParserGeneratorTest.kt | 15 +- .../XmlBindingTraitParserGeneratorTest.kt | 13 +- .../AwsQuerySerializerGeneratorTest.kt | 13 +- .../Ec2QuerySerializerGeneratorTest.kt | 11 +- .../serialize/JsonSerializerGeneratorTest.kt | 15 +- .../XmlBindingTraitSerializerGeneratorTest.kt | 15 +- .../transformers/EventStreamNormalizerTest.kt | 1 + .../transformers/OperationNormalizerTest.kt | 1 + .../transformers/RecursiveShapeBoxerTest.kt | 3 +- .../RecursiveShapesIntegrationTest.kt | 7 +- .../client/testutil/AddRustTestsDecorator.kt | 12 +- .../codegen/client/util/SyntheticsTest.kt | 2 + codegen-core/build.gradle.kts | 2 + .../codegen/core}/rustlang/CargoDependency.kt | 8 +- .../codegen/core/rustlang/RustGenerics.kt | 36 ++-- .../rust/codegen/core}/rustlang/RustModule.kt | 2 +- .../core}/rustlang/RustReservedWords.kt | 12 +- .../rust/codegen/core}/rustlang/RustTypes.kt | 4 +- .../rust/codegen/core}/rustlang/RustWriter.kt | 8 +- .../codegen/core}/rustlang/UseDeclarations.kt | 2 +- .../rust/codegen/core}/rustlang/Writable.kt | 7 +- .../codegen/core/smithy/CodegenContext.kt | 7 +- .../codegen/core}/smithy/CodegenDelegator.kt | 24 +-- .../codegen/core/smithy}/CodegenTarget.kt | 2 +- .../codegen/core}/smithy/CoreRustSettings.kt | 2 +- .../rust/codegen/core}/smithy/RuntimeTypes.kt | 35 ++-- .../core}/smithy/SymbolMetadataProvider.kt | 8 +- .../codegen/core}/smithy/SymbolVisitor.kt | 7 +- .../smithy/customize/NamedSectionGenerator.kt | 8 +- .../customize/OperationCustomization.kt | 6 +- .../smithy/generators/BuilderGenerator.kt | 48 ++--- .../smithy/generators/CargoTomlGenerator.kt | 12 +- .../core}/smithy/generators/EnumGenerator.kt | 27 +-- .../core}/smithy/generators/Instantiator.kt | 35 ++-- .../core}/smithy/generators/LibRsGenerator.kt | 20 +-- .../smithy/generators/StructureGenerator.kt | 41 ++--- .../generators/TypeConversionGenerator.kt | 16 +- .../core}/smithy/generators/UnionGenerator.kt | 21 +-- .../error/CombinedErrorGenerator.kt | 38 ++-- .../smithy/generators/error/ErrorGenerator.kt | 26 +-- .../error/ServerCombinedErrorGenerator.kt | 24 +-- .../error/TopLevelErrorGenerator.kt | 63 ++++--- .../generators/http/HttpBindingGenerator.kt | 64 +++---- .../http/RequestBindingGenerator.kt | 40 ++--- .../http/ResponseBindingGenerator.kt | 16 +- .../http/RestRequestSpecGenerator.kt | 18 +- .../protocol/MakeOperationGenerator.kt | 58 +++--- .../generators/protocol/ProtocolGenerator.kt | 88 +++++++++ .../generators/protocol/ProtocolSupport.kt | 19 ++ .../smithy/protocols/HttpBindingResolver.kt | 2 +- .../HttpBoundProtocolPayloadGenerator.kt | 50 +++--- .../smithy/protocols/InlineFunctionNamer.kt | 4 +- .../core}/smithy/protocols/Protocol.kt | 55 +----- .../core/smithy/protocols/ProtocolLoader.kt | 29 +++ .../core}/smithy/protocols/XmlNameIndex.kt | 2 +- .../parse/AwsQueryParserGenerator.kt | 14 +- .../parse/Ec2QueryParserGenerator.kt | 14 +- .../parse/EventStreamUnmarshallerGenerator.kt | 38 ++-- .../protocols/parse/JsonParserGenerator.kt | 68 ++++--- .../protocols/parse/RestXmlParserGenerator.kt | 14 +- .../parse/StructuredDataParserGenerator.kt | 4 +- .../parse/XmlBindingTraitParserGenerator.kt | 71 ++++---- .../serialize/AwsQuerySerializerGenerator.kt | 8 +- .../serialize/Ec2QuerySerializerGenerator.kt | 8 +- .../EventStreamErrorMarshallerGenerator.kt | 36 ++-- .../EventStreamMarshallerGenerator.kt | 38 ++-- .../serialize/JsonSerializerGenerator.kt | 60 +++---- .../serialize/QuerySerializerGenerator.kt | 64 +++---- .../protocols/serialize/SerializerUtil.kt | 6 +- .../StructuredDataSerializerGenerator.kt | 4 +- .../protocols/serialize/ValueExpression.kt | 2 +- .../XmlBindingTraitSerializerGenerator.kt | 67 ++++--- .../core/smithy/traits/AllowInvalidXmlRoot.kt | 19 ++ .../core/smithy/traits}/RustBoxTrait.kt | 2 +- .../transformers/EventStreamNormalizer.kt | 2 +- .../transformers/OperationNormalizer.kt | 6 +- .../transformers/RecursiveShapeBoxer.kt | 4 +- .../smithy/rust/codegen/core/util/Smithy.kt | 2 + .../rust/codegen/core}/util/Synthetics.kt | 3 +- .../smithy/PythonCodegenServerPlugin.kt | 15 +- .../smithy/PythonServerCargoDependency.kt | 6 +- .../smithy/PythonServerCodegenVisitor.kt | 15 +- .../python/smithy/PythonServerRuntimeType.kt | 4 +- .../smithy/PythonServerSymbolProvider.kt | 21 ++- .../PythonServerCodegenDecorator.kt | 33 ++-- .../generators/PythonApplicationGenerator.kt | 32 ++-- .../PythonServerCombinedErrorGenerator.kt | 22 +-- .../generators/PythonServerEnumGenerator.kt | 20 +-- .../generators/PythonServerModuleGenerator.kt | 12 +- .../PythonServerOperationHandlerGenerator.kt | 20 +-- .../PythonServerServiceGenerator.kt | 18 +- .../PythonServerStructureGenerator.kt | 22 +-- .../PythonServerSymbolProviderTest.kt | 5 +- .../server/smithy/RustCodegenServerPlugin.kt | 13 +- .../server/smithy/ServerCargoDependency.kt | 10 +- .../server/smithy/ServerCodegenVisitor.kt | 36 ++-- .../server/smithy/ServerRuntimeType.kt | 6 +- .../AdditionalErrorsDecorator.kt | 13 +- .../ServerRequiredCustomizations.kt | 13 +- .../smithy/generators/ServerEnumGenerator.kt | 18 +- .../ServerHttpSensitivityGenerator.kt | 18 +- .../generators/ServerOperationGenerator.kt | 24 +-- .../ServerOperationHandlerGenerator.kt | 32 ++-- .../ServerOperationRegistryGenerator.kt | 56 +++--- .../generators/ServerServiceGenerator.kt | 39 ++-- .../generators/ServerServiceGeneratorV2.kt | 36 ++-- .../http/ServerRequestBindingGenerator.kt | 18 +- .../http/ServerResponseBindingGenerator.kt | 14 +- .../generators/protocol/ServerProtocol.kt | 76 ++++---- .../protocol/ServerProtocolGenerator.kt | 32 ++++ .../protocol/ServerProtocolTestGenerator.kt | 97 +++++----- .../server/smithy/protocols/ServerAwsJson.kt | 28 +-- .../ServerHttpBoundProtocolGenerator.kt | 86 ++++----- .../smithy/protocols/ServerProtocolLoader.kt | 9 +- .../smithy/protocols/ServerRestJsonFactory.kt | 6 +- .../smithy/protocols/ServerRestXmlFactory.kt | 6 +- .../smithy/testutil/ServerTestHelpers.kt | 6 +- .../server/smithy/ServerCodegenVisitorTest.kt | 3 +- .../AdditionalErrorsDecoratorTest.kt | 2 +- .../ServerCombinedErrorGeneratorTest.kt | 8 +- .../generators/ServerEnumGeneratorTest.kt | 2 +- .../ServerHttpSensitivityGeneratorTest.kt | 6 +- .../ServerOperationRegistryGeneratorTest.kt | 2 +- .../smithy/protocols/EventStreamTestTools.kt | 34 ++-- .../EventStreamUnmarshallerGeneratorTest.kt | 14 +- .../EventStreamMarshallerGeneratorTest.kt | 16 +- .../customize/CombinedCodegenDecoratorTest.kt | 10 +- 238 files changed, 2971 insertions(+), 2652 deletions(-) create mode 100644 codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolGenerator.kt delete mode 100644 codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolGenerator.kt create mode 100644 codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/ClientProtocolLoader.kt rename codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/{GenericsGeneratorTest.kt => RustGenericsTest.kt} (79%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/rustlang/CargoDependency.kt (96%) rename codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/GenericsGenerator.kt => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustGenerics.kt (77%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/rustlang/RustModule.kt (95%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/rustlang/RustReservedWords.kt (93%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/rustlang/RustTypes.kt (99%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/rustlang/RustWriter.kt (98%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/rustlang/UseDeclarations.kt (95%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/rustlang/Writable.kt (93%) rename codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CoreCodegenContext.kt => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenContext.kt (91%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/CodegenDelegator.kt (89%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy}/CodegenTarget.kt (80%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/CoreRustSettings.kt (99%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/RuntimeTypes.kt (92%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/SymbolMetadataProvider.kt (95%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/SymbolVisitor.kt (98%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/customize/NamedSectionGenerator.kt (83%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/customize/OperationCustomization.kt (91%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/BuilderGenerator.kt (86%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/CargoTomlGenerator.kt (85%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/EnumGenerator.kt (89%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/Instantiator.kt (91%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/LibRsGenerator.kt (78%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/StructureGenerator.kt (83%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/TypeConversionGenerator.kt (76%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/UnionGenerator.kt (87%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/error/CombinedErrorGenerator.kt (89%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/error/ErrorGenerator.kt (83%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/error/ServerCombinedErrorGenerator.kt (85%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/error/TopLevelErrorGenerator.kt (64%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/http/HttpBindingGenerator.kt (92%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/http/RequestBindingGenerator.kt (89%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/http/ResponseBindingGenerator.kt (63%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/http/RestRequestSpecGenerator.kt (83%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/protocol/MakeOperationGenerator.kt (78%) create mode 100644 codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/ProtocolGenerator.kt create mode 100644 codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/ProtocolSupport.kt rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/HttpBindingResolver.kt (99%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt (88%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/InlineFunctionNamer.kt (94%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/Protocol.kt (50%) create mode 100644 codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/ProtocolLoader.kt rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/XmlNameIndex.kt (97%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/parse/AwsQueryParserGenerator.kt (82%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/parse/Ec2QueryParserGenerator.kt (74%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt (92%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/parse/JsonParserGenerator.kt (90%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/parse/RestXmlParserGenerator.kt (81%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/parse/StructuredDataParserGenerator.kt (92%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt (92%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/serialize/AwsQuerySerializerGenerator.kt (74%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/serialize/Ec2QuerySerializerGenerator.kt (76%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt (84%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt (87%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/serialize/JsonSerializerGenerator.kt (90%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/serialize/QuerySerializerGenerator.kt (85%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/serialize/SerializerUtil.kt (87%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/serialize/StructuredDataSerializerGenerator.kt (94%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/serialize/ValueExpression.kt (87%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt (89%) create mode 100644 codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/traits/AllowInvalidXmlRoot.kt rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/traits}/RustBoxTrait.kt (92%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/transformers/EventStreamNormalizer.kt (98%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/transformers/OperationNormalizer.kt (95%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/transformers/RecursiveShapeBoxer.kt (96%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/util/Synthetics.kt (94%) create mode 100644 codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolGenerator.kt diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt index f63e7078d88..aec623d221a 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsCodegenDecorator.kt @@ -9,6 +9,7 @@ import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customizations.DocsRsMetadataDecorator import software.amazon.smithy.rust.codegen.client.smithy.customizations.DocsRsMetadataSettings import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rustsdk.customize.apigateway.ApiGatewayDecorator import software.amazon.smithy.rustsdk.customize.auth.DisabledAuthDecorator import software.amazon.smithy.rustsdk.customize.ec2.Ec2Decorator @@ -48,7 +49,7 @@ val DECORATORS = listOf( DocsRsMetadataDecorator(DocsRsMetadataSettings(targets = listOf("x86_64-unknown-linux-gnu"), allFeatures = true)), ) -class AwsCodegenDecorator : CombinedCodegenDecorator(DECORATORS) { +class AwsCodegenDecorator : CombinedCodegenDecorator(DECORATORS) { override val name: String = "AwsSdkCodegenDecorator" override val order: Byte = -1 } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt index 7fd4d56a834..af3ae09c6a3 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt @@ -11,35 +11,36 @@ import software.amazon.smithy.model.node.Node import software.amazon.smithy.model.node.ObjectNode import software.amazon.smithy.model.node.StringNode import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.rustlang.withBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsSection import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig -import software.amazon.smithy.rust.codegen.client.smithy.generators.operationBuildError +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection +import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.orNull import kotlin.io.path.readText -class AwsEndpointDecorator : RustCodegenDecorator { +class AwsEndpointDecorator : RustCodegenDecorator { override val name: String = "AwsEndpoint" override val order: Byte = 0 @@ -84,22 +85,22 @@ class AwsEndpointDecorator : RustCodegenDecorator { return baseCustomizations + PubUseEndpoint(codegenContext.runtimeConfig) } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } class EndpointConfigCustomization( - private val coreCodegenContext: CoreCodegenContext, + private val codegenContext: CodegenContext, private val endpointData: ObjectNode, ) : ConfigCustomization() { - private val runtimeConfig = coreCodegenContext.runtimeConfig + private val runtimeConfig = codegenContext.runtimeConfig private val resolveAwsEndpoint = runtimeConfig.awsEndpoint().asType().copy(name = "ResolveAwsEndpoint") private val smithyEndpointResolver = CargoDependency.SmithyHttp(runtimeConfig).asType().member("endpoint::ResolveEndpoint") private val placeholderEndpointParams = runtimeConfig.awsEndpoint().asType().member("Params") private val endpointShim = runtimeConfig.awsEndpoint().asType().member("EndpointShim") - private val moduleUseName = coreCodegenContext.moduleUseName() + private val moduleUseName = codegenContext.moduleUseName() private val codegenScope = arrayOf( "SmithyResolver" to smithyEndpointResolver, "PlaceholderParams" to placeholderEndpointParams, @@ -108,18 +109,24 @@ class EndpointConfigCustomization( "aws_types" to awsTypes(runtimeConfig).asType(), ) - override fun section(section: ServiceConfig): Writable = writable { - when (section) { - is ServiceConfig.ConfigStruct -> rustTemplate( - "pub (crate) endpoint_resolver: std::sync::Arc>,", - *codegenScope, - ) - is ServiceConfig.ConfigImpl -> emptySection - is ServiceConfig.BuilderStruct -> - rustTemplate("endpoint_resolver: Option>>,", *codegenScope) - ServiceConfig.BuilderImpl -> - rustTemplate( - """ + override fun section(section: ServiceConfig): Writable = + writable { + when (section) { + is ServiceConfig.ConfigStruct -> rustTemplate( + "pub (crate) endpoint_resolver: std::sync::Arc>,", + *codegenScope, + ) + + is ServiceConfig.ConfigImpl -> emptySection + is ServiceConfig.BuilderStruct -> + rustTemplate( + "endpoint_resolver: Option>>,", + *codegenScope, + ) + + ServiceConfig.BuilderImpl -> + rustTemplate( + """ /// Overrides the endpoint resolver to use when making requests. /// /// When unset, the client will used a generated endpoint resolver based on the endpoint metadata @@ -147,22 +154,24 @@ class EndpointConfigCustomization( self } """, - *codegenScope, - ) - ServiceConfig.BuilderBuild -> { - val resolverGenerator = EndpointResolverGenerator(coreCodegenContext, endpointData) - rustTemplate( - """ + *codegenScope, + ) + + ServiceConfig.BuilderBuild -> { + val resolverGenerator = EndpointResolverGenerator(codegenContext, endpointData) + rustTemplate( + """ endpoint_resolver: self.endpoint_resolver.unwrap_or_else(|| std::sync::Arc::new(#{EndpointShim}::from_resolver(#{Resolver}())) ), """, - *codegenScope, "Resolver" to resolverGenerator.resolver(), - ) + *codegenScope, "Resolver" to resolverGenerator.resolver(), + ) + } + + else -> emptySection } - else -> emptySection } - } } // This is an experiment in a slightly different way to create runtime types. All code MAY be refactored to use this pattern @@ -208,9 +217,9 @@ class PubUseEndpoint(private val runtimeConfig: RuntimeConfig) : LibRsCustomizat } } -class EndpointResolverGenerator(coreCodegenContext: CoreCodegenContext, private val endpointData: ObjectNode) { - private val runtimeConfig = coreCodegenContext.runtimeConfig - private val endpointPrefix = coreCodegenContext.serviceShape.expectTrait().endpointPrefix +class EndpointResolverGenerator(codegenContext: CodegenContext, private val endpointData: ObjectNode) { + private val runtimeConfig = codegenContext.runtimeConfig + private val endpointPrefix = codegenContext.serviceShape.expectTrait().endpointPrefix private val awsEndpoint = runtimeConfig.awsEndpoint().asType() private val awsTypes = runtimeConfig.awsTypes().asType() private val codegenScope = diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt index 40ba2c6cf81..52443b23a73 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt @@ -8,32 +8,33 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.traits.TitleTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.DependencyScope -import software.amazon.smithy.rust.codegen.client.rustlang.Feature -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.GenericTypeArg -import software.amazon.smithy.rust.codegen.client.smithy.generators.GenericsGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsSection import software.amazon.smithy.rust.codegen.client.smithy.generators.client.CustomizableOperationGenerator import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerator import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerics import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientSection +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope +import software.amazon.smithy.rust.codegen.core.rustlang.Feature +import software.amazon.smithy.rust.codegen.core.rustlang.GenericTypeArg +import software.amazon.smithy.rust.codegen.core.rustlang.RustGenerics +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rustsdk.AwsRuntimeType.defaultMiddleware @@ -77,14 +78,18 @@ private class AwsClientGenerics(private val types: Types) : FluentClientGenerics override val bounds = writable { } /** Bounds for generated `send()` functions */ - override fun sendBounds(operation: Symbol, operationOutput: Symbol, operationError: RuntimeType, retryClassifier: RuntimeType): Writable = writable { } + override fun sendBounds( + operation: Symbol, + operationOutput: Symbol, + operationError: RuntimeType, + retryClassifier: RuntimeType, + ): Writable = + writable { } - override fun toGenericsGenerator(): GenericsGenerator { - return GenericsGenerator() - } + override fun toRustGenerics() = RustGenerics() } -class AwsFluentClientDecorator : RustCodegenDecorator { +class AwsFluentClientDecorator : RustCodegenDecorator { override val name: String = "FluentClient" // Must run after the AwsPresigningDecorator so that the presignable trait is correctly added to operations @@ -124,12 +129,13 @@ class AwsFluentClientDecorator : RustCodegenDecorator { Attribute.DocInline.render(this) rust("pub use client::Client;") } + else -> emptySection } } } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } @@ -203,17 +209,17 @@ private class AwsFluentClientExtensions(types: Types) { } } -private class AwsFluentClientDocs(private val coreCodegenContext: CoreCodegenContext) : FluentClientCustomization() { - private val serviceName = coreCodegenContext.serviceShape.expectTrait().value - private val serviceShape = coreCodegenContext.serviceShape - private val crateName = coreCodegenContext.moduleUseName() +private class AwsFluentClientDocs(private val codegenContext: CodegenContext) : FluentClientCustomization() { + private val serviceName = codegenContext.serviceShape.expectTrait().value + private val serviceShape = codegenContext.serviceShape + private val crateName = codegenContext.moduleUseName() private val codegenScope = - arrayOf("aws_config" to coreCodegenContext.runtimeConfig.awsConfig().copy(scope = DependencyScope.Dev).asType()) + arrayOf("aws_config" to codegenContext.runtimeConfig.awsConfig().copy(scope = DependencyScope.Dev).asType()) // If no `aws-config` version is provided, assume that docs referencing `aws-config` cannot be given. // Also, STS and SSO must NOT reference `aws-config` since that would create a circular dependency. private fun suppressUsageDocs(): Boolean = - SdkSettings.from(coreCodegenContext.settings).awsConfigVersion == null || + SdkSettings.from(codegenContext.settings).awsConfigVersion == null || setOf( ShapeId.from("com.amazonaws.sts#AWSSecurityTokenServiceV20110615"), ShapeId.from("com.amazonaws.sso#SWBPortalService"), @@ -262,6 +268,7 @@ private class AwsFluentClientDocs(private val coreCodegenContext: CoreCodegenCon ) } } + else -> emptySection } } @@ -274,8 +281,8 @@ private fun renderCustomizableOperationSendMethod( ) { val smithyHttp = CargoDependency.SmithyHttp(runtimeConfig).asType() - val operationGenerics = GenericsGenerator(GenericTypeArg("O"), GenericTypeArg("Retry")) - val handleGenerics = generics.toGenericsGenerator() + val operationGenerics = RustGenerics(GenericTypeArg("O"), GenericTypeArg("Retry")) + val handleGenerics = generics.toRustGenerics() val combinedGenerics = operationGenerics + handleGenerics val codegenScope = arrayOf( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecorator.kt index e077de8bd69..a65cb4fcaef 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecorator.kt @@ -16,29 +16,30 @@ import software.amazon.smithy.model.shapes.ToShapeId import software.amazon.smithy.model.traits.HttpQueryTrait import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.transform.ModelTransformer -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.docs -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientSection -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.errorSymbol -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.MakeOperationGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBoundProtocolPayloadGenerator -import software.amazon.smithy.rust.codegen.client.util.cloneOperation +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.docs +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.errorSymbol +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.MakeOperationGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBoundProtocolPayloadGenerator +import software.amazon.smithy.rust.codegen.core.util.cloneOperation import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rustsdk.AwsRuntimeType.defaultMiddleware @@ -85,7 +86,7 @@ internal val PRESIGNABLE_OPERATIONS by lazy { class AwsPresigningDecorator internal constructor( private val presignableOperations: Map = PRESIGNABLE_OPERATIONS, -) : RustCodegenDecorator { +) : RustCodegenDecorator { companion object { const val ORDER: Byte = 0 } @@ -117,7 +118,7 @@ class AwsPresigningDecorator internal constructor( return presignableTransforms.fold(intermediate) { m, t -> t.transform(m) } } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) private fun addSyntheticOperations(model: Model): Model { @@ -133,11 +134,11 @@ class AwsPresigningDecorator internal constructor( } class AwsInputPresignedMethod( - private val coreCodegenContext: CoreCodegenContext, + private val codegenContext: CodegenContext, private val operationShape: OperationShape, ) : OperationCustomization() { - private val runtimeConfig = coreCodegenContext.runtimeConfig - private val symbolProvider = coreCodegenContext.symbolProvider + private val runtimeConfig = codegenContext.runtimeConfig + private val symbolProvider = codegenContext.symbolProvider private val codegenScope = arrayOf( "Error" to AwsRuntimeType.Presigning.member("config::Error"), @@ -151,18 +152,19 @@ class AwsInputPresignedMethod( "Middleware" to runtimeConfig.defaultMiddleware(), ) - override fun section(section: OperationSection): Writable = writable { - if (section is OperationSection.InputImpl && section.operationShape.hasTrait()) { - writeInputPresignedMethod(section) + override fun section(section: OperationSection): Writable = + writable { + if (section is OperationSection.InputImpl && section.operationShape.hasTrait()) { + writeInputPresignedMethod(section) + } } - } private fun RustWriter.writeInputPresignedMethod(section: OperationSection.InputImpl) { - val operationError = operationShape.errorSymbol(coreCodegenContext.model, symbolProvider, coreCodegenContext.target) + val operationError = operationShape.errorSymbol(codegenContext.model, symbolProvider, codegenContext.target) val presignableOp = PRESIGNABLE_OPERATIONS.getValue(operationShape.id) val makeOperationOp = if (presignableOp.hasModelTransforms()) { - coreCodegenContext.model.expectShape(syntheticShapeId(operationShape.id), OperationShape::class.java) + codegenContext.model.expectShape(syntheticShapeId(operationShape.id), OperationShape::class.java) } else { section.operationShape } @@ -170,9 +172,9 @@ class AwsInputPresignedMethod( val protocol = section.protocol MakeOperationGenerator( - coreCodegenContext, + codegenContext, protocol, - HttpBoundProtocolPayloadGenerator(coreCodegenContext, protocol), + HttpBoundProtocolPayloadGenerator(codegenContext, protocol), // Prefixed with underscore to avoid colliding with modeled functions functionName = makeOperationFn, public = false, @@ -254,29 +256,30 @@ class AwsPresignedFluentBuilderMethod( "SdkError" to CargoDependency.SmithyHttp(runtimeConfig).asType().member("result::SdkError"), ) - override fun section(section: FluentClientSection): Writable = writable { - if (section is FluentClientSection.FluentBuilderImpl && section.operationShape.hasTrait(PresignableTrait::class.java)) { - documentPresignedMethod(hasConfigArg = false) - rustBlockTemplate( - """ + override fun section(section: FluentClientSection): Writable = + writable { + if (section is FluentClientSection.FluentBuilderImpl && section.operationShape.hasTrait(PresignableTrait::class.java)) { + documentPresignedMethod(hasConfigArg = false) + rustBlockTemplate( + """ pub async fn presigned( self, presigning_config: #{PresigningConfig}, ) -> Result<#{PresignedRequest}, #{SdkError}<#{OpError}>> """, - *codegenScope, - "OpError" to section.operationErrorType, - ) { - rustTemplate( - """ + *codegenScope, + "OpError" to section.operationErrorType, + ) { + rustTemplate( + """ let input = self.inner.build().map_err(|err| #{SdkError}::ConstructionFailure(err.into()))?; input.presigned(&self.handle.conf, presigning_config).await """, - *codegenScope, - ) + *codegenScope, + ) + } } } - } } interface PresignModelTransform { diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsReadmeDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsReadmeDecorator.kt index fe1f1db4e58..05175db3d66 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsReadmeDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsReadmeDecorator.kt @@ -9,12 +9,13 @@ import org.jsoup.Jsoup import org.jsoup.nodes.Element import org.jsoup.nodes.TextNode import software.amazon.smithy.model.traits.DocumentationTrait -import software.amazon.smithy.rust.codegen.client.rustlang.raw import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.ManifestCustomizations +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.raw +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.generators.ManifestCustomizations import software.amazon.smithy.rust.codegen.core.util.getTrait import java.util.logging.Logger @@ -26,11 +27,11 @@ private const val SPACE_SIGIL = "[[smithy-rs-nbsp]]" /** * Generates a README.md for each service crate for display on crates.io. */ -class AwsReadmeDecorator : RustCodegenDecorator { +class AwsReadmeDecorator : RustCodegenDecorator { override val name: String = "AwsReadmeDecorator" override val order: Byte = 0 - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) override fun crateManifestCustomizations(codegenContext: ClientCodegenContext): ManifestCustomizations = diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt index a3f9e7170b7..eb87bf56dd6 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsRuntimeDependency.kt @@ -6,12 +6,12 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.codegen.core.CodegenException -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.Visibility -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeCrateLocation -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.crateLocation +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeCrateLocation +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.crateLocation import java.io.File import java.nio.file.Path diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CrateLicenseDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CrateLicenseDecorator.kt index de6f1f8dde4..2f5baf4c0d4 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CrateLicenseDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CrateLicenseDecorator.kt @@ -5,13 +5,14 @@ package software.amazon.smithy.rustsdk -import software.amazon.smithy.rust.codegen.client.rustlang.raw import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.raw +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate -class CrateLicenseDecorator : RustCodegenDecorator { +class CrateLicenseDecorator : RustCodegenDecorator { override val name: String = "CrateLicense" override val order: Byte = 0 @@ -23,6 +24,6 @@ class CrateLicenseDecorator : RustCodegenDecorator { } } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt index 4880a30fe25..47e74d3ad0f 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt @@ -6,24 +6,25 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsSection import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection -class CredentialsProviderDecorator : RustCodegenDecorator { +class CredentialsProviderDecorator : RustCodegenDecorator { override val name: String = "CredentialsProvider" override val order: Byte = 0 @@ -49,7 +50,7 @@ class CredentialsProviderDecorator : RustCodegenDecorator return baseCustomizations + PubUseCredentials(codegenContext.runtimeConfig) } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } @@ -63,18 +64,24 @@ class CredentialProviderConfig(runtimeConfig: RuntimeConfig) : ConfigCustomizati "DefaultProvider" to defaultProvider, ) - override fun section(section: ServiceConfig) = writable { - when (section) { - is ServiceConfig.ConfigStruct -> rustTemplate( - """pub(crate) credentials_provider: #{credentials}::SharedCredentialsProvider,""", - *codegenScope, - ) - is ServiceConfig.ConfigImpl -> emptySection - is ServiceConfig.BuilderStruct -> - rustTemplate("credentials_provider: Option<#{credentials}::SharedCredentialsProvider>,", *codegenScope) - ServiceConfig.BuilderImpl -> { - rustTemplate( - """ + override fun section(section: ServiceConfig) = + writable { + when (section) { + is ServiceConfig.ConfigStruct -> rustTemplate( + """pub(crate) credentials_provider: #{credentials}::SharedCredentialsProvider,""", + *codegenScope, + ) + + is ServiceConfig.ConfigImpl -> emptySection + is ServiceConfig.BuilderStruct -> + rustTemplate( + "credentials_provider: Option<#{credentials}::SharedCredentialsProvider>,", + *codegenScope, + ) + + ServiceConfig.BuilderImpl -> { + rustTemplate( + """ /// Sets the credentials provider for this service pub fn credentials_provider(mut self, credentials_provider: impl #{credentials}::ProvideCredentials + 'static) -> Self { self.credentials_provider = Some(#{credentials}::SharedCredentialsProvider::new(credentials_provider)); @@ -87,15 +94,16 @@ class CredentialProviderConfig(runtimeConfig: RuntimeConfig) : ConfigCustomizati self } """, + *codegenScope, + ) + } + + ServiceConfig.BuilderBuild -> rustTemplate( + "credentials_provider: self.credentials_provider.unwrap_or_else(|| #{credentials}::SharedCredentialsProvider::new(#{DefaultProvider})),", *codegenScope, ) } - ServiceConfig.BuilderBuild -> rustTemplate( - "credentials_provider: self.credentials_provider.unwrap_or_else(|| #{credentials}::SharedCredentialsProvider::new(#{DefaultProvider})),", - *codegenScope, - ) } - } } class CredentialsProviderFeature(private val runtimeConfig: RuntimeConfig) : OperationCustomization() { @@ -109,6 +117,7 @@ class CredentialsProviderFeature(private val runtimeConfig: RuntimeConfig) : Ope setProvider(runtimeConfig), ) } + else -> emptySection } } @@ -117,7 +126,13 @@ class CredentialsProviderFeature(private val runtimeConfig: RuntimeConfig) : Ope class PubUseCredentials(private val runtimeConfig: RuntimeConfig) : LibRsCustomization() { override fun section(section: LibRsSection): Writable { return when (section) { - is LibRsSection.Body -> writable { rust("pub use #T::Credentials;", awsTypes(runtimeConfig).asType()) } + is LibRsSection.Body -> writable { + rust( + "pub use #T::Credentials;", + awsTypes(runtimeConfig).asType(), + ) + } + else -> emptySection } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt index ba21e3bec37..a14c9843cba 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpRequestChecksumDecorator.kt @@ -7,20 +7,21 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.aws.traits.HttpChecksumTrait import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.Visibility -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.operationBuildError +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection +import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError import software.amazon.smithy.rust.codegen.core.util.expectMember import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.inputShape @@ -41,7 +42,7 @@ fun RuntimeConfig.awsInlineableBodyWithChecksum() = RuntimeType.forInlineDepende ), ) -class HttpRequestChecksumDecorator : RustCodegenDecorator { +class HttpRequestChecksumDecorator : RustCodegenDecorator { override val name: String = "HttpRequestChecksum" override val order: Byte = 0 @@ -53,7 +54,7 @@ class HttpRequestChecksumDecorator : RustCodegenDecorator return baseCustomizations + HttpRequestChecksumCustomization(codegenContext, operation) } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumDecorator.kt index ecc83f04291..c695c5c4072 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/HttpResponseChecksumDecorator.kt @@ -8,13 +8,14 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.aws.traits.HttpChecksumTrait import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.util.expectMember import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.inputShape @@ -28,7 +29,7 @@ private fun HttpChecksumTrait.requestValidationModeMember( return operationShape.inputShape(codegenContext.model).expectMember(requestValidationModeMember) } -class HttpResponseChecksumDecorator : RustCodegenDecorator { +class HttpResponseChecksumDecorator : RustCodegenDecorator { override val name: String = "HttpResponseChecksum" override val order: Byte = 0 @@ -40,7 +41,7 @@ class HttpResponseChecksumDecorator : RustCodegenDecorator return baseCustomizations + HttpResponseChecksumCustomization(codegenContext, operation) } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/InlineAwsDependency.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/InlineAwsDependency.kt index 30b3e338319..98c5ab0e993 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/InlineAwsDependency.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/InlineAwsDependency.kt @@ -5,9 +5,9 @@ package software.amazon.smithy.rustsdk -import software.amazon.smithy.rust.codegen.client.rustlang.InlineDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustDependency -import software.amazon.smithy.rust.codegen.client.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.rustlang.InlineDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustDependency +import software.amazon.smithy.rust.codegen.core.rustlang.Visibility object InlineAwsDependency { fun forRustFile(file: String, visibility: Visibility = Visibility.PRIVATE, vararg additionalDependency: RustDependency): InlineDependency = diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt index 4b0c479c21b..76d42c82556 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/IntegrationTestDependencies.kt @@ -5,23 +5,24 @@ package software.amazon.smithy.rustsdk -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency.Companion.BytesUtils -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency.Companion.TempFile -import software.amazon.smithy.rust.codegen.client.rustlang.CratesIo -import software.amazon.smithy.rust.codegen.client.rustlang.DependencyScope -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsSection +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.BytesUtils +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency.Companion.TempFile +import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo +import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection import java.nio.file.Files import java.nio.file.Paths -class IntegrationTestDecorator : RustCodegenDecorator { +class IntegrationTestDecorator : RustCodegenDecorator { override val name: String = "IntegrationTest" override val order: Byte = 0 @@ -51,7 +52,7 @@ class IntegrationTestDecorator : RustCodegenDecorator { } } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } @@ -92,26 +93,28 @@ class IntegrationTestDependencies( } class TranscribeTestDependencies : LibRsCustomization() { - override fun section(section: LibRsSection): Writable = writable { - addDependency(AsyncStream) - addDependency(FuturesCore) - addDependency(Hound) - } + override fun section(section: LibRsSection): Writable = + writable { + addDependency(AsyncStream) + addDependency(FuturesCore) + addDependency(Hound) + } } class S3TestDependencies( private val runtimeConfig: RuntimeConfig, ) : LibRsCustomization() { - override fun section(section: LibRsSection): Writable = writable { - addDependency(AsyncStd) - addDependency(BytesUtils) - addDependency(Smol) - addDependency(TempFile) - runtimeConfig.runtimeCrate("async", scope = DependencyScope.Dev) - runtimeConfig.runtimeCrate("client", scope = DependencyScope.Dev) - runtimeConfig.runtimeCrate("http", scope = DependencyScope.Dev) - runtimeConfig.runtimeCrate("types", scope = DependencyScope.Dev) - } + override fun section(section: LibRsSection): Writable = + writable { + addDependency(AsyncStd) + addDependency(BytesUtils) + addDependency(Smol) + addDependency(TempFile) + runtimeConfig.runtimeCrate("async", scope = DependencyScope.Dev) + runtimeConfig.runtimeCrate("client", scope = DependencyScope.Dev) + runtimeConfig.runtimeCrate("http", scope = DependencyScope.Dev) + runtimeConfig.runtimeCrate("types", scope = DependencyScope.Dev) + } } private val AsyncStd = CargoDependency("async-std", CratesIo("1.12.0"), scope = DependencyScope.Dev) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt index 8c4fa3d33bb..3a6aaf40a66 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt @@ -6,21 +6,22 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsSection import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection /* Example Generated Code */ /* @@ -70,7 +71,7 @@ fn test_1() { } */ -class RegionDecorator : RustCodegenDecorator { +class RegionDecorator : RustCodegenDecorator { override val name: String = "Region" override val order: Byte = 0 @@ -96,23 +97,25 @@ class RegionDecorator : RustCodegenDecorator { return baseCustomizations + PubUseRegion(codegenContext.runtimeConfig) } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } -class RegionProviderConfig(coreCodegenContext: CoreCodegenContext) : ConfigCustomization() { - private val region = region(coreCodegenContext.runtimeConfig) - private val moduleUseName = coreCodegenContext.moduleUseName() +class RegionProviderConfig(codegenContext: CodegenContext) : ConfigCustomization() { + private val region = region(codegenContext.runtimeConfig) + private val moduleUseName = codegenContext.moduleUseName() private val codegenScope = arrayOf("Region" to region.member("Region")) - override fun section(section: ServiceConfig) = writable { - when (section) { - is ServiceConfig.ConfigStruct -> rustTemplate("pub(crate) region: Option<#{Region}>,", *codegenScope) - is ServiceConfig.ConfigImpl -> emptySection - is ServiceConfig.BuilderStruct -> - rustTemplate("region: Option<#{Region}>,", *codegenScope) - ServiceConfig.BuilderImpl -> - rustTemplate( - """ + override fun section(section: ServiceConfig) = + writable { + when (section) { + is ServiceConfig.ConfigStruct -> rustTemplate("pub(crate) region: Option<#{Region}>,", *codegenScope) + is ServiceConfig.ConfigImpl -> emptySection + is ServiceConfig.BuilderStruct -> + rustTemplate("region: Option<#{Region}>,", *codegenScope) + + ServiceConfig.BuilderImpl -> + rustTemplate( + """ /// Sets the AWS region to use when making requests. /// /// ## Examples @@ -129,14 +132,15 @@ class RegionProviderConfig(coreCodegenContext: CoreCodegenContext) : ConfigCusto self } """, + *codegenScope, + ) + + ServiceConfig.BuilderBuild -> rustTemplate( + """region: self.region,""", *codegenScope, ) - ServiceConfig.BuilderBuild -> rustTemplate( - """region: self.region,""", - *codegenScope, - ) + } } - } } class RegionConfigPlugin : OperationCustomization() { @@ -160,7 +164,12 @@ class RegionConfigPlugin : OperationCustomization() { class PubUseRegion(private val runtimeConfig: RuntimeConfig) : LibRsCustomization() { override fun section(section: LibRsSection): Writable { return when (section) { - is LibRsSection.Body -> writable { rust("pub use #T::Region;", region(runtimeConfig)) } + is LibRsSection.Body -> writable { + rust( + "pub use #T::Region;", + region(runtimeConfig), + ) + } else -> emptySection } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RetryClassifierDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RetryClassifierDecorator.kt index 30d3126f406..4d1aa4973d6 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RetryClassifierDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RetryClassifierDecorator.kt @@ -6,18 +6,19 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection -class RetryClassifierDecorator : RustCodegenDecorator { +class RetryClassifierDecorator : RustCodegenDecorator { override val name: String = "RetryPolicy" override val order: Byte = 0 @@ -29,7 +30,7 @@ class RetryClassifierDecorator : RustCodegenDecorator { return baseCustomizations + RetryClassifierFeature(codegenContext.runtimeConfig) } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkConfigDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkConfigDecorator.kt index ee4f37f03dd..4d0489ef675 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkConfigDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkConfigDecorator.kt @@ -5,18 +5,19 @@ package software.amazon.smithy.rustsdk -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate /** * Adds functionality for constructing `::Config` objects from `aws_types::SdkConfig`s @@ -24,7 +25,7 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.config.Servi * - `From<&aws_types::SdkConfig> for ::config::Builder`: Enabling customization * - `pub fn new(&aws_types::SdkConfig) -> ::Config`: Direct construction without customization */ -class SdkConfigDecorator : RustCodegenDecorator { +class SdkConfigDecorator : RustCodegenDecorator { override val name: String = "SdkConfig" override val order: Byte = 0 @@ -68,7 +69,7 @@ class SdkConfigDecorator : RustCodegenDecorator { } } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkSettings.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkSettings.kt index bf62ecb8639..bdae9bf35eb 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkSettings.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkSettings.kt @@ -5,7 +5,7 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.model.node.ObjectNode -import software.amazon.smithy.rust.codegen.client.smithy.CoreRustSettings +import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings import software.amazon.smithy.rust.codegen.core.util.orNull import java.nio.file.Path import java.nio.file.Paths diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/ServiceConfigDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/ServiceConfigDecorator.kt index 5077a8e4bb3..e8729060e8a 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/ServiceConfigDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/ServiceConfigDecorator.kt @@ -5,16 +5,17 @@ package software.amazon.smithy.rustsdk -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.docs -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.docs +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext -class ServiceConfigDecorator : RustCodegenDecorator { +class ServiceConfigDecorator : RustCodegenDecorator { override val name: String = "ServiceConfigGenerator" override val order: Byte = 0 @@ -23,7 +24,7 @@ class ServiceConfigDecorator : RustCodegenDecorator { baseCustomizations: List, ): List = baseCustomizations + SharedConfigDocsCustomization() - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SigV4SigningDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SigV4SigningDecorator.kt index 9f61d1f0683..97b8813bfb9 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SigV4SigningDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SigV4SigningDecorator.kt @@ -13,20 +13,21 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.traits.OptionalAuthTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.EventStreamSigningConfig +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.hasEventStreamOperations @@ -42,11 +43,11 @@ import software.amazon.smithy.rust.codegen.core.util.letIf * - sets a default `OperationSigningConfig` A future enhancement will customize this for specific services that need * different behavior. */ -class SigV4SigningDecorator : RustCodegenDecorator { +class SigV4SigningDecorator : RustCodegenDecorator { override val name: String = "SigV4Signing" override val order: Byte = 0 - private fun applies(coreCodegenContext: CoreCodegenContext): Boolean = coreCodegenContext.serviceShape.hasTrait() + private fun applies(codegenContext: CodegenContext): Boolean = codegenContext.serviceShape.hasTrait() override fun configCustomizations( codegenContext: ClientCodegenContext, @@ -76,7 +77,7 @@ class SigV4SigningDecorator : RustCodegenDecorator { } } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } @@ -179,10 +180,16 @@ class SigV4SigningFeature( // some operations are either unsigned or optionally signed: val authSchemes = serviceIndex.getEffectiveAuthSchemes(service, operation) if (!authSchemes.containsKey(SigV4Trait.ID)) { - rustTemplate("signing_config.signing_requirements = #{sig_auth}::signer::SigningRequirements::Disabled;", *codegenScope) + rustTemplate( + "signing_config.signing_requirements = #{sig_auth}::signer::SigningRequirements::Disabled;", + *codegenScope, + ) } else { if (operation.hasTrait()) { - rustTemplate("signing_config.signing_requirements = #{sig_auth}::signer::SigningRequirements::Optional;", *codegenScope) + rustTemplate( + "signing_config.signing_requirements = #{sig_auth}::signer::SigningRequirements::Optional;", + *codegenScope, + ) } } rustTemplate( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt index c3a1d5feed8..f18c9cd06bd 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/UserAgentDecorator.kt @@ -7,29 +7,30 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.aws.traits.ServiceTrait import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsSection import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.expectTrait /** * Inserts a UserAgent configuration into the operation */ -class UserAgentDecorator : RustCodegenDecorator { +class UserAgentDecorator : RustCodegenDecorator { override val name: String = "UserAgent" override val order: Byte = 10 @@ -57,7 +58,7 @@ class UserAgentDecorator : RustCodegenDecorator { return baseCustomizations + UserAgentFeature(codegenContext.runtimeConfig) } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/apigateway/ApiGatewayDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/apigateway/ApiGatewayDecorator.kt index 449b74b4a08..23d489a5ce4 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/apigateway/ApiGatewayDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/apigateway/ApiGatewayDecorator.kt @@ -7,23 +7,24 @@ package software.amazon.smithy.rustsdk.customize.apigateway import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.util.letIf -class ApiGatewayDecorator : RustCodegenDecorator { +class ApiGatewayDecorator : RustCodegenDecorator { override val name: String = "ApiGateway" override val order: Byte = 0 - private fun applies(coreCodegenContext: CoreCodegenContext) = - coreCodegenContext.serviceShape.id == ShapeId.from("com.amazonaws.apigateway#BackplaneControlService") + private fun applies(codegenContext: CodegenContext) = + codegenContext.serviceShape.id == ShapeId.from("com.amazonaws.apigateway#BackplaneControlService") override fun operationCustomizations( codegenContext: ClientCodegenContext, @@ -35,7 +36,7 @@ class ApiGatewayDecorator : RustCodegenDecorator { } } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/auth/DisabledAuthDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/auth/DisabledAuthDecorator.kt index ced0423b20c..57acccd6a5b 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/auth/DisabledAuthDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/auth/DisabledAuthDecorator.kt @@ -12,13 +12,14 @@ import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.traits.AuthTrait import software.amazon.smithy.model.transform.ModelTransformer import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext private fun String.shapeId() = ShapeId.from(this) // / STS (and possibly other services) need to have auth manually set to [] -class DisabledAuthDecorator : RustCodegenDecorator { +class DisabledAuthDecorator : RustCodegenDecorator { override val name: String = "OptionalAuth" override val order: Byte = 0 @@ -48,6 +49,6 @@ class DisabledAuthDecorator : RustCodegenDecorator { } } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/Ec2Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/Ec2Decorator.kt index c9400a4190f..630ac0af028 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/Ec2Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/ec2/Ec2Decorator.kt @@ -9,11 +9,12 @@ import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.util.letIf -class Ec2Decorator : RustCodegenDecorator { +class Ec2Decorator : RustCodegenDecorator { override val name: String = "Ec2" override val order: Byte = 0 private val ec2 = ShapeId.from("com.amazonaws.ec2#AmazonEC2") @@ -30,6 +31,6 @@ class Ec2Decorator : RustCodegenDecorator { ) } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/AccountIdAutofill.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/AccountIdAutofill.kt index af0460cadd9..a1017425123 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/AccountIdAutofill.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/AccountIdAutofill.kt @@ -7,11 +7,11 @@ package software.amazon.smithy.rustsdk.customize.glacier import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.util.inputShape class AccountIdAutofill() : OperationCustomization() { diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/ApiVersionHeader.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/ApiVersionHeader.kt index 9d29cd826c0..8bc2d3b0610 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/ApiVersionHeader.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/ApiVersionHeader.kt @@ -5,12 +5,12 @@ package software.amazon.smithy.rustsdk.customize.glacier -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.util.dq class ApiVersionHeader( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/GlacierDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/GlacierDecorator.kt index 27ba93680c8..166ca7e3b14 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/GlacierDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/GlacierDecorator.kt @@ -8,17 +8,18 @@ package software.amazon.smithy.rustsdk.customize.glacier import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization val Glacier: ShapeId = ShapeId.from("com.amazonaws.glacier#Glacier") -class GlacierDecorator : RustCodegenDecorator { +class GlacierDecorator : RustCodegenDecorator { override val name: String = "Glacier" override val order: Byte = 0 - private fun applies(coreCodegenContext: CoreCodegenContext) = coreCodegenContext.serviceShape.id == Glacier + private fun applies(codegenContext: CodegenContext) = codegenContext.serviceShape.id == Glacier override fun operationCustomizations( codegenContext: ClientCodegenContext, @@ -38,6 +39,6 @@ class GlacierDecorator : RustCodegenDecorator { return baseCustomizations + extras } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/TreeHashHeader.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/TreeHashHeader.kt index 54a91005502..f762ffe2e40 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/TreeHashHeader.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/TreeHashHeader.kt @@ -7,16 +7,16 @@ package software.amazon.smithy.rustsdk.customize.glacier import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection -import software.amazon.smithy.rust.codegen.client.smithy.generators.operationBuildError import software.amazon.smithy.rust.codegen.client.testutil.TokioWithTestMacros +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection +import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError import software.amazon.smithy.rustsdk.InlineAwsDependency val TreeHashDependencies = listOf( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/route53/Route53Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/route53/Route53Decorator.kt index 4db45856d64..adff13cf80b 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/route53/Route53Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/route53/Route53Decorator.kt @@ -12,15 +12,16 @@ import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.traits.HttpLabelTrait import software.amazon.smithy.model.transform.ModelTransformer -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.letIf @@ -29,7 +30,7 @@ import java.util.logging.Logger val Route53: ShapeId = ShapeId.from("com.amazonaws.route53#AWSDnsV20130401") -class Route53Decorator : RustCodegenDecorator { +class Route53Decorator : RustCodegenDecorator { override val name: String = "Route53" override val order: Byte = 0 private val logger: Logger = Logger.getLogger(javaClass.name) @@ -60,7 +61,7 @@ class Route53Decorator : RustCodegenDecorator { } else baseCustomizations } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) private fun isResourceId(shape: Shape): Boolean { diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt index d64672d96df..e99ef76e54b 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt @@ -13,24 +13,25 @@ import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.transform.ModelTransformer -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsSection -import software.amazon.smithy.rust.codegen.client.smithy.protocols.AllowInvalidXmlRoot -import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolMap +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestXml import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestXmlFactory +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolMap +import software.amazon.smithy.rust.codegen.core.smithy.traits.AllowInvalidXmlRoot import software.amazon.smithy.rust.codegen.core.util.letIf import software.amazon.smithy.rustsdk.AwsRuntimeType import java.util.logging.Logger @@ -38,7 +39,7 @@ import java.util.logging.Logger /** * Top level decorator for S3 */ -class S3Decorator : RustCodegenDecorator { +class S3Decorator : RustCodegenDecorator { override val name: String = "S3" override val order: Byte = 0 private val logger: Logger = Logger.getLogger(javaClass.name) @@ -52,8 +53,8 @@ class S3Decorator : RustCodegenDecorator { override fun protocols( serviceId: ShapeId, - currentProtocols: ProtocolMap, - ): ProtocolMap = + currentProtocols: ProtocolMap, + ): ProtocolMap = currentProtocols.letIf(applies(serviceId)) { it + mapOf( RestXmlTrait.ID to RestXmlFactory { protocolConfig -> @@ -80,7 +81,7 @@ class S3Decorator : RustCodegenDecorator { it + S3PubUse() } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) private fun isInInvalidXmlRootAllowList(shape: Shape): Boolean { @@ -88,8 +89,8 @@ class S3Decorator : RustCodegenDecorator { } } -class S3(coreCodegenContext: CoreCodegenContext) : RestXml(coreCodegenContext) { - private val runtimeConfig = coreCodegenContext.runtimeConfig +class S3(codegenContext: CodegenContext) : RestXml(codegenContext) { + private val runtimeConfig = codegenContext.runtimeConfig private val errorScope = arrayOf( "Bytes" to RuntimeType.Bytes, "Error" to RuntimeType.GenericError(runtimeConfig), @@ -128,7 +129,12 @@ class S3(coreCodegenContext: CoreCodegenContext) : RestXml(coreCodegenContext) { class S3PubUse : LibRsCustomization() { override fun section(section: LibRsSection): Writable = when (section) { - is LibRsSection.Body -> writable { rust("pub use #T::ErrorExt;", AwsRuntimeType.S3Errors) } + is LibRsSection.Body -> writable { + rust( + "pub use #T::ErrorExt;", + AwsRuntimeType.S3Errors, + ) + } else -> emptySection } } diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/sts/STSDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/sts/STSDecorator.kt index d3ef7f8f702..874fd3979e6 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/sts/STSDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/sts/STSDecorator.kt @@ -13,13 +13,14 @@ import software.amazon.smithy.model.traits.ErrorTrait import software.amazon.smithy.model.traits.RetryableTrait import software.amazon.smithy.model.transform.ModelTransformer import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.letIf import java.util.logging.Logger -class STSDecorator : RustCodegenDecorator { +class STSDecorator : RustCodegenDecorator { override val name: String = "STS" override val order: Byte = 0 private val logger: Logger = Logger.getLogger(javaClass.name) @@ -45,6 +46,6 @@ class STSDecorator : RustCodegenDecorator { } } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt index 3489bc7c940..11dd45f2bb1 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt @@ -7,23 +7,24 @@ package software.amazon.smithy.rustsdk import org.junit.jupiter.api.Test import software.amazon.smithy.model.node.ObjectNode -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.CodegenVisitor -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate import software.amazon.smithy.rust.codegen.client.smithy.customizations.AllowLintsGenerator import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCustomizations import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.client.testutil.stubConfigCustomization import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization import software.amazon.smithy.rust.codegen.core.util.runCommand internal class EndpointConfigCustomizationTest { @@ -127,7 +128,7 @@ internal class EndpointConfigCustomizationTest { private fun validateEndpointCustomizationForService(service: String, test: ((RustCrate) -> Unit)? = null) { val (context, testDir) = generatePluginContext(model, service = service, runtimeConfig = AwsTestRuntimeConfig) - val codegenDecorator = object : RustCodegenDecorator { + val codegenDecorator = object : RustCodegenDecorator { override val name: String = "tests and config" override val order: Byte = 0 override fun configCustomizations( @@ -151,7 +152,7 @@ internal class EndpointConfigCustomizationTest { } } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } val customization = CombinedCodegenDecorator(listOf(RequiredCustomizations(), codegenDecorator)) diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/RegionProviderConfigTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/RegionProviderConfigTest.kt index 86a35f1a35d..c71ddb63834 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/RegionProviderConfigTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/RegionProviderConfigTest.kt @@ -6,10 +6,10 @@ package software.amazon.smithy.rustsdk import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.smithy.CoreRustSettings import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.rustSettings import software.amazon.smithy.rust.codegen.client.testutil.validateConfigCustomizations +import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings internal class RegionProviderConfigTest { @Test diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt index c80a0cff3b6..61d6558a1c4 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt @@ -6,12 +6,12 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.model.Model -import software.amazon.smithy.rust.codegen.client.smithy.CoreRustSettings -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeCrateLocation import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext import software.amazon.smithy.rust.codegen.client.testutil.testRustSettings +import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeCrateLocation import java.io.File // In aws-sdk-codegen, the working dir when gradle runs tests is actually `./aws`. So, to find the smithy runtime, we need diff --git a/codegen-client/build.gradle.kts b/codegen-client/build.gradle.kts index 10aedcab238..a836fd9100c 100644 --- a/codegen-client/build.gradle.kts +++ b/codegen-client/build.gradle.kts @@ -25,9 +25,7 @@ val kotestVersion: String by project dependencies { implementation(project(":codegen-core")) implementation(kotlin("stdlib-jdk8")) - implementation("org.jsoup:jsoup:1.14.3") api("software.amazon.smithy:smithy-codegen-core:$smithyVersion") - api("com.moandjiezana.toml:toml4j:0.7.2") implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion") implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion") implementation("software.amazon.smithy:smithy-waiters:$smithyVersion") diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenContext.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenContext.kt index 1464a2e6006..03eeeb24a0f 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenContext.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientCodegenContext.kt @@ -8,13 +8,15 @@ package software.amazon.smithy.rust.codegen.client.smithy import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider /** * [ClientCodegenContext] contains code-generation context that is _specific_ to the [RustCodegenPlugin] plugin * from the `rust-codegen` subproject. * - * It inherits from [CoreCodegenContext], which contains code-generation context that is common to _all_ smithy-rs plugins. + * It inherits from [CodegenContext], which contains code-generation context that is common to _all_ smithy-rs plugins. */ data class ClientCodegenContext( override val model: Model, @@ -22,6 +24,6 @@ data class ClientCodegenContext( override val serviceShape: ServiceShape, override val protocol: ShapeId, override val settings: ClientRustSettings, -) : CoreCodegenContext( +) : CodegenContext( model, symbolProvider, serviceShape, protocol, settings, CodegenTarget.CLIENT, ) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustSettings.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustSettings.kt index 252422dc5cb..6450c9a71fa 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustSettings.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ClientRustSettings.kt @@ -8,6 +8,10 @@ package software.amazon.smithy.rust.codegen.client.smithy import software.amazon.smithy.model.Model import software.amazon.smithy.model.node.ObjectNode import software.amazon.smithy.model.shapes.ShapeId +import software.amazon.smithy.rust.codegen.core.smithy.CODEGEN_SETTINGS +import software.amazon.smithy.rust.codegen.core.smithy.CoreCodegenConfig +import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.util.orNull import java.util.Optional diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt index 87f1974fee8..0e66b6ba3d7 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt @@ -18,21 +18,25 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.transform.ModelTransformer import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.BuilderGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.EnumGenerator import software.amazon.smithy.rust.codegen.client.smithy.generators.ServiceGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.StructureGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.implBlock -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolGeneratorFactory -import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolLoader +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.client.smithy.protocols.ClientProtocolLoader import software.amazon.smithy.rust.codegen.client.smithy.transformers.AddErrorMessage -import software.amazon.smithy.rust.codegen.client.smithy.transformers.EventStreamNormalizer -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer -import software.amazon.smithy.rust.codegen.client.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.client.smithy.transformers.RemoveEventStreamOperations +import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait +import software.amazon.smithy.rust.codegen.core.smithy.transformers.EventStreamNormalizer +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.core.util.CommandFailed import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait @@ -43,8 +47,10 @@ import java.util.logging.Logger /** * Base Entrypoint for Code generation */ -class CodegenVisitor(context: PluginContext, private val codegenDecorator: RustCodegenDecorator) : - ShapeVisitor.Default() { +class CodegenVisitor( + context: PluginContext, + private val codegenDecorator: RustCodegenDecorator, +) : ShapeVisitor.Default() { private val logger = Logger.getLogger(javaClass.name) private val settings = ClientRustSettings.from(context.model, context.settings) @@ -54,8 +60,8 @@ class CodegenVisitor(context: PluginContext, private val codegenDecorator: RustC private val fileManifest = context.fileManifest private val model: Model private val codegenContext: ClientCodegenContext - private val protocolGeneratorFactory: ProtocolGeneratorFactory - private val protocolGenerator: ProtocolGenerator + private val protocolGeneratorFactory: ProtocolGeneratorFactory + private val protocolGenerator: ClientProtocolGenerator init { val symbolVisitorConfig = @@ -67,8 +73,8 @@ class CodegenVisitor(context: PluginContext, private val codegenDecorator: RustC ) val baseModel = baselineTransform(context.model) val service = settings.getService(baseModel) - val (protocol, generator) = ProtocolLoader( - codegenDecorator.protocols(service.id, ProtocolLoader.DefaultProtocols), + val (protocol, generator) = ClientProtocolLoader( + codegenDecorator.protocols(service.id, ClientProtocolLoader.DefaultProtocols), ).protocolFor(context.model, service) protocolGeneratorFactory = generator model = codegenDecorator.transformModel(service, baseModel) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProvider.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProvider.kt index 2f9d42819d3..6802d444c4d 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProvider.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProvider.kt @@ -10,15 +10,20 @@ import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.Shape -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.render -import software.amazon.smithy.rust.codegen.client.rustlang.stripOuter -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.eventStreamErrorSymbol -import software.amazon.smithy.rust.codegen.client.smithy.transformers.eventStreamErrors +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.render +import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.WrappingSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.eventStreamErrorSymbol +import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticOutputTrait +import software.amazon.smithy.rust.codegen.core.smithy.transformers.eventStreamErrors import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.isEventStream import software.amazon.smithy.rust.codegen.core.util.isInputEventStream diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustCodegenPlugin.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustCodegenPlugin.kt index 66c4061f0ca..9a30b3cafe5 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustCodegenPlugin.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustCodegenPlugin.kt @@ -10,14 +10,17 @@ import software.amazon.smithy.build.SmithyBuildPlugin import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute.Companion.NonExhaustive -import software.amazon.smithy.rust.codegen.client.rustlang.RustReservedWordSymbolProvider import software.amazon.smithy.rust.codegen.client.smithy.customizations.ClientCustomizations import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.NoOpEventStreamSigningDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCustomizations -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientDecorator +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute.Companion.NonExhaustive +import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.BaseSymbolMetadataProvider +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig import java.util.logging.Level import java.util.logging.Logger diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ServerCodegenContext.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ServerCodegenContext.kt index 0ca4dae06cc..ffa48f68fde 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ServerCodegenContext.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ServerCodegenContext.kt @@ -8,13 +8,15 @@ package software.amazon.smithy.rust.codegen.client.smithy import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider /** * [ServerCodegenContext] contains code-generation context that is _specific_ to the [RustCodegenServerPlugin] plugin * from the `rust-codegen-server` subproject. * - * It inherits from [CoreCodegenContext], which contains code-generation context that is common to _all_ smithy-rs plugins. + * It inherits from [CodegenContext], which contains code-generation context that is common to _all_ smithy-rs plugins. * * This class has to live in the `codegen` subproject because it is referenced in common generators to both client * and server (like [JsonParserGenerator]). @@ -25,6 +27,6 @@ data class ServerCodegenContext( override val serviceShape: ServiceShape, override val protocol: ShapeId, override val settings: ServerRustSettings, -) : CoreCodegenContext( +) : CodegenContext( model, symbolProvider, serviceShape, protocol, settings, CodegenTarget.SERVER, ) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ServerRustSettings.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ServerRustSettings.kt index 3b8791db2bf..69404e96183 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ServerRustSettings.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ServerRustSettings.kt @@ -8,6 +8,10 @@ package software.amazon.smithy.rust.codegen.client.smithy import software.amazon.smithy.model.Model import software.amazon.smithy.model.node.ObjectNode import software.amazon.smithy.model.shapes.ShapeId +import software.amazon.smithy.rust.codegen.core.smithy.CODEGEN_SETTINGS +import software.amazon.smithy.rust.codegen.core.smithy.CoreCodegenConfig +import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import java.util.Optional /** diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/StreamingTraitSymbolProvider.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/StreamingTraitSymbolProvider.kt index 88e1ba9511d..cd362acccf5 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/StreamingTraitSymbolProvider.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/StreamingTraitSymbolProvider.kt @@ -13,7 +13,14 @@ import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustMetadata +import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata +import software.amazon.smithy.rust.codegen.core.smithy.Default +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.SymbolMetadataProvider +import software.amazon.smithy.rust.codegen.core.smithy.WrappingSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.expectRustMetadata +import software.amazon.smithy.rust.codegen.core.smithy.setDefault import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticOutputTrait import software.amazon.smithy.rust.codegen.core.util.hasStreamingMember diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/AllowLintsGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/AllowLintsGenerator.kt index 752f90100aa..f96b21336ec 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/AllowLintsGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/AllowLintsGenerator.kt @@ -5,10 +5,10 @@ package software.amazon.smithy.rust.codegen.client.smithy.customizations -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsSection +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection val AllowedRustcLints = listOf( // Deprecated items should be safe to compile, so don't block the compilation. diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientCustomizations.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientCustomizations.kt index 3037e97adf2..6ff57e85abe 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientCustomizations.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientCustomizations.kt @@ -6,14 +6,15 @@ package software.amazon.smithy.rust.codegen.client.smithy.customizations import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization /** * Customizations that apply only to generated clients. */ -class ClientCustomizations : RustCodegenDecorator { +class ClientCustomizations : RustCodegenDecorator { override val name: String = "ClientCustomizations" override val order: Byte = 0 @@ -22,6 +23,6 @@ class ClientCustomizations : RustCodegenDecorator { baseCustomizations: List, ): List = baseCustomizations + ClientDocsGenerator() - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientDocsGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientDocsGenerator.kt index 9a2503c520a..adfb3b87219 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientDocsGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ClientDocsGenerator.kt @@ -5,11 +5,11 @@ package software.amazon.smithy.rust.codegen.client.smithy.customizations -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.containerDocs -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsSection +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.containerDocs +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection class ClientDocsGenerator : LibRsCustomization() { override fun section(section: LibRsSection): Writable { @@ -21,9 +21,10 @@ class ClientDocsGenerator : LibRsCustomization() { } } - private fun crateLayout(): Writable = writable { - containerDocs( - """ + private fun crateLayout(): Writable = + writable { + containerDocs( + """ The entry point for most customers will be [`Client`]. [`Client`] exposes one method for each API offered by the service. @@ -34,6 +35,6 @@ class ClientDocsGenerator : LibRsCustomization() { The other modules within this crate are not required for normal usage. """.trimEnd(), - ) - } + ) + } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/CrateVersionGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/CrateVersionGenerator.kt index 3de97eed5ce..d3b350ed025 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/CrateVersionGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/CrateVersionGenerator.kt @@ -5,23 +5,24 @@ package software.amazon.smithy.rust.codegen.client.smithy.customizations -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsSection +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection /** * Add `PGK_VERSION` const in lib.rs to enable knowing the version of the current module */ class CrateVersionGenerator : LibRsCustomization() { - override fun section(section: LibRsSection) = writable { - if (section is LibRsSection.Body) { - rust( - """ - /// Crate version number. - pub static PKG_VERSION: &str = env!("CARGO_PKG_VERSION"); - """, - ) + override fun section(section: LibRsSection) = + writable { + if (section is LibRsSection.Body) { + rust( + """ + /// Crate version number. + pub static PKG_VERSION: &str = env!("CARGO_PKG_VERSION"); + """, + ) + } } - } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/DocsRsMetadataDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/DocsRsMetadataDecorator.kt index 309784c7306..7809ccffbd7 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/DocsRsMetadataDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/DocsRsMetadataDecorator.kt @@ -6,9 +6,10 @@ package software.amazon.smithy.rust.codegen.client.smithy.customizations import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.ManifestCustomizations +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.generators.ManifestCustomizations /** * See https://docs.rs/about/metadata for more information @@ -50,7 +51,7 @@ fun DocsRsMetadataSettings.asMap(): Map { * This decorator is not used by default, code generators must manually configure and include it in their builds. */ class DocsRsMetadataDecorator(private val docsRsMetadataSettings: DocsRsMetadataSettings) : - RustCodegenDecorator { + RustCodegenDecorator { override val name: String = "docsrs-metadata" override val order: Byte = 0 @@ -58,6 +59,6 @@ class DocsRsMetadataDecorator(private val docsRsMetadataSettings: DocsRsMetadata return docsRsMetadataSettings.asMap() } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/EndpointPrefixGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/EndpointPrefixGenerator.kt index 892aba0505e..110ca580c6f 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/EndpointPrefixGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/EndpointPrefixGenerator.kt @@ -7,24 +7,24 @@ package software.amazon.smithy.rust.codegen.client.smithy.customizations import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.EndpointTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.client.smithy.generators.EndpointTraitBindings +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection -class EndpointPrefixGenerator(private val coreCodegenContext: CoreCodegenContext, private val shape: OperationShape) : +class EndpointPrefixGenerator(private val codegenContext: CodegenContext, private val shape: OperationShape) : OperationCustomization() { override fun section(section: OperationSection): Writable = when (section) { is OperationSection.MutateRequest -> writable { shape.getTrait(EndpointTrait::class.java).map { epTrait -> val endpointTraitBindings = EndpointTraitBindings( - coreCodegenContext.model, - coreCodegenContext.symbolProvider, - coreCodegenContext.runtimeConfig, + codegenContext.model, + codegenContext.symbolProvider, + codegenContext.runtimeConfig, shape, epTrait, ) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpChecksumRequiredGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpChecksumRequiredGenerator.kt index 5a3ee39e58c..75feb396f0a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpChecksumRequiredGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpChecksumRequiredGenerator.kt @@ -8,29 +8,29 @@ package software.amazon.smithy.rust.codegen.client.smithy.customizations import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.HttpChecksumRequiredTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection -import software.amazon.smithy.rust.codegen.client.smithy.generators.operationBuildError +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection +import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError import software.amazon.smithy.rust.codegen.core.util.hasStreamingMember import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.inputShape class HttpChecksumRequiredGenerator( - private val coreCodegenContext: CoreCodegenContext, + private val codegenContext: CodegenContext, private val operationShape: OperationShape, ) : OperationCustomization() { override fun section(section: OperationSection): Writable { if (!operationShape.hasTrait()) { return emptySection } - if (operationShape.inputShape(coreCodegenContext.model).hasStreamingMember(coreCodegenContext.model)) { + if (operationShape.inputShape(codegenContext.model).hasStreamingMember(codegenContext.model)) { throw CodegenException("HttpChecksum required cannot be applied to a streaming shape") } return when (section) { @@ -52,8 +52,8 @@ class HttpChecksumRequiredGenerator( """, "md5" to CargoDependency.Md5.asType(), "http" to CargoDependency.Http.asType(), - "base64_encode" to RuntimeType.Base64Encode(coreCodegenContext.runtimeConfig), - "BuildError" to coreCodegenContext.runtimeConfig.operationBuildError(), + "base64_encode" to RuntimeType.Base64Encode(codegenContext.runtimeConfig), + "BuildError" to codegenContext.runtimeConfig.operationBuildError(), ) } else -> emptySection diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpVersionListCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpVersionListCustomization.kt index ff2c1079f9b..8550adcefad 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpVersionListCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/HttpVersionListCustomization.kt @@ -7,14 +7,14 @@ package software.amazon.smithy.rust.codegen.client.smithy.customizations import software.amazon.smithy.aws.traits.protocols.AwsProtocolTrait import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.isEventStream @@ -24,19 +24,19 @@ private fun RuntimeConfig.defaultHttpVersionList(): RuntimeType = this.httpVersionModule().member("DEFAULT_HTTP_VERSION_LIST") class HttpVersionListCustomization( - private val coreCodegenContext: CoreCodegenContext, + private val codegenContext: CodegenContext, private val operationShape: OperationShape, ) : OperationCustomization() { - private val defaultHttpVersions = coreCodegenContext.runtimeConfig.defaultHttpVersionList().fullyQualifiedName() + private val defaultHttpVersions = codegenContext.runtimeConfig.defaultHttpVersionList().fullyQualifiedName() override fun section(section: OperationSection): Writable { - val awsProtocolTrait = coreCodegenContext.serviceShape.getTrait() + val awsProtocolTrait = codegenContext.serviceShape.getTrait() val supportedHttpProtocolVersions = if (awsProtocolTrait == null) { // No protocol trait was defined, use default http versions "$defaultHttpVersions.clone()" } else { // Figure out whether we're dealing with an EventStream operation and fetch the corresponding list of desired HTTP versions - val versionList = if (operationShape.isEventStream(coreCodegenContext.model)) awsProtocolTrait.eventStreamHttp else awsProtocolTrait.http + val versionList = if (operationShape.isEventStream(codegenContext.model)) awsProtocolTrait.eventStreamHttp else awsProtocolTrait.http if (versionList.isEmpty()) { // If no desired versions are specified, go with the default "$defaultHttpVersions.clone()" diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/IdempotencyTokenGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/IdempotencyTokenGenerator.kt index d0bc823a748..049b92a25d4 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/IdempotencyTokenGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/IdempotencyTokenGenerator.kt @@ -7,19 +7,19 @@ package software.amazon.smithy.rust.codegen.client.smithy.customizations import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.IdempotencyTokenTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.util.findMemberWithTrait import software.amazon.smithy.rust.codegen.core.util.inputShape -class IdempotencyTokenGenerator(coreCodegenContext: CoreCodegenContext, private val operationShape: OperationShape) : +class IdempotencyTokenGenerator(codegenContext: CodegenContext, private val operationShape: OperationShape) : OperationCustomization() { - private val model = coreCodegenContext.model - private val symbolProvider = coreCodegenContext.symbolProvider + private val model = codegenContext.model + private val symbolProvider = codegenContext.symbolProvider private val idempotencyTokenMember = operationShape.inputShape(model).findMemberWithTrait(model) override fun section(section: OperationSection): Writable { if (idempotencyTokenMember == null) { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt index bb4e5f88d65..aeaa693f5df 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt @@ -5,21 +5,21 @@ package software.amazon.smithy.rust.codegen.client.smithy.customizations -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate -class ResiliencyConfigCustomization(coreCodegenContext: CoreCodegenContext) : ConfigCustomization() { - private val retryConfig = smithyTypesRetry(coreCodegenContext.runtimeConfig) - private val sleepModule = smithyAsyncRtSleep(coreCodegenContext.runtimeConfig) - private val timeoutModule = smithyTypesTimeout(coreCodegenContext.runtimeConfig) - private val moduleUseName = coreCodegenContext.moduleUseName() +class ResiliencyConfigCustomization(codegenContext: CodegenContext) : ConfigCustomization() { + private val retryConfig = smithyTypesRetry(codegenContext.runtimeConfig) + private val sleepModule = smithyAsyncRtSleep(codegenContext.runtimeConfig) + private val timeoutModule = smithyTypesTimeout(codegenContext.runtimeConfig) + private val moduleUseName = codegenContext.moduleUseName() private val codegenScope = arrayOf( "AsyncSleep" to sleepModule.member("AsyncSleep"), "RetryConfig" to retryConfig.member("RetryConfig"), @@ -27,19 +27,21 @@ class ResiliencyConfigCustomization(coreCodegenContext: CoreCodegenContext) : Co "TimeoutConfig" to timeoutModule.member("TimeoutConfig"), ) - override fun section(section: ServiceConfig) = writable { - when (section) { - is ServiceConfig.ConfigStruct -> rustTemplate( - """ + override fun section(section: ServiceConfig) = + writable { + when (section) { + is ServiceConfig.ConfigStruct -> rustTemplate( + """ retry_config: Option<#{RetryConfig}>, sleep_impl: Option>, timeout_config: Option<#{TimeoutConfig}>, """, - *codegenScope, - ) - is ServiceConfig.ConfigImpl -> { - rustTemplate( - """ + *codegenScope, + ) + + is ServiceConfig.ConfigImpl -> { + rustTemplate( + """ /// Return a reference to the retry configuration contained in this config, if any. pub fn retry_config(&self) -> Option<&#{RetryConfig}> { self.retry_config.as_ref() @@ -55,21 +57,23 @@ class ResiliencyConfigCustomization(coreCodegenContext: CoreCodegenContext) : Co self.timeout_config.as_ref() } """, - *codegenScope, - ) - } - is ServiceConfig.BuilderStruct -> - rustTemplate( - """ + *codegenScope, + ) + } + + is ServiceConfig.BuilderStruct -> + rustTemplate( + """ retry_config: Option<#{RetryConfig}>, sleep_impl: Option>, timeout_config: Option<#{TimeoutConfig}>, """, - *codegenScope, - ) - ServiceConfig.BuilderImpl -> - rustTemplate( - """ + *codegenScope, + ) + + ServiceConfig.BuilderImpl -> + rustTemplate( + """ /// Set the retry_config for the builder /// /// ## Examples @@ -204,19 +208,21 @@ class ResiliencyConfigCustomization(coreCodegenContext: CoreCodegenContext) : Co self } """, - *codegenScope, - ) - ServiceConfig.BuilderBuild -> rustTemplate( - """ + *codegenScope, + ) + + ServiceConfig.BuilderBuild -> rustTemplate( + """ retry_config: self.retry_config, sleep_impl: self.sleep_impl, timeout_config: self.timeout_config, """, - *codegenScope, - ) - else -> emptySection + *codegenScope, + ) + + else -> emptySection + } } - } } class ResiliencyReExportCustomization(private val runtimeConfig: RuntimeConfig) { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/SmithyTypesPubUseGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/SmithyTypesPubUseGenerator.kt index 94aa834566d..f605e3a7124 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/SmithyTypesPubUseGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/SmithyTypesPubUseGenerator.kt @@ -7,16 +7,16 @@ package software.amazon.smithy.rust.codegen.client.smithy.customizations import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.docs -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsSection +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.docs +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection import software.amazon.smithy.rust.codegen.core.util.hasEventStreamMember import software.amazon.smithy.rust.codegen.core.util.hasStreamingMember @@ -70,19 +70,21 @@ internal fun pubUseTypes(runtimeConfig: RuntimeConfig, model: Model): List { - val types = pubUseTypes(runtimeConfig, section.model) - if (types.isNotEmpty()) { - docs("Re-exported types from supporting crates.") - rustBlock("pub mod types") { - types.forEach { type -> rust("pub use #T;", type) } + override fun section(section: LibRsSection) = + writable { + when (section) { + is LibRsSection.Body -> { + val types = pubUseTypes(runtimeConfig, section.model) + if (types.isNotEmpty()) { + docs("Re-exported types from supporting crates.") + rustBlock("pub mod types") { + types.forEach { type -> rust("pub use #T;", type) } + } } } - } - else -> { + + else -> { + } } } - } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt index b6280b75034..f4cfce3898c 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NoOpEventStreamSigningDecorator.kt @@ -5,25 +5,25 @@ package software.amazon.smithy.rust.codegen.client.smithy.customize -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.EventStreamSigningConfig +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.util.hasEventStreamOperations /** * The NoOpEventStreamSigningDecorator: * - adds a `new_event_stream_signer()` method to `config` to create an Event Stream NoOp signer */ -open class NoOpEventStreamSigningDecorator : RustCodegenDecorator { +open class NoOpEventStreamSigningDecorator : RustCodegenDecorator { override val name: String = "NoOpEventStreamSigning" override val order: Byte = Byte.MIN_VALUE - private fun applies(codegenContext: CoreCodegenContext, baseCustomizations: List): Boolean = + private fun applies(codegenContext: CodegenContext, baseCustomizations: List): Boolean = codegenContext.serviceShape.hasEventStreamOperations(codegenContext.model) && // and if there is no other `EventStreamSigningConfig`, apply this one !baseCustomizations.any { it is EventStreamSigningConfig } @@ -41,7 +41,7 @@ open class NoOpEventStreamSigningDecorator : RustCodegen ) } - override fun supportsCodegenContext(clazz: Class) = true + override fun supportsCodegenContext(clazz: Class) = true } class NoOpEventStreamSigningConfig( diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RequiredCustomizations.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RequiredCustomizations.kt index d792847b9aa..3ae662bfcde 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RequiredCustomizations.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RequiredCustomizations.kt @@ -6,10 +6,7 @@ package software.amazon.smithy.rust.codegen.client.smithy.customize import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.Feature import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate import software.amazon.smithy.rust.codegen.client.smithy.customizations.AllowLintsGenerator import software.amazon.smithy.rust.codegen.client.smithy.customizations.CrateVersionGenerator import software.amazon.smithy.rust.codegen.client.smithy.customizations.EndpointPrefixGenerator @@ -19,15 +16,20 @@ import software.amazon.smithy.rust.codegen.client.smithy.customizations.Idempote import software.amazon.smithy.rust.codegen.client.smithy.customizations.ResiliencyConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.customizations.ResiliencyReExportCustomization import software.amazon.smithy.rust.codegen.client.smithy.customizations.SmithyTypesPubUseGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.Feature +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization /** * A set of customizations that are included in all protocols. * * This exists as a convenient place to gather these modifications, these are not true customizations. */ -class RequiredCustomizations : RustCodegenDecorator { +class RequiredCustomizations : RustCodegenDecorator { override val name: String = "Required" override val order: Byte = -1 @@ -64,6 +66,6 @@ class RequiredCustomizations : RustCodegenDecorator { ResiliencyReExportCustomization(codegenContext.runtimeConfig).extras(rustCrate) } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt index edb96225cff..2b22ed040b4 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt @@ -10,12 +10,13 @@ import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.ManifestCustomizations import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization -import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolMap +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.ManifestCustomizations +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolMap import software.amazon.smithy.rust.codegen.core.util.deepMergeWith import java.util.ServiceLoader import java.util.logging.Logger @@ -27,7 +28,7 @@ import java.util.logging.Logger * AWS services. A different downstream customer may wish to add a different set of derive * attributes to the generated classes. */ -interface RustCodegenDecorator { +interface RustCodegenDecorator { /** * The name of this [RustCodegenDecorator], used for logging and debug information */ @@ -64,12 +65,12 @@ interface RustCodegenDecorator { fun extras(codegenContext: C, rustCrate: RustCrate) {} - fun protocols(serviceId: ShapeId, currentProtocols: ProtocolMap): ProtocolMap = + fun protocols(serviceId: ShapeId, currentProtocols: ProtocolMap): ProtocolMap = currentProtocols fun transformModel(service: ServiceShape, model: Model): Model = model - fun supportsCodegenContext(clazz: Class): Boolean + fun supportsCodegenContext(clazz: Class): Boolean } /** @@ -77,21 +78,21 @@ interface RustCodegenDecorator { * * This makes the actual concrete codegen simpler by not needing to deal with multiple separate decorators. */ -open class CombinedCodegenDecorator(decorators: List>) : - RustCodegenDecorator { +open class CombinedCodegenDecorator(decorators: List>) : + RustCodegenDecorator { private val orderedDecorators = decorators.sortedBy { it.order } override val name: String get() = "MetaDecorator" override val order: Byte get() = 0 - fun withDecorator(decorator: RustCodegenDecorator) = CombinedCodegenDecorator(orderedDecorators + decorator) + fun withDecorator(decorator: RustCodegenDecorator) = CombinedCodegenDecorator(orderedDecorators + decorator) override fun configCustomizations( codegenContext: C, baseCustomizations: List, ): List { - return orderedDecorators.foldRight(baseCustomizations) { decorator: RustCodegenDecorator, customizations -> + return orderedDecorators.foldRight(baseCustomizations) { decorator: RustCodegenDecorator, customizations -> decorator.configCustomizations(codegenContext, customizations) } } @@ -101,7 +102,7 @@ open class CombinedCodegenDecorator(decorators: List, ): List { - return orderedDecorators.foldRight(baseCustomizations) { decorator: RustCodegenDecorator, customizations -> + return orderedDecorators.foldRight(baseCustomizations) { decorator: RustCodegenDecorator, customizations -> decorator.operationCustomizations(codegenContext, operation, customizations) } } @@ -118,7 +119,7 @@ open class CombinedCodegenDecorator(decorators: List): ProtocolMap { + override fun protocols(serviceId: ShapeId, currentProtocols: ProtocolMap): ProtocolMap { return orderedDecorators.foldRight(currentProtocols) { decorator, protocolMap -> decorator.protocols(serviceId, protocolMap) } @@ -140,22 +141,22 @@ open class CombinedCodegenDecorator(decorators: List): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = // `CombinedCodegenDecorator` can work with all types of codegen context. - CoreCodegenContext::class.java.isAssignableFrom(clazz) + CodegenContext::class.java.isAssignableFrom(clazz) companion object { - inline fun fromClasspath( + inline fun fromClasspath( context: PluginContext, - vararg extras: RustCodegenDecorator, + vararg extras: RustCodegenDecorator, logger: Logger = Logger.getLogger("RustCodegenSPILoader"), - ): CombinedCodegenDecorator { + ): CombinedCodegenDecorator { val decorators = ServiceLoader.load( RustCodegenDecorator::class.java, context.pluginClassLoader.orElse(RustCodegenDecorator::class.java.classLoader), ) - val filteredDecorators = filterDecorators(decorators, logger).toList() + val filteredDecorators = filterDecorators(decorators, logger).toList() return CombinedCodegenDecorator(filteredDecorators + extras) } @@ -165,10 +166,10 @@ open class CombinedCodegenDecorator(decorators: List filterDecorators( - decorators: Iterable>, + inline fun filterDecorators( + decorators: Iterable>, logger: Logger = Logger.getLogger("RustCodegenSPILoader"), - ): Sequence> = + ): Sequence> = decorators.asSequence() .onEach { logger.info("Discovered Codegen Decorator: ${it.javaClass.name}") @@ -183,7 +184,7 @@ open class CombinedCodegenDecorator(decorators: List(decorators: List + it as RustCodegenDecorator } } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt index 0742725435e..ad97f369ab4 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt @@ -8,16 +8,17 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.EndpointTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.generators.http.rustFormatString -import software.amazon.smithy.rust.codegen.client.smithy.isOptional +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.generators.OperationBuildError +import software.amazon.smithy.rust.codegen.core.smithy.generators.http.rustFormatString +import software.amazon.smithy.rust.codegen.core.smithy.isOptional import software.amazon.smithy.rust.codegen.core.util.inputShape fun EndpointTrait.prefixFormatString(): String { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/NestedAccessorGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/NestedAccessorGenerator.kt index 0c6b8897890..d0fabc932a0 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/NestedAccessorGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/NestedAccessorGenerator.kt @@ -7,20 +7,20 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustMetadata -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.Visibility -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.isOptional -import software.amazon.smithy.rust.codegen.client.smithy.makeOptional -import software.amazon.smithy.rust.codegen.client.smithy.mapRustType -import software.amazon.smithy.rust.codegen.client.smithy.protocols.lensName +import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.isOptional +import software.amazon.smithy.rust.codegen.core.smithy.makeOptional +import software.amazon.smithy.rust.codegen.core.smithy.mapRustType +import software.amazon.smithy.rust.codegen.core.smithy.protocols.lensName /** Generator for accessing nested fields through optional values **/ class NestedAccessorGenerator(private val symbolProvider: RustSymbolProvider) { @@ -65,26 +65,31 @@ class NestedAccessorGenerator(private val symbolProvider: RustSymbolProvider) { } } - private fun generateBody(path: List, reference: Boolean): Writable = writable { - val ref = if (reference) { "&" } else { "" } - if (path.isEmpty()) { - rust("Some(input)") - } else { - val head = path.first() - if (symbolProvider.toSymbol(head).isOptional()) { - rust( - """ + private fun generateBody(path: List, reference: Boolean): Writable = + writable { + val ref = if (reference) { + "&" + } else { + "" + } + if (path.isEmpty()) { + rust("Some(input)") + } else { + val head = path.first() + if (symbolProvider.toSymbol(head).isOptional()) { + rust( + """ let input = match ${ref}input.${symbolProvider.toMemberName(head)} { None => return None, Some(t) => t }; """, - ) - } else { - rust("let input = input.${symbolProvider.toMemberName(head)};") + ) + } else { + rust("let input = input.${symbolProvider.toMemberName(head)};") + } + // Note: although _this_ function is recursive, it generates a series of `if let` statements with early returns. + generateBody(path.drop(1), reference)(this) } - // Note: although _this_ function is recursive, it generates a series of `if let` statements with early returns. - generateBody(path.drop(1), reference)(this) } - } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt index b0ae7339930..8e3df9d58fe 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt @@ -11,24 +11,26 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.traits.IdempotencyTokenTrait import software.amazon.smithy.model.traits.PaginatedTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustMetadata -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.Visibility -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.render -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.stripOuter -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerics -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.errorSymbol -import software.amazon.smithy.rust.codegen.client.smithy.rustType +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.render +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.generators.builderSymbol +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.errorSymbol +import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.util.PANIC import software.amazon.smithy.rust.codegen.core.util.findMemberWithTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait @@ -52,16 +54,16 @@ class PaginatorGenerator private constructor( ) { companion object { fun paginatorType( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, generics: FluentClientGenerics, operationShape: OperationShape, retryClassifier: RuntimeType, ): RuntimeType? { - return if (operationShape.isPaginated(coreCodegenContext.model)) { + return if (operationShape.isPaginated(codegenContext.model)) { PaginatorGenerator( - coreCodegenContext.model, - coreCodegenContext.symbolProvider, - coreCodegenContext.serviceShape, + codegenContext.model, + codegenContext.symbolProvider, + codegenContext.serviceShape, operationShape, generics, retryClassifier, @@ -217,12 +219,13 @@ class PaginatorGenerator private constructor( } /** Generate an `.items()` function to expose flattened pagination when modeled */ - private fun itemsFn(): Writable = writable { - itemsPaginator()?.also { itemPaginatorType -> - val documentedPath = - paginationInfo.itemsMemberPath.joinToString(".") { symbolProvider.toMemberName(it) } - rustTemplate( - """ + private fun itemsFn(): Writable = + writable { + itemsPaginator()?.also { itemPaginatorType -> + val documentedPath = + paginationInfo.itemsMemberPath.joinToString(".") { symbolProvider.toMemberName(it) } + rustTemplate( + """ /// Create a flattened paginator /// /// This paginator automatically flattens results using `$documentedPath`. Queries to the underlying service @@ -231,10 +234,10 @@ class PaginatorGenerator private constructor( #{ItemPaginator}(self) } """, - "ItemPaginator" to itemPaginatorType, - ) + "ItemPaginator" to itemPaginatorType, + ) + } } - } /** Generate a struct with a `items()` method that flattens the paginator **/ private fun itemsPaginator(): RuntimeType? = if (paginationInfo.itemsMemberPath.isEmpty()) { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceGenerator.kt index 219d8d08f0e..8f971da3fb3 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceGenerator.kt @@ -6,16 +6,16 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators import software.amazon.smithy.model.knowledge.TopDownIndex -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfigGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.TopLevelErrorGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolTestGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.TopLevelErrorGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.core.util.inputShape /** @@ -26,10 +26,10 @@ import software.amazon.smithy.rust.codegen.core.util.inputShape */ class ServiceGenerator( private val rustCrate: RustCrate, - private val protocolGenerator: ProtocolGenerator, + private val protocolGenerator: ClientProtocolGenerator, private val protocolSupport: ProtocolSupport, private val clientCodegenContext: ClientCodegenContext, - private val decorator: RustCodegenDecorator, + private val decorator: RustCodegenDecorator, ) { private val index = TopDownIndex.of(clientCodegenContext.model) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt index 7e795be7217..d3d43563fd5 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt @@ -5,17 +5,17 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators.client -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.docs -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate -import software.amazon.smithy.rust.codegen.client.smithy.generators.GenericTypeArg -import software.amazon.smithy.rust.codegen.client.smithy.generators.GenericsGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.GenericTypeArg +import software.amazon.smithy.rust.codegen.core.rustlang.RustGenerics +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.docs +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate /** * Generates the code required to add the `.customize()` function to the @@ -59,8 +59,8 @@ class CustomizableOperationGenerator( } private fun renderCustomizableOperationModule(writer: RustWriter) { - val operationGenerics = GenericsGenerator(GenericTypeArg("O"), GenericTypeArg("Retry")) - val handleGenerics = generics.toGenericsGenerator() + val operationGenerics = RustGenerics(GenericTypeArg("O"), GenericTypeArg("Retry")) + val handleGenerics = generics.toRustGenerics() val combinedGenerics = operationGenerics + handleGenerics val codegenScope = arrayOf( @@ -145,8 +145,8 @@ class CustomizableOperationGenerator( val smithyHttp = CargoDependency.SmithyHttp(runtimeConfig).asType() val smithyClient = CargoDependency.SmithyClient(runtimeConfig).asType() - val operationGenerics = GenericsGenerator(GenericTypeArg("O"), GenericTypeArg("Retry")) - val handleGenerics = generics.toGenericsGenerator() + val operationGenerics = RustGenerics(GenericTypeArg("O"), GenericTypeArg("Retry")) + val handleGenerics = generics.toRustGenerics() val combinedGenerics = operationGenerics + handleGenerics val codegenScope = arrayOf( diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientCore.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientCore.kt index a3b812693f1..fb9750119bf 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientCore.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientCore.kt @@ -7,15 +7,15 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators.client import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.MemberShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asArgument -import software.amazon.smithy.rust.codegen.client.rustlang.deprecatedShape -import software.amazon.smithy.rust.codegen.client.rustlang.docs -import software.amazon.smithy.rust.codegen.client.rustlang.documentShape -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.smithy.generators.setterName +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asArgument +import software.amazon.smithy.rust.codegen.core.rustlang.deprecatedShape +import software.amazon.smithy.rust.codegen.core.rustlang.docs +import software.amazon.smithy.rust.codegen.core.rustlang.documentShape +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.smithy.generators.setterName class FluentClientCore(private val model: Model) { /** Generate and write Rust code for a builder method that sets a Vec */ diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt index 91535206d95..8e8cf8f8b26 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientDecorator.kt @@ -7,24 +7,25 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators.client import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ServiceShape -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.Feature -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate -import software.amazon.smithy.rust.codegen.client.smithy.customize.NamedSectionGenerator import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.customize.Section -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsSection +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.Feature +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.customize.NamedSectionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.customize.Section +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection -class FluentClientDecorator : RustCodegenDecorator { +class FluentClientDecorator : RustCodegenDecorator { override val name: String = "FluentClient" override val order: Byte = 0 @@ -62,7 +63,7 @@ class FluentClientDecorator : RustCodegenDecorator { } } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } @@ -79,9 +80,9 @@ sealed class FluentClientSection(name: String) : Section(name) { abstract class FluentClientCustomization : NamedSectionGenerator() -class GenericFluentClient(coreCodegenContext: CoreCodegenContext) : FluentClientCustomization() { - private val moduleUseName = coreCodegenContext.moduleUseName() - private val clientDep = CargoDependency.SmithyClient(coreCodegenContext.runtimeConfig) +class GenericFluentClient(codegenContext: CodegenContext) : FluentClientCustomization() { + private val moduleUseName = codegenContext.moduleUseName() + private val clientDep = CargoDependency.SmithyClient(codegenContext.runtimeConfig) private val codegenScope = arrayOf("client" to clientDep.asType()) override fun section(section: FluentClientSection): Writable { return when (section) { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt index ae83e920a6d..4fe0f8eb9f2 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt @@ -12,42 +12,42 @@ import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.DocumentationTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustReservedWords -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asArgumentType -import software.amazon.smithy.rust.codegen.client.rustlang.asOptional -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.deprecatedShape -import software.amazon.smithy.rust.codegen.client.rustlang.docLink -import software.amazon.smithy.rust.codegen.client.rustlang.docs -import software.amazon.smithy.rust.codegen.client.rustlang.documentShape -import software.amazon.smithy.rust.codegen.client.rustlang.escape -import software.amazon.smithy.rust.codegen.client.rustlang.normalizeHtml -import software.amazon.smithy.rust.codegen.client.rustlang.qualifiedName -import software.amazon.smithy.rust.codegen.client.rustlang.render -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTypeParameters -import software.amazon.smithy.rust.codegen.client.rustlang.stripOuter -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.customize.writeCustomizations -import software.amazon.smithy.rust.codegen.client.smithy.expectRustMetadata -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget import software.amazon.smithy.rust.codegen.client.smithy.generators.PaginatorGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.builderSymbol -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.errorSymbol import software.amazon.smithy.rust.codegen.client.smithy.generators.isPaginated -import software.amazon.smithy.rust.codegen.client.smithy.generators.setterName import software.amazon.smithy.rust.codegen.client.smithy.generators.smithyHttp -import software.amazon.smithy.rust.codegen.client.smithy.rustType +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asArgumentType +import software.amazon.smithy.rust.codegen.core.rustlang.asOptional +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.deprecatedShape +import software.amazon.smithy.rust.codegen.core.rustlang.docLink +import software.amazon.smithy.rust.codegen.core.rustlang.docs +import software.amazon.smithy.rust.codegen.core.rustlang.documentShape +import software.amazon.smithy.rust.codegen.core.rustlang.escape +import software.amazon.smithy.rust.codegen.core.rustlang.normalizeHtml +import software.amazon.smithy.rust.codegen.core.rustlang.qualifiedName +import software.amazon.smithy.rust.codegen.core.rustlang.render +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTypeParameters +import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.customize.writeCustomizations +import software.amazon.smithy.rust.codegen.core.smithy.expectRustMetadata +import software.amazon.smithy.rust.codegen.core.smithy.generators.builderSymbol +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.errorSymbol +import software.amazon.smithy.rust.codegen.core.smithy.generators.setterName +import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.orNull import software.amazon.smithy.rust.codegen.core.util.outputShape @@ -316,7 +316,7 @@ class FluentClientGenerator( "customizable_op_type_params" to rustTypeParameters( symbolProvider.toSymbol(operation), retryClassifier, - generics.toGenericsGenerator(), + generics.toRustGenerics(), ), ) PaginatorGenerator.paginatorType(codegenContext, generics, operation, retryClassifier)?.also { paginatorType -> diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerics.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerics.kt index e5300d1a053..f8551568203 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerics.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerics.kt @@ -6,13 +6,13 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators.client import software.amazon.smithy.codegen.core.Symbol -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.GenericTypeArg -import software.amazon.smithy.rust.codegen.client.smithy.generators.GenericsGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.GenericTypeArg +import software.amazon.smithy.rust.codegen.core.rustlang.RustGenerics +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType interface FluentClientGenerics { /** Declaration with defaults set */ @@ -30,8 +30,8 @@ interface FluentClientGenerics { /** Bounds for generated `send()` functions */ fun sendBounds(operation: Symbol, output: Symbol, error: RuntimeType, retryClassifier: RuntimeType): Writable - /** Convert this `FluentClientGenerics` into the more general `GenericsGenerator` */ - fun toGenericsGenerator(): GenericsGenerator + /** Convert this `FluentClientGenerics` into the more general `RustGenerics` */ + fun toRustGenerics(): RustGenerics } data class FlexibleClientGenerics( @@ -89,7 +89,7 @@ data class FlexibleClientGenerics( ) } - override fun toGenericsGenerator(): GenericsGenerator = GenericsGenerator( + override fun toRustGenerics(): RustGenerics = RustGenerics( GenericTypeArg("C", client.member("bounds::SmithyConnector")), GenericTypeArg("M", client.member("bounds::SmithyMiddleware")), GenericTypeArg("R", client.member("retry::NewRequestPolicy")), diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/EventStreamSigningConfig.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/EventStreamSigningConfig.kt index 55f86c299a5..66515034295 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/EventStreamSigningConfig.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/EventStreamSigningConfig.kt @@ -5,12 +5,12 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators.config -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType open class EventStreamSigningConfig( runtimeConfig: RuntimeConfig, diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/IdempotencyTokenProviderCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/IdempotencyTokenProviderCustomization.kt index b33ac66a130..59c983bdd42 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/IdempotencyTokenProviderCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/IdempotencyTokenProviderCustomization.kt @@ -5,11 +5,11 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators.config -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.NamedSectionGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.NamedSectionGenerator /** * Add a `make_token` field to Service config. See below for the resulting generated code. diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGenerator.kt index 68eb2c0001b..926eef97935 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGenerator.kt @@ -10,14 +10,14 @@ import software.amazon.smithy.model.knowledge.OperationIndex import software.amazon.smithy.model.knowledge.TopDownIndex import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.traits.IdempotencyTokenTrait -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.docs -import software.amazon.smithy.rust.codegen.client.rustlang.raw -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.customize.NamedSectionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.customize.Section +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.docs +import software.amazon.smithy.rust.codegen.core.rustlang.raw +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.customize.NamedSectionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.customize.Section import software.amazon.smithy.rust.codegen.core.util.hasTrait /** @@ -111,9 +111,9 @@ typealias ConfigCustomization = NamedSectionGenerator class ServiceConfigGenerator(private val customizations: List = listOf()) { companion object { - fun withBaseBehavior(coreCodegenContext: CoreCodegenContext, extraCustomizations: List): ServiceConfigGenerator { + fun withBaseBehavior(codegenContext: CodegenContext, extraCustomizations: List): ServiceConfigGenerator { val baseFeatures = mutableListOf() - if (coreCodegenContext.serviceShape.needsIdempotencyToken(coreCodegenContext.model)) { + if (codegenContext.serviceShape.needsIdempotencyToken(codegenContext.model)) { baseFeatures.add(IdempotencyTokenProviderCustomization()) } return ServiceConfigGenerator(baseFeatures + extraCustomizations) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolGenerator.kt new file mode 100644 index 00000000000..9b66e011874 --- /dev/null +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ClientProtocolGenerator.kt @@ -0,0 +1,93 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rust.codegen.client.smithy.generators.protocol + +import software.amazon.smithy.model.shapes.OperationShape +import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.docLink +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection +import software.amazon.smithy.rust.codegen.core.smithy.customize.writeCustomizations +import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.MakeOperationGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolTraitImplGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.util.inputShape + +open class ClientProtocolGenerator( + codegenContext: CodegenContext, + private val protocol: Protocol, + private val makeOperationGenerator: MakeOperationGenerator, + private val traitGenerator: ProtocolTraitImplGenerator, +) : ProtocolGenerator(codegenContext, protocol, makeOperationGenerator, traitGenerator) { + /** + * Render all code required for serializing requests and deserializing responses for the operation + * + * This primarily relies on two components: + * 1. [traitGenerator]: Generate implementations of the `ParseHttpResponse` trait for the operations + * 2. [makeOperationGenerator]: Generate the `make_operation()` method which is used to serialize operations + * to HTTP requests + */ + fun renderOperation( + operationWriter: RustWriter, + inputWriter: RustWriter, + operationShape: OperationShape, + customizations: List, + ) { + val inputShape = operationShape.inputShape(model) + val builderGenerator = BuilderGenerator(model, symbolProvider, operationShape.inputShape(model)) + builderGenerator.render(inputWriter) + + // impl OperationInputShape { ... } + val operationName = symbolProvider.toSymbol(operationShape).name + inputWriter.implBlock(inputShape, symbolProvider) { + writeCustomizations( + customizations, + OperationSection.InputImpl(customizations, operationShape, inputShape, protocol), + ) + makeOperationGenerator.generateMakeOperation(this, operationShape, customizations) + + // pub fn builder() -> ... { } + builderGenerator.renderConvenienceMethod(this) + } + + // pub struct Operation { ... } + val fluentBuilderName = FluentClientGenerator.clientOperationFnName(operationShape, symbolProvider) + operationWriter.rust( + """ + /// Operation shape for `$operationName`. + /// + /// This is usually constructed for you using the the fluent builder returned by + /// [`$fluentBuilderName`](${docLink("crate::client::Client::$fluentBuilderName")}). + /// + /// See [`crate::client::fluent_builders::$operationName`] for more details about the operation. + """, + ) + Attribute.Derives(setOf(RuntimeType.Clone, RuntimeType.Default, RuntimeType.Debug)).render(operationWriter) + operationWriter.rustBlock("pub struct $operationName") { + write("_private: ()") + } + operationWriter.implBlock(operationShape, symbolProvider) { + builderGenerator.renderConvenienceMethod(this) + + rust("/// Creates a new `$operationName` operation.") + rustBlock("pub fn new() -> Self") { + rust("Self { _private: () }") + } + + writeCustomizations(customizations, OperationSection.OperationImplBlock(customizations)) + } + traitGenerator.generateTraitImpls(operationWriter, operationShape, customizations) + } +} diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolGenerator.kt deleted file mode 100644 index 8a788196f77..00000000000 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolGenerator.kt +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.rust.codegen.client.smithy.generators.protocol - -import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.docLink -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection -import software.amazon.smithy.rust.codegen.client.smithy.customize.writeCustomizations -import software.amazon.smithy.rust.codegen.client.smithy.generators.BuilderGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.implBlock -import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol -import software.amazon.smithy.rust.codegen.core.util.inputShape - -/** - * Payload Body Generator. - * - * Used to generate payloads that will go into HTTP bodies for HTTP requests (used by clients) - * and responses (used by servers). - * - * **Note:** There is only one real implementation of this interface. The other implementation is test-only. - * All protocols use the same class. - * - * Different protocols (e.g. JSON vs. XML) need to use different functionality to generate payload bodies. - */ -interface ProtocolPayloadGenerator { - data class PayloadMetadata(val takesOwnership: Boolean) - - /** - * Code generation needs to handle whether [generatePayload] takes ownership of the input or output - * for a given operation shape. - * - * Most operations will use the HTTP payload as a reference, but for operations that will consume the entire stream - * later,they will need to take ownership and different code needs to be generated. - */ - fun payloadMetadata(operationShape: OperationShape): PayloadMetadata - - /** - * Write the payload into [writer]. - * - * [self] is the name of the variable binding for the Rust struct that is to be serialized into the payload. - * - * This should be an expression that returns bytes: - * - a `Vec` for non-streaming operations; or - * - a `ByteStream` for streaming operations. - */ - fun generatePayload(writer: RustWriter, self: String, operationShape: OperationShape) -} - -/** - * Protocol Trait implementation generator - * - * **Note:** There is only one real implementation of this interface. The other implementation is test-only. - * All protocols use the same class. - * - * Protocols implement one of two traits to enable parsing HTTP responses: - * 1. `ParseHttpResponse`: Streaming binary operations - * 2. `ParseStrictResponse`: Non-streaming operations for the body must be "strict" (as in, not lazy) where the parser - * must have the complete body to return a result. - */ -interface ProtocolTraitImplGenerator { - fun generateTraitImpls(operationWriter: RustWriter, operationShape: OperationShape, customizations: List) -} - -/** - * Class providing scaffolding for HTTP based protocols that must build an HTTP request (headers / URL) and a body. - */ -open class ProtocolGenerator( - coreCodegenContext: CoreCodegenContext, - /** - * `Protocol` contains all protocol specific information. Each smithy protocol, e.g. RestJson, RestXml, etc. will - * have their own implementation of the protocol interface which defines how an input shape becomes and http::Request - * and an output shape is build from an `http::Response`. - */ - private val protocol: Protocol, - /** - * Operations generate a `make_operation(&config)` method to build a `aws_smithy_http::Operation` that can be dispatched - * This is the serializer side of request dispatch - */ - private val makeOperationGenerator: MakeOperationGenerator, - /** - * Operations generate implementations of ParseHttpResponse or ParseStrictResponse. - * This is the deserializer side of request dispatch (parsing the response) - */ - private val traitGenerator: ProtocolTraitImplGenerator, -) { - private val symbolProvider = coreCodegenContext.symbolProvider - private val model = coreCodegenContext.model - - /** - * Render all code required for serializing requests and deserializing responses for the operation - * - * This primarily relies on two components: - * 1. [traitGenerator]: Generate implementations of the `ParseHttpResponse` trait for the operations - * 2. [makeOperationGenerator]: Generate the `make_operation()` method which is used to serialize operations - * to HTTP requests - */ - fun renderOperation( - operationWriter: RustWriter, - inputWriter: RustWriter, - operationShape: OperationShape, - customizations: List, - ) { - val inputShape = operationShape.inputShape(model) - val builderGenerator = BuilderGenerator(model, symbolProvider, operationShape.inputShape(model)) - builderGenerator.render(inputWriter) - - // impl OperationInputShape { ... } - val operationName = symbolProvider.toSymbol(operationShape).name - inputWriter.implBlock(inputShape, symbolProvider) { - writeCustomizations( - customizations, - OperationSection.InputImpl(customizations, operationShape, inputShape, protocol), - ) - makeOperationGenerator.generateMakeOperation(this, operationShape, customizations) - - // pub fn builder() -> ... { } - builderGenerator.renderConvenienceMethod(this) - } - - // pub struct Operation { ... } - val fluentBuilderName = FluentClientGenerator.clientOperationFnName(operationShape, symbolProvider) - operationWriter.rust( - """ - /// Operation shape for `$operationName`. - /// - /// This is usually constructed for you using the the fluent builder returned by - /// [`$fluentBuilderName`](${docLink("crate::client::Client::$fluentBuilderName")}). - /// - /// See [`crate::client::fluent_builders::$operationName`] for more details about the operation. - """, - ) - Attribute.Derives(setOf(RuntimeType.Clone, RuntimeType.Default, RuntimeType.Debug)).render(operationWriter) - operationWriter.rustBlock("pub struct $operationName") { - write("_private: ()") - } - operationWriter.implBlock(operationShape, symbolProvider) { - builderGenerator.renderConvenienceMethod(this) - - rust("/// Creates a new `$operationName` operation.") - rustBlock("pub fn new() -> Self") { - rust("Self { _private: () }") - } - - writeCustomizations(customizations, OperationSection.OperationImplBlock(customizations)) - } - traitGenerator.generateTraitImpls(operationWriter, operationShape, customizations) - } - - /** - * The server implementation uses this method to generate implementations of the `from_request` and `into_response` - * traits for operation input and output shapes, respectively. - */ - fun serverRenderOperation( - operationWriter: RustWriter, - operationShape: OperationShape, - ) { - traitGenerator.generateTraitImpls(operationWriter, operationShape, emptyList()) - } -} diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt index efc452973e6..52fb86d933d 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt @@ -19,23 +19,24 @@ import software.amazon.smithy.protocoltests.traits.HttpRequestTestCase import software.amazon.smithy.protocoltests.traits.HttpRequestTestsTrait import software.amazon.smithy.protocoltests.traits.HttpResponseTestCase import software.amazon.smithy.protocoltests.traits.HttpResponseTestsTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustMetadata -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Visibility -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.escape -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.Instantiator -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.errorSymbol import software.amazon.smithy.rust.codegen.client.testutil.TokioTest +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.escape +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.Instantiator +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.errorSymbol +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.findMemberWithTrait import software.amazon.smithy.rust.codegen.core.util.getTrait @@ -47,41 +48,28 @@ import software.amazon.smithy.rust.codegen.core.util.outputShape import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import java.util.logging.Logger -data class ProtocolSupport( - /* Client support */ - val requestSerialization: Boolean, - val requestBodySerialization: Boolean, - val responseDeserialization: Boolean, - val errorDeserialization: Boolean, - /* Server support */ - val requestDeserialization: Boolean, - val requestBodyDeserialization: Boolean, - val responseSerialization: Boolean, - val errorSerialization: Boolean, -) - /** * Generate protocol tests for an operation */ class ProtocolTestGenerator( - private val coreCodegenContext: CoreCodegenContext, + private val codegenContext: CodegenContext, private val protocolSupport: ProtocolSupport, private val operationShape: OperationShape, private val writer: RustWriter, ) { private val logger = Logger.getLogger(javaClass.name) - private val inputShape = operationShape.inputShape(coreCodegenContext.model) - private val outputShape = operationShape.outputShape(coreCodegenContext.model) - private val operationSymbol = coreCodegenContext.symbolProvider.toSymbol(operationShape) - private val operationIndex = OperationIndex.of(coreCodegenContext.model) + private val inputShape = operationShape.inputShape(codegenContext.model) + private val outputShape = operationShape.outputShape(codegenContext.model) + private val operationSymbol = codegenContext.symbolProvider.toSymbol(operationShape) + private val operationIndex = OperationIndex.of(codegenContext.model) - private val instantiator = with(coreCodegenContext) { + private val instantiator = with(codegenContext) { Instantiator(symbolProvider, model, runtimeConfig, CodegenTarget.CLIENT) } private val codegenScope = arrayOf( - "SmithyHttp" to CargoDependency.SmithyHttp(coreCodegenContext.runtimeConfig).asType(), + "SmithyHttp" to CargoDependency.SmithyHttp(codegenContext.runtimeConfig).asType(), "Http" to CargoDependency.Http.asType(), "AssertEq" to CargoDependency.PrettyAssertions.asType().member("assert_eq!"), ) @@ -138,7 +126,7 @@ class ProtocolTestGenerator( private fun List.filterMatching(): List { return if (RunOnly.isNullOrEmpty()) { this.filter { testCase -> - testCase.testCase.protocol == coreCodegenContext.protocol && + testCase.testCase.protocol == codegenContext.protocol && !DisableTests.contains(testCase.testCase.id) } } else { @@ -182,7 +170,7 @@ class ProtocolTestGenerator( rust("/* test case disabled for this protocol (not yet supported) */") return } - val customToken = if (inputShape.findMemberWithTrait(coreCodegenContext.model) != null) { + val customToken = if (inputShape.findMemberWithTrait(codegenContext.model) != null) { """.make_token("00000000-0000-4000-8000-000000000000")""" } else "" rust( @@ -248,7 +236,7 @@ class ProtocolTestGenerator( } private fun expectFail(testCase: HttpMessageTestCase): Boolean = ExpectFail.find { - it.id == testCase.id && it.action == testCase.action() && it.service == coreCodegenContext.serviceShape.id.toString() + it.id == testCase.id && it.action == testCase.action() && it.service == codegenContext.serviceShape.id.toString() } != null private fun RustWriter.renderHttpResponseTestCase( @@ -277,11 +265,11 @@ class ProtocolTestGenerator( .body(#T::from(${testCase.body.orNull()?.dq()?.replace("#", "##") ?: "vec![]"})) .unwrap(); """, - RuntimeType.sdkBody(runtimeConfig = coreCodegenContext.runtimeConfig), + RuntimeType.sdkBody(runtimeConfig = codegenContext.runtimeConfig), ) write( "let mut op_response = #T::new(http_response);", - RuntimeType.operationModule(coreCodegenContext.runtimeConfig).member("Response"), + RuntimeType.operationModule(codegenContext.runtimeConfig).member("Response"), ) rustTemplate( """ @@ -296,12 +284,12 @@ class ProtocolTestGenerator( """, "op" to operationSymbol, "bytes" to RuntimeType.Bytes, - "parse_http_response" to CargoDependency.SmithyHttp(coreCodegenContext.runtimeConfig).asType() + "parse_http_response" to CargoDependency.SmithyHttp(codegenContext.runtimeConfig).asType() .member("response::ParseHttpResponse"), ) if (expectedShape.hasTrait()) { - val errorSymbol = operationShape.errorSymbol(coreCodegenContext.model, coreCodegenContext.symbolProvider, coreCodegenContext.target) - val errorVariant = coreCodegenContext.symbolProvider.toSymbol(expectedShape).name + val errorSymbol = operationShape.errorSymbol(codegenContext.model, codegenContext.symbolProvider, codegenContext.target) + val errorVariant = codegenContext.symbolProvider.toSymbol(expectedShape).name rust("""let parsed = parsed.expect_err("should be error response");""") rustBlock("if let #TKind::$errorVariant(actual_error) = parsed.kind", errorSymbol) { rustTemplate("#{AssertEq}(expected_output, actual_error);", *codegenScope) @@ -312,8 +300,8 @@ class ProtocolTestGenerator( } else { rust("let parsed = parsed.unwrap();") outputShape.members().forEach { member -> - val memberName = coreCodegenContext.symbolProvider.toMemberName(member) - if (member.isStreaming(coreCodegenContext.model)) { + val memberName = codegenContext.symbolProvider.toMemberName(member) + if (member.isStreaming(codegenContext.model)) { rustTemplate( """ #{AssertEq}( @@ -324,10 +312,10 @@ class ProtocolTestGenerator( *codegenScope, ) } else { - when (coreCodegenContext.model.expectShape(member.target)) { + when (codegenContext.model.expectShape(member.target)) { is DoubleShape, is FloatShape -> { addUseImports( - RuntimeType.ProtocolTestHelper(coreCodegenContext.runtimeConfig, "FloatEquals").toSymbol(), + RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "FloatEquals").toSymbol(), ) rust( """ @@ -361,8 +349,8 @@ class ProtocolTestGenerator( "#T(&body, ${ rustWriter.escape(body).dq() }, #T::from(${(mediaType ?: "unknown").dq()}))", - RuntimeType.ProtocolTestHelper(coreCodegenContext.runtimeConfig, "validate_body"), - RuntimeType.ProtocolTestHelper(coreCodegenContext.runtimeConfig, "MediaType"), + RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "validate_body"), + RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "MediaType"), ) } } @@ -403,7 +391,7 @@ class ProtocolTestGenerator( assertOk(rustWriter) { write( "#T($actualExpression, $variableName)", - RuntimeType.ProtocolTestHelper(coreCodegenContext.runtimeConfig, "validate_headers"), + RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "validate_headers"), ) } } @@ -457,7 +445,7 @@ class ProtocolTestGenerator( assertOk(rustWriter) { write( "#T($actualExpression, $expectedVariableName)", - RuntimeType.ProtocolTestHelper(coreCodegenContext.runtimeConfig, checkFunction), + RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, checkFunction), ) } } @@ -467,7 +455,7 @@ class ProtocolTestGenerator( * for pretty prettying protocol test helper results */ private fun assertOk(rustWriter: RustWriter, inner: RustWriter.() -> Unit) { - rustWriter.write("#T(", RuntimeType.ProtocolTestHelper(coreCodegenContext.runtimeConfig, "assert_ok")) + rustWriter.write("#T(", RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "assert_ok")) inner(rustWriter) rustWriter.write(");") } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsJson.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsJson.kt index a50da4220ec..ae2d8e058ee 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsJson.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsJson.kt @@ -12,21 +12,26 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ToShapeId import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport -import software.amazon.smithy.rust.codegen.client.smithy.generators.serializationError -import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.JsonParserGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.StructuredDataParserGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.JsonSerializerGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.StructuredDataSerializerGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.core.smithy.generators.serializationError +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingDescriptor +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpLocation +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.JsonParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.JsonSerializerGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serializeFunctionName import software.amazon.smithy.rust.codegen.core.util.inputShape sealed class AwsJsonVersion { @@ -41,7 +46,8 @@ sealed class AwsJsonVersion { } } -class AwsJsonFactory(private val version: AwsJsonVersion) : ProtocolGeneratorFactory { +class AwsJsonFactory(private val version: AwsJsonVersion) : + ProtocolGeneratorFactory { override fun protocol(codegenContext: ClientCodegenContext): Protocol = AwsJson(codegenContext, version) override fun buildProtocolGenerator(codegenContext: ClientCodegenContext): HttpBoundProtocolGenerator = @@ -98,12 +104,12 @@ class AwsJsonHttpBindingResolver( * customizes wraps [JsonSerializerGenerator] to add this functionality. */ class AwsJsonSerializerGenerator( - private val coreCodegenContext: CoreCodegenContext, + private val codegenContext: CodegenContext, httpBindingResolver: HttpBindingResolver, private val jsonSerializerGenerator: JsonSerializerGenerator = - JsonSerializerGenerator(coreCodegenContext, httpBindingResolver, ::awsJsonFieldName), + JsonSerializerGenerator(codegenContext, httpBindingResolver, ::awsJsonFieldName), ) : StructuredDataSerializerGenerator by jsonSerializerGenerator { - private val runtimeConfig = coreCodegenContext.runtimeConfig + private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( "Error" to runtimeConfig.serializationError(), "SdkBody" to RuntimeType.sdkBody(runtimeConfig), @@ -112,12 +118,12 @@ class AwsJsonSerializerGenerator( override fun operationInputSerializer(operationShape: OperationShape): RuntimeType { var serializer = jsonSerializerGenerator.operationInputSerializer(operationShape) if (serializer == null) { - val inputShape = operationShape.inputShape(coreCodegenContext.model) - val fnName = coreCodegenContext.symbolProvider.serializeFunctionName(operationShape) + val inputShape = operationShape.inputShape(codegenContext.model) + val fnName = codegenContext.symbolProvider.serializeFunctionName(operationShape) serializer = RuntimeType.forInlineFun(fnName, RustModule.private("operation_ser")) { it.rustBlockTemplate( "pub fn $fnName(_input: &#{target}) -> Result<#{SdkBody}, #{Error}>", - *codegenScope, "target" to coreCodegenContext.symbolProvider.toSymbol(inputShape), + *codegenScope, "target" to codegenContext.symbolProvider.toSymbol(inputShape), ) { rustTemplate("""Ok(#{SdkBody}::from("{}"))""", *codegenScope) } @@ -128,10 +134,10 @@ class AwsJsonSerializerGenerator( } open class AwsJson( - val coreCodegenContext: CoreCodegenContext, + val codegenContext: CodegenContext, val awsJsonVersion: AwsJsonVersion, ) : Protocol { - private val runtimeConfig = coreCodegenContext.runtimeConfig + private val runtimeConfig = codegenContext.runtimeConfig private val errorScope = arrayOf( "Bytes" to RuntimeType.Bytes, "Error" to RuntimeType.GenericError(runtimeConfig), @@ -145,18 +151,18 @@ open class AwsJson( val version: AwsJsonVersion get() = awsJsonVersion override val httpBindingResolver: HttpBindingResolver = - AwsJsonHttpBindingResolver(coreCodegenContext.model, awsJsonVersion) + AwsJsonHttpBindingResolver(codegenContext.model, awsJsonVersion) override val defaultTimestampFormat: TimestampFormatTrait.Format = TimestampFormatTrait.Format.EPOCH_SECONDS override fun additionalRequestHeaders(operationShape: OperationShape): List> = - listOf("x-amz-target" to "${coreCodegenContext.serviceShape.id.name}.${operationShape.id.name}") + listOf("x-amz-target" to "${codegenContext.serviceShape.id.name}.${operationShape.id.name}") override fun structuredDataParser(operationShape: OperationShape): StructuredDataParserGenerator = - JsonParserGenerator(coreCodegenContext, httpBindingResolver, ::awsJsonFieldName) + JsonParserGenerator(codegenContext, httpBindingResolver, ::awsJsonFieldName) override fun structuredDataSerializer(operationShape: OperationShape): StructuredDataSerializerGenerator = - AwsJsonSerializerGenerator(coreCodegenContext, httpBindingResolver) + AwsJsonSerializerGenerator(codegenContext, httpBindingResolver) override fun parseHttpGenericError(operationShape: OperationShape): RuntimeType = RuntimeType.forInlineFun("parse_http_generic_error", jsonDeserModule) { writer -> diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsQuery.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsQuery.kt index d0f4ca0c14a..4a95ea12699 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsQuery.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsQuery.kt @@ -12,19 +12,23 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ToShapeId import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport -import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.AwsQueryParserGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.StructuredDataParserGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.AwsQuerySerializerGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.StructuredDataSerializerGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory +import software.amazon.smithy.rust.codegen.core.smithy.protocols.StaticHttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.AwsQueryParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.AwsQuerySerializerGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator import software.amazon.smithy.rust.codegen.core.util.getTrait class AwsQueryFactory : ProtocolGeneratorFactory { @@ -63,8 +67,8 @@ class AwsQueryBindingResolver(private val model: Model) : } } -class AwsQueryProtocol(private val coreCodegenContext: CoreCodegenContext) : Protocol { - private val runtimeConfig = coreCodegenContext.runtimeConfig +class AwsQueryProtocol(private val codegenContext: CodegenContext) : Protocol { + private val runtimeConfig = codegenContext.runtimeConfig private val awsQueryErrors: RuntimeType = RuntimeType.wrappedXmlErrors(runtimeConfig) private val errorScope = arrayOf( "Bytes" to RuntimeType.Bytes, @@ -75,15 +79,15 @@ class AwsQueryProtocol(private val coreCodegenContext: CoreCodegenContext) : Pro ) private val xmlDeserModule = RustModule.private("xml_deser") - override val httpBindingResolver: HttpBindingResolver = AwsQueryBindingResolver(coreCodegenContext.model) + override val httpBindingResolver: HttpBindingResolver = AwsQueryBindingResolver(codegenContext.model) override val defaultTimestampFormat: TimestampFormatTrait.Format = TimestampFormatTrait.Format.DATE_TIME override fun structuredDataParser(operationShape: OperationShape): StructuredDataParserGenerator = - AwsQueryParserGenerator(coreCodegenContext, awsQueryErrors) + AwsQueryParserGenerator(codegenContext, awsQueryErrors) override fun structuredDataSerializer(operationShape: OperationShape): StructuredDataSerializerGenerator = - AwsQuerySerializerGenerator(coreCodegenContext) + AwsQuerySerializerGenerator(codegenContext) override fun parseHttpGenericError(operationShape: OperationShape): RuntimeType = RuntimeType.forInlineFun("parse_http_generic_error", xmlDeserModule) { writer -> diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/ClientProtocolLoader.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/ClientProtocolLoader.kt new file mode 100644 index 00000000000..d97f52c26ec --- /dev/null +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/ClientProtocolLoader.kt @@ -0,0 +1,33 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rust.codegen.client.smithy.protocols + +import software.amazon.smithy.aws.traits.protocols.AwsJson1_0Trait +import software.amazon.smithy.aws.traits.protocols.AwsJson1_1Trait +import software.amazon.smithy.aws.traits.protocols.AwsQueryTrait +import software.amazon.smithy.aws.traits.protocols.Ec2QueryTrait +import software.amazon.smithy.aws.traits.protocols.RestJson1Trait +import software.amazon.smithy.aws.traits.protocols.RestXmlTrait +import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolLoader +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolMap + +class ClientProtocolLoader(supportedProtocols: ProtocolMap) : + ProtocolLoader(supportedProtocols) { + + companion object { + val DefaultProtocols = mapOf( + AwsJson1_0Trait.ID to AwsJsonFactory(AwsJsonVersion.Json10), + AwsJson1_1Trait.ID to AwsJsonFactory(AwsJsonVersion.Json11), + AwsQueryTrait.ID to AwsQueryFactory(), + Ec2QueryTrait.ID to Ec2QueryFactory(), + RestJson1Trait.ID to RestJsonFactory(), + RestXmlTrait.ID to RestXmlFactory(), + ) + val Default = ClientProtocolLoader(DefaultProtocols) + } +} diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Ec2Query.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Ec2Query.kt index 8af691bfe69..cd19cf2336e 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Ec2Query.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Ec2Query.kt @@ -9,19 +9,23 @@ import software.amazon.smithy.model.pattern.UriPattern import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport -import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.Ec2QueryParserGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.StructuredDataParserGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.Ec2QuerySerializerGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.StructuredDataSerializerGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory +import software.amazon.smithy.rust.codegen.core.smithy.protocols.StaticHttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.Ec2QueryParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.Ec2QuerySerializerGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator class Ec2QueryFactory : ProtocolGeneratorFactory { override fun protocol(codegenContext: ClientCodegenContext): Protocol = Ec2QueryProtocol(codegenContext) @@ -45,8 +49,8 @@ class Ec2QueryFactory : ProtocolGeneratorFactory diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt index 1d63ce1f031..55e4fe5182e 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt @@ -9,35 +9,39 @@ import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.ErrorTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.assignment -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection -import software.amazon.smithy.rust.codegen.client.smithy.customize.writeCustomizations -import software.amazon.smithy.rust.codegen.client.smithy.generators.StructureGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.builderSymbol -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.errorSymbol -import software.amazon.smithy.rust.codegen.client.smithy.generators.http.ResponseBindingGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.MakeOperationGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolTraitImplGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.setterName -import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.StructuredDataParserGenerator -import software.amazon.smithy.rust.codegen.client.smithy.transformers.errorMessageMember -import software.amazon.smithy.rust.codegen.client.smithy.transformers.operationErrors +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.assignment +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection +import software.amazon.smithy.rust.codegen.core.smithy.customize.writeCustomizations +import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.builderSymbol +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.errorSymbol +import software.amazon.smithy.rust.codegen.core.smithy.generators.http.ResponseBindingGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.MakeOperationGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolTraitImplGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.setterName +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingDescriptor +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBoundProtocolPayloadGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpLocation +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.transformers.operationErrors import software.amazon.smithy.rust.codegen.core.util.UNREACHABLE import software.amazon.smithy.rust.codegen.core.util.dq +import software.amazon.smithy.rust.codegen.core.util.errorMessageMember import software.amazon.smithy.rust.codegen.core.util.hasStreamingMember import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.isStreaming @@ -45,28 +49,28 @@ import software.amazon.smithy.rust.codegen.core.util.outputShape import software.amazon.smithy.rust.codegen.core.util.toSnakeCase class HttpBoundProtocolGenerator( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, protocol: Protocol, -) : ProtocolGenerator( - coreCodegenContext, +) : ClientProtocolGenerator( + codegenContext, protocol, MakeOperationGenerator( - coreCodegenContext, + codegenContext, protocol, - HttpBoundProtocolPayloadGenerator(coreCodegenContext, protocol), + HttpBoundProtocolPayloadGenerator(codegenContext, protocol), public = true, includeDefaultPayloadHeaders = true, ), - HttpBoundProtocolTraitImplGenerator(coreCodegenContext, protocol), + HttpBoundProtocolTraitImplGenerator(codegenContext, protocol), ) class HttpBoundProtocolTraitImplGenerator( - private val coreCodegenContext: CoreCodegenContext, + private val codegenContext: CodegenContext, private val protocol: Protocol, ) : ProtocolTraitImplGenerator { - private val symbolProvider = coreCodegenContext.symbolProvider - private val model = coreCodegenContext.model - private val runtimeConfig = coreCodegenContext.runtimeConfig + private val symbolProvider = codegenContext.symbolProvider + private val model = codegenContext.model + private val runtimeConfig = codegenContext.runtimeConfig private val httpBindingResolver = protocol.httpBindingResolver private val operationDeserModule = RustModule.private("operation_deser") @@ -121,7 +125,7 @@ class HttpBoundProtocolTraitImplGenerator( }""", *codegenScope, "O" to outputSymbol, - "E" to operationShape.errorSymbol(model, symbolProvider, coreCodegenContext.target), + "E" to operationShape.errorSymbol(model, symbolProvider, codegenContext.target), "parse_error" to parseError(operationShape), "parse_response" to parseResponse(operationShape, customizations), ) @@ -152,7 +156,7 @@ class HttpBoundProtocolTraitImplGenerator( } """, "O" to outputSymbol, - "E" to operationShape.errorSymbol(model, symbolProvider, coreCodegenContext.target), + "E" to operationShape.errorSymbol(model, symbolProvider, codegenContext.target), "parse_streaming_response" to parseStreamingResponse(operationShape, customizations), "parse_error" to parseError(operationShape), *codegenScope, @@ -163,7 +167,7 @@ class HttpBoundProtocolTraitImplGenerator( val fnName = "parse_${operationShape.id.name.toSnakeCase()}_error" val outputShape = operationShape.outputShape(model) val outputSymbol = symbolProvider.toSymbol(outputShape) - val errorSymbol = operationShape.errorSymbol(model, symbolProvider, coreCodegenContext.target) + val errorSymbol = operationShape.errorSymbol(model, symbolProvider, codegenContext.target) return RuntimeType.forInlineFun(fnName, operationDeserModule) { Attribute.Custom("allow(clippy::unnecessary_wraps)").render(it) it.rustBlockTemplate( @@ -237,7 +241,7 @@ class HttpBoundProtocolTraitImplGenerator( val fnName = "parse_${operationShape.id.name.toSnakeCase()}" val outputShape = operationShape.outputShape(model) val outputSymbol = symbolProvider.toSymbol(outputShape) - val errorSymbol = operationShape.errorSymbol(model, symbolProvider, coreCodegenContext.target) + val errorSymbol = operationShape.errorSymbol(model, symbolProvider, codegenContext.target) return RuntimeType.forInlineFun(fnName, operationDeserModule) { Attribute.Custom("allow(clippy::unnecessary_wraps)").render(it) it.rustBlockTemplate( @@ -266,7 +270,7 @@ class HttpBoundProtocolTraitImplGenerator( val fnName = "parse_${operationShape.id.name.toSnakeCase()}_response" val outputShape = operationShape.outputShape(model) val outputSymbol = symbolProvider.toSymbol(outputShape) - val errorSymbol = operationShape.errorSymbol(model, symbolProvider, coreCodegenContext.target) + val errorSymbol = operationShape.errorSymbol(model, symbolProvider, codegenContext.target) return RuntimeType.forInlineFun(fnName, operationDeserModule) { Attribute.Custom("allow(clippy::unnecessary_wraps)").render(it) it.rustBlockTemplate( @@ -295,7 +299,7 @@ class HttpBoundProtocolTraitImplGenerator( errorSymbol: RuntimeType, customizations: List, ) { - val httpBindingGenerator = ResponseBindingGenerator(protocol, coreCodegenContext, operationShape) + val httpBindingGenerator = ResponseBindingGenerator(protocol, codegenContext, operationShape) val structuredDataParser = protocol.structuredDataParser(operationShape) Attribute.AllowUnusedMut.render(this) rust("let mut output = #T::default();", outputShape.builderSymbol(symbolProvider)) @@ -348,7 +352,7 @@ class HttpBoundProtocolTraitImplGenerator( httpBindingGenerator: ResponseBindingGenerator, structuredDataParser: StructuredDataParserGenerator, ): Writable? { - val errorSymbol = operationShape.errorSymbol(model, symbolProvider, coreCodegenContext.target) + val errorSymbol = operationShape.errorSymbol(model, symbolProvider, codegenContext.target) val member = binding.member return when (binding.location) { HttpLocation.HEADER -> writable { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestJson.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestJson.kt index 123acd4f5e6..02f880d1b80 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestJson.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestJson.kt @@ -14,18 +14,23 @@ import software.amazon.smithy.model.traits.JsonNameTrait import software.amazon.smithy.model.traits.MediaTypeTrait import software.amazon.smithy.model.traits.StreamingTrait import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport -import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.JsonParserGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.StructuredDataParserGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.JsonSerializerGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.StructuredDataSerializerGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpTraitHttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolContentTypes +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.JsonParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.JsonSerializerGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.outputShape @@ -85,8 +90,8 @@ class RestJsonHttpBindingResolver( } } -open class RestJson(val coreCodegenContext: CoreCodegenContext) : Protocol { - private val runtimeConfig = coreCodegenContext.runtimeConfig +open class RestJson(val codegenContext: CodegenContext) : Protocol { + private val runtimeConfig = codegenContext.runtimeConfig private val errorScope = arrayOf( "Bytes" to RuntimeType.Bytes, "Error" to RuntimeType.GenericError(runtimeConfig), @@ -98,7 +103,7 @@ open class RestJson(val coreCodegenContext: CoreCodegenContext) : Protocol { private val jsonDeserModule = RustModule.private("json_deser") override val httpBindingResolver: HttpBindingResolver = - RestJsonHttpBindingResolver(coreCodegenContext.model, ProtocolContentTypes("application/json", "application/json", "application/vnd.amazon.eventstream")) + RestJsonHttpBindingResolver(codegenContext.model, ProtocolContentTypes("application/json", "application/json", "application/vnd.amazon.eventstream")) override val defaultTimestampFormat: TimestampFormatTrait.Format = TimestampFormatTrait.Format.EPOCH_SECONDS @@ -110,10 +115,10 @@ open class RestJson(val coreCodegenContext: CoreCodegenContext) : Protocol { listOf("x-amzn-errortype" to errorShape.id.name) override fun structuredDataParser(operationShape: OperationShape): StructuredDataParserGenerator = - JsonParserGenerator(coreCodegenContext, httpBindingResolver, ::restJsonFieldName) + JsonParserGenerator(codegenContext, httpBindingResolver, ::restJsonFieldName) override fun structuredDataSerializer(operationShape: OperationShape): StructuredDataSerializerGenerator = - JsonSerializerGenerator(coreCodegenContext, httpBindingResolver, ::restJsonFieldName) + JsonSerializerGenerator(codegenContext, httpBindingResolver, ::restJsonFieldName) override fun parseHttpGenericError(operationShape: OperationShape): RuntimeType = RuntimeType.forInlineFun("parse_http_generic_error", jsonDeserModule) { writer -> diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestXml.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestXml.kt index 09de074078b..cb3a82674ae 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestXml.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestXml.kt @@ -6,24 +6,26 @@ package software.amazon.smithy.rust.codegen.client.smithy.protocols import software.amazon.smithy.aws.traits.protocols.RestXmlTrait -import software.amazon.smithy.model.node.Node import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.model.traits.AnnotationTrait import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport -import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.RestXmlParserGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.StructuredDataParserGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.StructuredDataSerializerGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.XmlBindingTraitSerializerGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpTraitHttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolContentTypes +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.RestXmlParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.XmlBindingTraitSerializerGenerator import software.amazon.smithy.rust.codegen.core.util.expectTrait class RestXmlFactory( @@ -51,9 +53,9 @@ class RestXmlFactory( } } -open class RestXml(val coreCodegenContext: CoreCodegenContext) : Protocol { - private val restXml = coreCodegenContext.serviceShape.expectTrait() - private val runtimeConfig = coreCodegenContext.runtimeConfig +open class RestXml(val codegenContext: CodegenContext) : Protocol { + private val restXml = codegenContext.serviceShape.expectTrait() + private val runtimeConfig = codegenContext.runtimeConfig private val errorScope = arrayOf( "Bytes" to RuntimeType.Bytes, "Error" to RuntimeType.GenericError(runtimeConfig), @@ -69,17 +71,17 @@ open class RestXml(val coreCodegenContext: CoreCodegenContext) : Protocol { } override val httpBindingResolver: HttpBindingResolver = - HttpTraitHttpBindingResolver(coreCodegenContext.model, ProtocolContentTypes("application/xml", "application/xml", "application/vnd.amazon.eventstream")) + HttpTraitHttpBindingResolver(codegenContext.model, ProtocolContentTypes("application/xml", "application/xml", "application/vnd.amazon.eventstream")) override val defaultTimestampFormat: TimestampFormatTrait.Format = TimestampFormatTrait.Format.DATE_TIME override fun structuredDataParser(operationShape: OperationShape): StructuredDataParserGenerator { - return RestXmlParserGenerator(coreCodegenContext, restXmlErrors) + return RestXmlParserGenerator(codegenContext, restXmlErrors) } override fun structuredDataSerializer(operationShape: OperationShape): StructuredDataSerializerGenerator { - return XmlBindingTraitSerializerGenerator(coreCodegenContext, httpBindingResolver) + return XmlBindingTraitSerializerGenerator(codegenContext, httpBindingResolver) } override fun parseHttpGenericError(operationShape: OperationShape): RuntimeType = @@ -102,12 +104,3 @@ open class RestXml(val coreCodegenContext: CoreCodegenContext) : Protocol { } } } - -/** - * Indicates that a service is expected to send XML where the root element name does not match the modeled member name. - */ -class AllowInvalidXmlRoot : AnnotationTrait(ID, Node.objectNode()) { - companion object { - val ID: ShapeId = ShapeId.from("smithy.api.internal#allowInvalidXmlRoot") - } -} diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/AddErrorMessage.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/AddErrorMessage.kt index bfb4163afd7..7e69ce6995a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/AddErrorMessage.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/AddErrorMessage.kt @@ -6,17 +6,14 @@ package software.amazon.smithy.rust.codegen.client.smithy.transformers import software.amazon.smithy.model.Model -import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.ErrorTrait import software.amazon.smithy.model.transform.ModelTransformer +import software.amazon.smithy.rust.codegen.core.util.errorMessageMember import software.amazon.smithy.rust.codegen.core.util.hasTrait -import software.amazon.smithy.rust.codegen.core.util.orNull import java.util.logging.Logger -fun StructureShape.errorMessageMember(): MemberShape? = this.getMember("message").or { this.getMember("Message") }.orNull() - /** * Ensure that all errors have error messages. * diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/Rust.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/Rust.kt index cf45c94eca7..9340d0e27af 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/Rust.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/Rust.kt @@ -16,18 +16,18 @@ import software.amazon.smithy.model.node.ObjectNode import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.traits.EnumDefinition -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.raw -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenConfig -import software.amazon.smithy.rust.codegen.client.smithy.DefaultPublicModules -import software.amazon.smithy.rust.codegen.client.smithy.MaybeRenamed -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.raw +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.smithy.CoreCodegenConfig +import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules +import software.amazon.smithy.rust.codegen.core.smithy.MaybeRenamed +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.core.util.CommandFailed import software.amazon.smithy.rust.codegen.core.util.PANIC import software.amazon.smithy.rust.codegen.core.util.dq diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestConfigCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestConfigCustomization.kt index f2f850e35fd..d91ea1f6d67 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestConfigCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestConfigCustomization.kt @@ -5,13 +5,13 @@ package software.amazon.smithy.rust.codegen.client.testutil -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfigGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.writable /** * Test helper to produce a valid config customization to test that a [ConfigCustomization] can be used in conjunction diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt index 88ead1eb765..ffd625fe1b3 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt @@ -11,26 +11,26 @@ import software.amazon.smithy.model.node.ObjectNode import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.CratesIo -import software.amazon.smithy.rust.codegen.client.rustlang.DependencyScope -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenConfig import software.amazon.smithy.rust.codegen.client.smithy.ClientRustSettings -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenConfig -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.CoreRustSettings -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeCrateLocation import software.amazon.smithy.rust.codegen.client.smithy.RustCodegenPlugin -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.SymbolVisitorConfig -import software.amazon.smithy.rust.codegen.client.smithy.generators.BuilderGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.StructureGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.implBlock +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo +import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.CoreCodegenConfig +import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeCrateLocation +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.letIf import java.io.File @@ -106,7 +106,7 @@ fun testCodegenContext( serviceShape: ServiceShape? = null, settings: CoreRustSettings = testRustSettings(), codegenTarget: CodegenTarget = CodegenTarget.CLIENT, -): CoreCodegenContext = CoreCodegenContext( +): CodegenContext = CodegenContext( model, testSymbolProvider(model), serviceShape diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/SymbolBuilderTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/SymbolBuilderTest.kt index 96437c61402..640cfc46fa7 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/SymbolBuilderTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/SymbolBuilderTest.kt @@ -26,15 +26,15 @@ import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.ErrorTrait import software.amazon.smithy.model.traits.SparseTrait -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.render -import software.amazon.smithy.rust.codegen.client.smithy.Errors -import software.amazon.smithy.rust.codegen.client.smithy.Models -import software.amazon.smithy.rust.codegen.client.smithy.Operations -import software.amazon.smithy.rust.codegen.client.smithy.isOptional -import software.amazon.smithy.rust.codegen.client.smithy.rustType import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.render +import software.amazon.smithy.rust.codegen.core.smithy.Errors +import software.amazon.smithy.rust.codegen.core.smithy.Models +import software.amazon.smithy.rust.codegen.core.smithy.Operations +import software.amazon.smithy.rust.codegen.core.smithy.isOptional +import software.amazon.smithy.rust.codegen.core.smithy.rustType class SymbolBuilderTest { private fun Symbol.referenceClosure(): List { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt index ef5188e9bfa..d36fdac0716 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt @@ -6,23 +6,24 @@ package software.amazon.smithy.rust.codegen.client.customizations import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.CodegenVisitor -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCustomizations import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.client.testutil.AddRustTestsDecorator import software.amazon.smithy.rust.codegen.client.testutil.TokioTest import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.util.runCommand // If any of these tests fail, and you want to understand why, run them with logging: @@ -58,7 +59,7 @@ internal class HttpVersionListGeneratorTest { """.asSmithyModel() val (ctx, testDir) = generatePluginContext(model) val moduleName = ctx.settings.expectStringMember("module").value.replace('-', '_') - val combinedCodegenDecorator: CombinedCodegenDecorator = + val combinedCodegenDecorator: CombinedCodegenDecorator = CombinedCodegenDecorator.fromClasspath(ctx, RequiredCustomizations()) .withDecorator( AddRustTestsDecorator("validate_defaults") { @@ -114,7 +115,7 @@ internal class HttpVersionListGeneratorTest { """.asSmithyModel() val (ctx, testDir) = generatePluginContext(model) val moduleName = ctx.settings.expectStringMember("module").value.replace('-', '_') - val combinedCodegenDecorator: CombinedCodegenDecorator = + val combinedCodegenDecorator: CombinedCodegenDecorator = CombinedCodegenDecorator.fromClasspath(ctx, RequiredCustomizations()) .withDecorator( AddRustTestsDecorator("validate_http") { @@ -184,9 +185,9 @@ internal class HttpVersionListGeneratorTest { val (ctx, testDir) = generatePluginContext(model, addModuleToEventStreamAllowList = true) val moduleName = ctx.settings.expectStringMember("module").value.replace('-', '_') - val combinedCodegenDecorator: CombinedCodegenDecorator = + val combinedCodegenDecorator: CombinedCodegenDecorator = CombinedCodegenDecorator.fromClasspath(ctx, RequiredCustomizations()) - .withDecorator(object : AddRustTestsDecorator("validate_eventstream_http", { + .withDecorator(object : AddRustTestsDecorator("validate_eventstream_http", { TokioTest.render(this) rust( """ diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/ResiliencyConfigCustomizationTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/ResiliencyConfigCustomizationTest.kt index 8cb3506f705..fc30f13dc87 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/ResiliencyConfigCustomizationTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/ResiliencyConfigCustomizationTest.kt @@ -8,14 +8,14 @@ package software.amazon.smithy.rust.codegen.client.customizations import org.junit.jupiter.api.Test import software.amazon.smithy.rust.codegen.client.smithy.customizations.ResiliencyConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.customizations.ResiliencyReExportCustomization -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer -import software.amazon.smithy.rust.codegen.client.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.rustSettings import software.amazon.smithy.rust.codegen.client.testutil.stubConfigProject import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer internal class ResiliencyConfigCustomizationTest { private val baseModel = """ diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/SmithyTypesPubUseGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/SmithyTypesPubUseGeneratorTest.kt index f499693c9a0..6450e40c74d 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/SmithyTypesPubUseGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/SmithyTypesPubUseGeneratorTest.kt @@ -7,10 +7,10 @@ package software.amazon.smithy.rust.codegen.client.customizations import org.junit.jupiter.api.Test import software.amazon.smithy.model.Model -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType import software.amazon.smithy.rust.codegen.client.smithy.customizations.pubUseTypes import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType class SmithyTypesPubUseGeneratorTest { private fun emptyModel() = modelWithMember() diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/EnumGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/EnumGeneratorTest.kt index 24855a63166..031600f1aa2 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/EnumGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/EnumGeneratorTest.kt @@ -11,13 +11,13 @@ import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.traits.EnumTrait -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.smithy.generators.EnumGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.EnumMemberModel import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumMemberModel import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.core.util.orNull diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/GenericsGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/RustGenericsTest.kt similarity index 79% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/GenericsGeneratorTest.kt rename to codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/RustGenericsTest.kt index ea269e87df0..73fd5500e92 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/GenericsGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/RustGenericsTest.kt @@ -7,16 +7,16 @@ package software.amazon.smithy.rust.codegen.client.generators import io.kotest.matchers.string.shouldContain import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.GenericTypeArg -import software.amazon.smithy.rust.codegen.client.smithy.generators.GenericsGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.GenericTypeArg +import software.amazon.smithy.rust.codegen.core.rustlang.RustGenerics +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.RuntimeType -class GenericsGeneratorTest { +class RustGenericsTest { @Test fun `declaration is correct for no args`() { - val gg = GenericsGenerator() + val gg = RustGenerics() val writer = RustWriter.forModule("model") writer.rustTemplate("A#{decl:W}B", "decl" to gg.declaration()) @@ -25,7 +25,7 @@ class GenericsGeneratorTest { @Test fun `declaration is correct for 1 arg`() { - val gg = GenericsGenerator(GenericTypeArg("T")) + val gg = RustGenerics(GenericTypeArg("T")) val writer = RustWriter.forModule("model") writer.rustTemplate("#{decl:W}", "decl" to gg.declaration()) @@ -34,7 +34,7 @@ class GenericsGeneratorTest { @Test fun `declaration is correct for several args`() { - val gg = GenericsGenerator(GenericTypeArg("T"), GenericTypeArg("U"), GenericTypeArg("V")) + val gg = RustGenerics(GenericTypeArg("T"), GenericTypeArg("U"), GenericTypeArg("V")) val writer = RustWriter.forModule("model") writer.rustTemplate("#{decl:W}", "decl" to gg.declaration()) @@ -43,7 +43,7 @@ class GenericsGeneratorTest { @Test fun `bounds is correct for no args`() { - val gg = GenericsGenerator() + val gg = RustGenerics() val writer = RustWriter.forModule("model") writer.rustTemplate("A#{bounds:W}B", "bounds" to gg.bounds()) @@ -52,7 +52,7 @@ class GenericsGeneratorTest { @Test fun `bounds is correct for 1 arg`() { - val gg = GenericsGenerator(GenericTypeArg("T", testRT("Test"))) + val gg = RustGenerics(GenericTypeArg("T", testRT("Test"))) val writer = RustWriter.forModule("model") writer.rustTemplate("#{bounds:W}", "bounds" to gg.bounds()) @@ -61,7 +61,7 @@ class GenericsGeneratorTest { @Test fun `bounds is correct for several args`() { - val gg = GenericsGenerator( + val gg = RustGenerics( GenericTypeArg("A", testRT("Apple")), GenericTypeArg("PL", testRT("Plum")), GenericTypeArg("PE", testRT("Pear")), @@ -78,7 +78,7 @@ class GenericsGeneratorTest { @Test fun `bounds skips arg with no bounds`() { - val gg = GenericsGenerator( + val gg = RustGenerics( GenericTypeArg("A", testRT("Apple")), GenericTypeArg("PL"), GenericTypeArg("PE", testRT("Pear")), @@ -94,7 +94,7 @@ class GenericsGeneratorTest { @Test fun `bounds generates nothing if all args are skipped`() { - val gg = GenericsGenerator( + val gg = RustGenerics( GenericTypeArg("A"), GenericTypeArg("PL"), GenericTypeArg("PE"), @@ -107,10 +107,10 @@ class GenericsGeneratorTest { @Test fun `Adding GenericGenerators works`() { - val ggA = GenericsGenerator( + val ggA = RustGenerics( GenericTypeArg("A", testRT("Apple")), ) - val ggB = GenericsGenerator( + val ggB = RustGenerics( GenericTypeArg("B", testRT("Banana")), ) RustWriter.forModule("model").let { writer -> diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/StructureGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/StructureGeneratorTest.kt index 00fac0b016c..7f9b771a095 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/StructureGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/StructureGeneratorTest.kt @@ -10,21 +10,21 @@ import io.kotest.matchers.string.shouldNotContain import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.RustMetadata -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Visibility -import software.amazon.smithy.rust.codegen.client.rustlang.docs -import software.amazon.smithy.rust.codegen.client.rustlang.raw -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.smithy.generators.StructureGenerator -import software.amazon.smithy.rust.codegen.client.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.rustlang.docs +import software.amazon.smithy.rust.codegen.core.rustlang.raw +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator +import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.core.util.lookup class StructureGeneratorTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/UnionGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/UnionGeneratorTest.kt index a05f219b2d1..f770df48bc4 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/UnionGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/UnionGeneratorTest.kt @@ -8,12 +8,12 @@ package software.amazon.smithy.rust.codegen.client.generators import io.kotest.matchers.string.shouldContain import org.junit.jupiter.api.Test import software.amazon.smithy.codegen.core.SymbolProvider -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator import software.amazon.smithy.rust.codegen.core.util.lookup class UnionGeneratorTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/http/RequestBindingGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/http/RequestBindingGeneratorTest.kt index e17e79dde9e..e2bbad162b4 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/http/RequestBindingGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/http/RequestBindingGeneratorTest.kt @@ -11,16 +11,7 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.HttpTrait -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.http.RequestBindingGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.http.uriFormatString -import software.amazon.smithy.rust.codegen.client.smithy.generators.operationBuildError import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestJson -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel @@ -29,6 +20,15 @@ import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilde import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.http.RequestBindingGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.http.uriFormatString +import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.expectTrait diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/http/ResponseBindingGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/http/ResponseBindingGeneratorTest.kt index 03486aab4a0..dd7af8de691 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/http/ResponseBindingGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/http/ResponseBindingGeneratorTest.kt @@ -8,17 +8,7 @@ package software.amazon.smithy.rust.codegen.client.generators.http import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.generators.http.ResponseBindingGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpLocation -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpTraitHttpBindingResolver -import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolContentTypes import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestJson -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest @@ -26,6 +16,16 @@ import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilde import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.generators.http.ResponseBindingGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpLocation +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpTraitHttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolContentTypes +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.util.outputShape class ResponseBindingGeneratorTest { @@ -70,7 +70,7 @@ class ResponseBindingGeneratorTest { private val model = OperationNormalizer.transform(baseModel) private val operationShape = model.expectShape(ShapeId.from("smithy.example#PutObject"), OperationShape::class.java) private val symbolProvider = testSymbolProvider(model) - private val testCoreCodegenContext: CoreCodegenContext = testCodegenContext(model) + private val testCodegenContext: CodegenContext = testCodegenContext(model) private fun RustWriter.renderOperation() { operationShape.outputShape(model).renderWithModelBuilder(model, symbolProvider, this) @@ -80,8 +80,8 @@ class ResponseBindingGeneratorTest { .filter { it.location == HttpLocation.HEADER } bindings.forEach { binding -> val runtimeType = ResponseBindingGenerator( - RestJson(testCoreCodegenContext), - testCoreCodegenContext, + RestJson(testCodegenContext), + testCodegenContext, operationShape, ).generateDeserializeHeaderFn(binding) // little hack to force these functions to be generated diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/InlineDependencyTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/InlineDependencyTest.kt index 972bfbd9248..52103a35def 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/InlineDependencyTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/InlineDependencyTest.kt @@ -9,9 +9,14 @@ import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import org.junit.jupiter.api.Test import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.InlineDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock internal class InlineDependencyTest { - fun makeDep(name: String) = InlineDependency(name, RustModule.private("module")) { + private fun makeDep(name: String) = InlineDependency(name, RustModule.private("module")) { it.rustBlock("fn foo()") {} } diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustReservedWordSymbolProviderTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustReservedWordSymbolProviderTest.kt index ba0849d1c17..36904eab7df 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustReservedWordSymbolProviderTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustReservedWordSymbolProviderTest.kt @@ -11,10 +11,11 @@ import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.traits.EnumDefinition -import software.amazon.smithy.rust.codegen.client.smithy.MaybeRenamed -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.MaybeRenamed +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.core.util.PANIC import software.amazon.smithy.rust.codegen.core.util.orNull import software.amazon.smithy.rust.codegen.core.util.toPascalCase diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustTypesTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustTypesTest.kt index 9f9dafc0c31..b9f36e3560f 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustTypesTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustTypesTest.kt @@ -8,6 +8,11 @@ package software.amazon.smithy.rust.codegen.client.rustlang import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain import org.junit.jupiter.api.Test +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.render +import software.amazon.smithy.rust.codegen.core.rustlang.rustInlineTemplate internal class RustTypesTest { private fun forInputExpectOutput(t: Writable, expectedOutput: String) { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustWriterTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustWriterTest.kt index aa88fca2f31..a09066cc82a 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustWriterTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustWriterTest.kt @@ -15,12 +15,23 @@ import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.SetShape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndRun import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.shouldCompile import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.docs +import software.amazon.smithy.rust.codegen.core.rustlang.isEmpty +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.util.lookup class RustWriterTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/UseDeclarationsTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/UseDeclarationsTest.kt index da53e8a05f3..0d88defcad3 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/UseDeclarationsTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/UseDeclarationsTest.kt @@ -8,6 +8,7 @@ package software.amazon.smithy.rust.codegen.client.rustlang import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.rust.codegen.client.testutil.shouldCompile +import software.amazon.smithy.rust.codegen.core.rustlang.UseDeclarations class UseDeclarationsTest { private fun useDecl() = UseDeclarations("test") diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/WritableTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/WritableTest.kt index 329cb463f19..f770d5be611 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/WritableTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/WritableTest.kt @@ -7,9 +7,16 @@ package software.amazon.smithy.rust.codegen.client.rustlang import io.kotest.matchers.string.shouldContain import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.GenericTypeArg -import software.amazon.smithy.rust.codegen.client.smithy.generators.GenericsGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.GenericTypeArg +import software.amazon.smithy.rust.codegen.core.rustlang.RustGenerics +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.join +import software.amazon.smithy.rust.codegen.core.rustlang.rustInlineTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTypeParameters +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType internal class RustTypeParametersTest { private fun forInputExpectOutput(input: Any, expectedOutput: String) { @@ -44,8 +51,8 @@ internal class RustTypeParametersTest { } @Test - fun `rustTypeParameters accepts GenericsGenerator`() { - forInputExpectOutput(GenericsGenerator(GenericTypeArg("A"), GenericTypeArg("B")), "''") + fun `rustTypeParameters accepts RustGenerics`() { + forInputExpectOutput(RustGenerics(GenericTypeArg("A"), GenericTypeArg("B")), "''") } @Test @@ -56,7 +63,7 @@ internal class RustTypeParametersTest { RustType.Unit, RuntimeType("String", namespace = "std::string", dependency = null), "T", - GenericsGenerator(GenericTypeArg("A"), GenericTypeArg("B")), + RustGenerics(GenericTypeArg("A"), GenericTypeArg("B")), ) writer.rustInlineTemplate("'") writer.rustInlineTemplate("#{tps:W}", "tps" to tps) diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenDelegatorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenDelegatorTest.kt index f2de8280828..c2e47b6993a 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenDelegatorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenDelegatorTest.kt @@ -7,9 +7,10 @@ package software.amazon.smithy.rust.codegen.client.smithy import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.CratesIo -import software.amazon.smithy.rust.codegen.client.rustlang.DependencyScope.Compile +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo +import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope.Compile +import software.amazon.smithy.rust.codegen.core.smithy.mergeDependencyFeatures class CodegenDelegatorTest { @Test diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProviderTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProviderTest.kt index 87adb5f0f3a..4f9fd822385 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProviderTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProviderTest.kt @@ -10,12 +10,14 @@ import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.client.testutil.TestSymbolVisitorConfig import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor +import software.amazon.smithy.rust.codegen.core.smithy.rustType +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer class EventStreamSymbolProviderTest { @Test diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RuntimeTypesTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RuntimeTypesTest.kt index d85bd0e9739..074a2f83edf 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RuntimeTypesTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RuntimeTypesTest.kt @@ -11,9 +11,14 @@ import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.Arguments import org.junit.jupiter.params.provider.MethodSource import software.amazon.smithy.model.node.Node -import software.amazon.smithy.rust.codegen.client.rustlang.CratesIo -import software.amazon.smithy.rust.codegen.client.rustlang.DependencyLocation -import software.amazon.smithy.rust.codegen.client.rustlang.Local +import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo +import software.amazon.smithy.rust.codegen.core.rustlang.DependencyLocation +import software.amazon.smithy.rust.codegen.core.rustlang.Local +import software.amazon.smithy.rust.codegen.core.smithy.CrateVersionMap +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeCrateLocation +import software.amazon.smithy.rust.codegen.core.smithy.crateLocation +import software.amazon.smithy.rust.codegen.core.smithy.defaultRuntimeCrateVersion import java.util.Optional class RuntimeTypesTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/StreamingShapeSymbolProviderTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/StreamingShapeSymbolProviderTest.kt index 2af307a9432..584e097565a 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/StreamingShapeSymbolProviderTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/StreamingShapeSymbolProviderTest.kt @@ -8,9 +8,11 @@ package software.amazon.smithy.rust.codegen.client.smithy import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.MemberShape -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.Default +import software.amazon.smithy.rust.codegen.core.smithy.defaultValue +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.util.lookup internal class StreamingShapeSymbolProviderTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/BuilderGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/BuilderGeneratorTest.kt index d9c98427aa6..a941f7218d1 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/BuilderGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/BuilderGeneratorTest.kt @@ -11,15 +11,18 @@ import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.traits.EnumDefinition import software.amazon.smithy.rust.codegen.client.generators.StructureGeneratorTest -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.smithy.Default -import software.amazon.smithy.rust.codegen.client.smithy.MaybeRenamed -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.SymbolVisitorConfig -import software.amazon.smithy.rust.codegen.client.smithy.setDefault import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.smithy.Default +import software.amazon.smithy.rust.codegen.core.smithy.MaybeRenamed +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock +import software.amazon.smithy.rust.codegen.core.smithy.setDefault internal class BuilderGeneratorTest { private val model = StructureGeneratorTest.model diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CargoTomlGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CargoTomlGeneratorTest.kt index 39492f974ed..c31aecfaf5e 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CargoTomlGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CargoTomlGeneratorTest.kt @@ -6,12 +6,12 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.CratesIo import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.Version +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo class CargoTomlGeneratorTest { private val CargoMetadata: CargoDependency = CargoDependency("cargo_metadata", CratesIo("0.15.0")) diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CombinedErrorGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CombinedErrorGeneratorTest.kt index 099b8a452c9..92f44feb442 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CombinedErrorGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CombinedErrorGeneratorTest.kt @@ -7,15 +7,15 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.CombinedErrorGenerator -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.CombinedErrorGenerator +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.util.lookup class CombinedErrorGeneratorTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt index 6a9e859e5d7..920faba4b96 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt @@ -9,17 +9,12 @@ import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.EndpointTrait -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.Visibility -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.CodegenVisitor -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCustomizations import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.TokioTest @@ -28,6 +23,14 @@ import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock +import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.core.util.runCommand import kotlin.io.path.ExperimentalPathApi @@ -144,7 +147,7 @@ internal class EndpointTraitBindingsTest { """.asSmithyModel() val (ctx, testDir) = generatePluginContext(model) val moduleName = ctx.settings.expectStringMember("module").value.replace('-', '_') - val codegenDecorator = object : RustCodegenDecorator { + val codegenDecorator = object : RustCodegenDecorator { override val name: String = "add tests" override val order: Byte = 0 @@ -173,10 +176,10 @@ internal class EndpointTraitBindingsTest { } } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ClientCodegenContext::class.java) } - val combinedCodegenDecorator: CombinedCodegenDecorator = + val combinedCodegenDecorator: CombinedCodegenDecorator = CombinedCodegenDecorator.fromClasspath(ctx, RequiredCustomizations()).withDecorator(codegenDecorator) val visitor = CodegenVisitor(ctx, combinedCodegenDecorator) visitor.execute() diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/InstantiatorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/InstantiatorTest.kt index b164a32a6a2..6d47fff4cab 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/InstantiatorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/InstantiatorTest.kt @@ -12,17 +12,20 @@ import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.raw -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.raw +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.generators.Instantiator +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.lookup diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGeneratorTest.kt index 2f7fbf656d0..3afcc7d08a4 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGeneratorTest.kt @@ -8,16 +8,16 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators.config import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.ServiceShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.customize.NamedSectionGenerator import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.customize.NamedSectionGenerator import software.amazon.smithy.rust.codegen.core.util.lookup internal class ServiceConfigGeneratorTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt index 03d27153075..ef563106885 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt @@ -11,23 +11,27 @@ import org.junit.jupiter.api.assertThrows import software.amazon.smithy.aws.traits.protocols.RestJson1Trait import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.escape -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.CodegenVisitor -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.errorSymbol -import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol -import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolGeneratorFactory -import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolMap import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestJson import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.escape +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.errorSymbol +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.MakeOperationGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolPayloadGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolTraitImplGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolMap import software.amazon.smithy.rust.codegen.core.util.CommandFailed import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.outputShape @@ -44,10 +48,10 @@ private class TestProtocolPayloadGenerator(private val body: String) : ProtocolP } private class TestProtocolTraitImplGenerator( - private val coreCodegenContext: CoreCodegenContext, + private val codegenContext: CodegenContext, private val correctResponse: String, ) : ProtocolTraitImplGenerator { - private val symbolProvider = coreCodegenContext.symbolProvider + private val symbolProvider = codegenContext.symbolProvider override fun generateTraitImpls(operationWriter: RustWriter, operationShape: OperationShape, customizations: List) { operationWriter.rustTemplate( @@ -58,9 +62,9 @@ private class TestProtocolTraitImplGenerator( ${operationWriter.escape(correctResponse)} } }""", - "parse_strict" to RuntimeType.parseStrictResponse(coreCodegenContext.runtimeConfig), - "output" to symbolProvider.toSymbol(operationShape.outputShape(coreCodegenContext.model)), - "error" to operationShape.errorSymbol(coreCodegenContext.model, symbolProvider, coreCodegenContext.target), + "parse_strict" to RuntimeType.parseStrictResponse(codegenContext.runtimeConfig), + "output" to symbolProvider.toSymbol(operationShape.outputShape(codegenContext.model)), + "error" to operationShape.errorSymbol(codegenContext.model, symbolProvider, codegenContext.target), "response" to RuntimeType.Http("Response"), "bytes" to RuntimeType.Bytes, ) @@ -68,12 +72,12 @@ private class TestProtocolTraitImplGenerator( } private class TestProtocolMakeOperationGenerator( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, protocol: Protocol, body: String, private val httpRequestBuilder: String, ) : MakeOperationGenerator( - coreCodegenContext, + codegenContext, protocol, TestProtocolPayloadGenerator(body), public = true, @@ -87,28 +91,28 @@ private class TestProtocolMakeOperationGenerator( // A stubbed test protocol to do enable testing intentionally broken protocols private class TestProtocolGenerator( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, protocol: Protocol, httpRequestBuilder: String, body: String, correctResponse: String, -) : ProtocolGenerator( - coreCodegenContext, +) : ClientProtocolGenerator( + codegenContext, protocol, - TestProtocolMakeOperationGenerator(coreCodegenContext, protocol, body, httpRequestBuilder), - TestProtocolTraitImplGenerator(coreCodegenContext, correctResponse), + TestProtocolMakeOperationGenerator(codegenContext, protocol, body, httpRequestBuilder), + TestProtocolTraitImplGenerator(codegenContext, correctResponse), ) private class TestProtocolFactory( private val httpRequestBuilder: String, private val body: String, private val correctResponse: String, -) : ProtocolGeneratorFactory { +) : ProtocolGeneratorFactory { override fun protocol(codegenContext: ClientCodegenContext): Protocol { return RestJson(codegenContext) } - override fun buildProtocolGenerator(codegenContext: ClientCodegenContext): ProtocolGenerator { + override fun buildProtocolGenerator(codegenContext: ClientCodegenContext): ClientProtocolGenerator { return TestProtocolGenerator( codegenContext, protocol(codegenContext), @@ -220,21 +224,22 @@ class ProtocolTestGeneratorTest { correctResponse: String = """Ok(crate::output::SayHelloOutput::builder().value("hey there!").build())""", ): Path { val (pluginContext, testDir) = generatePluginContext(model) + val codegenDecorator = object : RustCodegenDecorator { + override val name: String = "mock" + override val order: Byte = 0 + override fun protocols( + serviceId: ShapeId, + currentProtocols: ProtocolMap, + ): ProtocolMap = + // Intentionally replace the builtin implementation of RestJson1 with our fake protocol + mapOf(RestJson1Trait.ID to TestProtocolFactory(httpRequestBuilder, body, correctResponse)) + + override fun supportsCodegenContext(clazz: Class): Boolean = + clazz.isAssignableFrom(ClientCodegenContext::class.java) + } val visitor = CodegenVisitor( pluginContext, - object : RustCodegenDecorator { - override val name: String = "mock" - override val order: Byte = 0 - override fun protocols( - serviceId: ShapeId, - currentProtocols: ProtocolMap, - ): ProtocolMap = - // Intentionally replace the builtin implementation of RestJson1 with our fake protocol - mapOf(RestJson1Trait.ID to TestProtocolFactory(httpRequestBuilder, body, correctResponse)) - - override fun supportsCodegenContext(clazz: Class): Boolean = - clazz.isAssignableFrom(ClientCodegenContext::class.java) - }, + codegenDecorator, ) visitor.execute() println("file:///$testDir/src/operation.rs") diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/InlineFunctionNamerTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/InlineFunctionNamerTest.kt index 996d4453402..623b4d1ac42 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/InlineFunctionNamerTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/InlineFunctionNamerTest.kt @@ -10,6 +10,8 @@ import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.protocols.deserializeFunctionName +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serializeFunctionName import software.amazon.smithy.rust.codegen.core.util.lookup class InlineFunctionNamerTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/AwsQueryParserGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/AwsQueryParserGeneratorTest.kt index 9e3258e8e2d..638e4bc59d4 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/AwsQueryParserGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/AwsQueryParserGeneratorTest.kt @@ -8,10 +8,6 @@ package software.amazon.smithy.rust.codegen.client.smithy.protocols.parse import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer -import software.amazon.smithy.rust.codegen.client.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel @@ -20,6 +16,11 @@ import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilde import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.AwsQueryParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.core.util.outputShape diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/Ec2QueryParserGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/Ec2QueryParserGeneratorTest.kt index 8ad6273857e..aac9f12ed77 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/Ec2QueryParserGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/Ec2QueryParserGeneratorTest.kt @@ -8,10 +8,6 @@ package software.amazon.smithy.rust.codegen.client.smithy.protocols.parse import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer -import software.amazon.smithy.rust.codegen.client.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel @@ -20,6 +16,11 @@ import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilde import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.Ec2QueryParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.core.util.outputShape diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/JsonParserGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/JsonParserGeneratorTest.kt index dd757fefaa2..ad94eb2105a 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/JsonParserGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/JsonParserGeneratorTest.kt @@ -9,14 +9,7 @@ import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.smithy.generators.EnumGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpTraitHttpBindingResolver -import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolContentTypes import software.amazon.smithy.rust.codegen.client.smithy.protocols.restJsonFieldName -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer -import software.amazon.smithy.rust.codegen.client.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest @@ -24,6 +17,14 @@ import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilde import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpTraitHttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolContentTypes +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.JsonParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.core.util.outputShape diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/XmlBindingTraitParserGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/XmlBindingTraitParserGeneratorTest.kt index 6cb3b5aba9a..b5dea3f9fe3 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/XmlBindingTraitParserGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/XmlBindingTraitParserGeneratorTest.kt @@ -9,12 +9,6 @@ import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.EnumGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer -import software.amazon.smithy.rust.codegen.client.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel @@ -23,6 +17,13 @@ import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilde import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.XmlBindingTraitParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.core.util.outputShape diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/AwsQuerySerializerGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/AwsQuerySerializerGeneratorTest.kt index e31e0ea2729..400d4c6b80a 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/AwsQuerySerializerGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/AwsQuerySerializerGeneratorTest.kt @@ -10,12 +10,6 @@ import org.junit.jupiter.params.provider.CsvSource import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.EnumGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer -import software.amazon.smithy.rust.codegen.client.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest @@ -23,6 +17,13 @@ import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilde import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.AwsQuerySerializerGenerator +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.lookup diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/Ec2QuerySerializerGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/Ec2QuerySerializerGeneratorTest.kt index ca9bb6fd6a4..512fcd9aa53 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/Ec2QuerySerializerGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/Ec2QuerySerializerGeneratorTest.kt @@ -9,11 +9,6 @@ import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.smithy.generators.EnumGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer -import software.amazon.smithy.rust.codegen.client.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest @@ -21,6 +16,12 @@ import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilde import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.Ec2QuerySerializerGenerator +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.lookup diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/JsonSerializerGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/JsonSerializerGeneratorTest.kt index 56bc924f7aa..be3341700a5 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/JsonSerializerGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/JsonSerializerGeneratorTest.kt @@ -9,14 +9,7 @@ import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.smithy.generators.EnumGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpTraitHttpBindingResolver -import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolContentTypes import software.amazon.smithy.rust.codegen.client.smithy.protocols.restJsonFieldName -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer -import software.amazon.smithy.rust.codegen.client.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest @@ -24,6 +17,14 @@ import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilde import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpTraitHttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolContentTypes +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.JsonSerializerGenerator +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.lookup diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/XmlBindingTraitSerializerGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/XmlBindingTraitSerializerGeneratorTest.kt index d4ad16fb3bb..e352da919a8 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/XmlBindingTraitSerializerGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/XmlBindingTraitSerializerGeneratorTest.kt @@ -9,13 +9,6 @@ import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.smithy.generators.EnumGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpTraitHttpBindingResolver -import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolContentTypes -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer -import software.amazon.smithy.rust.codegen.client.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest @@ -23,6 +16,14 @@ import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilde import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpTraitHttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolContentTypes +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.XmlBindingTraitSerializerGenerator +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.lookup diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/EventStreamNormalizerTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/EventStreamNormalizerTest.kt index a24c579453a..90564e81a58 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/EventStreamNormalizerTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/EventStreamNormalizerTest.kt @@ -11,6 +11,7 @@ import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticEventStreamUnionTrait +import software.amazon.smithy.rust.codegen.core.smithy.transformers.EventStreamNormalizer import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/OperationNormalizerTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/OperationNormalizerTest.kt index e2110779269..0fde36acbcd 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/OperationNormalizerTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/OperationNormalizerTest.kt @@ -15,6 +15,7 @@ import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticOutputTrait +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.util.orNull internal class OperationNormalizerTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapeBoxerTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapeBoxerTest.kt index 4ec569e8a23..2327b3fa0c1 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapeBoxerTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapeBoxerTest.kt @@ -8,8 +8,9 @@ package software.amazon.smithy.rust.codegen.client.smithy.transformers import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.MemberShape -import software.amazon.smithy.rust.codegen.client.smithy.RustBoxTrait import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.smithy.traits.RustBoxTrait +import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.lookup diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapesIntegrationTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapesIntegrationTest.kt index 00574e930f0..67b73e77c3e 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapesIntegrationTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapesIntegrationTest.kt @@ -10,12 +10,13 @@ import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.smithy.generators.StructureGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.core.util.CommandFailed import software.amazon.smithy.rust.codegen.core.util.lookup diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/testutil/AddRustTestsDecorator.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/testutil/AddRustTestsDecorator.kt index c923aea3727..0bb1a6c7ce5 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/testutil/AddRustTestsDecorator.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/testutil/AddRustTestsDecorator.kt @@ -4,15 +4,15 @@ */ package software.amazon.smithy.rust.codegen.client.testutil -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate -open class AddRustTestsDecorator( +open class AddRustTestsDecorator( private val testsFileName: String, private val testWritable: Writable, -) : RustCodegenDecorator { +) : RustCodegenDecorator { override val name: String = "add tests" override val order: Byte = 0 @@ -23,5 +23,5 @@ open class AddRustTestsDecorator( } // Don't allow this class to be discovered on the classpath; always return false - override fun supportsCodegenContext(clazz: Class): Boolean = false + override fun supportsCodegenContext(clazz: Class): Boolean = false } diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/util/SyntheticsTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/util/SyntheticsTest.kt index a2058bc83c5..1feaf49662c 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/util/SyntheticsTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/util/SyntheticsTest.kt @@ -11,7 +11,9 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.util.cloneOperation import software.amazon.smithy.rust.codegen.core.util.orNull +import software.amazon.smithy.rust.codegen.core.util.rename class SyntheticsTest { @Test diff --git a/codegen-core/build.gradle.kts b/codegen-core/build.gradle.kts index f1c349b2ed7..4cb3e06fead 100644 --- a/codegen-core/build.gradle.kts +++ b/codegen-core/build.gradle.kts @@ -25,7 +25,9 @@ val kotestVersion: String by project dependencies { implementation(kotlin("stdlib-jdk8")) + implementation("org.jsoup:jsoup:1.14.3") api("software.amazon.smithy:smithy-codegen-core:$smithyVersion") + api("com.moandjiezana.toml:toml4j:0.7.2") implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion") implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion") implementation("software.amazon.smithy:smithy-waiters:$smithyVersion") diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/CargoDependency.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt similarity index 96% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/CargoDependency.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt index 18aa5a31941..62361e4863b 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/CargoDependency.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt @@ -3,12 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.rustlang +package software.amazon.smithy.rust.codegen.core.rustlang import software.amazon.smithy.codegen.core.SymbolDependency import software.amazon.smithy.codegen.core.SymbolDependencyContainer -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.util.dq import java.nio.file.Path @@ -115,7 +115,7 @@ class InlineDependency( } } -fun CargoDependency.asType(): RuntimeType = RuntimeType(null, dependency = this, namespace = rustName) +fun CargoDependency.asType() = RuntimeType(null, dependency = this, namespace = rustName) data class Feature(val name: String, val default: Boolean, val deps: List) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/GenericsGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustGenerics.kt similarity index 77% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/GenericsGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustGenerics.kt index 64235ee48ff..b5de87b76ca 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/GenericsGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustGenerics.kt @@ -3,12 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators +package software.amazon.smithy.rust.codegen.core.rustlang -import software.amazon.smithy.rust.codegen.client.rustlang.rustInlineTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType data class GenericTypeArg( val typeArg: String, @@ -54,7 +51,7 @@ data class GenericTypeArg( * // } * ``` */ -class GenericsGenerator(vararg genericTypeArgs: GenericTypeArg) { +class RustGenerics(vararg genericTypeArgs: GenericTypeArg) { private val typeArgs: List init { @@ -74,22 +71,23 @@ class GenericsGenerator(vararg genericTypeArgs: GenericTypeArg) { * // Writes "fn eat_fruit_salad()" * ``` */ - fun declaration(withAngleBrackets: Boolean = true) = writable { - // Write nothing if this generator is empty - if (typeArgs.isNotEmpty()) { - val typeArgs = typeArgs.joinToString(", ") { it.typeArg } + fun declaration(withAngleBrackets: Boolean = true) = + writable { + // Write nothing if this generator is empty + if (typeArgs.isNotEmpty()) { + val typeArgs = typeArgs.joinToString(", ") { it.typeArg } - if (withAngleBrackets) { - rustInlineTemplate("<") - } + if (withAngleBrackets) { + rustInlineTemplate("<") + } - rustInlineTemplate(typeArgs) + rustInlineTemplate(typeArgs) - if (withAngleBrackets) { - rustInlineTemplate(">") + if (withAngleBrackets) { + rustInlineTemplate(">") + } } } - } /** * Returns bounded generic type args formatted for use in a "where" clause. @@ -147,7 +145,7 @@ class GenericsGenerator(vararg genericTypeArgs: GenericTypeArg) { * // Writes "fn eat_fruit()" * */ - operator fun plus(operationGenerics: GenericsGenerator): GenericsGenerator { - return GenericsGenerator(*(typeArgs + operationGenerics.typeArgs).toTypedArray()) + operator fun plus(operationGenerics: RustGenerics): RustGenerics { + return RustGenerics(*(typeArgs + operationGenerics.typeArgs).toTypedArray()) } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustModule.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt similarity index 95% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustModule.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt index 382bd1811f9..0ec62243d15 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustModule.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.rustlang +package software.amazon.smithy.rust.codegen.core.rustlang data class RustModule(val name: String, val rustMetadata: RustMetadata, val documentation: String?) { fun render(writer: RustWriter) { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustReservedWords.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustReservedWords.kt similarity index 93% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustReservedWords.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustReservedWords.kt index becc7c0c1e6..33f15aa89e5 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustReservedWords.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustReservedWords.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.rustlang +package software.amazon.smithy.rust.codegen.core.rustlang import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider import software.amazon.smithy.codegen.core.ReservedWords @@ -14,11 +14,11 @@ import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumDefinition -import software.amazon.smithy.rust.codegen.client.smithy.MaybeRenamed -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.WrappingSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.renamedFrom +import software.amazon.smithy.rust.codegen.core.smithy.MaybeRenamed +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.WrappingSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.renamedFrom import software.amazon.smithy.rust.codegen.core.util.letIf import software.amazon.smithy.rust.codegen.core.util.orNull import software.amazon.smithy.rust.codegen.core.util.toPascalCase diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustTypes.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustTypes.kt similarity index 99% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustTypes.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustTypes.kt index 60819a4c50e..24344b57c7b 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustTypes.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustTypes.kt @@ -3,9 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.rustlang +package software.amazon.smithy.rust.codegen.core.rustlang -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.util.dq /** diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustWriter.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriter.kt similarity index 98% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustWriter.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriter.kt index 24d59c01ab7..f733003217a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustWriter.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriter.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.rustlang +package software.amazon.smithy.rust.codegen.core.rustlang import org.intellij.lang.annotations.Language import org.jsoup.Jsoup @@ -20,9 +20,9 @@ import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.traits.DeprecatedTrait import software.amazon.smithy.model.traits.DocumentationTrait -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.isOptional -import software.amazon.smithy.rust.codegen.client.smithy.rustType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.isOptional +import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.letIf import software.amazon.smithy.rust.codegen.core.util.orNull diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/UseDeclarations.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/UseDeclarations.kt similarity index 95% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/UseDeclarations.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/UseDeclarations.kt index c2e51150981..4e409bf126e 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/UseDeclarations.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/UseDeclarations.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.rustlang +package software.amazon.smithy.rust.codegen.core.rustlang import software.amazon.smithy.codegen.core.ImportContainer import software.amazon.smithy.codegen.core.Symbol diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/Writable.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/Writable.kt similarity index 93% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/Writable.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/Writable.kt index c453fe06533..f1ed5ad9443 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/Writable.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/Writable.kt @@ -3,12 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.rustlang +package software.amazon.smithy.rust.codegen.core.rustlang import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.codegen.core.Symbol -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.GenericsGenerator +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType typealias Writable = RustWriter.() -> Unit @@ -103,7 +102,7 @@ fun rustTypeParameters( when (typeParameter) { is Symbol, is RuntimeType, is RustType -> rustInlineTemplate("#{it}", "it" to typeParameter) is String -> rustInlineTemplate(typeParameter) - is GenericsGenerator -> rustInlineTemplate( + is RustGenerics -> rustInlineTemplate( "#{gg:W}", "gg" to typeParameter.declaration(withAngleBrackets = false), ) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CoreCodegenContext.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenContext.kt similarity index 91% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CoreCodegenContext.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenContext.kt index 75c109d369c..743eb63ebc6 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CoreCodegenContext.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenContext.kt @@ -3,22 +3,21 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy +package software.amazon.smithy.rust.codegen.core.smithy import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget /** - * [CoreCodegenContext] contains code-generation context that is _common to all_ smithy-rs plugins. + * [CodegenContext] contains code-generation context that is _common to all_ smithy-rs plugins. * * Code-generation context is pervasive read-only global data that gets passed around to the generators. * * If your data is specific to the `rust-codegen` client plugin, put it in [ClientCodegenContext] instead. * If your data is specific to the `rust-server-codegen` server plugin, put it in [ServerCodegenContext] instead. */ -open class CoreCodegenContext( +open class CodegenContext( /** * The smithy model. * diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenDelegator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt similarity index 89% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenDelegator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt index db33989787e..53473cb6716 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenDelegator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt @@ -3,23 +3,23 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy +package software.amazon.smithy.rust.codegen.core.smithy import software.amazon.smithy.build.FileManifest import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.codegen.core.WriterDelegator import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.Shape -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.Feature -import software.amazon.smithy.rust.codegen.client.rustlang.InlineDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.smithy.generators.CargoTomlGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.ManifestCustomizations +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.Feature +import software.amazon.smithy.rust.codegen.core.rustlang.InlineDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.smithy.generators.CargoTomlGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.ManifestCustomizations /** * RustCrate abstraction. @@ -224,7 +224,7 @@ private fun CargoDependency.mergeWith(other: CargoDependency): CargoDependency { ) } -internal fun mergeDependencyFeatures(cargoDependencies: List): List = +fun mergeDependencyFeatures(cargoDependencies: List): List = cargoDependencies.groupBy { it.key } .mapValues { group -> group.value.reduce { acc, next -> acc.mergeWith(next) } } .values diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CodegenTarget.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenTarget.kt similarity index 80% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CodegenTarget.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenTarget.kt index 5ff7fe5cf54..27ea5dcc68f 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CodegenTarget.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenTarget.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators +package software.amazon.smithy.rust.codegen.core.smithy /** * Code generation mode: In some situations, codegen has different behavior for client vs. server (eg. required fields) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CoreRustSettings.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CoreRustSettings.kt similarity index 99% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CoreRustSettings.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CoreRustSettings.kt index 10e91a599f4..ffe91eb170e 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CoreRustSettings.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CoreRustSettings.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy +package software.amazon.smithy.rust.codegen.core.smithy import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.model.Model diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RuntimeTypes.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeTypes.kt similarity index 92% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RuntimeTypes.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeTypes.kt index 66de796b83b..781014bd850 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RuntimeTypes.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeTypes.kt @@ -3,27 +3,27 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy +package software.amazon.smithy.rust.codegen.core.smithy import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.node.Node import software.amazon.smithy.model.node.ObjectNode import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.CratesIo -import software.amazon.smithy.rust.codegen.client.rustlang.DependencyLocation -import software.amazon.smithy.rust.codegen.client.rustlang.DependencyScope -import software.amazon.smithy.rust.codegen.client.rustlang.InlineDependency -import software.amazon.smithy.rust.codegen.client.rustlang.Local -import software.amazon.smithy.rust.codegen.client.rustlang.RustDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rustInlineTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable import software.amazon.smithy.rust.codegen.core.Version +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo +import software.amazon.smithy.rust.codegen.core.rustlang.DependencyLocation +import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope +import software.amazon.smithy.rust.codegen.core.rustlang.InlineDependency +import software.amazon.smithy.rust.codegen.core.rustlang.Local +import software.amazon.smithy.rust.codegen.core.rustlang.RustDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rustInlineTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.util.orNull import java.util.Optional @@ -128,7 +128,12 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n /** * Get a writable for this `RuntimeType` */ - val writable = writable { rustInlineTemplate("#{this:T}", "this" to this@RuntimeType) } + val writable = writable { + rustInlineTemplate( + "#{this:T}", + "this" to this@RuntimeType, + ) + } /** * Convert this [RuntimeType] into a [Symbol]. diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/SymbolMetadataProvider.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolMetadataProvider.kt similarity index 95% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/SymbolMetadataProvider.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolMetadataProvider.kt index 8c7d7e70c46..8c5a56b5778 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/SymbolMetadataProvider.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolMetadataProvider.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy +package software.amazon.smithy.rust.codegen.core.smithy import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.codegen.core.Symbol @@ -16,9 +16,9 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumDefinition import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.StreamingTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.RustMetadata -import software.amazon.smithy.rust.codegen.client.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata +import software.amazon.smithy.rust.codegen.core.rustlang.Visibility import software.amazon.smithy.rust.codegen.core.util.hasTrait /** diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/SymbolVisitor.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt similarity index 98% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/SymbolVisitor.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt index 0100fbd39f8..3b2024faed7 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/SymbolVisitor.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy +package software.amazon.smithy.rust.codegen.core.smithy import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.codegen.core.SymbolProvider @@ -37,8 +37,9 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumDefinition import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.ErrorTrait -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.stripOuter +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter +import software.amazon.smithy.rust.codegen.core.smithy.traits.RustBoxTrait import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticOutputTrait import software.amazon.smithy.rust.codegen.core.util.PANIC diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NamedSectionGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/customize/NamedSectionGenerator.kt similarity index 83% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NamedSectionGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/customize/NamedSectionGenerator.kt index 8bbbbc7f70d..516bfc4284e 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/NamedSectionGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/customize/NamedSectionGenerator.kt @@ -3,11 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.customize +package software.amazon.smithy.rust.codegen.core.smithy.customize -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.writable +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.writable /** * An overrideable section for code generation. Usage: diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/OperationCustomization.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/customize/OperationCustomization.kt similarity index 91% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/OperationCustomization.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/customize/OperationCustomization.kt index c59b62ebdac..a7dd176a9e2 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/OperationCustomization.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/customize/OperationCustomization.kt @@ -3,12 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.customize +package software.amazon.smithy.rust.codegen.core.smithy.customize import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol sealed class OperationSection(name: String) : Section(name) { abstract val customizations: List diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/BuilderGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt similarity index 86% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/BuilderGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt index d9a6d8edaad..c561b04c396 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/BuilderGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt @@ -3,35 +3,35 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators +package software.amazon.smithy.rust.codegen.core.smithy.generators import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustReservedWords -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asArgument -import software.amazon.smithy.rust.codegen.client.rustlang.asOptional -import software.amazon.smithy.rust.codegen.client.rustlang.conditionalBlock -import software.amazon.smithy.rust.codegen.client.rustlang.deprecatedShape -import software.amazon.smithy.rust.codegen.client.rustlang.docs -import software.amazon.smithy.rust.codegen.client.rustlang.documentShape -import software.amazon.smithy.rust.codegen.client.rustlang.render -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.stripOuter -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.smithy.Default -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.defaultValue -import software.amazon.smithy.rust.codegen.client.smithy.expectRustMetadata -import software.amazon.smithy.rust.codegen.client.smithy.isOptional -import software.amazon.smithy.rust.codegen.client.smithy.makeOptional -import software.amazon.smithy.rust.codegen.client.smithy.rustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asArgument +import software.amazon.smithy.rust.codegen.core.rustlang.asOptional +import software.amazon.smithy.rust.codegen.core.rustlang.conditionalBlock +import software.amazon.smithy.rust.codegen.core.rustlang.deprecatedShape +import software.amazon.smithy.rust.codegen.core.rustlang.docs +import software.amazon.smithy.rust.codegen.core.rustlang.documentShape +import software.amazon.smithy.rust.codegen.core.rustlang.render +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.smithy.Default +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.defaultValue +import software.amazon.smithy.rust.codegen.core.smithy.expectRustMetadata +import software.amazon.smithy.rust.codegen.core.smithy.isOptional +import software.amazon.smithy.rust.codegen.core.smithy.makeOptional +import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.toSnakeCase diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CargoTomlGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt similarity index 85% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CargoTomlGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt index a6000ad0dc6..cceced878b3 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CargoTomlGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGenerator.kt @@ -3,15 +3,15 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators +package software.amazon.smithy.rust.codegen.core.smithy.generators import com.moandjiezana.toml.TomlWriter -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.DependencyScope -import software.amazon.smithy.rust.codegen.client.rustlang.Feature -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.smithy.CoreRustSettings import software.amazon.smithy.rust.codegen.core.Version +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope +import software.amazon.smithy.rust.codegen.core.rustlang.Feature +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings import software.amazon.smithy.rust.codegen.core.util.deepMergeWith /** diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EnumGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt similarity index 89% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EnumGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt index 1d5447caf3d..f2b25032b5a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EnumGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt @@ -3,25 +3,26 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators +package software.amazon.smithy.rust.codegen.core.smithy.generators import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.traits.DocumentationTrait import software.amazon.smithy.model.traits.EnumDefinition import software.amazon.smithy.model.traits.EnumTrait -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.deprecatedShape -import software.amazon.smithy.rust.codegen.client.rustlang.docs -import software.amazon.smithy.rust.codegen.client.rustlang.documentShape -import software.amazon.smithy.rust.codegen.client.rustlang.escape -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.smithy.MaybeRenamed -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.expectRustMetadata +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.deprecatedShape +import software.amazon.smithy.rust.codegen.core.rustlang.docs +import software.amazon.smithy.rust.codegen.core.rustlang.documentShape +import software.amazon.smithy.rust.codegen.core.rustlang.escape +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.MaybeRenamed +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.expectRustMetadata import software.amazon.smithy.rust.codegen.core.util.doubleQuote import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.getTrait diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/Instantiator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt similarity index 91% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/Instantiator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt index 3cf94d8b71b..a869e732559 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/Instantiator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators +package software.amazon.smithy.rust.codegen.core.smithy.generators import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.model.Model @@ -29,22 +29,23 @@ import software.amazon.smithy.model.shapes.TimestampShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.HttpPrefixHeadersTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.conditionalBlock -import software.amazon.smithy.rust.codegen.client.rustlang.escape -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.stripOuter -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.isOptional -import software.amazon.smithy.rust.codegen.client.smithy.rustType +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.conditionalBlock +import software.amazon.smithy.rust.codegen.core.rustlang.escape +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.isOptional +import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.expectMember import software.amazon.smithy.rust.codegen.core.util.hasTrait diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/LibRsGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt similarity index 78% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/LibRsGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt index 7da60fe44fc..3be71980804 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/LibRsGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/LibRsGenerator.kt @@ -3,19 +3,19 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators +package software.amazon.smithy.rust.codegen.core.smithy.generators import software.amazon.smithy.model.Model import software.amazon.smithy.model.traits.DocumentationTrait -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.containerDocs -import software.amazon.smithy.rust.codegen.client.rustlang.escape -import software.amazon.smithy.rust.codegen.client.rustlang.isEmpty -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.smithy.CoreRustSettings -import software.amazon.smithy.rust.codegen.client.smithy.customize.NamedSectionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.customize.Section +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.containerDocs +import software.amazon.smithy.rust.codegen.core.rustlang.escape +import software.amazon.smithy.rust.codegen.core.rustlang.isEmpty +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings +import software.amazon.smithy.rust.codegen.core.smithy.customize.NamedSectionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.customize.Section import software.amazon.smithy.rust.codegen.core.util.getTrait sealed class LibRsSection(name: String) : Section(name) { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/StructureGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt similarity index 83% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/StructureGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt index 91dd67d871e..5bf6e0a6b88 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/StructureGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators +package software.amazon.smithy.rust.codegen.core.smithy.generators import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.codegen.core.SymbolProvider @@ -13,25 +13,26 @@ import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.ErrorTrait import software.amazon.smithy.model.traits.SensitiveTrait -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asDeref -import software.amazon.smithy.rust.codegen.client.rustlang.asRef -import software.amazon.smithy.rust.codegen.client.rustlang.deprecatedShape -import software.amazon.smithy.rust.codegen.client.rustlang.documentShape -import software.amazon.smithy.rust.codegen.client.rustlang.isCopy -import software.amazon.smithy.rust.codegen.client.rustlang.isDeref -import software.amazon.smithy.rust.codegen.client.rustlang.render -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.canUseDefault -import software.amazon.smithy.rust.codegen.client.smithy.expectRustMetadata -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.ErrorGenerator -import software.amazon.smithy.rust.codegen.client.smithy.isOptional -import software.amazon.smithy.rust.codegen.client.smithy.renamedFrom -import software.amazon.smithy.rust.codegen.client.smithy.rustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asDeref +import software.amazon.smithy.rust.codegen.core.rustlang.asRef +import software.amazon.smithy.rust.codegen.core.rustlang.deprecatedShape +import software.amazon.smithy.rust.codegen.core.rustlang.documentShape +import software.amazon.smithy.rust.codegen.core.rustlang.isCopy +import software.amazon.smithy.rust.codegen.core.rustlang.isDeref +import software.amazon.smithy.rust.codegen.core.rustlang.render +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.canUseDefault +import software.amazon.smithy.rust.codegen.core.smithy.expectRustMetadata +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.ErrorGenerator +import software.amazon.smithy.rust.codegen.core.smithy.isOptional +import software.amazon.smithy.rust.codegen.core.smithy.renamedFrom +import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.getTrait diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/TypeConversionGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/TypeConversionGenerator.kt similarity index 76% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/TypeConversionGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/TypeConversionGenerator.kt index 9ae2f63f5e6..dd46fcba423 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/TypeConversionGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/TypeConversionGenerator.kt @@ -3,20 +3,20 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators +package software.amazon.smithy.rust.codegen.core.smithy.generators import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.TimestampShape -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.rustType +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.rustType /* * Utility class used to force casting a non primitive type into one overriden by a new symbol provider, diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/UnionGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt similarity index 87% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/UnionGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt index 388dc2e14dd..5075430ed33 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/UnionGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGenerator.kt @@ -3,21 +3,22 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators +package software.amazon.smithy.rust.codegen.core.smithy.generators import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.UnionShape -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.deprecatedShape -import software.amazon.smithy.rust.codegen.client.rustlang.docs -import software.amazon.smithy.rust.codegen.client.rustlang.documentShape -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.smithy.expectRustMetadata -import software.amazon.smithy.rust.codegen.client.smithy.renamedFrom +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.deprecatedShape +import software.amazon.smithy.rust.codegen.core.rustlang.docs +import software.amazon.smithy.rust.codegen.core.rustlang.documentShape +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.expectRustMetadata +import software.amazon.smithy.rust.codegen.core.smithy.renamedFrom import software.amazon.smithy.rust.codegen.core.util.toSnakeCase fun CodegenTarget.renderUnknownVariant() = when (this) { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/error/CombinedErrorGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt similarity index 89% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/error/CombinedErrorGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt index 86f1c37fd2f..9c973ff0925 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/error/CombinedErrorGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators.error +package software.amazon.smithy.rust.codegen.core.smithy.generators.error import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model @@ -12,24 +12,24 @@ import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.RetryableTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.RustMetadata -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Visibility -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.deprecatedShape -import software.amazon.smithy.rust.codegen.client.rustlang.documentShape -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.customize.Section -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.transformers.eventStreamErrors -import software.amazon.smithy.rust.codegen.client.smithy.transformers.operationErrors +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.deprecatedShape +import software.amazon.smithy.rust.codegen.core.rustlang.documentShape +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.customize.Section +import software.amazon.smithy.rust.codegen.core.smithy.transformers.eventStreamErrors +import software.amazon.smithy.rust.codegen.core.smithy.transformers.operationErrors import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.toSnakeCase diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/error/ErrorGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ErrorGenerator.kt similarity index 83% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/error/ErrorGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ErrorGenerator.kt index 748e0bff8ae..8f9382b5acc 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/error/ErrorGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ErrorGenerator.kt @@ -3,24 +3,24 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators.error +package software.amazon.smithy.rust.codegen.core.smithy.generators.error import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.ErrorTrait import software.amazon.smithy.model.traits.RetryableTrait -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType.Companion.StdError -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.isOptional -import software.amazon.smithy.rust.codegen.client.smithy.transformers.errorMessageMember +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.StdError +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.isOptional import software.amazon.smithy.rust.codegen.core.util.dq +import software.amazon.smithy.rust.codegen.core.util.errorMessageMember import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.letIf diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/error/ServerCombinedErrorGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ServerCombinedErrorGenerator.kt similarity index 85% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/error/ServerCombinedErrorGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ServerCombinedErrorGenerator.kt index 77196149a35..de6c09a5ac2 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/error/ServerCombinedErrorGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ServerCombinedErrorGenerator.kt @@ -3,22 +3,22 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators.error +package software.amazon.smithy.rust.codegen.core.smithy.generators.error import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.RustMetadata -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Visibility -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.deprecatedShape -import software.amazon.smithy.rust.codegen.client.rustlang.documentShape -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.deprecatedShape +import software.amazon.smithy.rust.codegen.core.rustlang.documentShape +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.util.toSnakeCase /** diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/error/TopLevelErrorGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt similarity index 64% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/error/TopLevelErrorGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt index db7c3a6e637..4253622fffd 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/error/TopLevelErrorGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt @@ -3,29 +3,28 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators.error +package software.amazon.smithy.rust.codegen.core.smithy.generators.error import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustMetadata -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Visibility -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.deprecatedShape -import software.amazon.smithy.rust.codegen.client.rustlang.documentShape -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.transformers.allErrors -import software.amazon.smithy.rust.codegen.client.smithy.transformers.eventStreamErrors +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.deprecatedShape +import software.amazon.smithy.rust.codegen.core.rustlang.documentShape +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.transformers.allErrors +import software.amazon.smithy.rust.codegen.core.smithy.transformers.eventStreamErrors /** * Each service defines its own "top-level" error combining all possible errors that a service can emit. @@ -42,15 +41,15 @@ import software.amazon.smithy.rust.codegen.client.smithy.transformers.eventStrea * } * ``` */ -class TopLevelErrorGenerator(private val coreCodegenContext: CoreCodegenContext, private val operations: List) { - private val symbolProvider = coreCodegenContext.symbolProvider - private val model = coreCodegenContext.model +class TopLevelErrorGenerator(private val codegenContext: CodegenContext, private val operations: List) { + private val symbolProvider = codegenContext.symbolProvider + private val model = codegenContext.model - private val allErrors = operations.flatMap { it.allErrors(model) }.map { it.id }.distinctBy { it.getName(coreCodegenContext.serviceShape) } - .map { coreCodegenContext.model.expectShape(it, StructureShape::class.java) } - .sortedBy { it.id.getName(coreCodegenContext.serviceShape) } + private val allErrors = operations.flatMap { it.allErrors(model) }.map { it.id }.distinctBy { it.getName(codegenContext.serviceShape) } + .map { codegenContext.model.expectShape(it, StructureShape::class.java) } + .sortedBy { it.id.getName(codegenContext.serviceShape) } - private val sdkError = CargoDependency.SmithyHttp(coreCodegenContext.runtimeConfig).asType().member("result::SdkError") + private val sdkError = CargoDependency.SmithyHttp(codegenContext.runtimeConfig).asType().member("result::SdkError") fun render(crate: RustCrate) { crate.withModule(RustModule.default("error_meta", visibility = Visibility.PRIVATE)) { writer -> writer.renderDefinition() @@ -58,10 +57,10 @@ class TopLevelErrorGenerator(private val coreCodegenContext: CoreCodegenContext, // Every operation error can be converted into service::Error operations.forEach { operationShape -> // operation errors - writer.renderImplFrom(operationShape.errorSymbol(model, symbolProvider, coreCodegenContext.target), operationShape.errors) + writer.renderImplFrom(operationShape.errorSymbol(model, symbolProvider, codegenContext.target), operationShape.errors) } // event stream errors - operations.map { it.eventStreamErrors(coreCodegenContext.model) } + operations.map { it.eventStreamErrors(codegenContext.model) } .flatMap { it.entries } .associate { it.key to it.value } .forEach { (unionShape, errors) -> @@ -69,7 +68,7 @@ class TopLevelErrorGenerator(private val coreCodegenContext: CoreCodegenContext, unionShape.eventStreamErrorSymbol( model, symbolProvider, - coreCodegenContext.target, + codegenContext.target, ), errors.map { it.id }, ) @@ -93,7 +92,7 @@ class TopLevelErrorGenerator(private val coreCodegenContext: CoreCodegenContext, } private fun RustWriter.renderImplFrom(symbol: RuntimeType, errors: List) { - if (errors.isNotEmpty() || CodegenTarget.CLIENT == coreCodegenContext.target) { + if (errors.isNotEmpty() || CodegenTarget.CLIENT == codegenContext.target) { rustBlock( "impl From<#T<#T, R>> for Error where R: Send + Sync + std::fmt::Debug + 'static", sdkError, @@ -126,8 +125,8 @@ class TopLevelErrorGenerator(private val coreCodegenContext: CoreCodegenContext, private fun RustWriter.renderDefinition() { rust("/// All possible error types for this service.") RustMetadata( - additionalAttributes = listOf(Attribute.NonExhaustive), - visibility = Visibility.PUBLIC, + additionalAttributes = listOf(software.amazon.smithy.rust.codegen.core.rustlang.Attribute.NonExhaustive), + visibility = software.amazon.smithy.rust.codegen.core.rustlang.Visibility.PUBLIC, ).withDerives(RuntimeType.Debug).render(this) rustBlock("enum Error") { allErrors.forEach { error -> diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/HttpBindingGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt similarity index 92% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/HttpBindingGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt index c2590675e7c..e76ed60ac99 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/HttpBindingGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators.http +package software.amazon.smithy.rust.codegen.core.smithy.generators.http import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.model.knowledge.HttpBinding @@ -21,31 +21,31 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.MediaTypeTrait import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asOptional -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.autoDeref -import software.amazon.smithy.rust.codegen.client.rustlang.render -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.stripOuter -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.operationBuildError -import software.amazon.smithy.rust.codegen.client.smithy.makeOptional -import software.amazon.smithy.rust.codegen.client.smithy.mapRustType -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBindingDescriptor -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpLocation -import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol -import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.EventStreamUnmarshallerGenerator -import software.amazon.smithy.rust.codegen.client.smithy.rustType +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asOptional +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.autoDeref +import software.amazon.smithy.rust.codegen.core.rustlang.render +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError +import software.amazon.smithy.rust.codegen.core.smithy.makeOptional +import software.amazon.smithy.rust.codegen.core.smithy.mapRustType +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingDescriptor +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpLocation +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.EventStreamUnmarshallerGenerator +import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.util.UNREACHABLE import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.hasTrait @@ -88,14 +88,14 @@ enum class HttpMessageType { */ class HttpBindingGenerator( private val protocol: Protocol, - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, private val operationShape: OperationShape, ) { - private val runtimeConfig = coreCodegenContext.runtimeConfig - private val symbolProvider = coreCodegenContext.symbolProvider - private val target = coreCodegenContext.target - private val model = coreCodegenContext.model - private val service = coreCodegenContext.serviceShape + private val runtimeConfig = codegenContext.runtimeConfig + private val symbolProvider = codegenContext.symbolProvider + private val target = codegenContext.target + private val model = codegenContext.model + private val service = codegenContext.serviceShape private val index = HttpBindingIndex.of(model) private val headerUtil = CargoDependency.SmithyHttp(runtimeConfig).asType().member("header") private val defaultTimestampFormat = TimestampFormatTrait.Format.EPOCH_SECONDS diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/RequestBindingGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt similarity index 89% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/RequestBindingGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt index 84e3f772133..9a55d74a488 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/RequestBindingGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGenerator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators.http +package software.amazon.smithy.rust.codegen.core.smithy.generators.http import software.amazon.smithy.model.knowledge.HttpBinding import software.amazon.smithy.model.knowledge.HttpBindingIndex @@ -13,20 +13,20 @@ import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.traits.HttpTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.autoDeref -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationBuildError -import software.amazon.smithy.rust.codegen.client.smithy.generators.operationBuildError -import software.amazon.smithy.rust.codegen.client.smithy.isOptional -import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.autoDeref +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.OperationBuildError +import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError +import software.amazon.smithy.rust.codegen.core.smithy.isOptional +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.expectMember import software.amazon.smithy.rust.codegen.core.util.inputShape @@ -53,16 +53,16 @@ fun SmithyPattern.rustFormatString(prefix: String, separator: String): String { * headers & URL based on the HTTP trait implementation. */ class RequestBindingGenerator( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, private val protocol: Protocol, private val operationShape: OperationShape, ) { - private val model = coreCodegenContext.model + private val model = codegenContext.model private val inputShape = operationShape.inputShape(model) - private val symbolProvider = coreCodegenContext.symbolProvider - private val runtimeConfig = coreCodegenContext.runtimeConfig + private val symbolProvider = codegenContext.symbolProvider + private val runtimeConfig = codegenContext.runtimeConfig private val httpTrait = protocol.httpBindingResolver.httpTrait(operationShape) - private val httpBindingGenerator = HttpBindingGenerator(protocol, coreCodegenContext, operationShape) + private val httpBindingGenerator = HttpBindingGenerator(protocol, codegenContext, operationShape) private val index = HttpBindingIndex.of(model) private val Encoder = CargoDependency.SmithyTypes(runtimeConfig).asType().member("primitive::Encoder") diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/ResponseBindingGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/ResponseBindingGenerator.kt similarity index 63% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/ResponseBindingGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/ResponseBindingGenerator.kt index 7eeeb2b5c54..1de4cd2897d 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/ResponseBindingGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/ResponseBindingGenerator.kt @@ -3,21 +3,21 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators.http +package software.amazon.smithy.rust.codegen.core.smithy.generators.http import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBindingDescriptor -import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingDescriptor +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol class ResponseBindingGenerator( protocol: Protocol, - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, operationShape: OperationShape, ) { - private val httpBindingGenerator = HttpBindingGenerator(protocol, coreCodegenContext, operationShape) + private val httpBindingGenerator = HttpBindingGenerator(protocol, codegenContext, operationShape) fun generateDeserializeHeaderFn(binding: HttpBindingDescriptor): RuntimeType = httpBindingGenerator.generateDeserializeHeaderFn(binding) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/RestRequestSpecGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RestRequestSpecGenerator.kt similarity index 83% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/RestRequestSpecGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RestRequestSpecGenerator.kt index ce029373018..df401f76367 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/http/RestRequestSpecGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RestRequestSpecGenerator.kt @@ -3,17 +3,17 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators.http +package software.amazon.smithy.rust.codegen.core.smithy.generators.http import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBindingResolver +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver /** * [RestRequestSpecGenerator] generates a restJson1 or restXml specific `RequestSpec`. Both protocols are routed the same. diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/MakeOperationGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt similarity index 78% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/MakeOperationGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt index a18be2d44ac..cda444132cc 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/MakeOperationGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/MakeOperationGenerator.kt @@ -3,30 +3,30 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators.protocol +package software.amazon.smithy.rust.codegen.core.smithy.generators.protocol import software.amazon.smithy.aws.traits.ServiceTrait import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.docs -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.rustlang.withBlockTemplate -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationSection -import software.amazon.smithy.rust.codegen.client.smithy.customize.writeCustomizations -import software.amazon.smithy.rust.codegen.client.smithy.generators.http.RequestBindingGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.operationBuildError -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpLocation -import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.docs +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection +import software.amazon.smithy.rust.codegen.core.smithy.customize.writeCustomizations +import software.amazon.smithy.rust.codegen.core.smithy.generators.http.RequestBindingGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpLocation +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.findStreamingMember import software.amazon.smithy.rust.codegen.core.util.getTrait @@ -35,7 +35,7 @@ import software.amazon.smithy.rust.codegen.core.util.letIf /** Generates the `make_operation` function on input structs */ open class MakeOperationGenerator( - protected val coreCodegenContext: CoreCodegenContext, + protected val codegenContext: CodegenContext, private val protocol: Protocol, private val bodyGenerator: ProtocolPayloadGenerator, private val public: Boolean, @@ -43,25 +43,25 @@ open class MakeOperationGenerator( private val includeDefaultPayloadHeaders: Boolean, private val functionName: String = "make_operation", ) { - protected val model = coreCodegenContext.model - protected val runtimeConfig = coreCodegenContext.runtimeConfig - protected val symbolProvider = coreCodegenContext.symbolProvider + protected val model = codegenContext.model + protected val runtimeConfig = codegenContext.runtimeConfig + protected val symbolProvider = codegenContext.symbolProvider protected val httpBindingResolver = protocol.httpBindingResolver private val defaultClassifier = CargoDependency.SmithyHttp(runtimeConfig) .asType().member("retry::DefaultResponseRetryClassifier") private val sdkId = - coreCodegenContext.serviceShape.getTrait()?.sdkId?.lowercase()?.replace(" ", "") - ?: coreCodegenContext.serviceShape.id.getName(coreCodegenContext.serviceShape) + codegenContext.serviceShape.getTrait()?.sdkId?.lowercase()?.replace(" ", "") + ?: codegenContext.serviceShape.id.getName(codegenContext.serviceShape) private val codegenScope = arrayOf( "config" to RuntimeType.Config, "header_util" to CargoDependency.SmithyHttp(runtimeConfig).asType().member("header"), "http" to RuntimeType.http, "HttpRequestBuilder" to RuntimeType.HttpRequestBuilder, - "OpBuildError" to coreCodegenContext.runtimeConfig.operationBuildError(), + "OpBuildError" to codegenContext.runtimeConfig.operationBuildError(), "operation" to RuntimeType.operationModule(runtimeConfig), - "SdkBody" to RuntimeType.sdkBody(coreCodegenContext.runtimeConfig), + "SdkBody" to RuntimeType.sdkBody(codegenContext.runtimeConfig), ) fun generateMakeOperation( @@ -162,7 +162,7 @@ open class MakeOperationGenerator( open fun createHttpRequest(writer: RustWriter, operationShape: OperationShape) { val httpBindingGenerator = RequestBindingGenerator( - coreCodegenContext, + codegenContext, protocol, operationShape, ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/ProtocolGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/ProtocolGenerator.kt new file mode 100644 index 00000000000..025df135a3d --- /dev/null +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/ProtocolGenerator.kt @@ -0,0 +1,88 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rust.codegen.core.smithy.generators.protocol + +import software.amazon.smithy.model.shapes.OperationShape +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol + +/** + * Payload Body Generator. + * + * Used to generate payloads that will go into HTTP bodies for HTTP requests (used by clients) + * and responses (used by servers). + * + * **Note:** There is only one real implementation of this interface. The other implementation is test-only. + * All protocols use the same class. + * + * Different protocols (e.g. JSON vs. XML) need to use different functionality to generate payload bodies. + */ +interface ProtocolPayloadGenerator { + data class PayloadMetadata(val takesOwnership: Boolean) + + /** + * Code generation needs to handle whether [generatePayload] takes ownership of the input or output + * for a given operation shape. + * + * Most operations will use the HTTP payload as a reference, but for operations that will consume the entire stream + * later,they will need to take ownership and different code needs to be generated. + */ + fun payloadMetadata(operationShape: OperationShape): PayloadMetadata + + /** + * Write the payload into [writer]. + * + * [self] is the name of the variable binding for the Rust struct that is to be serialized into the payload. + * + * This should be an expression that returns bytes: + * - a `Vec` for non-streaming operations; or + * - a `ByteStream` for streaming operations. + */ + fun generatePayload(writer: RustWriter, self: String, operationShape: OperationShape) +} + +/** + * Protocol Trait implementation generator + * + * **Note:** There is only one real implementation of this interface. The other implementation is test-only. + * All protocols use the same class. + * + * Protocols implement one of two traits to enable parsing HTTP responses: + * 1. `ParseHttpResponse`: Streaming binary operations + * 2. `ParseStrictResponse`: Non-streaming operations for the body must be "strict" (as in, not lazy) where the parser + * must have the complete body to return a result. + */ +interface ProtocolTraitImplGenerator { + fun generateTraitImpls(operationWriter: RustWriter, operationShape: OperationShape, customizations: List) +} + +/** + * Class providing scaffolding for HTTP based protocols that must build an HTTP request (headers / URL) and a body. + */ +abstract class ProtocolGenerator( + codegenContext: CodegenContext, + /** + * `Protocol` contains all protocol specific information. Each smithy protocol, e.g. RestJson, RestXml, etc. will + * have their own implementation of the protocol interface which defines how an input shape becomes and http::Request + * and an output shape is build from an `http::Response`. + */ + private val protocol: Protocol, + /** + * Operations generate a `make_operation(&config)` method to build a `aws_smithy_http::Operation` that can be dispatched + * This is the serializer side of request dispatch + */ + private val makeOperationGenerator: MakeOperationGenerator, + /** + * Operations generate implementations of ParseHttpResponse or ParseStrictResponse. + * This is the deserializer side of request dispatch (parsing the response) + */ + private val traitGenerator: ProtocolTraitImplGenerator, +) { + protected val symbolProvider = codegenContext.symbolProvider + protected val model = codegenContext.model +} diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/ProtocolSupport.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/ProtocolSupport.kt new file mode 100644 index 00000000000..c66dae4ce5b --- /dev/null +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/protocol/ProtocolSupport.kt @@ -0,0 +1,19 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rust.codegen.core.smithy.generators.protocol + +data class ProtocolSupport( + /* Client support */ + val requestSerialization: Boolean, + val requestBodySerialization: Boolean, + val responseDeserialization: Boolean, + val errorDeserialization: Boolean, + /* Server support */ + val requestDeserialization: Boolean, + val requestBodyDeserialization: Boolean, + val responseSerialization: Boolean, + val errorSerialization: Boolean, +) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBindingResolver.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBindingResolver.kt similarity index 99% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBindingResolver.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBindingResolver.kt index 46150481266..cf14e07e2e7 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBindingResolver.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBindingResolver.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols +package software.amazon.smithy.rust.codegen.core.smithy.protocols import software.amazon.smithy.model.Model import software.amazon.smithy.model.knowledge.HttpBinding diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt similarity index 88% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt index c8f7e855baa..b7bf02f8f56 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols +package software.amazon.smithy.rust.codegen.core.smithy.protocols import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.model.shapes.BlobShape @@ -14,25 +14,25 @@ import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.rustlang.withBlockTemplate -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.http.HttpMessageType -import software.amazon.smithy.rust.codegen.client.smithy.generators.operationBuildError -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolPayloadGenerator -import software.amazon.smithy.rust.codegen.client.smithy.isOptional -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.EventStreamErrorMarshallerGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.EventStreamMarshallerGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.StructuredDataSerializerGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.http.HttpMessageType +import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolPayloadGenerator +import software.amazon.smithy.rust.codegen.core.smithy.isOptional +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.EventStreamErrorMarshallerGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.EventStreamMarshallerGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator import software.amazon.smithy.rust.codegen.core.util.PANIC import software.amazon.smithy.rust.codegen.core.util.UNREACHABLE import software.amazon.smithy.rust.codegen.core.util.expectMember @@ -46,14 +46,14 @@ import software.amazon.smithy.rust.codegen.core.util.outputShape import software.amazon.smithy.rust.codegen.core.util.toSnakeCase class HttpBoundProtocolPayloadGenerator( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, private val protocol: Protocol, private val httpMessageType: HttpMessageType = HttpMessageType.REQUEST, ) : ProtocolPayloadGenerator { - private val symbolProvider = coreCodegenContext.symbolProvider - private val model = coreCodegenContext.model - private val runtimeConfig = coreCodegenContext.runtimeConfig - private val target = coreCodegenContext.target + private val symbolProvider = codegenContext.symbolProvider + private val model = codegenContext.model + private val runtimeConfig = codegenContext.runtimeConfig + private val target = codegenContext.target private val httpBindingResolver = protocol.httpBindingResolver private val operationSerModule = RustModule.private("operation_ser") diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/InlineFunctionNamer.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/InlineFunctionNamer.kt similarity index 94% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/InlineFunctionNamer.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/InlineFunctionNamer.kt index 16d1c28668a..6b21fd21156 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/InlineFunctionNamer.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/InlineFunctionNamer.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols +package software.amazon.smithy.rust.codegen.core.smithy.protocols import software.amazon.smithy.model.shapes.DocumentShape import software.amazon.smithy.model.shapes.ListShape @@ -15,7 +15,7 @@ import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.util.PANIC import software.amazon.smithy.rust.codegen.core.util.toSnakeCase diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Protocol.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Protocol.kt similarity index 50% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Protocol.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Protocol.kt index 1be6d8ec115..c5d93ae3b00 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Protocol.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Protocol.kt @@ -3,29 +3,17 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols +package software.amazon.smithy.rust.codegen.core.smithy.protocols -import software.amazon.smithy.aws.traits.protocols.AwsJson1_0Trait -import software.amazon.smithy.aws.traits.protocols.AwsJson1_1Trait -import software.amazon.smithy.aws.traits.protocols.AwsQueryTrait -import software.amazon.smithy.aws.traits.protocols.Ec2QueryTrait -import software.amazon.smithy.aws.traits.protocols.RestJson1Trait -import software.amazon.smithy.aws.traits.protocols.RestXmlTrait -import software.amazon.smithy.codegen.core.CodegenException -import software.amazon.smithy.model.Model -import software.amazon.smithy.model.knowledge.ServiceIndex import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.model.traits.Trait -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport -import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.StructuredDataParserGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.StructuredDataSerializerGenerator +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator /** * Describes a protocol to the [HttpBoundProtocolGenerator]. @@ -75,37 +63,10 @@ interface Protocol { fun parseEventStreamGenericError(operationShape: OperationShape): RuntimeType } -typealias ProtocolMap = Map> +typealias ProtocolMap = Map> -interface ProtocolGeneratorFactory { +interface ProtocolGeneratorFactory { fun protocol(codegenContext: C): Protocol fun buildProtocolGenerator(codegenContext: C): T fun support(): ProtocolSupport } - -open class ProtocolLoader(private val supportedProtocols: ProtocolMap) { - fun protocolFor( - model: Model, - serviceShape: ServiceShape, - ): Pair> { - val protocols: MutableMap = ServiceIndex.of(model).getProtocols(serviceShape) - val matchingProtocols = - protocols.keys.mapNotNull { protocolId -> supportedProtocols[protocolId]?.let { protocolId to it } } - if (matchingProtocols.isEmpty()) { - throw CodegenException("No matching protocol — service offers: ${protocols.keys}. We offer: ${supportedProtocols.keys}") - } - return matchingProtocols.first() - } - - companion object { - val DefaultProtocols = mapOf( - AwsJson1_0Trait.ID to AwsJsonFactory(AwsJsonVersion.Json10), - AwsJson1_1Trait.ID to AwsJsonFactory(AwsJsonVersion.Json11), - AwsQueryTrait.ID to AwsQueryFactory(), - Ec2QueryTrait.ID to Ec2QueryFactory(), - RestJson1Trait.ID to RestJsonFactory(), - RestXmlTrait.ID to RestXmlFactory(), - ) - val Default = ProtocolLoader(DefaultProtocols) - } -} diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/ProtocolLoader.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/ProtocolLoader.kt new file mode 100644 index 00000000000..5bf333ab8da --- /dev/null +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/ProtocolLoader.kt @@ -0,0 +1,29 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rust.codegen.core.smithy.protocols + +import software.amazon.smithy.codegen.core.CodegenException +import software.amazon.smithy.model.Model +import software.amazon.smithy.model.knowledge.ServiceIndex +import software.amazon.smithy.model.shapes.ServiceShape +import software.amazon.smithy.model.shapes.ShapeId +import software.amazon.smithy.model.traits.Trait +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext + +open class ProtocolLoader(private val supportedProtocols: ProtocolMap) { + fun protocolFor( + model: Model, + serviceShape: ServiceShape, + ): Pair> { + val protocols: MutableMap = ServiceIndex.of(model).getProtocols(serviceShape) + val matchingProtocols = + protocols.keys.mapNotNull { protocolId -> supportedProtocols[protocolId]?.let { protocolId to it } } + if (matchingProtocols.isEmpty()) { + throw CodegenException("No matching protocol — service offers: ${protocols.keys}. We offer: ${supportedProtocols.keys}") + } + return matchingProtocols.first() + } +} diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/XmlNameIndex.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/XmlNameIndex.kt similarity index 97% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/XmlNameIndex.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/XmlNameIndex.kt index a153ba7c65f..e3f1be1ff7e 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/XmlNameIndex.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/XmlNameIndex.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols +package software.amazon.smithy.rust.codegen.core.smithy.protocols import software.amazon.smithy.model.Model import software.amazon.smithy.model.knowledge.KnowledgeIndex diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/AwsQueryParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/AwsQueryParserGenerator.kt similarity index 82% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/AwsQueryParserGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/AwsQueryParserGenerator.kt index 3649cd09381..cb0569c22d0 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/AwsQueryParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/AwsQueryParserGenerator.kt @@ -3,11 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.parse +package software.amazon.smithy.rust.codegen.core.smithy.protocols.parse -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType /** * The AWS query protocol's responses are identical to REST XML's, except that they are wrapped @@ -25,14 +25,14 @@ import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType * of the response parsing, but it overrides [operationParser] to add the protocol differences. */ class AwsQueryParserGenerator( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, xmlErrors: RuntimeType, private val xmlBindingTraitParserGenerator: XmlBindingTraitParserGenerator = XmlBindingTraitParserGenerator( - coreCodegenContext, + codegenContext, xmlErrors, ) { context, inner -> - val operationName = coreCodegenContext.symbolProvider.toSymbol(context.shape).name + val operationName = codegenContext.symbolProvider.toSymbol(context.shape).name val responseWrapperName = operationName + "Response" val resultWrapperName = operationName + "Result" rustTemplate( diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/Ec2QueryParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/Ec2QueryParserGenerator.kt similarity index 74% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/Ec2QueryParserGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/Ec2QueryParserGenerator.kt index 1cb756c6ccb..c33e2573776 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/Ec2QueryParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/Ec2QueryParserGenerator.kt @@ -3,11 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.parse +package software.amazon.smithy.rust.codegen.core.smithy.protocols.parse -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType /** * The EC2 query protocol's responses are identical to REST XML's, except that they are wrapped @@ -23,14 +23,14 @@ import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType * of the response parsing, but it overrides [operationParser] to add the protocol differences. */ class Ec2QueryParserGenerator( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, xmlErrors: RuntimeType, private val xmlBindingTraitParserGenerator: XmlBindingTraitParserGenerator = XmlBindingTraitParserGenerator( - coreCodegenContext, + codegenContext, xmlErrors, ) { context, inner -> - val operationName = coreCodegenContext.symbolProvider.toSymbol(context.shape).name + val operationName = codegenContext.symbolProvider.toSymbol(context.shape).name val responseWrapperName = operationName + "Response" rustTemplate( """ diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt similarity index 92% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt index 2036ca246d9..97d6bb1c832 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.parse +package software.amazon.smithy.rust.codegen.core.smithy.protocols.parse import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model @@ -22,25 +22,25 @@ import software.amazon.smithy.model.shapes.TimestampShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EventHeaderTrait import software.amazon.smithy.model.traits.EventPayloadTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.eventStreamErrorSymbol -import software.amazon.smithy.rust.codegen.client.smithy.generators.renderUnknownVariant -import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol -import software.amazon.smithy.rust.codegen.client.smithy.transformers.eventStreamErrors +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.eventStreamErrorSymbol +import software.amazon.smithy.rust.codegen.core.smithy.generators.renderUnknownVariant +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticEventStreamUnionTrait +import software.amazon.smithy.rust.codegen.core.smithy.transformers.eventStreamErrors import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/JsonParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt similarity index 90% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/JsonParserGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt index 2fbf75ba8dd..5169242adde 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/JsonParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.parse +package software.amazon.smithy.rust.codegen.core.smithy.protocols.parse import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.BooleanShape @@ -20,33 +20,31 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.SparseTrait import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.escape -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.rustlang.withBlockTemplate -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.canUseDefault -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.StructureGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.TypeConversionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.builderSymbol -import software.amazon.smithy.rust.codegen.client.smithy.generators.renderUnknownVariant -import software.amazon.smithy.rust.codegen.client.smithy.generators.setterName -import software.amazon.smithy.rust.codegen.client.smithy.isRustBoxed -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBindingResolver -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpLocation -import software.amazon.smithy.rust.codegen.client.smithy.protocols.deserializeFunctionName +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.escape +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.canUseDefault +import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.TypeConversionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.builderSymbol +import software.amazon.smithy.rust.codegen.core.smithy.generators.renderUnknownVariant +import software.amazon.smithy.rust.codegen.core.smithy.generators.setterName +import software.amazon.smithy.rust.codegen.core.smithy.isRustBoxed +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpLocation +import software.amazon.smithy.rust.codegen.core.smithy.protocols.deserializeFunctionName import software.amazon.smithy.rust.codegen.core.util.PANIC import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.hasTrait @@ -55,15 +53,15 @@ import software.amazon.smithy.rust.codegen.core.util.outputShape import software.amazon.smithy.utils.StringUtils class JsonParserGenerator( - private val coreCodegenContext: CoreCodegenContext, + private val codegenContext: CodegenContext, private val httpBindingResolver: HttpBindingResolver, /** Function that maps a MemberShape into a JSON field name */ private val jsonName: (MemberShape) -> String, ) : StructuredDataParserGenerator { - private val model = coreCodegenContext.model - private val symbolProvider = coreCodegenContext.symbolProvider - private val runtimeConfig = coreCodegenContext.runtimeConfig - private val target = coreCodegenContext.target + private val model = codegenContext.model + private val symbolProvider = codegenContext.symbolProvider + private val runtimeConfig = codegenContext.runtimeConfig + private val target = codegenContext.target private val smithyJson = CargoDependency.smithyJson(runtimeConfig).asType() private val jsonDeserModule = RustModule.private("json_deser") private val typeConversionGenerator = TypeConversionGenerator(model, symbolProvider, runtimeConfig) @@ -370,7 +368,7 @@ class JsonParserGenerator( *codegenScope, ) { startObjectOrNull { - rust("let mut map = #T::new();", RustType.HashMap.RuntimeType) + rust("let mut map = #T::new();", software.amazon.smithy.rust.codegen.core.rustlang.RustType.HashMap.RuntimeType) objectKeyLoop(hasMembers = true) { withBlock("let key =", "?;") { deserializeStringInner(keyTarget, "key") @@ -409,7 +407,7 @@ class JsonParserGenerator( *codegenScope, ) { startObjectOrNull { - Attribute.AllowUnusedMut.render(this) + software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) rustTemplate("let mut builder = #{Shape}::builder();", *codegenScope, "Shape" to symbol) deserializeStructInner(shape.members()) withBlock("Ok(Some(builder.build()", "))") { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/RestXmlParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/RestXmlParserGenerator.kt similarity index 81% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/RestXmlParserGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/RestXmlParserGenerator.kt index b718071c52b..ed41cfd85a9 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/RestXmlParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/RestXmlParserGenerator.kt @@ -3,23 +3,23 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.parse +package software.amazon.smithy.rust.codegen.core.smithy.protocols.parse -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.protocols.AllowInvalidXmlRoot +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.traits.AllowInvalidXmlRoot import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticOutputTrait import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.orNull class RestXmlParserGenerator( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, xmlErrors: RuntimeType, private val xmlBindingTraitParserGenerator: XmlBindingTraitParserGenerator = XmlBindingTraitParserGenerator( - coreCodegenContext, + codegenContext, xmlErrors, ) { context, inner -> val shapeName = context.outputShapeName diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/StructuredDataParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/StructuredDataParserGenerator.kt similarity index 92% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/StructuredDataParserGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/StructuredDataParserGenerator.kt index 7b1a6f491c7..2bd6c923e0d 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/StructuredDataParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/StructuredDataParserGenerator.kt @@ -3,12 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.parse +package software.amazon.smithy.rust.codegen.core.smithy.protocols.parse import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType interface StructuredDataParserGenerator { /** diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt similarity index 92% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt index 051631d672c..92ab1a4971b 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.parse +package software.amazon.smithy.rust.codegen.core.smithy.protocols.parse import software.amazon.smithy.aws.traits.customizations.S3UnwrappedXmlOutputTrait import software.amazon.smithy.codegen.core.CodegenException @@ -24,33 +24,32 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.model.traits.XmlFlattenedTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.conditionalBlock -import software.amazon.smithy.rust.codegen.client.rustlang.escape -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.rustlang.withBlockTemplate -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.StructureGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.builderSymbol -import software.amazon.smithy.rust.codegen.client.smithy.generators.renderUnknownVariant -import software.amazon.smithy.rust.codegen.client.smithy.generators.setterName -import software.amazon.smithy.rust.codegen.client.smithy.isOptional -import software.amazon.smithy.rust.codegen.client.smithy.isRustBoxed -import software.amazon.smithy.rust.codegen.client.smithy.protocols.XmlMemberIndex -import software.amazon.smithy.rust.codegen.client.smithy.protocols.XmlNameIndex -import software.amazon.smithy.rust.codegen.client.smithy.protocols.deserializeFunctionName +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.conditionalBlock +import software.amazon.smithy.rust.codegen.core.rustlang.escape +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.builderSymbol +import software.amazon.smithy.rust.codegen.core.smithy.generators.renderUnknownVariant +import software.amazon.smithy.rust.codegen.core.smithy.generators.setterName +import software.amazon.smithy.rust.codegen.core.smithy.isOptional +import software.amazon.smithy.rust.codegen.core.smithy.isRustBoxed +import software.amazon.smithy.rust.codegen.core.smithy.protocols.XmlMemberIndex +import software.amazon.smithy.rust.codegen.core.smithy.protocols.XmlNameIndex +import software.amazon.smithy.rust.codegen.core.smithy.protocols.deserializeFunctionName import software.amazon.smithy.rust.codegen.core.util.PANIC import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.expectMember @@ -69,7 +68,7 @@ data class OperationWrapperContext( ) class XmlBindingTraitParserGenerator( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, private val xmlErrors: RuntimeType, private val writeOperationWrapper: RustWriter.(OperationWrapperContext, OperationInnerWriteable) -> Unit, ) : StructuredDataParserGenerator { @@ -95,12 +94,12 @@ class XmlBindingTraitParserGenerator( */ data class Ctx(val tag: String, val accum: String?) - private val symbolProvider = coreCodegenContext.symbolProvider - private val smithyXml = CargoDependency.smithyXml(coreCodegenContext.runtimeConfig).asType() + private val symbolProvider = codegenContext.symbolProvider + private val smithyXml = CargoDependency.smithyXml(codegenContext.runtimeConfig).asType() private val xmlError = smithyXml.member("decode::XmlError") private val scopedDecoder = smithyXml.member("decode::ScopedDecoder") - private val runtimeConfig = coreCodegenContext.runtimeConfig + private val runtimeConfig = codegenContext.runtimeConfig // The symbols we want all the time private val codegenScope = arrayOf( @@ -112,10 +111,10 @@ class XmlBindingTraitParserGenerator( "ScopedDecoder" to scopedDecoder, "aws_smithy_types" to CargoDependency.SmithyTypes(runtimeConfig).asType(), ) - private val model = coreCodegenContext.model + private val model = codegenContext.model private val index = HttpBindingIndex.of(model) private val xmlIndex = XmlNameIndex.of(model) - private val target = coreCodegenContext.target + private val target = codegenContext.target private val xmlDeserModule = RustModule.private("xml_deser") /** @@ -467,7 +466,7 @@ class XmlBindingTraitParserGenerator( "pub fn $fnName(decoder: &mut #{ScopedDecoder}) -> Result<#{Shape}, #{XmlError}>", *codegenScope, "Shape" to symbol, ) { - Attribute.AllowUnusedMut.render(this) + software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) rustTemplate("let mut builder = #{Shape}::builder();", *codegenScope, "Shape" to symbol) val members = shape.xmlMembers() if (members.isNotEmpty()) { @@ -534,7 +533,7 @@ class XmlBindingTraitParserGenerator( *codegenScope, "Map" to symbolProvider.toSymbol(target), ) { - rust("let mut out = #T::new();", RustType.HashMap.RuntimeType) + rust("let mut out = #T::new();", software.amazon.smithy.rust.codegen.core.rustlang.RustType.HashMap.RuntimeType) parseLoop(Ctx(tag = "decoder", accum = null)) { ctx -> rustBlock("s if ${XmlName("entry").matchExpression("s")} => ") { rust("#T(&mut ${ctx.tag}, &mut out)?;", mapEntryParser(target, ctx)) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/AwsQuerySerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/AwsQuerySerializerGenerator.kt similarity index 74% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/AwsQuerySerializerGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/AwsQuerySerializerGenerator.kt index 25961611e43..8e84f5b0b2e 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/AwsQuerySerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/AwsQuerySerializerGenerator.kt @@ -3,18 +3,18 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize +package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.traits.XmlFlattenedTrait import software.amazon.smithy.model.traits.XmlNameTrait -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.util.getTrait -class AwsQuerySerializerGenerator(coreCodegenContext: CoreCodegenContext) : QuerySerializerGenerator(coreCodegenContext) { +class AwsQuerySerializerGenerator(codegenContext: CodegenContext) : QuerySerializerGenerator(codegenContext) { override val protocolName: String get() = "AWS Query" override fun MemberShape.queryKeyName(prioritizedFallback: String?): String = diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/Ec2QuerySerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/Ec2QuerySerializerGenerator.kt similarity index 76% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/Ec2QuerySerializerGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/Ec2QuerySerializerGenerator.kt index f340ee05c91..ed3a83c667a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/Ec2QuerySerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/Ec2QuerySerializerGenerator.kt @@ -3,19 +3,19 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize +package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize import software.amazon.smithy.aws.traits.protocols.Ec2QueryNameTrait import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.traits.XmlNameTrait -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.utils.StringUtils -class Ec2QuerySerializerGenerator(coreCodegenContext: CoreCodegenContext) : QuerySerializerGenerator(coreCodegenContext) { +class Ec2QuerySerializerGenerator(codegenContext: CodegenContext) : QuerySerializerGenerator(codegenContext) { override val protocolName: String get() = "EC2 Query" override fun MemberShape.queryKeyName(prioritizedFallback: String?): String = diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt similarity index 84% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt index de02c7561bf..3d06da554c2 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize +package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model @@ -13,24 +13,24 @@ import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EventHeaderTrait import software.amazon.smithy.model.traits.EventPayloadTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.render -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.eventStreamErrorSymbol -import software.amazon.smithy.rust.codegen.client.smithy.generators.renderUnknownVariant -import software.amazon.smithy.rust.codegen.client.smithy.generators.unknownVariantError -import software.amazon.smithy.rust.codegen.client.smithy.rustType -import software.amazon.smithy.rust.codegen.client.smithy.transformers.eventStreamErrors +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.render +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.eventStreamErrorSymbol +import software.amazon.smithy.rust.codegen.core.smithy.generators.renderUnknownVariant +import software.amazon.smithy.rust.codegen.core.smithy.generators.unknownVariantError +import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticEventStreamUnionTrait +import software.amazon.smithy.rust.codegen.core.smithy.transformers.eventStreamErrors import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt similarity index 87% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt index 2b3e4616461..133f2b9bb6b 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize +package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model @@ -21,24 +21,24 @@ import software.amazon.smithy.model.shapes.TimestampShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EventHeaderTrait import software.amazon.smithy.model.traits.EventPayloadTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.render -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.renderUnknownVariant -import software.amazon.smithy.rust.codegen.client.smithy.generators.unknownVariantError -import software.amazon.smithy.rust.codegen.client.smithy.isOptional -import software.amazon.smithy.rust.codegen.client.smithy.rustType +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.render +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.renderUnknownVariant +import software.amazon.smithy.rust.codegen.core.smithy.generators.unknownVariantError +import software.amazon.smithy.rust.codegen.core.smithy.isOptional +import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.toPascalCase diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/JsonSerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt similarity index 90% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/JsonSerializerGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt index 650b079ef11..e9501ecdddd 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/JsonSerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize +package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.BooleanShape @@ -21,30 +21,30 @@ import software.amazon.smithy.model.shapes.TimestampShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.TimestampFormatTrait.Format.EPOCH_SECONDS -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.customize.NamedSectionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.customize.Section -import software.amazon.smithy.rust.codegen.client.smithy.generators.TypeConversionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.renderUnknownVariant -import software.amazon.smithy.rust.codegen.client.smithy.generators.serializationError -import software.amazon.smithy.rust.codegen.client.smithy.isOptional -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBindingResolver -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpLocation -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serializeFunctionName -import software.amazon.smithy.rust.codegen.client.smithy.rustType +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.customize.NamedSectionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.customize.Section +import software.amazon.smithy.rust.codegen.core.smithy.generators.TypeConversionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.renderUnknownVariant +import software.amazon.smithy.rust.codegen.core.smithy.generators.serializationError +import software.amazon.smithy.rust.codegen.core.smithy.isOptional +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpLocation +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serializeFunctionName +import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticOutputTrait import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.expectTrait @@ -66,7 +66,7 @@ sealed class JsonSection(name: String) : Section(name) { typealias JsonCustomization = NamedSectionGenerator class JsonSerializerGenerator( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, private val httpBindingResolver: HttpBindingResolver, /** Function that maps a MemberShape into a JSON field name */ private val jsonName: (MemberShape) -> String, @@ -146,10 +146,10 @@ class JsonSerializerGenerator( val shape: StructureShape, ) - private val model = coreCodegenContext.model - private val symbolProvider = coreCodegenContext.symbolProvider - private val target = coreCodegenContext.target - private val runtimeConfig = coreCodegenContext.runtimeConfig + private val model = codegenContext.model + private val symbolProvider = codegenContext.symbolProvider + private val target = codegenContext.target + private val runtimeConfig = codegenContext.runtimeConfig private val smithyTypes = CargoDependency.SmithyTypes(runtimeConfig).asType() private val smithyJson = CargoDependency.smithyJson(runtimeConfig).asType() private val codegenScope = arrayOf( diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/QuerySerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt similarity index 85% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/QuerySerializerGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt index 4d59e387732..518da051a35 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/QuerySerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize +package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.BooleanShape @@ -20,33 +20,33 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.model.traits.XmlNameTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.renderUnknownVariant -import software.amazon.smithy.rust.codegen.client.smithy.generators.serializationError -import software.amazon.smithy.rust.codegen.client.smithy.isOptional -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serializeFunctionName -import software.amazon.smithy.rust.codegen.client.smithy.rustType +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.renderUnknownVariant +import software.amazon.smithy.rust.codegen.core.smithy.generators.serializationError +import software.amazon.smithy.rust.codegen.core.smithy.isOptional +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serializeFunctionName +import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.orNull -abstract class QuerySerializerGenerator(coreCodegenContext: CoreCodegenContext) : StructuredDataSerializerGenerator { +abstract class QuerySerializerGenerator(codegenContext: CodegenContext) : StructuredDataSerializerGenerator { protected data class Context( /** Expression that yields a QueryValueWriter */ val writerExpression: String, @@ -87,11 +87,11 @@ abstract class QuerySerializerGenerator(coreCodegenContext: CoreCodegenContext) } } - protected val model = coreCodegenContext.model - protected val symbolProvider = coreCodegenContext.symbolProvider - protected val runtimeConfig = coreCodegenContext.runtimeConfig - private val target = coreCodegenContext.target - private val serviceShape = coreCodegenContext.serviceShape + protected val model = codegenContext.model + protected val symbolProvider = codegenContext.symbolProvider + protected val runtimeConfig = codegenContext.runtimeConfig + private val target = codegenContext.target + private val serviceShape = codegenContext.serviceShape private val serializerError = runtimeConfig.serializationError() private val smithyTypes = CargoDependency.SmithyTypes(runtimeConfig).asType() private val smithyQuery = CargoDependency.smithyQuery(runtimeConfig).asType() @@ -155,7 +155,7 @@ abstract class QuerySerializerGenerator(coreCodegenContext: CoreCodegenContext) val fnName = symbolProvider.serializeFunctionName(context.shape) val structureSymbol = symbolProvider.toSymbol(context.shape) val structureSerializer = RuntimeType.forInlineFun(fnName, querySerModule) { writer -> - Attribute.AllowUnusedMut.render(writer) + software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(writer) writer.rustBlockTemplate( "pub fn $fnName(mut writer: #{QueryValueWriter}, input: &#{Input}) -> Result<(), #{Error}>", "Input" to structureSymbol, @@ -248,7 +248,7 @@ abstract class QuerySerializerGenerator(coreCodegenContext: CoreCodegenContext) private fun RustWriter.structWriter(context: MemberContext, inner: RustWriter.(String) -> Unit) { val prefix = context.shape.queryKeyName() safeName("scope").also { scopeName -> - Attribute.AllowUnusedMut.render(this) + software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) rust("let mut $scopeName = ${context.writerExpression}.prefix(${prefix.dq()});") inner(scopeName) } @@ -265,7 +265,7 @@ abstract class QuerySerializerGenerator(coreCodegenContext: CoreCodegenContext) rust("let mut $listName = ${context.writerExpression}.start_list($flat, $memberOverride);") rustBlock("for $itemName in ${context.valueExpression.asRef()}") { val entryName = safeName("entry") - Attribute.AllowUnusedMut.render(this) + software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) rust("let mut $entryName = $listName.entry();") val targetShape = model.expectShape(context.shape.member.target) serializeMemberValue( @@ -292,7 +292,7 @@ abstract class QuerySerializerGenerator(coreCodegenContext: CoreCodegenContext) else -> keyName } val entryName = safeName("entry") - Attribute.AllowUnusedMut.render(this) + software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) rust("let mut $entryName = $mapName.entry($keyExpression);") serializeMember(MemberContext(entryName, ValueExpression.Reference(valueName), context.shape.value)) } @@ -304,7 +304,7 @@ abstract class QuerySerializerGenerator(coreCodegenContext: CoreCodegenContext) val fnName = symbolProvider.serializeFunctionName(context.shape) val unionSymbol = symbolProvider.toSymbol(context.shape) val unionSerializer = RuntimeType.forInlineFun(fnName, querySerModule) { writer -> - Attribute.AllowUnusedMut.render(writer) + software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(writer) writer.rustBlockTemplate( "pub fn $fnName(mut writer: #{QueryValueWriter}, input: &#{Input}) -> Result<(), #{Error}>", "Input" to unionSymbol, diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/SerializerUtil.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/SerializerUtil.kt similarity index 87% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/SerializerUtil.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/SerializerUtil.kt index 323e1ad93d7..a780218e892 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/SerializerUtil.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/SerializerUtil.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize +package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.BooleanShape @@ -12,8 +12,8 @@ import software.amazon.smithy.model.shapes.FloatShape import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.NumberShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock class SerializerUtil(private val model: Model) { fun RustWriter.ignoreZeroValues(shape: MemberShape, value: ValueExpression, inner: RustWriter.() -> Unit) { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/StructuredDataSerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/StructuredDataSerializerGenerator.kt similarity index 94% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/StructuredDataSerializerGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/StructuredDataSerializerGenerator.kt index dc18a21ebc2..962b9c87201 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/StructuredDataSerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/StructuredDataSerializerGenerator.kt @@ -3,13 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize +package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType interface StructuredDataSerializerGenerator { /** diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/ValueExpression.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/ValueExpression.kt similarity index 87% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/ValueExpression.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/ValueExpression.kt index 2d259c05b6f..4d7a2ce3e5b 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/ValueExpression.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/ValueExpression.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize +package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize sealed class ValueExpression { abstract val name: String diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt similarity index 89% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt index e4270443eb0..8f83d8fe6af 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize +package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.model.shapes.BlobShape @@ -23,32 +23,31 @@ import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.model.traits.XmlFlattenedTrait import software.amazon.smithy.model.traits.XmlNamespaceTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.autoDeref -import software.amazon.smithy.rust.codegen.client.rustlang.render -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.stripOuter -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.renderUnknownVariant -import software.amazon.smithy.rust.codegen.client.smithy.generators.serializationError -import software.amazon.smithy.rust.codegen.client.smithy.isOptional -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBindingResolver -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpLocation -import software.amazon.smithy.rust.codegen.client.smithy.protocols.XmlMemberIndex -import software.amazon.smithy.rust.codegen.client.smithy.protocols.XmlNameIndex -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serializeFunctionName -import software.amazon.smithy.rust.codegen.client.smithy.rustType +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.autoDeref +import software.amazon.smithy.rust.codegen.core.rustlang.render +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.renderUnknownVariant +import software.amazon.smithy.rust.codegen.core.smithy.generators.serializationError +import software.amazon.smithy.rust.codegen.core.smithy.isOptional +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpLocation +import software.amazon.smithy.rust.codegen.core.smithy.protocols.XmlMemberIndex +import software.amazon.smithy.rust.codegen.core.smithy.protocols.XmlNameIndex +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serializeFunctionName +import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait @@ -57,14 +56,14 @@ import software.amazon.smithy.rust.codegen.core.util.letIf import software.amazon.smithy.rust.codegen.core.util.outputShape class XmlBindingTraitSerializerGenerator( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, private val httpBindingResolver: HttpBindingResolver, ) : StructuredDataSerializerGenerator { - private val symbolProvider = coreCodegenContext.symbolProvider - private val runtimeConfig = coreCodegenContext.runtimeConfig - private val model = coreCodegenContext.model + private val symbolProvider = codegenContext.symbolProvider + private val runtimeConfig = codegenContext.runtimeConfig + private val model = codegenContext.model private val smithyXml = CargoDependency.smithyXml(runtimeConfig).asType() - private val target = coreCodegenContext.target + private val target = codegenContext.target private val codegenScope = arrayOf( "XmlWriter" to smithyXml.member("encode::XmlWriter"), @@ -76,7 +75,7 @@ class XmlBindingTraitSerializerGenerator( private val xmlSerModule = RustModule.private("xml_ser") private val xmlIndex = XmlNameIndex.of(model) - private val rootNamespace = coreCodegenContext.serviceShape.getTrait() + private val rootNamespace = codegenContext.serviceShape.getTrait() private val util = SerializerUtil(model) sealed class Ctx { @@ -276,7 +275,7 @@ class XmlBindingTraitSerializerGenerator( } } } - Attribute.AllowUnusedMut.render(this) + software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) rust("let mut scope = ${ctx.elementWriter}.finish();") val scopeCtx = Ctx.Scope("scope", ctx.input) members.dataMembers.forEach { member -> diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/traits/AllowInvalidXmlRoot.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/traits/AllowInvalidXmlRoot.kt new file mode 100644 index 00000000000..7bc3fdacbe2 --- /dev/null +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/traits/AllowInvalidXmlRoot.kt @@ -0,0 +1,19 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rust.codegen.core.smithy.traits + +import software.amazon.smithy.model.node.Node +import software.amazon.smithy.model.shapes.ShapeId +import software.amazon.smithy.model.traits.AnnotationTrait + +/** + * Indicates that a service is expected to send XML where the root element name does not match the modeled member name. + */ +class AllowInvalidXmlRoot : AnnotationTrait(ID, Node.objectNode()) { + companion object { + val ID: ShapeId = ShapeId.from("smithy.api.internal#allowInvalidXmlRoot") + } +} diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustBoxTrait.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/traits/RustBoxTrait.kt similarity index 92% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustBoxTrait.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/traits/RustBoxTrait.kt index 206de887255..2d5a3134012 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RustBoxTrait.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/traits/RustBoxTrait.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy +package software.amazon.smithy.rust.codegen.core.smithy.traits import software.amazon.smithy.model.node.Node import software.amazon.smithy.model.shapes.ShapeId diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/EventStreamNormalizer.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/EventStreamNormalizer.kt similarity index 98% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/EventStreamNormalizer.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/EventStreamNormalizer.kt index 4195891a349..508ea0fab68 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/EventStreamNormalizer.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/EventStreamNormalizer.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.transformers +package software.amazon.smithy.rust.codegen.core.smithy.transformers import software.amazon.smithy.model.Model import software.amazon.smithy.model.knowledge.OperationIndex diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/OperationNormalizer.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/OperationNormalizer.kt similarity index 95% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/OperationNormalizer.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/OperationNormalizer.kt index 1fae090fd92..1a00d431aea 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/OperationNormalizer.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/OperationNormalizer.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.transformers +package software.amazon.smithy.rust.codegen.core.smithy.transformers import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.OperationShape @@ -11,10 +11,10 @@ import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.transform.ModelTransformer -import software.amazon.smithy.rust.codegen.client.util.rename import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticOutputTrait import software.amazon.smithy.rust.codegen.core.util.orNull +import software.amazon.smithy.rust.codegen.core.util.rename import java.util.Optional import kotlin.streams.toList @@ -56,7 +56,7 @@ object OperationNormalizer { // Generate or modify the input and output of the given `Operation` to be a unique shape listOf(syntheticInputShape(model, operation), syntheticOutputShape(model, operation)) } - val shapeConflict = newShapes.firstOrNull() { shape -> model.getShape(shape.id).isPresent } + val shapeConflict = newShapes.firstOrNull { shape -> model.getShape(shape.id).isPresent } check( shapeConflict == null, ) { "shape $shapeConflict conflicted with an existing shape in the model (${model.getShape(shapeConflict!!.id)}. This is a bug." } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapeBoxer.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/RecursiveShapeBoxer.kt similarity index 96% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapeBoxer.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/RecursiveShapeBoxer.kt index f14c0e99082..4b47801a8d5 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapeBoxer.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/RecursiveShapeBoxer.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.transformers +package software.amazon.smithy.rust.codegen.core.smithy.transformers import software.amazon.smithy.codegen.core.TopologicalIndex import software.amazon.smithy.model.Model @@ -13,7 +13,7 @@ import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.SetShape import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.transform.ModelTransformer -import software.amazon.smithy.rust.codegen.client.smithy.RustBoxTrait +import software.amazon.smithy.rust.codegen.core.smithy.traits.RustBoxTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait object RecursiveShapeBoxer { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/util/Smithy.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/util/Smithy.kt index c4b547658d1..448107af0c8 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/util/Smithy.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/util/Smithy.kt @@ -42,6 +42,8 @@ fun StructureShape.expectMember(member: String): MemberShape = fun UnionShape.expectMember(member: String): MemberShape = this.getMember(member).orElseThrow { CodegenException("$member did not exist on $this") } +fun StructureShape.errorMessageMember(): MemberShape? = this.getMember("message").or { this.getMember("Message") }.orNull() + fun StructureShape.hasStreamingMember(model: Model) = this.findStreamingMember(model) != null fun UnionShape.hasStreamingMember(model: Model) = this.findMemberWithTrait(model) != null fun MemberShape.isStreaming(model: Model) = this.getMemberTrait(model, StreamingTrait::class.java).isPresent diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/util/Synthetics.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/util/Synthetics.kt similarity index 94% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/util/Synthetics.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/util/Synthetics.kt index 1f2c99cac57..f0746701e3f 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/util/Synthetics.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/util/Synthetics.kt @@ -3,14 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.util +package software.amazon.smithy.rust.codegen.core.util import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.ToShapeId -import software.amazon.smithy.rust.codegen.core.util.orNull /** * Clones an entire operation and its input/output shapes under a new name. diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonCodegenServerPlugin.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonCodegenServerPlugin.kt index 82fa706d7cd..3a235ec5be0 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonCodegenServerPlugin.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonCodegenServerPlugin.kt @@ -10,18 +10,17 @@ import software.amazon.smithy.build.SmithyBuildPlugin import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustReservedWordSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.BaseSymbolMetadataProvider import software.amazon.smithy.rust.codegen.client.smithy.EventStreamSymbolProvider import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.SymbolVisitor -import software.amazon.smithy.rust.codegen.client.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget +import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.BaseSymbolMetadataProvider +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.server.python.smithy.customizations.DECORATORS -import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerSymbolVisitor -import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonStreamingShapeMetadataProvider import software.amazon.smithy.rust.codegen.server.smithy.customizations.ServerRequiredCustomizations +import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator import java.util.logging.Level import java.util.logging.Logger @@ -44,7 +43,7 @@ class PythonCodegenServerPlugin : SmithyBuildPlugin { // - location (e.g. the mutate section of an operation) // - context (e.g. the of the operation) // - writer: The active RustWriter at the given location - val codegenDecorator: CombinedCodegenDecorator = + val codegenDecorator: CombinedCodegenDecorator = CombinedCodegenDecorator.fromClasspath( context, CombinedCodegenDecorator(DECORATORS + ServerRequiredCustomizations()), diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCargoDependency.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCargoDependency.kt index d92482f3249..6fd3b430c2d 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCargoDependency.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCargoDependency.kt @@ -5,9 +5,9 @@ package software.amazon.smithy.rust.codegen.server.python.smithy -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.CratesIo -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig /** * Object used *exclusively* in the runtime of the Python server, for separation concerns. diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt index 24d29311808..a3a5159d16e 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt @@ -14,20 +14,21 @@ import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait -import software.amazon.smithy.rust.codegen.client.smithy.DefaultPublicModules -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.BuilderGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.implBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerEnumGenerator import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerServiceGenerator import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerStructureGenerator import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenVisitor import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol +import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerProtocolLoader /** @@ -39,7 +40,7 @@ import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerProtoco */ class PythonServerCodegenVisitor( context: PluginContext, - codegenDecorator: RustCodegenDecorator, + codegenDecorator: RustCodegenDecorator, ) : ServerCodegenVisitor(context, codegenDecorator) { init { diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt index 4863a4f04fc..0452dacdf18 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerRuntimeType.kt @@ -5,8 +5,8 @@ package software.amazon.smithy.rust.codegen.server.python.smithy -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType /** * Object used *exclusively* in the runtime of the Python server, for separation concerns. diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerSymbolProvider.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerSymbolProvider.kt index ba298b536e8..1e6f2b7ea83 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerSymbolProvider.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerSymbolProvider.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.server.python.smithy.generators +package software.amazon.smithy.rust.codegen.server.python.smithy import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model @@ -15,19 +15,18 @@ import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.TimestampShape import software.amazon.smithy.model.shapes.UnionShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustMetadata -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.SymbolMetadataProvider -import software.amazon.smithy.rust.codegen.client.smithy.SymbolVisitor -import software.amazon.smithy.rust.codegen.client.smithy.SymbolVisitorConfig -import software.amazon.smithy.rust.codegen.client.smithy.expectRustMetadata +import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.SymbolMetadataProvider +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.smithy.expectRustMetadata import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticOutputTrait import software.amazon.smithy.rust.codegen.core.util.hasStreamingMember import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.isStreaming -import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerRuntimeType /** * Symbol visitor allowing that recursively replace symbols in nested shapes. @@ -42,8 +41,8 @@ import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerRunt */ class PythonServerSymbolVisitor( private val model: Model, - private val serviceShape: ServiceShape?, - private val config: SymbolVisitorConfig, + serviceShape: ServiceShape?, + config: SymbolVisitorConfig, ) : SymbolVisitor(model, serviceShape, config) { private val runtimeConfig = config().runtimeConfig diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/customizations/PythonServerCodegenDecorator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/customizations/PythonServerCodegenDecorator.kt index 9ab914f01b9..9718d88f043 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/customizations/PythonServerCodegenDecorator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/customizations/PythonServerCodegenDecorator.kt @@ -6,22 +6,23 @@ package software.amazon.smithy.rust.codegen.server.python.smithy.customizations import software.amazon.smithy.model.neighbor.Walker -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.docs -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsSection -import software.amazon.smithy.rust.codegen.client.smithy.generators.ManifestCustomizations +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.docs +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection +import software.amazon.smithy.rust.codegen.core.smithy.generators.ManifestCustomizations import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerRuntimeType import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerModuleGenerator import software.amazon.smithy.rust.codegen.server.smithy.customizations.AddInternalServerErrorToAllOperationsDecorator +import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator /** * Configure the [lib] section of `Cargo.toml`. @@ -30,7 +31,7 @@ import software.amazon.smithy.rust.codegen.server.smithy.customizations.AddInter * name = "$CRATE_NAME" * crate-type = ["cdylib"] */ -class CdylibManifestDecorator : RustCodegenDecorator { +class CdylibManifestDecorator : RustCodegenDecorator { override val name: String = "CdylibDecorator" override val order: Byte = 0 @@ -45,7 +46,7 @@ class CdylibManifestDecorator : RustCodegenDecorator { ), ) - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ServerCodegenContext::class.java) } @@ -70,7 +71,7 @@ class PubUsePythonTypes(private val codegenContext: ServerCodegenContext) : LibR /** * Render the Python shared library module export. */ -class PythonExportModuleDecorator : RustCodegenDecorator { +class PythonExportModuleDecorator : RustCodegenDecorator { override val name: String = "PythonExportModuleDecorator" override val order: Byte = 0 @@ -80,14 +81,14 @@ class PythonExportModuleDecorator : RustCodegenDecorator { PythonServerModuleGenerator(codegenContext, rustCrate, serviceShapes).render() } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ServerCodegenContext::class.java) } /** * Decorator applying the customization from [PubUsePythonTypes] class. */ -class PubUsePythonTypesDecorator : RustCodegenDecorator { +class PubUsePythonTypesDecorator : RustCodegenDecorator { override val name: String = "PubUsePythonTypesDecorator" override val order: Byte = 0 @@ -98,7 +99,7 @@ class PubUsePythonTypesDecorator : RustCodegenDecorator { return baseCustomizations + PubUsePythonTypes(codegenContext) } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ServerCodegenContext::class.java) } diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt index 8854a094475..1f3e3e197a6 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt @@ -7,16 +7,16 @@ package software.amazon.smithy.rust.codegen.server.python.smithy.generators import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.DocumentationTrait -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.Errors -import software.amazon.smithy.rust.codegen.client.smithy.Inputs -import software.amazon.smithy.rust.codegen.client.smithy.Outputs +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.Errors +import software.amazon.smithy.rust.codegen.core.smithy.Inputs +import software.amazon.smithy.rust.codegen.core.smithy.Outputs import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.outputShape @@ -61,14 +61,14 @@ import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency * that abstracts the processes / event loops / workers lifecycles. */ class PythonApplicationGenerator( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, private val operations: List, ) { - private val symbolProvider = coreCodegenContext.symbolProvider - private val libName = "lib${coreCodegenContext.settings.moduleName.toSnakeCase()}" - private val runtimeConfig = coreCodegenContext.runtimeConfig - private val model = coreCodegenContext.model - private val protocol = coreCodegenContext.protocol + private val symbolProvider = codegenContext.symbolProvider + private val libName = "lib${codegenContext.settings.moduleName.toSnakeCase()}" + private val runtimeConfig = codegenContext.runtimeConfig + private val model = codegenContext.model + private val protocol = codegenContext.protocol private val codegenScope = arrayOf( "SmithyPython" to PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig).asType(), diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerCombinedErrorGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerCombinedErrorGenerator.kt index 014e4347011..53d4713aa04 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerCombinedErrorGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerCombinedErrorGenerator.kt @@ -8,17 +8,17 @@ package software.amazon.smithy.rust.codegen.server.python.smithy.generators import software.amazon.smithy.model.Model import software.amazon.smithy.model.knowledge.OperationIndex import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.ServerCombinedErrorGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.errorSymbol +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.ServerCombinedErrorGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.errorSymbol import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerCargoDependency /** diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerEnumGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerEnumGenerator.kt index 68aa3153904..b804d12bbbd 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerEnumGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerEnumGenerator.kt @@ -8,16 +8,16 @@ package software.amazon.smithy.rust.codegen.server.python.smithy.generators import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.traits.EnumTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerCargoDependency import software.amazon.smithy.rust.codegen.server.smithy.generators.ServerEnumGenerator diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt index 654e7c10e05..2e0901778f8 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt @@ -10,13 +10,13 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ResourceShape import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.Shape -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerCargoDependency diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt index a158d677222..6f814d7ee3a 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt @@ -6,12 +6,12 @@ package software.amazon.smithy.rust.codegen.server.python.smithy.generators import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerCargoDependency import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency @@ -32,11 +32,11 @@ import software.amazon.smithy.rust.codegen.server.smithy.generators.ServerOperat * To call a Python coroutine, the same happens, but scheduled in a `tokio::Future`. */ class PythonServerOperationHandlerGenerator( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, private val operations: List, -) : ServerOperationHandlerGenerator(coreCodegenContext, operations) { - private val symbolProvider = coreCodegenContext.symbolProvider - private val runtimeConfig = coreCodegenContext.runtimeConfig +) : ServerOperationHandlerGenerator(codegenContext, operations) { + private val symbolProvider = codegenContext.symbolProvider + private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( "SmithyPython" to PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig).asType(), diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerServiceGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerServiceGenerator.kt index 3798148cfd7..ce1bf6a36f0 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerServiceGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerServiceGenerator.kt @@ -6,14 +6,14 @@ package software.amazon.smithy.rust.codegen.server.python.smithy.generators import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.server.smithy.generators.ServerServiceGenerator import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol +import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator /** * PythonServerServiceGenerator @@ -23,10 +23,10 @@ import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.Ser */ class PythonServerServiceGenerator( private val rustCrate: RustCrate, - protocolGenerator: ProtocolGenerator, + protocolGenerator: ServerProtocolGenerator, protocolSupport: ProtocolSupport, - private val protocol: ServerProtocol, - private val context: CoreCodegenContext, + protocol: ServerProtocol, + private val context: CodegenContext, ) : ServerServiceGenerator(rustCrate, protocolGenerator, protocolSupport, protocol, context) { override fun renderCombinedErrors(writer: RustWriter, operation: OperationShape) { diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerStructureGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerStructureGenerator.kt index 03e512d12a1..faea82110b7 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerStructureGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerStructureGenerator.kt @@ -10,17 +10,17 @@ import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.ErrorTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.render -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.generators.StructureGenerator -import software.amazon.smithy.rust.codegen.client.smithy.rustType +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.render +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator +import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerCargoDependency diff --git a/codegen-server/python/src/test/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerSymbolProviderTest.kt b/codegen-server/python/src/test/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerSymbolProviderTest.kt index 15f4021237d..e2ca3e8d29a 100644 --- a/codegen-server/python/src/test/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerSymbolProviderTest.kt +++ b/codegen-server/python/src/test/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerSymbolProviderTest.kt @@ -8,9 +8,10 @@ package software.amazon.smithy.rust.codegen.server.python.smithy.generators import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.smithy.rustType import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.smithy.rustType +import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerSymbolVisitor import software.amazon.smithy.rust.codegen.server.smithy.testutil.ServerTestSymbolVisitorConfig internal class PythonServerSymbolProviderTest { diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/RustCodegenServerPlugin.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/RustCodegenServerPlugin.kt index 061d8b1c86c..42c81072c76 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/RustCodegenServerPlugin.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/RustCodegenServerPlugin.kt @@ -10,17 +10,18 @@ import software.amazon.smithy.build.SmithyBuildPlugin import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustReservedWordSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.BaseSymbolMetadataProvider import software.amazon.smithy.rust.codegen.client.smithy.EventStreamSymbolProvider import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.StreamingShapeMetadataProvider import software.amazon.smithy.rust.codegen.client.smithy.StreamingShapeSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.SymbolVisitor -import software.amazon.smithy.rust.codegen.client.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget +import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.BaseSymbolMetadataProvider +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.server.smithy.customizations.ServerRequiredCustomizations +import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator import java.util.logging.Level import java.util.logging.Logger @@ -42,7 +43,7 @@ class RustCodegenServerPlugin : SmithyBuildPlugin { // - location (e.g. the mutate section of an operation) // - context (e.g. the of the operation) // - writer: The active RustWriter at the given location - val codegenDecorator: CombinedCodegenDecorator = + val codegenDecorator: CombinedCodegenDecorator = CombinedCodegenDecorator.fromClasspath(context, ServerRequiredCustomizations()) // ServerCodegenVisitor is the main driver of code generation that traverses the model and generates code diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCargoDependency.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCargoDependency.kt index 012c78a912a..6058519abfe 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCargoDependency.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCargoDependency.kt @@ -4,11 +4,11 @@ */ package software.amazon.smithy.rust.codegen.server.smithy -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.CratesIo -import software.amazon.smithy.rust.codegen.client.rustlang.DependencyScope -import software.amazon.smithy.rust.codegen.client.rustlang.InlineDependency -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo +import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope +import software.amazon.smithy.rust.codegen.core.rustlang.InlineDependency +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig /** * Object used *exclusively* in the runtime of the server, for separation concerns. diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt index 82f3cbf74dd..9e1e60980ab 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt @@ -17,30 +17,30 @@ import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.transform.ModelTransformer -import software.amazon.smithy.rust.codegen.client.smithy.CoreRustSettings -import software.amazon.smithy.rust.codegen.client.smithy.DefaultPublicModules -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.ServerRustSettings -import software.amazon.smithy.rust.codegen.client.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.BuilderGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.StructureGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.implBlock -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolGeneratorFactory -import software.amazon.smithy.rust.codegen.client.smithy.transformers.EventStreamNormalizer -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer -import software.amazon.smithy.rust.codegen.client.smithy.transformers.RecursiveShapeBoxer +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings +import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory +import software.amazon.smithy.rust.codegen.core.smithy.transformers.EventStreamNormalizer +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.core.util.CommandFailed import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.runCommand import software.amazon.smithy.rust.codegen.server.smithy.generators.ServerEnumGenerator import software.amazon.smithy.rust.codegen.server.smithy.generators.ServerServiceGenerator import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol +import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerProtocolLoader import java.util.logging.Logger @@ -50,7 +50,7 @@ import java.util.logging.Logger */ open class ServerCodegenVisitor( context: PluginContext, - private val codegenDecorator: RustCodegenDecorator, + private val codegenDecorator: RustCodegenDecorator, ) : ShapeVisitor.Default() { protected val logger = Logger.getLogger(javaClass.name) @@ -61,8 +61,8 @@ open class ServerCodegenVisitor( private val fileManifest = context.fileManifest protected var model: Model protected var codegenContext: ServerCodegenContext - protected var protocolGeneratorFactory: ProtocolGeneratorFactory - protected var protocolGenerator: ProtocolGenerator + protected var protocolGeneratorFactory: ProtocolGeneratorFactory + protected var protocolGenerator: ServerProtocolGenerator init { val symbolVisitorConfig = diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeType.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeType.kt index 3ae6c628226..4b7f18ba89e 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeType.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRuntimeType.kt @@ -5,9 +5,9 @@ package software.amazon.smithy.rust.codegen.server.smithy -import software.amazon.smithy.rust.codegen.client.rustlang.InlineDependency -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.rustlang.InlineDependency +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType /** * Object used *exclusively* in the runtime of the server, for separation concerns. diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecorator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecorator.kt index b4033fe7a13..2d8ff6ed548 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecorator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecorator.kt @@ -13,10 +13,11 @@ import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.ErrorTrait import software.amazon.smithy.model.traits.RequiredTrait import software.amazon.smithy.model.transform.ModelTransformer -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.transformers.allErrors +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.transformers.allErrors +import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator /** * Add at least one error to all operations in the model. @@ -32,14 +33,14 @@ import software.amazon.smithy.rust.codegen.client.smithy.transformers.allErrors * mkdir -p "$D" && echo "$C" > "$D/$F" * ``` */ -class AddInternalServerErrorToInfallibleOperationsDecorator : RustCodegenDecorator { +class AddInternalServerErrorToInfallibleOperationsDecorator : RustCodegenDecorator { override val name: String = "AddInternalServerErrorToInfallibleOperations" override val order: Byte = 0 override fun transformModel(service: ServiceShape, model: Model): Model = addErrorShapeToModelOperations(service, model) { shape -> shape.allErrors(model).isEmpty() } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ServerCodegenContext::class.java) } @@ -61,14 +62,14 @@ class AddInternalServerErrorToInfallibleOperationsDecorator : RustCodegenDecorat * mkdir -p "$D" && echo "$C" > "$D/$F" * ``` */ -class AddInternalServerErrorToAllOperationsDecorator : RustCodegenDecorator { +class AddInternalServerErrorToAllOperationsDecorator : RustCodegenDecorator { override val name: String = "AddInternalServerErrorToAllOperations" override val order: Byte = 0 override fun transformModel(service: ServiceShape, model: Model): Model = addErrorShapeToModelOperations(service, model) { true } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ServerCodegenContext::class.java) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt index b6ab91fe56f..4cd48a05c49 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt @@ -5,15 +5,16 @@ package software.amazon.smithy.rust.codegen.server.smithy.customizations -import software.amazon.smithy.rust.codegen.client.rustlang.Feature -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customizations.AllowLintsGenerator import software.amazon.smithy.rust.codegen.client.smithy.customizations.CrateVersionGenerator import software.amazon.smithy.rust.codegen.client.smithy.customizations.SmithyTypesPubUseGenerator import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.rustlang.Feature +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator /** * A set of customizations that are included in all protocols. @@ -22,7 +23,7 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.LibRsCustomi * * See [RequiredCustomizations] from the `rust-codegen` subproject for the client version of this decorator. */ -class ServerRequiredCustomizations : RustCodegenDecorator { +class ServerRequiredCustomizations : RustCodegenDecorator { override val name: String = "ServerRequired" override val order: Byte = -1 @@ -37,6 +38,6 @@ class ServerRequiredCustomizations : RustCodegenDecorator rustCrate.mergeFeature(Feature("rt-tokio", true, listOf("aws-smithy-http/rt-tokio"))) } - override fun supportsCodegenContext(clazz: Class): Boolean = + override fun supportsCodegenContext(clazz: Class): Boolean = clazz.isAssignableFrom(ServerCodegenContext::class.java) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerEnumGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerEnumGenerator.kt index 6ace15f028c..323a40ebf0f 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerEnumGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerEnumGenerator.kt @@ -7,15 +7,15 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.traits.EnumTrait -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.EnumGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.server.smithy.ServerRuntimeType diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt index f765f9565a8..2da280f83d4 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt @@ -17,20 +17,20 @@ import software.amazon.smithy.model.traits.HttpQueryParamsTrait import software.amazon.smithy.model.traits.HttpQueryTrait import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.SensitiveTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.plus -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.plus +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.orNull import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency -import java.util.* +import java.util.Optional /** Models the ways status codes can be bound and sensitive. */ class StatusCodeSensitivity(private val sensitive: Boolean, runtimeConfig: RuntimeConfig) { diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt index 62eabeee9bf..43816423574 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt @@ -6,29 +6,29 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.documentShape -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.documentShape +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.util.toPascalCase import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency class ServerOperationGenerator( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, private val operation: OperationShape, ) { - private val runtimeConfig = coreCodegenContext.runtimeConfig + private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType(), ) - private val symbolProvider = coreCodegenContext.symbolProvider - private val model = coreCodegenContext.model + private val symbolProvider = codegenContext.symbolProvider + private val model = codegenContext.model private val operationName = symbolProvider.toSymbol(operation).name.toPascalCase() private val operationId = operation.id diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt index 9e07d4bc489..38e1a114095 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt @@ -6,16 +6,16 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.errorSymbol -import software.amazon.smithy.rust.codegen.client.smithy.transformers.operationErrors +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.errorSymbol +import software.amazon.smithy.rust.codegen.core.smithy.transformers.operationErrors import software.amazon.smithy.rust.codegen.core.util.hasStreamingMember import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.outputShape @@ -28,15 +28,15 @@ import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerHttpBou * ServerOperationHandlerGenerator */ open class ServerOperationHandlerGenerator( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, private val operations: List, ) { private val serverCrate = "aws_smithy_http_server" - private val service = coreCodegenContext.serviceShape - private val model = coreCodegenContext.model - private val protocol = coreCodegenContext.protocol - private val symbolProvider = coreCodegenContext.symbolProvider - private val runtimeConfig = coreCodegenContext.runtimeConfig + private val service = codegenContext.serviceShape + private val model = codegenContext.model + private val protocol = codegenContext.protocol + private val symbolProvider = codegenContext.symbolProvider + private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( "AsyncTrait" to ServerCargoDependency.AsyncTrait.asType(), "Tower" to ServerCargoDependency.Tower.asType(), diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt index b11b3a74aff..aa549b455d5 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt @@ -7,27 +7,27 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.DocumentationTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.DependencyScope -import software.amazon.smithy.rust.codegen.client.rustlang.RustReservedWords -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.rustlang.withBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.Errors -import software.amazon.smithy.rust.codegen.client.smithy.Inputs -import software.amazon.smithy.rust.codegen.client.smithy.Outputs -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.errorSymbol +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope +import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.Errors +import software.amazon.smithy.rust.codegen.core.smithy.Inputs +import software.amazon.smithy.rust.codegen.core.smithy.Outputs +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.errorSymbol import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.outputShape @@ -48,16 +48,16 @@ import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.Ser * [`tower::Service`]: https://docs.rs/tower/latest/tower/trait.Service.html */ class ServerOperationRegistryGenerator( - private val coreCodegenContext: CoreCodegenContext, + private val codegenContext: CodegenContext, private val protocol: ServerProtocol, private val operations: List, ) { - private val crateName = coreCodegenContext.settings.moduleName - private val model = coreCodegenContext.model - private val symbolProvider = coreCodegenContext.symbolProvider - private val serviceName = coreCodegenContext.serviceShape.toShapeId().name + private val crateName = codegenContext.settings.moduleName + private val model = codegenContext.model + private val symbolProvider = codegenContext.symbolProvider + private val serviceName = codegenContext.serviceShape.toShapeId().name private val operationNames = operations.map { RustReservedWords.escapeIfNeeded(symbolProvider.toSymbol(it).name.toSnakeCase()) } - private val runtimeConfig = coreCodegenContext.runtimeConfig + private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( "Router" to ServerRuntimeType.Router(runtimeConfig), "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType(), @@ -320,7 +320,7 @@ ${operationImplementationStubs(operations)} } val sensitivityGens = operations.map { - ServerHttpSensitivityGenerator(model, it, coreCodegenContext.runtimeConfig) + ServerHttpSensitivityGenerator(model, it, codegenContext.runtimeConfig) } withBlockTemplate( diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt index 3afd9cb8de7..a9670d013b3 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt @@ -7,16 +7,17 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import software.amazon.smithy.model.knowledge.TopDownIndex import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.RustMetadata -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Visibility -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RustCrate -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol +import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolTestGenerator /** @@ -27,21 +28,21 @@ import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.Ser */ open class ServerServiceGenerator( private val rustCrate: RustCrate, - private val protocolGenerator: ProtocolGenerator, + private val protocolGenerator: ServerProtocolGenerator, private val protocolSupport: ProtocolSupport, private val protocol: ServerProtocol, - private val coreCodegenContext: CoreCodegenContext, + private val codegenContext: CodegenContext, ) { - private val index = TopDownIndex.of(coreCodegenContext.model) - protected val operations = index.getContainedOperations(coreCodegenContext.serviceShape).sortedBy { it.id } + private val index = TopDownIndex.of(codegenContext.model) + protected val operations = index.getContainedOperations(codegenContext.serviceShape).sortedBy { it.id } /** * Render Service Specific code. Code will end up in different files via [useShapeWriter]. See `SymbolVisitor.kt` * which assigns a symbol location to each shape. */ fun render() { - rustCrate.withModule(RustModule.Operation) { writer -> - ServerProtocolTestGenerator(coreCodegenContext, protocolSupport, protocolGenerator).render(writer) + rustCrate.withModule(DefaultPublicModules["operation"]!!) { writer -> + ServerProtocolTestGenerator(codegenContext, protocolSupport, protocolGenerator).render(writer) } for (operation in operations) { @@ -80,7 +81,7 @@ open class ServerServiceGenerator( ), ) { writer -> for (operation in operations) { - ServerOperationGenerator(coreCodegenContext, operation).render(writer) + ServerOperationGenerator(codegenContext, operation).render(writer) } } @@ -90,7 +91,7 @@ open class ServerServiceGenerator( ) { writer -> val serverProtocol = ServerProtocol.fromCoreProtocol(protocol) ServerServiceGeneratorV2( - coreCodegenContext, + codegenContext, serverProtocol, ).render(writer) } @@ -108,11 +109,11 @@ open class ServerServiceGenerator( // Render operations handler. open fun renderOperationHandler(writer: RustWriter, operations: List) { - ServerOperationHandlerGenerator(coreCodegenContext, operations).render(writer) + ServerOperationHandlerGenerator(codegenContext, operations).render(writer) } // Render operations registry. private fun renderOperationRegistry(writer: RustWriter, operations: List) { - ServerOperationRegistryGenerator(coreCodegenContext, protocol, operations).render(writer) + ServerOperationRegistryGenerator(codegenContext, protocol, operations).render(writer) } } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt index 64f09b7536c..9486b47488a 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt @@ -6,27 +6,27 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import software.amazon.smithy.model.knowledge.TopDownIndex -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustReservedWords -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.documentShape -import software.amazon.smithy.rust.codegen.client.rustlang.join -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.documentShape +import software.amazon.smithy.rust.codegen.core.rustlang.join +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.util.toPascalCase import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol class ServerServiceGeneratorV2( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, private val protocol: ServerProtocol, ) { - private val runtimeConfig = coreCodegenContext.runtimeConfig + private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( "Bytes" to CargoDependency.Bytes.asType(), @@ -36,16 +36,16 @@ class ServerServiceGeneratorV2( ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType(), "Tower" to CargoDependency.Tower.asType(), ) - private val model = coreCodegenContext.model - private val symbolProvider = coreCodegenContext.symbolProvider + private val model = codegenContext.model + private val symbolProvider = codegenContext.symbolProvider - private val service = coreCodegenContext.serviceShape + private val service = codegenContext.serviceShape private val serviceName = service.id.name.toPascalCase() private val builderName = "${serviceName}Builder" /** Calculate all `operationShape`s contained within the `ServiceShape`. */ - private val index = TopDownIndex.of(coreCodegenContext.model) - private val operations = index.getContainedOperations(coreCodegenContext.serviceShape).sortedBy { it.id } + private val index = TopDownIndex.of(codegenContext.model) + private val operations = index.getContainedOperations(codegenContext.serviceShape).sortedBy { it.id } /** The sequence of builder generics: `Op1`, ..., `OpN`. */ private val builderOps = (1..operations.size).map { "Op$it" } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/http/ServerRequestBindingGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/http/ServerRequestBindingGenerator.kt index 401901c48ac..55ff0fbe730 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/http/ServerRequestBindingGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/http/ServerRequestBindingGenerator.kt @@ -6,20 +6,20 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators.http import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.http.HttpBindingGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.http.HttpMessageType -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBindingDescriptor -import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.http.HttpBindingGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.http.HttpMessageType +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingDescriptor +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol class ServerRequestBindingGenerator( protocol: Protocol, - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, operationShape: OperationShape, ) { - private val httpBindingGenerator = HttpBindingGenerator(protocol, coreCodegenContext, operationShape) + private val httpBindingGenerator = HttpBindingGenerator(protocol, codegenContext, operationShape) fun generateDeserializeHeaderFn(binding: HttpBindingDescriptor): RuntimeType = httpBindingGenerator.generateDeserializeHeaderFn(binding) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/http/ServerResponseBindingGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/http/ServerResponseBindingGenerator.kt index 09e4bb65d81..1967e4304cc 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/http/ServerResponseBindingGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/http/ServerResponseBindingGenerator.kt @@ -7,18 +7,18 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators.http import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.Shape -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.http.HttpBindingGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.http.HttpMessageType -import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.http.HttpBindingGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.http.HttpMessageType +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol class ServerResponseBindingGenerator( protocol: Protocol, - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, operationShape: OperationShape, ) { - private val httpBindingGenerator = HttpBindingGenerator(protocol, coreCodegenContext, operationShape) + private val httpBindingGenerator = HttpBindingGenerator(protocol, codegenContext, operationShape) fun generateAddHeadersFn(shape: Shape): RuntimeType? = httpBindingGenerator.generateAddHeadersFn(shape, HttpMessageType.RESPONSE) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt index 5c55e2c2b38..a85b59c24f5 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt @@ -7,28 +7,28 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators.protocol import software.amazon.smithy.model.knowledge.TopDownIndex import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.http.RestRequestSpecGenerator import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsJson import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsJsonVersion -import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestJson import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestXml -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.StructuredDataSerializerGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.http.RestRequestSpecGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency import software.amazon.smithy.rust.codegen.server.smithy.ServerRuntimeType import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerAwsJsonSerializerGenerator -private fun allOperations(coreCodegenContext: CoreCodegenContext): List { - val index = TopDownIndex.of(coreCodegenContext.model) - return index.getContainedOperations(coreCodegenContext.serviceShape).sortedBy { it.id } +private fun allOperations(codegenContext: CodegenContext): List { + val index = TopDownIndex.of(codegenContext.model) + return index.getContainedOperations(codegenContext.serviceShape).sortedBy { it.id } } interface ServerProtocol : Protocol { @@ -79,21 +79,21 @@ interface ServerProtocol : Protocol { } class ServerAwsJsonProtocol( - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, awsJsonVersion: AwsJsonVersion, -) : AwsJson(coreCodegenContext, awsJsonVersion), ServerProtocol { - private val runtimeConfig = coreCodegenContext.runtimeConfig +) : AwsJson(codegenContext, awsJsonVersion), ServerProtocol { + private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(runtimeConfig).asType(), ) - private val symbolProvider = coreCodegenContext.symbolProvider - private val service = coreCodegenContext.serviceShape + private val symbolProvider = codegenContext.symbolProvider + private val service = codegenContext.serviceShape override fun structuredDataSerializer(operationShape: OperationShape): StructuredDataSerializerGenerator = - ServerAwsJsonSerializerGenerator(coreCodegenContext, httpBindingResolver, awsJsonVersion) + ServerAwsJsonSerializerGenerator(codegenContext, httpBindingResolver, awsJsonVersion) companion object { - fun fromCoreProtocol(awsJson: AwsJson): ServerAwsJsonProtocol = ServerAwsJsonProtocol(awsJson.coreCodegenContext, awsJson.version) + fun fromCoreProtocol(awsJson: AwsJson): ServerAwsJsonProtocol = ServerAwsJsonProtocol(awsJson.codegenContext, awsJson.version) } override fun markerStruct(): RuntimeType { @@ -110,7 +110,7 @@ class ServerAwsJsonProtocol( override fun routerType() = RuntimeType("AwsJsonRouter", ServerCargoDependency.SmithyHttpServer(runtimeConfig), "${runtimeConfig.crateSrcPrefix}_http_server::proto::aws_json::router") override fun routerConstruction(operationValues: Iterable): Writable = writable { - val allOperationShapes = allOperations(coreCodegenContext) + val allOperationShapes = allOperations(codegenContext) // TODO(https://github.com/awslabs/smithy-rs/issues/1724#issue-1367509999): This causes a panic: "symbol // visitor should not be invoked in service shapes" @@ -163,22 +163,22 @@ private fun restRouterType(runtimeConfig: RuntimeConfig) = RuntimeType("RestRout private fun restRouterConstruction( protocol: ServerProtocol, operationValues: Iterable, - coreCodegenContext: CoreCodegenContext, + codegenContext: CodegenContext, ): Writable = writable { - val operations = allOperations(coreCodegenContext) + val operations = allOperations(codegenContext) // TODO(https://github.com/awslabs/smithy-rs/issues/1724#issue-1367509999): This causes a panic: "symbol visitor // should not be invoked in service shapes" // val serviceName = symbolProvider.toSymbol(service).name - val serviceName = coreCodegenContext.serviceShape.id.name + val serviceName = codegenContext.serviceShape.id.name val pairs = writable { for ((operationShape, operationValue) in operations.zip(operationValues)) { - val operationName = coreCodegenContext.symbolProvider.toSymbol(operationShape).name + val operationName = codegenContext.symbolProvider.toSymbol(operationShape).name val key = protocol.serverRouterRequestSpec( operationShape, operationName, serviceName, - ServerCargoDependency.SmithyHttpServer(coreCodegenContext.runtimeConfig).asType().member("routing::request_spec"), + ServerCargoDependency.SmithyHttpServer(codegenContext.runtimeConfig).asType().member("routing::request_spec"), ) rustTemplate( """ @@ -189,7 +189,7 @@ private fun restRouterConstruction( """, "Key" to key, "OperationValue" to operationValue, - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(coreCodegenContext.runtimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(codegenContext.runtimeConfig).asType(), ) } } @@ -203,19 +203,19 @@ private fun restRouterConstruction( } class ServerRestJsonProtocol( - coreCodegenContext: CoreCodegenContext, -) : RestJson(coreCodegenContext), ServerProtocol { - val runtimeConfig = coreCodegenContext.runtimeConfig + codegenContext: CodegenContext, +) : RestJson(codegenContext), ServerProtocol { + val runtimeConfig = codegenContext.runtimeConfig companion object { - fun fromCoreProtocol(restJson: RestJson): ServerRestJsonProtocol = ServerRestJsonProtocol(restJson.coreCodegenContext) + fun fromCoreProtocol(restJson: RestJson): ServerRestJsonProtocol = ServerRestJsonProtocol(restJson.codegenContext) } override fun markerStruct() = ServerRuntimeType.Protocol("AwsRestJson1", "rest_json_1", runtimeConfig) override fun routerType() = restRouterType(runtimeConfig) - override fun routerConstruction(operationValues: Iterable): Writable = restRouterConstruction(this, operationValues, coreCodegenContext) + override fun routerConstruction(operationValues: Iterable): Writable = restRouterConstruction(this, operationValues, codegenContext) override fun serverRouterRequestSpec( operationShape: OperationShape, @@ -230,13 +230,13 @@ class ServerRestJsonProtocol( } class ServerRestXmlProtocol( - coreCodegenContext: CoreCodegenContext, -) : RestXml(coreCodegenContext), ServerProtocol { - val runtimeConfig = coreCodegenContext.runtimeConfig + codegenContext: CodegenContext, +) : RestXml(codegenContext), ServerProtocol { + val runtimeConfig = codegenContext.runtimeConfig companion object { fun fromCoreProtocol(restXml: RestXml): ServerRestXmlProtocol { - return ServerRestXmlProtocol(restXml.coreCodegenContext) + return ServerRestXmlProtocol(restXml.codegenContext) } } @@ -244,7 +244,7 @@ class ServerRestXmlProtocol( override fun routerType() = restRouterType(runtimeConfig) - override fun routerConstruction(operationValues: Iterable): Writable = restRouterConstruction(this, operationValues, coreCodegenContext) + override fun routerConstruction(operationValues: Iterable): Writable = restRouterConstruction(this, operationValues, codegenContext) override fun serverRouterRequestSpec( operationShape: OperationShape, diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolGenerator.kt new file mode 100644 index 00000000000..f46ade2f662 --- /dev/null +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolGenerator.kt @@ -0,0 +1,32 @@ +/* + * 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.protocol + +import software.amazon.smithy.model.shapes.OperationShape +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.MakeOperationGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolTraitImplGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol + +open class ServerProtocolGenerator( + codegenContext: CodegenContext, + protocol: Protocol, + makeOperationGenerator: MakeOperationGenerator, + private val traitGenerator: ProtocolTraitImplGenerator, +) : ProtocolGenerator(codegenContext, protocol, makeOperationGenerator, traitGenerator) { + /** + * The server implementation uses this method to generate implementations of the `from_request` and `into_response` + * traits for operation input and output shapes, respectively. + */ + fun renderOperation( + operationWriter: RustWriter, + operationShape: OperationShape, + ) { + traitGenerator.generateTraitImpls(operationWriter, operationShape, emptyList()) + } +} diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt index 237b38aa44f..08ecdc97950 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt @@ -23,27 +23,26 @@ import software.amazon.smithy.protocoltests.traits.HttpRequestTestCase import software.amazon.smithy.protocoltests.traits.HttpRequestTestsTrait import software.amazon.smithy.protocoltests.traits.HttpResponseTestCase import software.amazon.smithy.protocoltests.traits.HttpResponseTestsTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustMetadata -import software.amazon.smithy.rust.codegen.client.rustlang.RustReservedWords -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Visibility -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.escape -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.Instantiator -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport -import software.amazon.smithy.rust.codegen.client.smithy.transformers.allErrors import software.amazon.smithy.rust.codegen.client.testutil.TokioTest +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata +import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.escape +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.generators.Instantiator +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.core.smithy.transformers.allErrors import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.hasStreamingMember @@ -66,18 +65,18 @@ private const val PROTOCOL_TEST_HELPER_MODULE_NAME = "protocol_test_helper" * Generate protocol tests for an operation */ class ServerProtocolTestGenerator( - private val coreCodegenContext: CoreCodegenContext, + private val codegenContext: CodegenContext, private val protocolSupport: ProtocolSupport, - private val protocolGenerator: ProtocolGenerator, + private val protocolGenerator: ServerProtocolGenerator, ) { private val logger = Logger.getLogger(javaClass.name) - private val model = coreCodegenContext.model - private val symbolProvider = coreCodegenContext.symbolProvider - private val operationIndex = OperationIndex.of(coreCodegenContext.model) + private val model = codegenContext.model + private val symbolProvider = codegenContext.symbolProvider + private val operationIndex = OperationIndex.of(codegenContext.model) - private val serviceName = coreCodegenContext.serviceShape.id.name.toPascalCase() - private val operations = TopDownIndex.of(coreCodegenContext.model).getContainedOperations(coreCodegenContext.serviceShape).sortedBy { it.id } + private val serviceName = codegenContext.serviceShape.id.name.toPascalCase() + private val operations = TopDownIndex.of(codegenContext.model).getContainedOperations(codegenContext.serviceShape).sortedBy { it.id } private val operationInputOutputTypes = operations.associateWith { val inputSymbol = symbolProvider.toSymbol(it.inputShape(model)) @@ -97,20 +96,20 @@ class ServerProtocolTestGenerator( inputT to outputT } - private val instantiator = with(coreCodegenContext) { + private val instantiator = with(codegenContext) { Instantiator(symbolProvider, model, runtimeConfig, CodegenTarget.SERVER) } private val codegenScope = arrayOf( "Bytes" to RuntimeType.Bytes, - "SmithyHttp" to CargoDependency.SmithyHttp(coreCodegenContext.runtimeConfig).asType(), + "SmithyHttp" to CargoDependency.SmithyHttp(codegenContext.runtimeConfig).asType(), "Http" to CargoDependency.Http.asType(), "Hyper" to CargoDependency.Hyper.asType(), "Tokio" to ServerCargoDependency.TokioDev.asType(), "Tower" to CargoDependency.Tower.asType(), - "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(coreCodegenContext.runtimeConfig).asType(), + "SmithyHttpServer" to ServerCargoDependency.SmithyHttpServer(codegenContext.runtimeConfig).asType(), "AssertEq" to CargoDependency.PrettyAssertions.asType().member("assert_eq!"), - "Router" to ServerRuntimeType.Router(coreCodegenContext.runtimeConfig), + "Router" to ServerRuntimeType.Router(codegenContext.runtimeConfig), ) sealed class TestCase { @@ -145,7 +144,7 @@ class ServerProtocolTestGenerator( renderTestHelper(writer) for (operation in operations) { - protocolGenerator.serverRenderOperation(writer, operation) + protocolGenerator.renderOperation(writer, operation) renderOperationTestCases(operation, writer) } } @@ -226,7 +225,7 @@ class ServerProtocolTestGenerator( } private fun renderOperationTestCases(operationShape: OperationShape, writer: RustWriter) { - val outputShape = operationShape.outputShape(coreCodegenContext.model) + val outputShape = operationShape.outputShape(codegenContext.model) val operationSymbol = symbolProvider.toSymbol(operationShape) val requestTests = operationShape.getTrait() @@ -281,7 +280,7 @@ class ServerProtocolTestGenerator( private fun List.filterMatching(): List { return if (RunOnly.isNullOrEmpty()) { this.filter { testCase -> - testCase.protocol == coreCodegenContext.protocol && + testCase.protocol == codegenContext.protocol && !DisableTests.contains(testCase.id) } } else { @@ -295,7 +294,7 @@ class ServerProtocolTestGenerator( private fun List.fixBroken(): List = this.map { when (it) { is TestCase.RequestTest -> { - val howToFixIt = BrokenRequestTests[Pair(coreCodegenContext.serviceShape.id.toString(), it.id)] + val howToFixIt = BrokenRequestTests[Pair(codegenContext.serviceShape.id.toString(), it.id)] if (howToFixIt == null) { it } else { @@ -304,7 +303,7 @@ class ServerProtocolTestGenerator( } } is TestCase.ResponseTest -> { - val howToFixIt = BrokenResponseTests[Pair(coreCodegenContext.serviceShape.id.toString(), it.id)] + val howToFixIt = BrokenResponseTests[Pair(codegenContext.serviceShape.id.toString(), it.id)] if (howToFixIt == null) { it } else { @@ -389,7 +388,7 @@ class ServerProtocolTestGenerator( } private fun expectFail(testCase: TestCase): Boolean = ExpectFail.find { - it.id == testCase.id && it.testType == testCase.testType && it.service == coreCodegenContext.serviceShape.id.toString() + it.id == testCase.id && it.testType == testCase.testType && it.service == codegenContext.serviceShape.id.toString() } != null /** @@ -510,8 +509,8 @@ class ServerProtocolTestGenerator( /** Returns the body of the request test. */ private fun checkRequestHandler(operationShape: OperationShape, httpRequestTestCase: HttpRequestTestCase) = writable { - val inputShape = operationShape.inputShape(coreCodegenContext.model) - val outputShape = operationShape.outputShape(coreCodegenContext.model) + val inputShape = operationShape.inputShape(codegenContext.model) + val outputShape = operationShape.outputShape(codegenContext.model) // Construct expected request. withBlock("let expected = ", ";") { @@ -584,8 +583,8 @@ class ServerProtocolTestGenerator( // A streaming shape does not implement `PartialEq`, so we have to iterate over the input shape's members // and handle the equality assertion separately. for (member in inputShape.members()) { - val memberName = coreCodegenContext.symbolProvider.toMemberName(member) - if (member.isStreaming(coreCodegenContext.model)) { + val memberName = codegenContext.symbolProvider.toMemberName(member) + if (member.isStreaming(codegenContext.model)) { rustWriter.rustTemplate( """ #{AssertEq}( @@ -613,11 +612,11 @@ class ServerProtocolTestGenerator( // TODO(https://github.com/awslabs/smithy-rs/issues/1147) Handle the case of nested floating point members. if (hasFloatingPointMembers) { for (member in inputShape.members()) { - val memberName = coreCodegenContext.symbolProvider.toMemberName(member) - when (coreCodegenContext.model.expectShape(member.target)) { + val memberName = codegenContext.symbolProvider.toMemberName(member) + when (codegenContext.model.expectShape(member.target)) { is DoubleShape, is FloatShape -> { rustWriter.addUseImports( - RuntimeType.ProtocolTestHelper(coreCodegenContext.runtimeConfig, "FloatEquals") + RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "FloatEquals") .toSymbol(), ) rustWriter.rust( @@ -711,8 +710,8 @@ class ServerProtocolTestGenerator( "#T(&body, ${ rustWriter.escape(body).dq() }, #T::from(${(mediaType ?: "unknown").dq()}))", - RuntimeType.ProtocolTestHelper(coreCodegenContext.runtimeConfig, "validate_body"), - RuntimeType.ProtocolTestHelper(coreCodegenContext.runtimeConfig, "MediaType"), + RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "validate_body"), + RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "MediaType"), ) } } @@ -765,7 +764,7 @@ class ServerProtocolTestGenerator( assertOk(rustWriter) { write( "#T($actualExpression, $variableName)", - RuntimeType.ProtocolTestHelper(coreCodegenContext.runtimeConfig, "validate_headers"), + RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "validate_headers"), ) } } @@ -786,7 +785,7 @@ class ServerProtocolTestGenerator( assertOk(rustWriter) { write( "#T($actualExpression, $expectedVariableName)", - RuntimeType.ProtocolTestHelper(coreCodegenContext.runtimeConfig, checkFunction), + RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, checkFunction), ) } } @@ -796,7 +795,7 @@ class ServerProtocolTestGenerator( * for pretty prettying protocol test helper results */ private fun assertOk(rustWriter: RustWriter, inner: RustWriter.() -> Unit) { - rustWriter.write("#T(", RuntimeType.ProtocolTestHelper(coreCodegenContext.runtimeConfig, "assert_ok")) + rustWriter.write("#T(", RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "assert_ok")) inner(rustWriter) rustWriter.write(");") } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerAwsJson.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerAwsJson.kt index c93caca67ff..66587f6c9ba 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerAwsJson.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerAwsJson.kt @@ -6,21 +6,21 @@ package software.amazon.smithy.rust.codegen.server.smithy.protocols import software.amazon.smithy.model.traits.ErrorTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.escape -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsJsonVersion -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBindingResolver -import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolGeneratorFactory import software.amazon.smithy.rust.codegen.client.smithy.protocols.awsJsonFieldName -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.JsonCustomization -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.JsonSection -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.JsonSerializerGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.StructuredDataSerializerGenerator +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.escape +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.JsonCustomization +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.JsonSection +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.JsonSerializerGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerAwsJsonProtocol import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol @@ -81,12 +81,12 @@ class ServerAwsJsonError(private val awsJsonVersion: AwsJsonVersion) : JsonCusto * https://awslabs.github.io/smithy/1.0/spec/aws/aws-json-1_0-protocol.html#operation-error-serialization */ class ServerAwsJsonSerializerGenerator( - private val coreCodegenContext: CoreCodegenContext, + private val codegenContext: CodegenContext, private val httpBindingResolver: HttpBindingResolver, private val awsJsonVersion: AwsJsonVersion, private val jsonSerializerGenerator: JsonSerializerGenerator = JsonSerializerGenerator( - coreCodegenContext, + codegenContext, httpBindingResolver, ::awsJsonFieldName, customizations = listOf(ServerAwsJsonError(awsJsonVersion)), diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt index ce26142120b..5df9709e48b 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt @@ -24,45 +24,44 @@ import software.amazon.smithy.model.traits.HttpErrorTrait import software.amazon.smithy.model.traits.HttpPayloadTrait import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.MediaTypeTrait -import software.amazon.smithy.rust.codegen.client.rustlang.Attribute -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustType -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.rustlang.Writable -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.conditionalBlock -import software.amazon.smithy.rust.codegen.client.rustlang.render -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.client.rustlang.rustBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.withBlock -import software.amazon.smithy.rust.codegen.client.rustlang.withBlockTemplate -import software.amazon.smithy.rust.codegen.client.rustlang.writable -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeType import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.customize.OperationCustomization -import software.amazon.smithy.rust.codegen.client.smithy.extractSymbolFromOption -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.StructureGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.TypeConversionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.builderSymbol -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.errorSymbol -import software.amazon.smithy.rust.codegen.client.smithy.generators.http.HttpMessageType -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.MakeOperationGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolTraitImplGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.setterName -import software.amazon.smithy.rust.codegen.client.smithy.isOptional -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBindingDescriptor -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpBoundProtocolPayloadGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.HttpLocation -import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.StructuredDataParserGenerator -import software.amazon.smithy.rust.codegen.client.smithy.toOptional -import software.amazon.smithy.rust.codegen.client.smithy.transformers.operationErrors -import software.amazon.smithy.rust.codegen.client.smithy.wrapOptional +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustType +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.conditionalBlock +import software.amazon.smithy.rust.codegen.core.rustlang.render +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.rustlang.withBlockTemplate +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization +import software.amazon.smithy.rust.codegen.core.smithy.extractSymbolFromOption +import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.TypeConversionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.builderSymbol +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.errorSymbol +import software.amazon.smithy.rust.codegen.core.smithy.generators.http.HttpMessageType +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.MakeOperationGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolTraitImplGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.setterName +import software.amazon.smithy.rust.codegen.core.smithy.isOptional +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingDescriptor +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBoundProtocolPayloadGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpLocation +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.toOptional import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait +import software.amazon.smithy.rust.codegen.core.smithy.transformers.operationErrors +import software.amazon.smithy.rust.codegen.core.smithy.wrapOptional import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.findStreamingMember @@ -79,9 +78,10 @@ import software.amazon.smithy.rust.codegen.server.smithy.ServerRuntimeType import software.amazon.smithy.rust.codegen.server.smithy.generators.http.ServerRequestBindingGenerator import software.amazon.smithy.rust.codegen.server.smithy.generators.http.ServerResponseBindingGenerator import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol +import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator import java.util.logging.Logger -/* +/** * Implement operations' input parsing and output serialization. Protocols can plug their own implementations * and overrides by creating a protocol factory inheriting from this class and feeding it to the [ServerProtocolLoader]. * See `ServerRestJsonFactory.kt` for more info. @@ -89,7 +89,7 @@ import java.util.logging.Logger class ServerHttpBoundProtocolGenerator( codegenContext: ServerCodegenContext, protocol: ServerProtocol, -) : ProtocolGenerator( +) : ServerProtocolGenerator( codegenContext, protocol, MakeOperationGenerator( @@ -535,7 +535,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( val bindings = httpBindingResolver.errorResponseBindings(it) - Attribute.AllowUnusedMut.render(this) + software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) rustTemplate("let mut builder = #{http}::Response::builder();", *codegenScope) serverRenderResponseHeaders(operationShape, variantShape) @@ -571,7 +571,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( operationShape: OperationShape, bindings: List, ) { - Attribute.AllowUnusedMut.render(this) + software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) rustTemplate("let mut builder = #{http}::Response::builder();", *codegenScope) serverRenderResponseHeaders(operationShape) bindings.find { it.location == HttpLocation.RESPONSE_CODE } @@ -738,7 +738,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( ) { val httpBindingGenerator = ServerRequestBindingGenerator(protocol, codegenContext, operationShape) val structuredDataParser = protocol.structuredDataParser(operationShape) - Attribute.AllowUnusedMut.render(this) + software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) rust("let mut input = #T::default();", inputShape.builderSymbol(symbolProvider)) val parser = structuredDataParser.serverInputParser(operationShape) val noInputs = model.expectShape(operationShape.inputShape).expectTrait().originalId == null @@ -992,7 +992,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( rustTemplate( "let mut query_params: #{HashMap} = #{HashMap}::new();", - "HashMap" to RustType.HashMap.RuntimeType, + "HashMap" to software.amazon.smithy.rust.codegen.core.rustlang.RustType.HashMap.RuntimeType, ) } val (queryBindingsTargettingCollection, queryBindingsTargettingSimple) = diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerProtocolLoader.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerProtocolLoader.kt index 827230f2cc8..4fb304b499b 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerProtocolLoader.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerProtocolLoader.kt @@ -11,11 +11,12 @@ import software.amazon.smithy.aws.traits.protocols.RestJson1Trait import software.amazon.smithy.aws.traits.protocols.RestXmlTrait import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsJsonVersion -import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolLoader -import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolMap +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolLoader +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolMap +import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator -class ServerProtocolLoader(supportedProtocols: ProtocolMap) : - ProtocolLoader(supportedProtocols) { +class ServerProtocolLoader(supportedProtocols: ProtocolMap) : + ProtocolLoader(supportedProtocols) { companion object { val DefaultProtocols = mapOf( diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestJsonFactory.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestJsonFactory.kt index 88b299a643a..39f1e9947d8 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestJsonFactory.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestJsonFactory.kt @@ -6,10 +6,10 @@ package software.amazon.smithy.rust.codegen.server.smithy.protocols import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport -import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol -import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolGeneratorFactory import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestJson +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerRestJsonProtocol /** diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestXmlFactory.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestXmlFactory.kt index 6adf59900ee..96e6b06a0fd 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestXmlFactory.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestXmlFactory.kt @@ -6,10 +6,10 @@ package software.amazon.smithy.rust.codegen.server.smithy.protocols import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ProtocolSupport -import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol -import software.amazon.smithy.rust.codegen.client.smithy.protocols.ProtocolGeneratorFactory import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestXml +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerRestXmlProtocol /* diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt index e6e930e6313..8972fd02969 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt @@ -10,14 +10,14 @@ import software.amazon.smithy.model.knowledge.NullableIndex import software.amazon.smithy.model.node.ObjectNode import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenConfig import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.ServerRustSettings -import software.amazon.smithy.rust.codegen.client.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.server.smithy.RustCodegenServerPlugin // These are the settings we default to if the user does not override them in their `smithy-build.json`. diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitorTest.kt index bbbdf07ba59..3b496f1d286 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitorTest.kt @@ -13,6 +13,7 @@ import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodeg import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.server.smithy.customizations.ServerRequiredCustomizations +import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator import kotlin.io.path.createDirectory import kotlin.io.path.writeText @@ -48,7 +49,7 @@ class ServerCodegenVisitorTest { val (ctx, testDir) = generatePluginContext(model) testDir.resolve("src").createDirectory() testDir.resolve("src/main.rs").writeText("fn main() {}") - val codegenDecorator: CombinedCodegenDecorator = + val codegenDecorator: CombinedCodegenDecorator = CombinedCodegenDecorator.fromClasspath(ctx, ServerRequiredCustomizations()) val visitor = ServerCodegenVisitor(ctx, codegenDecorator) val baselineModel = visitor.baselineTransformInternalTest(model) diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecoratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecoratorTest.kt index a1d1a7d7a8c..0727a2154a9 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecoratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecoratorTest.kt @@ -9,8 +9,8 @@ import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ServiceShape -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.util.lookup class AdditionalErrorsDecoratorTest { diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerCombinedErrorGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerCombinedErrorGeneratorTest.kt index bbd64783cb3..1406573d894 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerCombinedErrorGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerCombinedErrorGeneratorTest.kt @@ -7,15 +7,15 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.ServerCombinedErrorGenerator -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.ServerCombinedErrorGenerator +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverTestSymbolProvider diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerEnumGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerEnumGeneratorTest.kt index 1f972cb3165..85f4b2e3f3d 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerEnumGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerEnumGeneratorTest.kt @@ -8,10 +8,10 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import io.kotest.matchers.string.shouldNotContain import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.StringShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverTestSymbolProvider diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt index 42bfdc7822c..1b3575a5fbc 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt @@ -8,14 +8,14 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import software.amazon.smithy.model.traits.HttpTrait -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.asType -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGeneratorTest.kt index ebf9b67ab60..3f3de45222e 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGeneratorTest.kt @@ -9,8 +9,8 @@ import io.kotest.matchers.string.shouldContain import org.junit.jupiter.api.Test import software.amazon.smithy.model.knowledge.TopDownIndex import software.amazon.smithy.model.shapes.ServiceShape -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerProtocolLoader diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/EventStreamTestTools.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/EventStreamTestTools.kt index 868a2898e4c..6a7227c658c 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/EventStreamTestTools.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/EventStreamTestTools.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.smithy.protocols +package software.amazon.smithy.rust.codegen.server.smithy.protocols import org.junit.jupiter.api.extension.ExtensionContext import org.junit.jupiter.params.provider.Arguments @@ -16,32 +16,32 @@ import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.ErrorTrait -import software.amazon.smithy.rust.codegen.client.rustlang.RustModule -import software.amazon.smithy.rust.codegen.client.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.generators.BuilderGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.generators.StructureGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.CombinedErrorGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.error.ServerCombinedErrorGenerator -import software.amazon.smithy.rust.codegen.client.smithy.generators.implBlock -import software.amazon.smithy.rust.codegen.client.smithy.generators.renderUnknownVariant import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsJson import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsJsonVersion import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsQueryProtocol import software.amazon.smithy.rust.codegen.client.smithy.protocols.Ec2QueryProtocol -import software.amazon.smithy.rust.codegen.client.smithy.protocols.Protocol import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestJson import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestXml -import software.amazon.smithy.rust.codegen.client.smithy.transformers.EventStreamNormalizer -import software.amazon.smithy.rust.codegen.client.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.client.testutil.TestWriterDelegator import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.CombinedErrorGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.error.ServerCombinedErrorGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock +import software.amazon.smithy.rust.codegen.core.smithy.generators.renderUnknownVariant +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.transformers.EventStreamNormalizer +import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.core.util.outputShape @@ -136,7 +136,7 @@ object EventStreamTestModels { val validSomeError: String, val validUnmodeledError: String, val target: CodegenTarget = CodegenTarget.CLIENT, - val protocolBuilder: (CoreCodegenContext) -> Protocol, + val protocolBuilder: (CodegenContext) -> Protocol, ) { override fun toString(): String = protocolShapeId } diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/parse/EventStreamUnmarshallerGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/parse/EventStreamUnmarshallerGeneratorTest.kt index b10b3f4f61a..bce3bfab2dd 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/parse/EventStreamUnmarshallerGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/parse/EventStreamUnmarshallerGeneratorTest.kt @@ -8,16 +8,16 @@ package software.amazon.smithy.rust.codegen.server.smithy.protocols.parse import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ArgumentsSource import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.rustlang.rust -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.generators.CodegenTarget -import software.amazon.smithy.rust.codegen.client.smithy.protocols.parse.EventStreamUnmarshallerGenerator import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.testRustSettings import software.amazon.smithy.rust.codegen.client.testutil.unitTest -import software.amazon.smithy.rust.codegen.smithy.protocols.EventStreamTestModels -import software.amazon.smithy.rust.codegen.smithy.protocols.EventStreamTestTools +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.EventStreamUnmarshallerGenerator +import software.amazon.smithy.rust.codegen.server.smithy.protocols.EventStreamTestModels +import software.amazon.smithy.rust.codegen.server.smithy.protocols.EventStreamTestTools class EventStreamUnmarshallerGeneratorTest { @ParameterizedTest @@ -25,7 +25,7 @@ class EventStreamUnmarshallerGeneratorTest { fun test(testCase: EventStreamTestModels.TestCase) { val test = EventStreamTestTools.generateTestProject(testCase) - val codegenContext = CoreCodegenContext( + val codegenContext = CodegenContext( test.model, test.symbolProvider, test.serviceShape, diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt index 97c57d46159..9fbbe47f504 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt @@ -8,18 +8,18 @@ package software.amazon.smithy.rust.codegen.server.smithy.protocols.serialize import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ArgumentsSource import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.client.rustlang.DependencyScope -import software.amazon.smithy.rust.codegen.client.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.client.smithy.CoreCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize.EventStreamMarshallerGenerator import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.testRustSettings import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope +import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.EventStreamMarshallerGenerator import software.amazon.smithy.rust.codegen.core.util.dq -import software.amazon.smithy.rust.codegen.smithy.protocols.EventStreamTestModels -import software.amazon.smithy.rust.codegen.smithy.protocols.EventStreamTestTools +import software.amazon.smithy.rust.codegen.server.smithy.protocols.EventStreamTestModels +import software.amazon.smithy.rust.codegen.server.smithy.protocols.EventStreamTestTools class EventStreamMarshallerGeneratorTest { @ParameterizedTest @@ -27,7 +27,7 @@ class EventStreamMarshallerGeneratorTest { fun test(testCase: EventStreamTestModels.TestCase) { val test = EventStreamTestTools.generateTestProject(testCase) - val codegenContext = CoreCodegenContext( + val codegenContext = CodegenContext( test.model, test.symbolProvider, test.serviceShape, diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/customize/CombinedCodegenDecoratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/customize/CombinedCodegenDecoratorTest.kt index 3d6affbbc2b..8277de48af2 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/customize/CombinedCodegenDecoratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/customize/CombinedCodegenDecoratorTest.kt @@ -12,15 +12,17 @@ import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCustomizations import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.server.smithy.customizations.ServerRequiredCustomizations +import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator internal class CombinedCodegenDecoratorTest { - private val clientDecorator: RustCodegenDecorator = RequiredCustomizations() - private val serverDecorator: RustCodegenDecorator = ServerRequiredCustomizations() + private val clientDecorator: RustCodegenDecorator = RequiredCustomizations() + private val serverDecorator: RustCodegenDecorator = ServerRequiredCustomizations() @Test fun filterClientDecorators() { - val filteredDecorators = CombinedCodegenDecorator.filterDecorators( + val filteredDecorators = CombinedCodegenDecorator.filterDecorators( listOf(clientDecorator, serverDecorator), ).toList() @@ -29,7 +31,7 @@ internal class CombinedCodegenDecoratorTest { @Test fun filterServerDecorators() { - val filteredDecorators = CombinedCodegenDecorator.filterDecorators( + val filteredDecorators = CombinedCodegenDecorator.filterDecorators( listOf(clientDecorator, serverDecorator), ).toList() From ef85116f772e3ae948551255ca9769140d3ec124 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Tue, 27 Sep 2022 09:33:16 -0700 Subject: [PATCH 03/57] Add ability to programmatically customize profile files (#1770) --- CHANGELOG.next.toml | 28 ++ .../aws-config/src/imds/client.rs | 6 +- .../aws-config/src/profile/app_name.rs | 9 +- .../aws-config/src/profile/credentials.rs | 79 +++-- .../src/profile/location_of_profile_files.md | 19 ++ .../aws-config/src/profile/mod.rs | 1 + .../aws-config/src/profile/parser.rs | 94 +++--- .../src/profile/parser/normalize.rs | 26 +- .../aws-config/src/profile/parser/parse.rs | 6 +- .../aws-config/src/profile/parser/source.rs | 308 +++++++++++++----- .../aws-config/src/profile/profile_file.rs | 257 +++++++++++++++ .../aws-config/src/profile/region.rs | 17 +- .../aws-config/src/profile/retry_config.rs | 15 +- 13 files changed, 679 insertions(+), 186 deletions(-) create mode 100644 aws/rust-runtime/aws-config/src/profile/location_of_profile_files.md create mode 100644 aws/rust-runtime/aws-config/src/profile/profile_file.rs diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index df706f8fa8b..94b888a4d42 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -53,3 +53,31 @@ of breaking changes and how to resolve them. references = ["smithy-rs#1740", "smithy-rs#256"] meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" } author = "jdisanti" + +[[aws-sdk-rust]] +message = """ +It is now possible to programmatically customize the locations of the profile config/credentials files in `aws-config`: +```rust +use aws_config::profile::{ProfileFileCredentialsProvider, ProfileFileRegionProvider}; +use aws_config::profile::profile_file::{ProfileFiles, ProfileFileKind}; + +let profile_files = ProfileFiles::builder() + .with_file(ProfileFileKind::Credentials, "some/path/to/credentials-file") + .build(); +let credentials_provider = ProfileFileCredentialsProvider::builder() + .profile_files(profile_files.clone()) + .build(); +let region_provider = ProfileFileRegionProvider::builder() + .profile_files(profile_files) + .build(); + +let sdk_config = aws_config::from_env() + .credentials_provider(credentials_provider) + .region(region_provider) + .load() + .await; +``` +""" +references = ["aws-sdk-rust#237", "smithy-rs#1770"] +meta = { "breaking" = false, "tada" = true, "bug" = false } +author = "jdisanti" diff --git a/aws/rust-runtime/aws-config/src/imds/client.rs b/aws/rust-runtime/aws-config/src/imds/client.rs index a1e39def074..10e6d419abf 100644 --- a/aws/rust-runtime/aws-config/src/imds/client.rs +++ b/aws/rust-runtime/aws-config/src/imds/client.rs @@ -37,7 +37,7 @@ use tokio::sync::OnceCell; use crate::connector::expect_connector; use crate::imds::client::token::TokenMiddleware; -use crate::profile::ProfileParseError; +use crate::profile::credentials::ProfileFileError; use crate::provider_config::ProviderConfig; use crate::{profile, PKG_VERSION}; use aws_sdk_sso::config::timeout::TimeoutConfig; @@ -439,7 +439,7 @@ pub enum BuildError { InvalidEndpointMode(InvalidEndpointMode), /// The AWS Profile (e.g. `~/.aws/config`) was invalid - InvalidProfile(ProfileParseError), + InvalidProfile(ProfileFileError), /// The specified endpoint was not a valid URI InvalidEndpointUri(InvalidUri), @@ -626,7 +626,7 @@ impl EndpointSource { } EndpointSource::Env(env, fs) => { // load an endpoint override from the environment - let profile = profile::load(fs, env) + let profile = profile::load(fs, env, &Default::default()) .await .map_err(BuildError::InvalidProfile)?; let uri_override = if let Ok(uri) = env.get(env::ENDPOINT) { diff --git a/aws/rust-runtime/aws-config/src/profile/app_name.rs b/aws/rust-runtime/aws-config/src/profile/app_name.rs index 44b35fc174a..e0af917967e 100644 --- a/aws/rust-runtime/aws-config/src/profile/app_name.rs +++ b/aws/rust-runtime/aws-config/src/profile/app_name.rs @@ -5,6 +5,7 @@ //! Load an app name from an AWS profile +use super::profile_file::ProfileFiles; use crate::provider_config::ProviderConfig; use aws_types::app_name::AppName; use aws_types::os_shim_internal::{Env, Fs}; @@ -14,6 +15,8 @@ use aws_types::os_shim_internal::{Env, Fs}; /// This provider will attempt to shared AWS shared configuration and then read the /// `sdk-ua-app-id` property from the active profile. /// +#[doc = include_str!("location_of_profile_files.md")] +/// /// # Examples /// /// **Loads "my-app" as the app name** @@ -35,6 +38,7 @@ pub struct ProfileFileAppNameProvider { fs: Fs, env: Env, profile_override: Option, + profile_files: ProfileFiles, } impl ProfileFileAppNameProvider { @@ -46,6 +50,7 @@ impl ProfileFileAppNameProvider { fs: Fs::real(), env: Env::real(), profile_override: None, + profile_files: Default::default(), } } @@ -56,7 +61,7 @@ impl ProfileFileAppNameProvider { /// Parses the profile config and attempts to find an app name. pub async fn app_name(&self) -> Option { - let profile = super::parser::load(&self.fs, &self.env) + let profile = super::parser::load(&self.fs, &self.env, &self.profile_files) .await .map_err(|err| tracing::warn!(err = %err, "failed to parse profile")) .ok()?; @@ -82,6 +87,7 @@ impl ProfileFileAppNameProvider { pub struct Builder { config: Option, profile_override: Option, + profile_files: Option, } impl Builder { @@ -104,6 +110,7 @@ impl Builder { env: conf.env(), fs: conf.fs(), profile_override: self.profile_override, + profile_files: self.profile_files.unwrap_or_default(), } } } diff --git a/aws/rust-runtime/aws-config/src/profile/credentials.rs b/aws/rust-runtime/aws-config/src/profile/credentials.rs index 7889bb6e1fc..1a025339cfe 100644 --- a/aws/rust-runtime/aws-config/src/profile/credentials.rs +++ b/aws/rust-runtime/aws-config/src/profile/credentials.rs @@ -22,22 +22,21 @@ //! - `exec` which contains a chain representation of providers to implement passing bootstrapped credentials //! through a series of providers. +use crate::profile::credentials::exec::named::NamedProviderFactory; +use crate::profile::credentials::exec::{ClientConfiguration, ProviderChain}; +use crate::profile::parser::ProfileParseError; +use crate::profile::profile_file::ProfileFiles; +use crate::profile::Profile; +use crate::provider_config::ProviderConfig; +use aws_types::credentials::{self, future, CredentialsError, ProvideCredentials}; use std::borrow::Cow; use std::collections::HashMap; use std::error::Error; use std::fmt::{Display, Formatter}; +use std::path::PathBuf; use std::sync::Arc; - -use aws_types::credentials::{self, future, CredentialsError, ProvideCredentials}; - use tracing::Instrument; -use crate::profile::credentials::exec::named::NamedProviderFactory; -use crate::profile::credentials::exec::{ClientConfiguration, ProviderChain}; -use crate::profile::parser::ProfileParseError; -use crate::profile::Profile; -use crate::provider_config::ProviderConfig; - mod exec; mod repr; @@ -142,29 +141,14 @@ impl ProvideCredentials for ProfileFileCredentialsProvider { /// /// SSO can also be used as a source profile for assume role chains. /// -/// ## Location of Profile Files -/// * The location of the config file will be loaded from the `AWS_CONFIG_FILE` environment variable -/// with a fallback to `~/.aws/config` -/// * The location of the credentials file will be loaded from the `AWS_SHARED_CREDENTIALS_FILE` -/// environment variable with a fallback to `~/.aws/credentials` -/// -/// ## Home directory resolution -/// Home directory resolution is implemented to match the behavior of the CLI & Python. `~` is only -/// used for home directory resolution when it: -/// - Starts the path -/// - Is followed immediately by `/` or a platform specific separator. (On windows, `~/` and `~\` both -/// resolve to the home directory. -/// -/// When determining the home directory, the following environment variables are checked: -/// - `HOME` on all platforms -/// - `USERPROFILE` on Windows -/// - The concatenation of `HOMEDRIVE` and `HOMEPATH` on Windows (`$HOMEDRIVE$HOMEPATH`) +#[doc = include_str!("location_of_profile_files.md")] #[derive(Debug)] pub struct ProfileFileCredentialsProvider { factory: NamedProviderFactory, client_config: ClientConfiguration, provider_config: ProviderConfig, profile_override: Option, + profile_files: ProfileFiles, } impl ProfileFileCredentialsProvider { @@ -178,6 +162,7 @@ impl ProfileFileCredentialsProvider { &self.provider_config, &self.factory, self.profile_override.as_deref(), + &self.profile_files, ) .await .map_err(|err| match err { @@ -225,6 +210,13 @@ impl ProfileFileCredentialsProvider { } } +#[doc(hidden)] +#[derive(Debug)] +pub struct CouldNotReadProfileFile { + pub(crate) path: PathBuf, + pub(crate) cause: std::io::Error, +} + /// An Error building a Credential source from an AWS Profile #[derive(Debug)] #[non_exhaustive] @@ -283,6 +275,10 @@ pub enum ProfileFileError { /// The name of the provider name: String, }, + + /// A custom profile file location didn't exist or could not be read + #[non_exhaustive] + CouldNotReadProfileFile(CouldNotReadProfileFile), } impl ProfileFileError { @@ -326,6 +322,13 @@ impl Display for ProfileFileError { "profile `{}` did not contain credential information", profile ), + ProfileFileError::CouldNotReadProfileFile(details) => { + write!( + f, + "Failed to read custom profile file at {:?}", + details.path + ) + } } } } @@ -334,16 +337,24 @@ impl Error for ProfileFileError { fn source(&self) -> Option<&(dyn Error + 'static)> { match self { ProfileFileError::CouldNotParseProfile(err) => Some(err), + ProfileFileError::CouldNotReadProfileFile(details) => Some(&details.cause), _ => None, } } } +impl From for ProfileFileError { + fn from(err: ProfileParseError) -> Self { + ProfileFileError::CouldNotParseProfile(err) + } +} + /// Builder for [`ProfileFileCredentialsProvider`] #[derive(Debug, Default)] pub struct Builder { provider_config: Option, profile_override: Option, + profile_files: Option, custom_providers: HashMap, Arc>, } @@ -409,6 +420,12 @@ impl Builder { self } + /// Set the profile file that should be used by the [`ProfileFileCredentialsProvider`] + pub fn profile_files(mut self, profile_files: ProfileFiles) -> Self { + self.profile_files = Some(profile_files); + self + } + /// Builds a [`ProfileFileCredentialsProvider`] pub fn build(self) -> ProfileFileCredentialsProvider { let build_span = tracing::debug_span!("build_profile_provider"); @@ -453,6 +470,7 @@ impl Builder { }, provider_config: conf, profile_override: self.profile_override, + profile_files: self.profile_files.unwrap_or_default(), } } } @@ -461,13 +479,10 @@ async fn build_provider_chain( provider_config: &ProviderConfig, factory: &NamedProviderFactory, profile_override: Option<&str>, + profile_files: &ProfileFiles, ) -> Result { - let profile_set = super::parser::load(&provider_config.fs(), &provider_config.env()) - .await - .map_err(|err| { - tracing::warn!(err = %err, "failed to parse profile"); - ProfileFileError::CouldNotParseProfile(err) - })?; + let profile_set = + super::parser::load(&provider_config.fs(), &provider_config.env(), profile_files).await?; let repr = repr::resolve_chain(&profile_set, profile_override)?; tracing::info!(chain = ?repr, "constructed abstract provider from config file"); exec::ProviderChain::from_repr(provider_config, repr, factory) diff --git a/aws/rust-runtime/aws-config/src/profile/location_of_profile_files.md b/aws/rust-runtime/aws-config/src/profile/location_of_profile_files.md new file mode 100644 index 00000000000..d712da7ff5d --- /dev/null +++ b/aws/rust-runtime/aws-config/src/profile/location_of_profile_files.md @@ -0,0 +1,19 @@ +## Location of Profile Files +* The location of the config file will be loaded from the `AWS_CONFIG_FILE` environment variable +with a fallback to `~/.aws/config` +* The location of the credentials file will be loaded from the `AWS_SHARED_CREDENTIALS_FILE` +environment variable with a fallback to `~/.aws/credentials` + +The location of these files can also be customized programmatically using [`ProfileFiles`](crate::profile::profile_file::ProfileFiles). + +## Home directory resolution +Home directory resolution is implemented to match the behavior of the CLI & Python. `~` is only +used for home directory resolution when it: +- Starts the path +- Is followed immediately by `/` or a platform specific separator. (On windows, `~/` and `~\` both + resolve to the home directory. + +When determining the home directory, the following environment variables are checked: +- `HOME` on all platforms +- `USERPROFILE` on Windows +- The concatenation of `HOMEDRIVE` and `HOMEPATH` on Windows (`$HOMEDRIVE$HOMEPATH`) diff --git a/aws/rust-runtime/aws-config/src/profile/mod.rs b/aws/rust-runtime/aws-config/src/profile/mod.rs index 62071013bac..f1a81cad51e 100644 --- a/aws/rust-runtime/aws-config/src/profile/mod.rs +++ b/aws/rust-runtime/aws-config/src/profile/mod.rs @@ -20,6 +20,7 @@ pub use parser::{load, Profile, ProfileSet, Property}; pub mod app_name; pub mod credentials; +pub mod profile_file; pub mod region; pub mod retry_config; diff --git a/aws/rust-runtime/aws-config/src/profile/parser.rs b/aws/rust-runtime/aws-config/src/profile/parser.rs index 3306cbb9907..f80a5842a04 100644 --- a/aws/rust-runtime/aws-config/src/profile/parser.rs +++ b/aws/rust-runtime/aws-config/src/profile/parser.rs @@ -3,17 +3,19 @@ * SPDX-License-Identifier: Apache-2.0 */ -mod normalize; -mod parse; -mod source; - use crate::profile::parser::parse::parse_profile_file; -use crate::profile::parser::source::{FileKind, Source}; +use crate::profile::parser::source::Source; +use crate::profile::profile_file::ProfileFiles; use aws_types::os_shim_internal::{Env, Fs}; use std::borrow::Cow; use std::collections::HashMap; pub use self::parse::ProfileParseError; +use super::credentials::ProfileFileError; + +mod normalize; +mod parse; +mod source; /// Read & parse AWS config files /// @@ -22,23 +24,7 @@ pub use self::parse::ProfileParseError; /// Although the basic behavior is straightforward, there are number of nuances to maintain backwards /// compatibility with other SDKs enumerated below. /// -/// ## Location of Profile Files -/// * The location of the config file will be loaded from the `AWS_CONFIG_FILE` environment variable -/// with a fallback to `~/.aws/config` -/// * The location of the credentials file will be loaded from the `AWS_SHARED_CREDENTIALS_FILE` -/// environment variable with a fallback to `~/.aws/credentials` -/// -/// ## Home directory resolution -/// Home directory resolution is implemented to match the behavior of the CLI & Python. `~` is only -/// used for home directory resolution when it: -/// - Starts the path -/// - Is followed immediately by `/` or a platform specific separator. (On windows, `~/` and `~\` both -/// resolve to the home directory. -/// -/// When determining the home directory, the following environment variables are checked: -/// - `HOME` on all platforms -/// - `USERPROFILE` on Windows -/// - The concatenation of `HOMEDRIVE` and `HOMEPATH` on Windows (`$HOMEDRIVE$HOMEPATH`) +#[doc = include_str!("location_of_profile_files.md")] /// /// ## Profile file syntax /// @@ -66,9 +52,13 @@ pub use self::parse::ProfileParseError; /// [other] /// aws_access_key_id = 456 /// ``` -pub async fn load(fs: &Fs, env: &Env) -> Result { - let source = source::load(env, fs).await; - ProfileSet::parse(source) +pub async fn load( + fs: &Fs, + env: &Env, + profile_files: &ProfileFiles, +) -> Result { + let source = source::load(env, fs, profile_files).await?; + Ok(ProfileSet::parse(source)?) } /// A top-level configuration source containing multiple named profiles @@ -141,16 +131,9 @@ impl ProfileSet { let mut base = ProfileSet::empty(); base.selected_profile = source.profile; - normalize::merge_in( - &mut base, - parse_profile_file(&source.config_file)?, - FileKind::Config, - ); - normalize::merge_in( - &mut base, - parse_profile_file(&source.credentials_file)?, - FileKind::Credentials, - ); + for file in source.files { + normalize::merge_in(&mut base, parse_profile_file(&file)?, file.kind); + } Ok(base) } @@ -215,6 +198,7 @@ impl Property { #[cfg(test)] mod test { use crate::profile::parser::source::{File, Source}; + use crate::profile::profile_file::ProfileFileKind; use crate::profile::ProfileSet; use arbitrary::{Arbitrary, Unstructured}; use serde::Deserialize; @@ -276,14 +260,18 @@ mod test { let (conf, creds): (Option<&str>, Option<&str>) = Arbitrary::arbitrary(&mut unstructured)?; let profile_source = Source { - config_file: File { - path: "~/.aws/config".to_string(), - contents: conf.unwrap_or_default().to_string(), - }, - credentials_file: File { - path: "~/.aws/config".to_string(), - contents: creds.unwrap_or_default().to_string(), - }, + files: vec![ + File { + kind: ProfileFileKind::Config, + path: Some("~/.aws/config".to_string()), + contents: conf.unwrap_or_default().to_string(), + }, + File { + kind: ProfileFileKind::Credentials, + path: Some("~/.aws/credentials".to_string()), + contents: creds.unwrap_or_default().to_string(), + }, + ], profile: "default".into(), }; // don't care if parse fails, just don't panic @@ -313,14 +301,18 @@ mod test { fn make_source(input: ParserInput) -> Source { Source { - config_file: File { - path: "~/.aws/config".to_string(), - contents: input.config_file.unwrap_or_default(), - }, - credentials_file: File { - path: "~/.aws/credentials".to_string(), - contents: input.credentials_file.unwrap_or_default(), - }, + files: vec![ + File { + kind: ProfileFileKind::Config, + path: Some("~/.aws/config".to_string()), + contents: input.config_file.unwrap_or_default(), + }, + File { + kind: ProfileFileKind::Credentials, + path: Some("~/.aws/credentials".to_string()), + contents: input.credentials_file.unwrap_or_default(), + }, + ], profile: "default".into(), } } diff --git a/aws/rust-runtime/aws-config/src/profile/parser/normalize.rs b/aws/rust-runtime/aws-config/src/profile/parser/normalize.rs index 81ad64327bc..2e645c3f11e 100644 --- a/aws/rust-runtime/aws-config/src/profile/parser/normalize.rs +++ b/aws/rust-runtime/aws-config/src/profile/parser/normalize.rs @@ -7,7 +7,7 @@ use std::borrow::Cow; use std::collections::HashMap; use crate::profile::parser::parse::{RawProfileSet, WHITESPACE}; -use crate::profile::parser::source::FileKind; +use crate::profile::profile_file::ProfileFileKind; use crate::profile::{Profile, ProfileSet, Property}; const DEFAULT: &str = "default"; @@ -38,7 +38,7 @@ impl ProfileName<'_> { /// 1. `name` must ALWAYS be a valid identifier /// 2. For Config files, the profile must either be `default` or it must have a profile prefix /// 3. For credentials files, the profile name MUST NOT have a profile prefix - fn valid_for(self, kind: FileKind) -> Result { + fn valid_for(self, kind: ProfileFileKind) -> Result { if validate_identifier(self.name).is_err() { return Err(format!( "profile `{}` ignored because `{}` was not a valid identifier", @@ -46,17 +46,17 @@ impl ProfileName<'_> { )); } match (self.name, kind, self.has_profile_prefix) { - (_, FileKind::Config, true) => Ok(self), - (DEFAULT, FileKind::Config, false) => Ok(self), - (_not_default, FileKind::Config, false) => Err(format!( + (_, ProfileFileKind::Config, true) => Ok(self), + (DEFAULT, ProfileFileKind::Config, false) => Ok(self), + (_not_default, ProfileFileKind::Config, false) => Err(format!( "profile `{}` ignored because config profiles must be of the form `[profile ]`", self.name )), - (_, FileKind::Credentials, true) => Err(format!( + (_, ProfileFileKind::Credentials, true) => Err(format!( "profile `{}` ignored because credential profiles must NOT begin with `profile`", self.name )), - (_, FileKind::Credentials, false) => Ok(self), + (_, ProfileFileKind::Credentials, false) => Ok(self), } } } @@ -68,7 +68,11 @@ impl ProfileName<'_> { /// - Profile names are validated (see `validate_profile_name`) /// - A profile named `profile default` takes priority over a profile named `default`. /// - Profiles with identical names are merged -pub(super) fn merge_in(base: &mut ProfileSet, raw_profile_set: RawProfileSet<'_>, kind: FileKind) { +pub(super) fn merge_in( + base: &mut ProfileSet, + raw_profile_set: RawProfileSet<'_>, + kind: ProfileFileKind, +) { // parse / validate profile names let validated_profiles = raw_profile_set .into_iter() @@ -148,11 +152,11 @@ mod tests { use tracing_test::traced_test; use crate::profile::parser::parse::RawProfileSet; - use crate::profile::parser::source::FileKind; use crate::profile::ProfileSet; use super::{merge_in, ProfileName}; use crate::profile::parser::normalize::validate_identifier; + use crate::profile::profile_file::ProfileFileKind; #[test] fn profile_name_parsing() { @@ -219,7 +223,7 @@ mod tests { out }); let mut base = ProfileSet::empty(); - merge_in(&mut base, profile, FileKind::Config); + merge_in(&mut base, profile, ProfileFileKind::Config); assert!(base .get_profile("default") .expect("contains default profile") @@ -235,7 +239,7 @@ mod tests { fn invalid_profile_generates_warning() { let mut profile: RawProfileSet<'_> = HashMap::new(); profile.insert("foo", HashMap::new()); - merge_in(&mut ProfileSet::empty(), profile, FileKind::Config); + merge_in(&mut ProfileSet::empty(), profile, ProfileFileKind::Config); assert!(logs_contain("profile `foo` ignored")); } } diff --git a/aws/rust-runtime/aws-config/src/profile/parser/parse.rs b/aws/rust-runtime/aws-config/src/profile/parser/parse.rs index b1d43e58b24..1d3c3acb057 100644 --- a/aws/rust-runtime/aws-config/src/profile/parser/parse.rs +++ b/aws/rust-runtime/aws-config/src/profile/parser/parse.rs @@ -110,7 +110,7 @@ pub(super) fn parse_profile_file(file: &File) -> Result, Profi state: State::Starting, location: Location { line_number: 0, - path: file.path.to_string(), + path: file.path.clone().unwrap_or_default(), }, }; parser.parse_profile(&file.contents)?; @@ -290,6 +290,7 @@ mod test { use super::{parse_profile_file, prepare_line, Location}; use crate::profile::parser::parse::{parse_property_line, PropertyError}; use crate::profile::parser::source::File; + use crate::profile::profile_file::ProfileFileKind; // most test cases covered by the JSON test suite @@ -330,7 +331,8 @@ mod test { #[test] fn error_line_numbers() { let file = File { - path: "~/.aws/config".into(), + kind: ProfileFileKind::Config, + path: Some("~/.aws/config".into()), contents: "[default\nk=v".into(), }; let err = parse_profile_file(&file).expect_err("parsing should fail"); diff --git a/aws/rust-runtime/aws-config/src/profile/parser/source.rs b/aws/rust-runtime/aws-config/src/profile/parser/source.rs index fd99f40e7d5..50057805da7 100644 --- a/aws/rust-runtime/aws-config/src/profile/parser/source.rs +++ b/aws/rust-runtime/aws-config/src/profile/parser/source.rs @@ -4,6 +4,8 @@ */ use crate::fs_util::{home_dir, Os}; +use crate::profile::credentials::{CouldNotReadProfileFile, ProfileFileError}; +use crate::profile::profile_file::{ProfileFile, ProfileFileKind, ProfileFiles}; use aws_types::os_shim_internal; use std::borrow::Cow; use std::io::ErrorKind; @@ -16,11 +18,8 @@ const HOME_EXPANSION_FAILURE_WARNING: &str = /// In-memory source of profile data pub(super) struct Source { - /// Contents and path of ~/.aws/config - pub(super) config_file: File, - - /// Contents and path of ~/.aws/credentials - pub(super) credentials_file: File, + /// Profile file sources + pub(super) files: Vec, /// Profile to use /// @@ -30,49 +29,44 @@ pub(super) struct Source { /// In-memory configuration file pub(super) struct File { - pub(super) path: String, + pub(super) kind: ProfileFileKind, + pub(super) path: Option, pub(super) contents: String, } -#[derive(Clone, Copy)] -pub(super) enum FileKind { - Config, - Credentials, -} - -impl FileKind { - fn default_path(&self) -> &'static str { - match &self { - FileKind::Credentials => "~/.aws/credentials", - FileKind::Config => "~/.aws/config", - } - } +/// Load a [Source](Source) from a given environment and filesystem. +pub(super) async fn load( + proc_env: &os_shim_internal::Env, + fs: &os_shim_internal::Fs, + profile_files: &ProfileFiles, +) -> Result { + let home = home_dir(proc_env, Os::real()); - fn override_environment_variable(&self) -> &'static str { - match &self { - FileKind::Config => "AWS_CONFIG_FILE", - FileKind::Credentials => "AWS_SHARED_CREDENTIALS_FILE", - } + let mut files = Vec::new(); + for file in &profile_files.files { + let file = load_config_file(file, &home, fs, proc_env) + .instrument(tracing::debug_span!("load_config_file", file = ?file)) + .await?; + files.push(file); } -} -/// Load a [Source](Source) from a given environment and filesystem. -pub(super) async fn load(proc_env: &os_shim_internal::Env, fs: &os_shim_internal::Fs) -> Source { - let home = home_dir(proc_env, Os::real()); - let config = load_config_file(FileKind::Config, &home, fs, proc_env) - .instrument(tracing::debug_span!("load_config_file")) - .await; - let credentials = load_config_file(FileKind::Credentials, &home, fs, proc_env) - .instrument(tracing::debug_span!("load_credentials_file")) - .await; - - Source { - config_file: config, - credentials_file: credentials, + Ok(Source { + files, profile: proc_env .get("AWS_PROFILE") .map(Cow::Owned) .unwrap_or(Cow::Borrowed("default")), + }) +} + +fn file_contents_to_string(path: &Path, contents: Vec) -> String { + // if the file is not valid utf-8, log a warning and use an empty file instead + match String::from_utf8(contents) { + Ok(contents) => contents, + Err(e) => { + tracing::warn!(path = ?path, error = %e, "config file did not contain utf-8 encoded data"); + Default::default() + } } } @@ -87,53 +81,74 @@ pub(super) async fn load(proc_env: &os_shim_internal::Env, fs: &os_shim_internal /// * `fs`: Filesystem abstraction /// * `environment`: Process environment abstraction async fn load_config_file( - kind: FileKind, + source: &ProfileFile, home_directory: &Option, fs: &os_shim_internal::Fs, environment: &os_shim_internal::Env, -) -> File { - let (path_is_default, path) = environment - .get(kind.override_environment_variable()) - .map(|p| (false, Cow::Owned(p))) - .ok() - .unwrap_or_else(|| (true, kind.default_path().into())); - let expanded = expand_home(path.as_ref(), path_is_default, home_directory); - if path != expanded.to_string_lossy() { - tracing::debug!(before = ?path, after = ?expanded, "home directory expanded"); - } - // read the data at the specified path - // if the path does not exist, log a warning but pretend it was actually an empty file - let data = match fs.read_to_end(&expanded).await { - Ok(data) => data, - Err(e) => { - match e.kind() { - ErrorKind::NotFound if path == kind.default_path() => { - tracing::debug!(path = %path, "config file not found") - } - ErrorKind::NotFound if path != kind.default_path() => { - // in the case where the user overrode the path with an environment variable, - // log more loudly than the case where the default path was missing - tracing::warn!(path = %path, env = %kind.override_environment_variable(), "config file overridden via environment variable not found") +) -> Result { + let (path, kind, contents) = match source { + ProfileFile::Default(kind) => { + let (path_is_default, path) = environment + .get(kind.override_environment_variable()) + .map(|p| (false, Cow::Owned(p))) + .ok() + .unwrap_or_else(|| (true, kind.default_path().into())); + let expanded = expand_home(path.as_ref(), path_is_default, home_directory); + if path != expanded.to_string_lossy() { + tracing::debug!(before = ?path, after = ?expanded, "home directory expanded"); + } + // read the data at the specified path + // if the path does not exist, log a warning but pretend it was actually an empty file + let data = match fs.read_to_end(&expanded).await { + Ok(data) => data, + Err(e) => { + // Important: The default config/credentials files MUST NOT return an error + match e.kind() { + ErrorKind::NotFound if path == kind.default_path() => { + tracing::debug!(path = %path, "config file not found") + } + ErrorKind::NotFound if path != kind.default_path() => { + // in the case where the user overrode the path with an environment variable, + // log more loudly than the case where the default path was missing + tracing::warn!(path = %path, env = %kind.override_environment_variable(), "config file overridden via environment variable not found") + } + _other => { + tracing::warn!(path = %path, error = %e, "failed to read config file") + } + }; + Default::default() } - _other => tracing::warn!(path = %path, error = %e, "failed to read config file"), }; - Default::default() + let contents = file_contents_to_string(&expanded, data); + (Some(Cow::Owned(expanded)), kind, contents) } - }; - // if the file is not valid utf-8, log a warning and use an empty file instead - let data = match String::from_utf8(data) { - Ok(data) => data, - Err(e) => { - tracing::warn!(path = %path, error = %e, "config file did not contain utf-8 encoded data"); - Default::default() + ProfileFile::FilePath { kind, path } => { + let data = match fs.read_to_end(&path).await { + Ok(data) => data, + Err(e) => { + return Err(ProfileFileError::CouldNotReadProfileFile( + CouldNotReadProfileFile { + path: path.clone(), + cause: e, + }, + )) + } + }; + ( + Some(Cow::Borrowed(path)), + kind, + file_contents_to_string(path, data), + ) } + ProfileFile::FileContents { kind, contents } => (None, kind, contents.clone()), }; - tracing::debug!(path = %path, size = ?data.len(), "config file loaded"); - File { + tracing::debug!(path = ?path, size = ?contents.len(), "config file loaded"); + Ok(File { + kind: *kind, // lossy is OK here, the name of this file is just for debugging purposes - path: expanded.to_string_lossy().into(), - contents: data, - } + path: path.map(|p| p.to_string_lossy().into()), + contents, + }) } fn expand_home( @@ -179,9 +194,11 @@ fn expand_home( #[cfg(test)] mod tests { + use crate::profile::credentials::ProfileFileError; use crate::profile::parser::source::{ - expand_home, load, load_config_file, FileKind, HOME_EXPANSION_FAILURE_WARNING, + expand_home, load, load_config_file, HOME_EXPANSION_FAILURE_WARNING, }; + use crate::profile::profile_file::{ProfileFile, ProfileFileKind, ProfileFiles}; use aws_types::os_shim_internal::{Env, Fs}; use futures_util::FutureExt; use serde::Deserialize; @@ -243,7 +260,7 @@ mod tests { let fs = Fs::from_map(fs); - let _src = load(&env, &fs).now_or_never(); + let _src = load(&env, &fs, &Default::default()).now_or_never(); assert!(logs_contain("config file loaded")); assert!(logs_contain("performing home directory substitution")); } @@ -254,7 +271,13 @@ mod tests { let env = Env::from_slice(&[]); let fs = Fs::from_slice(&[]); - let _src = load_config_file(FileKind::Config, &None, &fs, &env).now_or_never(); + let _src = load_config_file( + &ProfileFile::Default(ProfileFileKind::Config), + &None, + &fs, + &env, + ) + .now_or_never(); assert!(!logs_contain(HOME_EXPANSION_FAILURE_WARNING)); } @@ -264,7 +287,13 @@ mod tests { let env = Env::from_slice(&[("AWS_CONFIG_FILE", "~/some/path")]); let fs = Fs::from_slice(&[]); - let _src = load_config_file(FileKind::Config, &None, &fs, &env).now_or_never(); + let _src = load_config_file( + &ProfileFile::Default(ProfileFileKind::Config), + &None, + &fs, + &env, + ) + .now_or_never(); assert!(logs_contain(HOME_EXPANSION_FAILURE_WARNING)); } @@ -274,17 +303,19 @@ mod tests { let platform_matches = (cfg!(windows) && test_case.platform == "windows") || (!cfg!(windows) && test_case.platform != "windows"); if platform_matches { - let source = load(&env, &fs).await; + let source = load(&env, &fs, &Default::default()).await.unwrap(); if let Some(expected_profile) = test_case.profile { assert_eq!(source.profile, expected_profile, "{}", &test_case.name); } assert_eq!( - source.config_file.path, test_case.config_location, + source.files[0].path, + Some(test_case.config_location), "{}", &test_case.name ); assert_eq!( - source.credentials_file.path, test_case.credentials_location, + source.files[1].path, + Some(test_case.credentials_location), "{}", &test_case.name ) @@ -337,4 +368,115 @@ mod tests { "C:\\Users\\name\\.aws\\config" ); } + + #[tokio::test] + async fn programmatically_set_credentials_file_contents() { + let contents = "[default]\n\ + aws_access_key_id = AKIAFAKE\n\ + aws_secret_access_key = FAKE\n\ + "; + let env = Env::from_slice(&[]); + let fs = Fs::from_slice(&[]); + let profile_files = ProfileFiles::builder() + .with_contents(ProfileFileKind::Credentials, contents) + .build(); + let source = load(&env, &fs, &profile_files).await.unwrap(); + assert_eq!(1, source.files.len()); + assert_eq!("default", source.profile); + assert_eq!(contents, source.files[0].contents); + } + + #[tokio::test] + async fn programmatically_set_credentials_file_path() { + let contents = "[default]\n\ + aws_access_key_id = AKIAFAKE\n\ + aws_secret_access_key = FAKE\n\ + "; + let mut fs = HashMap::new(); + fs.insert( + "/custom/path/to/credentials".to_string(), + contents.to_string(), + ); + + let fs = Fs::from_map(fs); + let env = Env::from_slice(&[]); + let profile_files = ProfileFiles::builder() + .with_file(ProfileFileKind::Credentials, "/custom/path/to/credentials") + .build(); + let source = load(&env, &fs, &profile_files).await.unwrap(); + assert_eq!(1, source.files.len()); + assert_eq!("default", source.profile); + assert_eq!(contents, source.files[0].contents); + } + + #[tokio::test] + async fn programmatically_include_default_files() { + let config_contents = "[default]\nregion = us-east-1"; + let credentials_contents = "[default]\n\ + aws_access_key_id = AKIAFAKE\n\ + aws_secret_access_key = FAKE\n\ + "; + let custom_contents = "[profile some-profile]\n\ + aws_access_key_id = AKIAFAKEOTHER\n\ + aws_secret_access_key = FAKEOTHER\n\ + "; + let mut fs = HashMap::new(); + fs.insert( + "/user/name/.aws/config".to_string(), + config_contents.to_string(), + ); + fs.insert( + "/user/name/.aws/credentials".to_string(), + credentials_contents.to_string(), + ); + + let fs = Fs::from_map(fs); + let env = Env::from_slice(&[("HOME", "/user/name")]); + let profile_files = ProfileFiles::builder() + .with_contents(ProfileFileKind::Config, custom_contents) + .include_default_credentials_file(true) + .include_default_config_file(true) + .build(); + let source = load(&env, &fs, &profile_files).await.unwrap(); + assert_eq!(3, source.files.len()); + assert_eq!("default", source.profile); + assert_eq!(config_contents, source.files[0].contents); + assert_eq!(credentials_contents, source.files[1].contents); + assert_eq!(custom_contents, source.files[2].contents); + } + + #[tokio::test] + async fn default_files_must_not_error() { + let custom_contents = "[profile some-profile]\n\ + aws_access_key_id = AKIAFAKEOTHER\n\ + aws_secret_access_key = FAKEOTHER\n\ + "; + + let fs = Fs::from_slice(&[]); + let env = Env::from_slice(&[("HOME", "/user/name")]); + let profile_files = ProfileFiles::builder() + .with_contents(ProfileFileKind::Config, custom_contents) + .include_default_credentials_file(true) + .include_default_config_file(true) + .build(); + let source = load(&env, &fs, &profile_files).await.unwrap(); + assert_eq!(3, source.files.len()); + assert_eq!("default", source.profile); + assert_eq!("", source.files[0].contents); + assert_eq!("", source.files[1].contents); + assert_eq!(custom_contents, source.files[2].contents); + } + + #[tokio::test] + async fn misconfigured_programmatic_custom_profile_path_must_error() { + let fs = Fs::from_slice(&[]); + let env = Env::from_slice(&[]); + let profile_files = ProfileFiles::builder() + .with_file(ProfileFileKind::Config, "definitely-doesnt-exist") + .build(); + assert!(matches!( + load(&env, &fs, &profile_files).await, + Err(ProfileFileError::CouldNotReadProfileFile(_)) + )); + } } diff --git a/aws/rust-runtime/aws-config/src/profile/profile_file.rs b/aws/rust-runtime/aws-config/src/profile/profile_file.rs new file mode 100644 index 00000000000..76bdfb1fbae --- /dev/null +++ b/aws/rust-runtime/aws-config/src/profile/profile_file.rs @@ -0,0 +1,257 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +//! Config structs to programmatically customize the profile files that get loaded + +use std::fmt; +use std::path::PathBuf; + +/// Provides the ability to programmatically override the profile files that get loaded by the SDK. +/// +/// The [`Default`] for `ProfileFiles` includes the default SDK config and credential files located in +/// `~/.aws/config` and `~/.aws/credentials` respectively. +/// +/// Any number of config and credential files may be added to the `ProfileFiles` file set, with the +/// only requirement being that there is at least one of them. Custom file locations that are added +/// will produce errors if they don't exist, while the default config/credentials files paths are +/// allowed to not exist even if they're included. +/// +/// # Example: Using a custom profile file path for credentials and region +/// +/// ``` +/// use aws_config::profile::{ProfileFileCredentialsProvider, ProfileFileRegionProvider}; +/// use aws_config::profile::profile_file::{ProfileFiles, ProfileFileKind}; +/// +/// # async fn example() { +/// let profile_files = ProfileFiles::builder() +/// .with_file(ProfileFileKind::Credentials, "some/path/to/credentials-file") +/// .build(); +/// let credentials_provider = ProfileFileCredentialsProvider::builder() +/// .profile_files(profile_files.clone()) +/// .build(); +/// let region_provider = ProfileFileRegionProvider::builder() +/// .profile_files(profile_files) +/// .build(); +/// +/// let sdk_config = aws_config::from_env() +/// .credentials_provider(credentials_provider) +/// .region(region_provider) +/// .load() +/// .await; +/// # } +/// ``` +#[derive(Clone, Debug)] +pub struct ProfileFiles { + pub(crate) files: Vec, +} + +impl ProfileFiles { + /// Returns a builder to create `ProfileFiles` + pub fn builder() -> Builder { + Builder::new() + } +} + +impl Default for ProfileFiles { + fn default() -> Self { + Self { + files: vec![ + ProfileFile::Default(ProfileFileKind::Config), + ProfileFile::Default(ProfileFileKind::Credentials), + ], + } + } +} + +/// Profile file type (config or credentials) +#[derive(Copy, Clone, Debug)] +pub enum ProfileFileKind { + /// The SDK config file that typically resides in `~/.aws/config` + Config, + /// The SDK credentials file that typically resides in `~/.aws/credentials` + Credentials, +} + +impl ProfileFileKind { + pub(crate) fn default_path(&self) -> &'static str { + match &self { + ProfileFileKind::Credentials => "~/.aws/credentials", + ProfileFileKind::Config => "~/.aws/config", + } + } + + pub(crate) fn override_environment_variable(&self) -> &'static str { + match &self { + ProfileFileKind::Config => "AWS_CONFIG_FILE", + ProfileFileKind::Credentials => "AWS_SHARED_CREDENTIALS_FILE", + } + } +} + +/// A single profile file within a [`ProfileFiles`] file set. +#[derive(Clone)] +pub(crate) enum ProfileFile { + /// One of the default profile files (config or credentials in their default locations) + Default(ProfileFileKind), + /// A profile file at a custom location + FilePath { + kind: ProfileFileKind, + path: PathBuf, + }, + /// The direct contents of a profile file + FileContents { + kind: ProfileFileKind, + contents: String, + }, +} + +impl fmt::Debug for ProfileFile { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + Self::Default(kind) => f.debug_tuple("Default").field(kind).finish(), + Self::FilePath { kind, path } => f + .debug_struct("FilePath") + .field("kind", kind) + .field("path", path) + .finish(), + // Security: Redact the file contents since they may have credentials in them + Self::FileContents { kind, contents: _ } => f + .debug_struct("FileContents") + .field("kind", kind) + .field("contents", &"** redacted **") + .finish(), + } + } +} + +/// Builder for [`ProfileFiles`]. +#[derive(Clone, Default, Debug)] +pub struct Builder { + with_config: bool, + with_credentials: bool, + custom_sources: Vec, +} + +impl Builder { + /// Creates a new builder instance. + pub fn new() -> Self { + Default::default() + } + + /// Include the default SDK config file in the list of profile files to be loaded. + /// + /// The default SDK config typically resides in `~/.aws/config`. When this flag is enabled, + /// this config file will be included in the profile files that get loaded in the built + /// [`ProfileFiles`] file set. + /// + /// This flag defaults to `false` when using the builder to construct [`ProfileFiles`]. + pub fn include_default_config_file(mut self, include_default_config_file: bool) -> Self { + self.with_config = include_default_config_file; + self + } + + /// Include the default SDK credentials file in the list of profile files to be loaded. + /// + /// The default SDK config typically resides in `~/.aws/credentials`. When this flag is enabled, + /// this credentials file will be included in the profile files that get loaded in the built + /// [`ProfileFiles`] file set. + /// + /// This flag defaults to `false` when using the builder to construct [`ProfileFiles`]. + pub fn include_default_credentials_file( + mut self, + include_default_credentials_file: bool, + ) -> Self { + self.with_credentials = include_default_credentials_file; + self + } + + /// Include a custom `file` in the list of profile files to be loaded. + /// + /// The `kind` informs the parser how to treat the file. If it's intended to be like + /// the SDK credentials file typically in `~/.aws/config`, then use [`ProfileFileKind::Config`]. + /// Otherwise, use [`ProfileFileKind::Credentials`]. + pub fn with_file(mut self, kind: ProfileFileKind, file: impl Into) -> Self { + self.custom_sources.push(ProfileFile::FilePath { + kind, + path: file.into(), + }); + self + } + + /// Include custom file `contents` in the list of profile files to be loaded. + /// + /// The `kind` informs the parser how to treat the file. If it's intended to be like + /// the SDK credentials file typically in `~/.aws/config`, then use [`ProfileFileKind::Config`]. + /// Otherwise, use [`ProfileFileKind::Credentials`]. + pub fn with_contents(mut self, kind: ProfileFileKind, contents: impl Into) -> Self { + self.custom_sources.push(ProfileFile::FileContents { + kind, + contents: contents.into(), + }); + self + } + + /// Build the [`ProfileFiles`] file set. + pub fn build(self) -> ProfileFiles { + let mut files = self.custom_sources; + if self.with_credentials { + files.insert(0, ProfileFile::Default(ProfileFileKind::Credentials)); + } + if self.with_config { + files.insert(0, ProfileFile::Default(ProfileFileKind::Config)); + } + if files.is_empty() { + panic!("At least one profile file must be included in the `ProfileFiles` file set."); + } + ProfileFiles { files } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn redact_file_contents_in_profile_file_debug() { + let profile_file = ProfileFile::FileContents { + kind: ProfileFileKind::Config, + contents: "sensitive_contents".into(), + }; + let debug = format!("{:?}", profile_file); + assert!(!debug.contains("sensitive_contents")); + assert!(debug.contains("** redacted **")); + } + + #[test] + fn build_correctly_orders_default_config_credentials() { + let profile_files = ProfileFiles::builder() + .with_file(ProfileFileKind::Config, "foo") + .include_default_credentials_file(true) + .include_default_config_file(true) + .build(); + assert_eq!(3, profile_files.files.len()); + assert!(matches!( + profile_files.files[0], + ProfileFile::Default(ProfileFileKind::Config) + )); + assert!(matches!( + profile_files.files[1], + ProfileFile::Default(ProfileFileKind::Credentials) + )); + assert!(matches!( + profile_files.files[2], + ProfileFile::FilePath { + kind: ProfileFileKind::Config, + path: _ + } + )); + } + + #[test] + #[should_panic] + fn empty_builder_panics() { + ProfileFiles::builder().build(); + } +} diff --git a/aws/rust-runtime/aws-config/src/profile/region.rs b/aws/rust-runtime/aws-config/src/profile/region.rs index e294ed61ef1..547bff175fe 100644 --- a/aws/rust-runtime/aws-config/src/profile/region.rs +++ b/aws/rust-runtime/aws-config/src/profile/region.rs @@ -10,6 +10,7 @@ use crate::provider_config::ProviderConfig; use aws_types::os_shim_internal::{Env, Fs}; use aws_types::region::Region; +use super::profile_file::ProfileFiles; use super::ProfileSet; /// Load a region from a profile file @@ -17,6 +18,8 @@ use super::ProfileSet; /// This provider will attempt to load AWS shared configuration, then read the `region` property /// from the active profile. /// +#[doc = include_str!("location_of_profile_files.md")] +/// /// # Examples /// /// **Loads "us-west-2" as the region** @@ -39,6 +42,7 @@ pub struct ProfileFileRegionProvider { fs: Fs, env: Env, profile_override: Option, + profile_files: ProfileFiles, } /// Builder for [ProfileFileRegionProvider] @@ -46,6 +50,7 @@ pub struct ProfileFileRegionProvider { pub struct Builder { config: Option, profile_override: Option, + profile_files: Option, } impl Builder { @@ -55,12 +60,18 @@ impl Builder { self } - /// Override the profile name used by the [ProfileFileRegionProvider] + /// Override the profile name used by the [`ProfileFileRegionProvider`] pub fn profile_name(mut self, profile_name: impl Into) -> Self { self.profile_override = Some(profile_name.into()); self } + /// Set the profile file that should be used by the [`ProfileFileRegionProvider`] + pub fn profile_files(mut self, profile_files: ProfileFiles) -> Self { + self.profile_files = Some(profile_files); + self + } + /// Build a [ProfileFileRegionProvider] from this builder pub fn build(self) -> ProfileFileRegionProvider { let conf = self.config.unwrap_or_default(); @@ -68,6 +79,7 @@ impl Builder { env: conf.env(), fs: conf.fs(), profile_override: self.profile_override, + profile_files: self.profile_files.unwrap_or_default(), } } } @@ -81,6 +93,7 @@ impl ProfileFileRegionProvider { fs: Fs::real(), env: Env::real(), profile_override: None, + profile_files: ProfileFiles::default(), } } @@ -90,7 +103,7 @@ impl ProfileFileRegionProvider { } async fn region(&self) -> Option { - let profile_set = super::parser::load(&self.fs, &self.env) + let profile_set = super::parser::load(&self.fs, &self.env, &self.profile_files) .await .map_err(|err| tracing::warn!(err = %err, "failed to parse profile")) .ok()?; diff --git a/aws/rust-runtime/aws-config/src/profile/retry_config.rs b/aws/rust-runtime/aws-config/src/profile/retry_config.rs index c876d82f02c..e51a39fdde0 100644 --- a/aws/rust-runtime/aws-config/src/profile/retry_config.rs +++ b/aws/rust-runtime/aws-config/src/profile/retry_config.rs @@ -10,6 +10,7 @@ use std::str::FromStr; use aws_smithy_types::retry::{RetryConfigBuilder, RetryConfigErr, RetryMode}; use aws_types::os_shim_internal::{Env, Fs}; +use super::profile_file::ProfileFiles; use crate::provider_config::ProviderConfig; /// Load retry configuration properties from a profile file @@ -17,6 +18,8 @@ use crate::provider_config::ProviderConfig; /// This provider will attempt to load AWS shared configuration, then read retry configuration properties /// from the active profile. /// +#[doc = include_str!("location_of_profile_files.md")] +/// /// # Examples /// /// **Loads 2 as the `max_attempts` to make when sending a request** @@ -38,6 +41,7 @@ pub struct ProfileFileRetryConfigProvider { fs: Fs, env: Env, profile_override: Option, + profile_files: ProfileFiles, } /// Builder for [ProfileFileRetryConfigProvider] @@ -45,6 +49,7 @@ pub struct ProfileFileRetryConfigProvider { pub struct Builder { config: Option, profile_override: Option, + profile_files: Option, } impl Builder { @@ -60,6 +65,12 @@ impl Builder { self } + /// Set the profile file that should be used by the [`ProfileFileRetryConfigProvider`] + pub fn profile_files(mut self, profile_files: ProfileFiles) -> Self { + self.profile_files = Some(profile_files); + self + } + /// Build a [ProfileFileRetryConfigProvider] from this builder pub fn build(self) -> ProfileFileRetryConfigProvider { let conf = self.config.unwrap_or_default(); @@ -67,6 +78,7 @@ impl Builder { env: conf.env(), fs: conf.fs(), profile_override: self.profile_override, + profile_files: self.profile_files.unwrap_or_default(), } } } @@ -80,6 +92,7 @@ impl ProfileFileRetryConfigProvider { fs: Fs::real(), env: Env::real(), profile_override: None, + profile_files: Default::default(), } } @@ -90,7 +103,7 @@ impl ProfileFileRetryConfigProvider { /// Attempt to create a new RetryConfigBuilder from a profile file. pub async fn retry_config_builder(&self) -> Result { - let profile = match super::parser::load(&self.fs, &self.env).await { + let profile = match super::parser::load(&self.fs, &self.env, &self.profile_files).await { Ok(profile) => profile, Err(err) => { tracing::warn!(err = %err, "failed to parse profile"); From 7b96ae418abc973bc3b90ffe4677617e28b8aca3 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Tue, 27 Sep 2022 10:05:23 -0700 Subject: [PATCH 04/57] Don't error on duplicate pagination token (#1748) --- CHANGELOG.next.toml | 12 +++ .../dynamodb/tests/paginators.rs | 83 +++++++++++++++++-- .../smithy/generators/PaginatorGenerator.kt | 41 +++++---- 3 files changed, 115 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 94b888a4d42..90fb4b69f77 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -81,3 +81,15 @@ let sdk_config = aws_config::from_env() references = ["aws-sdk-rust#237", "smithy-rs#1770"] meta = { "breaking" = false, "tada" = true, "bug" = false } author = "jdisanti" + +[[aws-sdk-rust]] +message = "Paginators now stop on encountering a duplicate token by default rather than panic. This behavior can be customized by toggling the `stop_on_duplicate_token` property on the paginator before calling `send`." +references = ["aws-sdk-rust#620", "smithy-rs#1748"] +meta = { "breaking" = false, "tada" = false, "bug" = true } +author = "jdisanti" + +[[smithy-rs]] +message = "Paginators now stop on encountering a duplicate token by default rather than panic. This behavior can be customized by toggling the `stop_on_duplicate_token` property on the paginator before calling `send`." +references = ["aws-sdk-rust#620", "smithy-rs#1748"] +meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "client"} +author = "jdisanti" diff --git a/aws/sdk/integration-tests/dynamodb/tests/paginators.rs b/aws/sdk/integration-tests/dynamodb/tests/paginators.rs index b4e3e85c75a..3e3fd559efa 100644 --- a/aws/sdk/integration-tests/dynamodb/tests/paginators.rs +++ b/aws/sdk/integration-tests/dynamodb/tests/paginators.rs @@ -171,7 +171,7 @@ async fn paginators_handle_errors() { } #[tokio::test] -async fn paginators_error_on_repeated_token() { +async fn paginators_stop_on_duplicate_token_by_default() { let response = r#"{ "Count": 1, "Items": [{ @@ -212,11 +212,80 @@ async fn paginators_error_on_repeated_token() { .get("PostedBy"), Some(&AttributeValue::S("joe@example.com".to_string())) ); - let err = rows.try_next().await.expect_err("failure"); - assert!( - format!("{}", err).contains("next token did not change"), - "{}", - err + assert_eq!( + rows.try_next() + .await + .expect("no error") + .expect("not EOS") + .get("PostedBy"), + Some(&AttributeValue::S("joe@example.com".to_string())) + ); + assert_eq!(None, rows.try_next().await.expect("success")); +} + +#[tokio::test] +async fn paginators_can_continue_on_duplicate_token() { + let response = r#"{ + "Count": 1, + "Items": [{ + "PostedBy": { + "S": "joe@example.com" + } + }], + "LastEvaluatedKey": { + "PostedBy": { "S": "joe@example.com" } + } + }"#; + // send the same response twice with the same pagination token + let conn = TestConnection::new(vec![ + ( + mk_request(r#"{"TableName":"test-table","Limit":32}"#), + mk_response(response), + ), + ( + mk_request( + r#"{"TableName":"test-table","Limit":32,"ExclusiveStartKey":{"PostedBy":{"S":"joe@example.com"}}}"#, + ), + mk_response(response), + ), + ( + mk_request( + r#"{"TableName":"test-table","Limit":32,"ExclusiveStartKey":{"PostedBy":{"S":"joe@example.com"}}}"#, + ), + mk_response(response), + ), + ]); + let client = Client::from_conf_conn(stub_config(), conn.clone()); + let mut rows = client + .scan() + .table_name("test-table") + .into_paginator() + .stop_on_duplicate_token(false) + .page_size(32) + .items() + .send(); + assert_eq!( + rows.try_next() + .await + .expect("no error") + .expect("not EOS") + .get("PostedBy"), + Some(&AttributeValue::S("joe@example.com".to_string())) + ); + assert_eq!( + rows.try_next() + .await + .expect("no error") + .expect("not EOS") + .get("PostedBy"), + Some(&AttributeValue::S("joe@example.com".to_string())) + ); + assert_eq!( + rows.try_next() + .await + .expect("no error") + .expect("not EOS") + .get("PostedBy"), + Some(&AttributeValue::S("joe@example.com".to_string())) ); - assert_eq!(rows.try_next().await.expect("ok"), None); } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt index 8e3df9d58fe..ca459a503f8 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt @@ -132,7 +132,8 @@ class PaginatorGenerator private constructor( /// Paginator for #{operation:D} pub struct $paginatorName#{generics:W} { handle: std::sync::Arc, - builder: #{Builder} + builder: #{Builder}, + stop_on_duplicate_token: bool, } impl${generics.inst} ${paginatorName}${generics.inst} #{bounds:W} { @@ -141,6 +142,7 @@ class PaginatorGenerator private constructor( Self { handle, builder, + stop_on_duplicate_token: true, } } @@ -148,6 +150,17 @@ class PaginatorGenerator private constructor( #{items_fn:W} + /// Stop paginating when the service returns the same pagination token twice in a row. + /// + /// Defaults to true. + /// + /// For certain operations, it may be useful to continue on duplicate token. For example, + /// if an operation is for tailing a log file in real-time, then continuing may be desired. + /// This option can be set to `false` to accommodate these use cases. + pub fn stop_on_duplicate_token(mut self, stop_on_duplicate_token: bool) -> Self { + self.stop_on_duplicate_token = stop_on_duplicate_token; + self + } /// Create the pagination stream /// @@ -179,12 +192,12 @@ class PaginatorGenerator private constructor( Ok(ref resp) => { let new_token = #{output_token}(resp); let is_empty = new_token.map(|token| token.is_empty()).unwrap_or(true); - if !is_empty && new_token == input.$inputTokenMember.as_ref() { - let _ = tx.send(Err(#{SdkError}::ConstructionFailure("next token did not change, aborting paginator. This indicates an SDK or AWS service bug.".into()))).await; - return; + if !is_empty && new_token == input.$inputTokenMember.as_ref() && self.stop_on_duplicate_token { + true + } else { + input.$inputTokenMember = new_token.cloned(); + is_empty } - input.$inputTokenMember = new_token.cloned(); - is_empty }, Err(_) => true, }; @@ -226,14 +239,14 @@ class PaginatorGenerator private constructor( paginationInfo.itemsMemberPath.joinToString(".") { symbolProvider.toMemberName(it) } rustTemplate( """ - /// Create a flattened paginator - /// - /// This paginator automatically flattens results using `$documentedPath`. Queries to the underlying service - /// are dispatched lazily. - pub fn items(self) -> #{ItemPaginator}${generics.inst} { - #{ItemPaginator}(self) - } - """, + /// Create a flattened paginator + /// + /// This paginator automatically flattens results using `$documentedPath`. Queries to the underlying service + /// are dispatched lazily. + pub fn items(self) -> #{ItemPaginator}${generics.inst} { + #{ItemPaginator}(self) + } + """, "ItemPaginator" to itemPaginatorType, ) } From dcfb85578ef10e8d4fcb037c2fcf7d2a5e879f70 Mon Sep 17 00:00:00 2001 From: Harry Barber <106155934+hlbarber@users.noreply.github.com> Date: Wed, 28 Sep 2022 12:57:48 +0100 Subject: [PATCH 05/57] Add Instrumentation documentation (#1772) * Add documentation covering instrumentation approaches for Smithy Rust. * Tweak the logging in the Pokemon service to better exemplify instrumentation. * Remove `TraceLayer` which violates sensitivity contract. * Switch to [Pretty](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/format/struct.Pretty.html) logs to better showcase the outputs. * Update [Logging in the Presence of Sensitive Data](https://github.com/awslabs/smithy-rs/pull/1536) checklist. * Rename `logging` module to `instrumentation` to improve coherence across struct names and documentation. --- .../ServerHttpSensitivityGenerator.kt | 42 +++---- .../generators/ServerOperationGenerator.kt | 2 +- .../ServerOperationRegistryGenerator.kt | 2 +- .../ServerHttpSensitivityGeneratorTest.kt | 32 ++--- design/src/docs/instrumentation.md | 119 ++++++++++++++++++ design/src/rfcs/rfc0018_logging_sensitive.md | 13 +- .../src/bin/pokemon-service-tls.rs | 8 +- .../examples/pokemon-service/src/lambda.rs | 8 +- .../examples/pokemon-service/src/lib.rs | 8 +- .../examples/pokemon-service/src/main.rs | 8 +- .../src/{logging => instrumentation}/layer.rs | 0 .../src/{logging => instrumentation}/mod.rs | 2 +- .../{logging => instrumentation}/plugin.rs | 0 .../sensitivity/headers.rs | 4 +- .../sensitivity/mod.rs | 0 .../sensitivity/request.rs | 2 +- .../sensitivity/response.rs | 2 +- .../sensitivity/sensitive.rs | 4 +- .../sensitivity/uri/label.rs | 8 +- .../sensitivity/uri/mod.rs | 2 +- .../sensitivity/uri/query.rs | 6 +- .../{logging => instrumentation}/service.rs | 2 +- .../aws-smithy-http-server/src/lib.rs | 2 +- 23 files changed, 191 insertions(+), 85 deletions(-) create mode 100644 design/src/docs/instrumentation.md rename rust-runtime/aws-smithy-http-server/src/{logging => instrumentation}/layer.rs (100%) rename rust-runtime/aws-smithy-http-server/src/{logging => instrumentation}/mod.rs (97%) rename rust-runtime/aws-smithy-http-server/src/{logging => instrumentation}/plugin.rs (100%) rename rust-runtime/aws-smithy-http-server/src/{logging => instrumentation}/sensitivity/headers.rs (98%) rename rust-runtime/aws-smithy-http-server/src/{logging => instrumentation}/sensitivity/mod.rs (100%) rename rust-runtime/aws-smithy-http-server/src/{logging => instrumentation}/sensitivity/request.rs (98%) rename rust-runtime/aws-smithy-http-server/src/{logging => instrumentation}/sensitivity/response.rs (98%) rename rust-runtime/aws-smithy-http-server/src/{logging => instrumentation}/sensitivity/sensitive.rs (95%) rename rust-runtime/aws-smithy-http-server/src/{logging => instrumentation}/sensitivity/uri/label.rs (97%) rename rust-runtime/aws-smithy-http-server/src/{logging => instrumentation}/sensitivity/uri/mod.rs (99%) rename rust-runtime/aws-smithy-http-server/src/{logging => instrumentation}/sensitivity/uri/query.rs (96%) rename rust-runtime/aws-smithy-http-server/src/{logging => instrumentation}/service.rs (98%) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt index 2da280f83d4..5dace38b851 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGenerator.kt @@ -41,9 +41,9 @@ class StatusCodeSensitivity(private val sensitive: Boolean, runtimeConfig: Runti /** Returns the type of the `MakeFmt`. */ fun type(): Writable = writable { if (sensitive) { - rustTemplate("#{SmithyHttpServer}::logging::MakeSensitive", *codegenScope) + rustTemplate("#{SmithyHttpServer}::instrumentation::MakeSensitive", *codegenScope) } else { - rustTemplate("#{SmithyHttpServer}::logging::MakeIdentity", *codegenScope) + rustTemplate("#{SmithyHttpServer}::instrumentation::MakeIdentity", *codegenScope) } } @@ -86,9 +86,9 @@ class LabelSensitivity(internal val labelIndexes: List, internal val greedy /** Returns the type of the `MakeFmt`. */ fun type(): Writable = if (hasRedactions()) writable { - rustTemplate("#{SmithyHttpServer}::logging::sensitivity::uri::MakeLabel bool>", *codegenScope) + rustTemplate("#{SmithyHttpServer}::instrumentation::sensitivity::uri::MakeLabel bool>", *codegenScope) } else writable { - rustTemplate("#{SmithyHttpServer}::logging::MakeIdentity", *codegenScope) + rustTemplate("#{SmithyHttpServer}::instrumentation::MakeIdentity", *codegenScope) } /** Returns the value of the `GreedyLabel`. */ @@ -96,7 +96,7 @@ class LabelSensitivity(internal val labelIndexes: List, internal val greedy if (greedyLabel != null) { rustTemplate( """ - Some(#{SmithyHttpServer}::logging::sensitivity::uri::GreedyLabel::new(${greedyLabel.segmentIndex}, ${greedyLabel.endOffset}))""", + Some(#{SmithyHttpServer}::instrumentation::sensitivity::uri::GreedyLabel::new(${greedyLabel.segmentIndex}, ${greedyLabel.endOffset}))""", *codegenScope, ) } else { @@ -148,9 +148,9 @@ sealed class HeaderSensitivity( /** Returns the type of the `MakeDebug`. */ fun type(): Writable = writable { if (hasRedactions()) { - rustTemplate("#{SmithyHttpServer}::logging::sensitivity::headers::MakeHeaders #{SmithyHttpServer}::logging::sensitivity::headers::HeaderMarker>", *codegenScope) + rustTemplate("#{SmithyHttpServer}::instrumentation::sensitivity::headers::MakeHeaders #{SmithyHttpServer}::instrumentation::sensitivity::headers::HeaderMarker>", *codegenScope) } else { - rustTemplate("#{SmithyHttpServer}::logging::MakeIdentity", *codegenScope) + rustTemplate("#{SmithyHttpServer}::instrumentation::MakeIdentity", *codegenScope) } } @@ -194,7 +194,7 @@ sealed class HeaderSensitivity( let name_match = #{NameMatch:W}; #{SuffixAndValue:W} - #{SmithyHttpServer}::logging::sensitivity::headers::HeaderMarker { key_suffix, value } + #{SmithyHttpServer}::instrumentation::sensitivity::headers::HeaderMarker { key_suffix, value } } } as fn(&_) -> _ """, @@ -240,9 +240,9 @@ sealed class QuerySensitivity( /** Returns the type of the `MakeFmt`. */ fun type(): Writable = writable { if (hasRedactions()) { - rustTemplate("#{SmithyHttpServer}::logging::sensitivity::uri::MakeQuery #{SmithyHttpServer}::logging::sensitivity::uri::QueryMarker>", *codegenScope) + rustTemplate("#{SmithyHttpServer}::instrumentation::sensitivity::uri::MakeQuery #{SmithyHttpServer}::instrumentation::sensitivity::uri::QueryMarker>", *codegenScope) } else { - rustTemplate("#{SmithyHttpServer}::logging::MakeIdentity", *codegenScope) + rustTemplate("#{SmithyHttpServer}::instrumentation::MakeIdentity", *codegenScope) } } @@ -267,7 +267,7 @@ sealed class QuerySensitivity( |name: &str| { let key = $allKeysSensitive; let value = #{Value:W}; - #{SmithyHttpServer}::logging::sensitivity::uri::QueryMarker { key, value } + #{SmithyHttpServer}::instrumentation::sensitivity::uri::QueryMarker { key, value } } } as fn(&_) -> _ """, @@ -296,7 +296,7 @@ data class MakeFmt( * parts of the request/response HTTP as sensitive. * * These closures are provided to `RequestFmt` and `ResponseFmt` constructors, which in turn are provided to - * `InstrumentedOperation` to configure logging. These structures can be found in `aws_smithy_http_server::logging`. + * `InstrumentedOperation` to configure logging. These structures can be found in `aws_smithy_http_server::instrumentation`. * * See [Logging in the Presence of Sensitive Data](https://github.com/awslabs/smithy-rs/blob/main/design/src/rfcs/rfc0018_logging_sensitive.md) * for more details. @@ -458,10 +458,10 @@ class ServerHttpSensitivityGenerator( private fun defaultRequestFmt(): MakeFmt { val type = writable { - rustTemplate("#{SmithyHttpServer}::logging::sensitivity::DefaultRequestFmt", *codegenScope) + rustTemplate("#{SmithyHttpServer}::instrumentation::sensitivity::DefaultRequestFmt", *codegenScope) } val value = writable { - rustTemplate("#{SmithyHttpServer}::logging::sensitivity::RequestFmt::new()", *codegenScope) + rustTemplate("#{SmithyHttpServer}::instrumentation::sensitivity::RequestFmt::new()", *codegenScope) } return MakeFmt(type, value) } @@ -483,9 +483,9 @@ class ServerHttpSensitivityGenerator( val type = writable { rustTemplate( """ - #{SmithyHttpServer}::logging::sensitivity::RequestFmt< + #{SmithyHttpServer}::instrumentation::sensitivity::RequestFmt< #{HeaderType:W}, - #{SmithyHttpServer}::logging::sensitivity::uri::MakeUri< + #{SmithyHttpServer}::instrumentation::sensitivity::uri::MakeUri< #{LabelType:W}, #{QueryType:W} > @@ -498,18 +498,18 @@ class ServerHttpSensitivityGenerator( ) } - val value = writable { rustTemplate("#{SmithyHttpServer}::logging::sensitivity::RequestFmt::new()", *codegenScope) } + headerSensitivity.setter() + labelSensitivity.setter() + querySensitivity.setters() + val value = writable { rustTemplate("#{SmithyHttpServer}::instrumentation::sensitivity::RequestFmt::new()", *codegenScope) } + headerSensitivity.setter() + labelSensitivity.setter() + querySensitivity.setters() return MakeFmt(type, value) } private fun defaultResponseFmt(): MakeFmt { val type = writable { - rustTemplate("#{SmithyHttpServer}::logging::sensitivity::DefaultResponseFmt", *codegenScope) + rustTemplate("#{SmithyHttpServer}::instrumentation::sensitivity::DefaultResponseFmt", *codegenScope) } val value = writable { - rustTemplate("#{SmithyHttpServer}::logging::sensitivity::ResponseFmt::new()", *codegenScope) + rustTemplate("#{SmithyHttpServer}::instrumentation::sensitivity::ResponseFmt::new()", *codegenScope) } return MakeFmt(type, value) } @@ -527,7 +527,7 @@ class ServerHttpSensitivityGenerator( val type = writable { rustTemplate( - "#{SmithyHttpServer}::logging::sensitivity::ResponseFmt<#{HeaderType:W}, #{StatusType:W}>", + "#{SmithyHttpServer}::instrumentation::sensitivity::ResponseFmt<#{HeaderType:W}, #{StatusType:W}>", "HeaderType" to headerSensitivity.type(), "StatusType" to statusCodeSensitivity.type(), *codegenScope, @@ -535,7 +535,7 @@ class ServerHttpSensitivityGenerator( } val value = writable { - rustTemplate("#{SmithyHttpServer}::logging::sensitivity::ResponseFmt::new()", *codegenScope) + rustTemplate("#{SmithyHttpServer}::instrumentation::sensitivity::ResponseFmt::new()", *codegenScope) } + headerSensitivity.setter() + statusCodeSensitivity.setter() return MakeFmt(type, value) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt index 43816423574..b61b1baa457 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt @@ -61,7 +61,7 @@ class ServerOperationGenerator( type Error = #{Error:W}; } - impl #{SmithyHttpServer}::logging::sensitivity::Sensitivity for $operationName { + impl #{SmithyHttpServer}::instrumentation::sensitivity::Sensitivity for $operationName { type RequestFmt = #{RequestType:W}; type ResponseFmt = #{ResponseType:W}; diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt index aa549b455d5..1952c0f9340 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGenerator.kt @@ -338,7 +338,7 @@ ${operationImplementationStubs(operations)} let svc = #{ServerOperationHandler}::operation(registry.$operationName); let request_fmt = #{RequestFmt:W}; let response_fmt = #{ResponseFmt:W}; - let svc = #{SmithyHttpServer}::logging::InstrumentOperation::new(svc, "$operationName").request_fmt(request_fmt).response_fmt(response_fmt); + let svc = #{SmithyHttpServer}::instrumentation::InstrumentOperation::new(svc, "$operationName").request_fmt(request_fmt).response_fmt(response_fmt); (#{Tower}::util::BoxCloneService::new(svc), $requestSpecVarName) """, "RequestFmt" to sensitivityGen.requestFmt().value, diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt index 1b3575a5fbc..aba8b71da39 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt @@ -63,8 +63,8 @@ class ServerHttpSensitivityGeneratorTest { rustTemplate( """ let closure = #{Closure:W}; - assert_eq!(closure("query_a"), #{SmithyHttpServer}::logging::sensitivity::uri::QueryMarker { key: false, value: false }); - assert_eq!(closure("query_b"), #{SmithyHttpServer}::logging::sensitivity::uri::QueryMarker { key: false, value: true }); + assert_eq!(closure("query_a"), #{SmithyHttpServer}::instrumentation::sensitivity::uri::QueryMarker { key: false, value: false }); + assert_eq!(closure("query_b"), #{SmithyHttpServer}::instrumentation::sensitivity::uri::QueryMarker { key: false, value: true }); """, "Closure" to querySensitivity.closure(), *codegenScope, @@ -110,7 +110,7 @@ class ServerHttpSensitivityGeneratorTest { rustTemplate( """ let closure = #{Closure:W}; - assert_eq!(closure("wildcard"), #{SmithyHttpServer}::logging::sensitivity::uri::QueryMarker { key: true, value: true }); + assert_eq!(closure("wildcard"), #{SmithyHttpServer}::instrumentation::sensitivity::uri::QueryMarker { key: true, value: true }); """, "Closure" to querySensitivity.closure(), *codegenScope, @@ -158,7 +158,7 @@ class ServerHttpSensitivityGeneratorTest { rustTemplate( """ let closure = #{Closure:W}; - assert_eq!(closure("wildcard"), #{SmithyHttpServer}::logging::sensitivity::uri::QueryMarker { key: true, value: false }); + assert_eq!(closure("wildcard"), #{SmithyHttpServer}::instrumentation::sensitivity::uri::QueryMarker { key: true, value: false }); """, "Closure" to querySensitivity.closure(), *codegenScope, @@ -206,7 +206,7 @@ class ServerHttpSensitivityGeneratorTest { rustTemplate( """ let closure = #{Closure:W}; - assert_eq!(closure("wildcard"), #{SmithyHttpServer}::logging::sensitivity::uri::QueryMarker { key: false, value: true }); + assert_eq!(closure("wildcard"), #{SmithyHttpServer}::instrumentation::sensitivity::uri::QueryMarker { key: false, value: true }); """, "Closure" to querySensitivity.closure(), *codegenScope, @@ -284,9 +284,9 @@ class ServerHttpSensitivityGeneratorTest { """ let closure = #{Closure:W}; let name = #{Http}::header::HeaderName::from_static("header-a"); - assert_eq!(closure(&name), #{SmithyHttpServer}::logging::sensitivity::headers::HeaderMarker { value: false, key_suffix: None }); + assert_eq!(closure(&name), #{SmithyHttpServer}::instrumentation::sensitivity::headers::HeaderMarker { value: false, key_suffix: None }); let name = #{Http}::header::HeaderName::from_static("header-b"); - assert_eq!(closure(&name), #{SmithyHttpServer}::logging::sensitivity::headers::HeaderMarker { value: true, key_suffix: None }); + assert_eq!(closure(&name), #{SmithyHttpServer}::instrumentation::sensitivity::headers::HeaderMarker { value: true, key_suffix: None }); """, "Closure" to headerData.closure(), *codegenScope, @@ -332,11 +332,11 @@ class ServerHttpSensitivityGeneratorTest { """ let closure = #{Closure:W}; let name = #{Http}::header::HeaderName::from_static("prefix-a"); - assert_eq!(closure(&name), #{SmithyHttpServer}::logging::sensitivity::headers::HeaderMarker { value: true, key_suffix: Some(7) }); + assert_eq!(closure(&name), #{SmithyHttpServer}::instrumentation::sensitivity::headers::HeaderMarker { value: true, key_suffix: Some(7) }); let name = #{Http}::header::HeaderName::from_static("prefix-b"); - assert_eq!(closure(&name), #{SmithyHttpServer}::logging::sensitivity::headers::HeaderMarker { value: true, key_suffix: Some(7) }); + assert_eq!(closure(&name), #{SmithyHttpServer}::instrumentation::sensitivity::headers::HeaderMarker { value: true, key_suffix: Some(7) }); let name = #{Http}::header::HeaderName::from_static("other"); - assert_eq!(closure(&name), #{SmithyHttpServer}::logging::sensitivity::headers::HeaderMarker { value: false, key_suffix: None }); + assert_eq!(closure(&name), #{SmithyHttpServer}::instrumentation::sensitivity::headers::HeaderMarker { value: false, key_suffix: None }); """, "Closure" to headerData.closure(), *codegenScope, @@ -415,11 +415,11 @@ class ServerHttpSensitivityGeneratorTest { """ let closure = #{Closure:W}; let name = #{Http}::header::HeaderName::from_static("prefix-a"); - assert_eq!(closure(&name), #{SmithyHttpServer}::logging::sensitivity::headers::HeaderMarker { value: false, key_suffix: Some(7) }); + assert_eq!(closure(&name), #{SmithyHttpServer}::instrumentation::sensitivity::headers::HeaderMarker { value: false, key_suffix: Some(7) }); let name = #{Http}::header::HeaderName::from_static("prefix-b"); - assert_eq!(closure(&name), #{SmithyHttpServer}::logging::sensitivity::headers::HeaderMarker { value: false, key_suffix: Some(7) }); + assert_eq!(closure(&name), #{SmithyHttpServer}::instrumentation::sensitivity::headers::HeaderMarker { value: false, key_suffix: Some(7) }); let name = #{Http}::header::HeaderName::from_static("other"); - assert_eq!(closure(&name), #{SmithyHttpServer}::logging::sensitivity::headers::HeaderMarker { value: false, key_suffix: None }); + assert_eq!(closure(&name), #{SmithyHttpServer}::instrumentation::sensitivity::headers::HeaderMarker { value: false, key_suffix: None }); """, "Closure" to headerData.closure(), *codegenScope, @@ -469,11 +469,11 @@ class ServerHttpSensitivityGeneratorTest { """ let closure = #{Closure:W}; let name = #{Http}::header::HeaderName::from_static("prefix-a"); - assert_eq!(closure(&name), #{SmithyHttpServer}::logging::sensitivity::headers::HeaderMarker { value: true, key_suffix: None }); + assert_eq!(closure(&name), #{SmithyHttpServer}::instrumentation::sensitivity::headers::HeaderMarker { value: true, key_suffix: None }); let name = #{Http}::header::HeaderName::from_static("prefix-b"); - assert_eq!(closure(&name), #{SmithyHttpServer}::logging::sensitivity::headers::HeaderMarker { value: true, key_suffix: None }); + assert_eq!(closure(&name), #{SmithyHttpServer}::instrumentation::sensitivity::headers::HeaderMarker { value: true, key_suffix: None }); let name = #{Http}::header::HeaderName::from_static("other"); - assert_eq!(closure(&name), #{SmithyHttpServer}::logging::sensitivity::headers::HeaderMarker { value: false, key_suffix: None }); + assert_eq!(closure(&name), #{SmithyHttpServer}::instrumentation::sensitivity::headers::HeaderMarker { value: false, key_suffix: None }); """, "Closure" to headerData.closure(), *codegenScope, diff --git a/design/src/docs/instrumentation.md b/design/src/docs/instrumentation.md new file mode 100644 index 00000000000..b4647831f53 --- /dev/null +++ b/design/src/docs/instrumentation.md @@ -0,0 +1,119 @@ +# Instrumentation + +A Smithy Rust server uses the [`tracing`](https://github.com/tokio-rs/tracing) crate to provide instrumentation. The customer is responsible for setting up a [`Subscriber`](https://docs.rs/tracing/latest/tracing/subscriber/trait.Subscriber.html) in order to ingest and process [events](https://docs.rs/tracing/latest/tracing/struct.Event.html) - Smithy Rust makes no prescription on the choice of `Subscriber`. Common choices might include: + +- [`tracing_subscriber::fmt`](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/fmt/index.html) for printing to `stdout`. +- [`tracing-log`](https://crates.io/crates/tracing-log) to providing compatibility with the [`log`](https://crates.io/crates/log). + +Events are emitted and [spans](https://docs.rs/tracing/latest/tracing/struct.Span.html) are opened by the `aws-smithy-http-server`, `aws-smithy-http-server-python`, and generated crate. The [default](https://docs.rs/tracing/latest/tracing/struct.Metadata.html) [target](https://docs.rs/tracing/latest/tracing/struct.Metadata.html#method.target) is always used + +> The tracing macros default to using the module path where the span or event originated as the target, but it may be overridden. + +and therefore spans and events be filtered using the [`EnvFilter`](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html) and/or [`Targets`](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/targets/struct.Targets.html) filters with crate and module paths. + +For example, + +```bash +RUST_LOG=aws_smithy_http_server=warn,aws_smithy_http_server_python=error +``` + +and + +```rust +let filter = filter::Targets::new().with_target("aws_smithy_http_server", Level::DEBUG); +``` + +In general, Smithy Rust is conservative when using high-priority log levels: + +- ERROR + - Fatal errors, resulting in the termination of the service. + - Requires immediate remediation. +- WARN + - Non-fatal errors, resulting in incomplete operation. + - Indicates service misconfiguration, transient errors, or future changes in behavior. + - Requires inspection and remediation. +- INFO + - Informative events, which occur inside normal operating limits. + - Used for large state transitions, e.g. startup/shutdown. +- DEBUG + - Informative and sparse events, which occur inside normal operating limits. + - Used to debug coarse-grained progress of service. +- TRACE + - Informative and frequent events, which occur inside normal operating limits. + - Used to debug fine-grained progress of service. + +## Spans over the Request/Response lifecycle + +Smithy Rust is built on top of [`tower`](https://github.com/tower-rs/tower), which means that middleware can be used to encompass different periods of the lifecycle of the request and response and identify them with a span. + +An open-source example of such a middleware is [`TraceLayer`](https://docs.rs/tower-http/latest/tower_http/trace/struct.TraceLayer.html) provided by the [`tower-http`](https://docs.rs/tower-http/latest/tower_http/) crate. + +Smithy provides an out-the-box middleware which: + +- Opens a DEBUG level span, prior to request handling, including the operation name and request URI and headers. +- Emits a DEBUG level event, after to request handling, including the response headers and status code. + +This is applied by default and can be enabled and disabled by filtering on `aws_smithy_http_server::logging`. + + + + + +### Example + +The Pokémon service example, located at `rust-runtime/aws-smithy-http-server/examples/pokemon-service`, sets up a `tracing` `Subscriber` as follows: + +```rust +/// Setup `tracing::subscriber` to read the log level from RUST_LOG environment variable. +pub fn setup_tracing() { + let format = tracing_subscriber::fmt::layer().pretty(); + let filter = EnvFilter::try_from_default_env() + .or_else(|_| EnvFilter::try_new("info")) + .unwrap(); + tracing_subscriber::registry().with(format).with(filter).init(); +} +``` + +Running the Pokémon service example using + +```bash +RUST_LOG=aws_smithy_http_server=debug,pokemon_service=debug cargo r +``` + +and then using `cargo t` to run integration tests against the server, yields the following logs: + +```text + 2022-09-27T09:13:35.372517Z DEBUG aws_smithy_http_server::logging::service: response, headers: {"content-type": "application/json", "content-length": "17"}, status_code: 200 OK + at /smithy-rs/rust-runtime/aws-smithy-http-server/src/logging/service.rs:47 + in aws_smithy_http_server::logging::service::request with operation: get_server_statistics, method: GET, uri: /stats, headers: {"host": "localhost:13734"} + + 2022-09-27T09:13:35.374104Z DEBUG pokemon_service: attempting to authenticate storage user + at pokemon-service/src/lib.rs:184 + in aws_smithy_http_server::logging::service::request with operation: get_storage, method: GET, uri: /pokedex/{redacted}, headers: {"passcode": "{redacted}", "host": "localhost:13734"} + + 2022-09-27T09:13:35.374152Z DEBUG pokemon_service: authentication failed + at pokemon-service/src/lib.rs:188 + in aws_smithy_http_server::logging::service::request with operation: get_storage, method: GET, uri: /pokedex/{redacted}, headers: {"passcode": "{redacted}", "host": "localhost:13734"} + + 2022-09-27T09:13:35.374230Z DEBUG aws_smithy_http_server::logging::service: response, headers: {"content-type": "application/json", "x-amzn-errortype": "NotAuthorized", "content-length": "2"}, status_code: 401 Unauthorized + at /smithy-rs/rust-runtime/aws-smithy-http-server/src/logging/service.rs:47 + in aws_smithy_http_server::logging::service::request with operation: get_storage, method: GET, uri: /pokedex/{redacted}, headers: {"passcode": "{redacted}", "host": "localhost:13734"} +``` + +## Interactions with Sensitivity + +Instrumentation interacts with Smithy's [sensitive trait](https://awslabs.github.io/smithy/2.0/spec/documentation-traits.html#sensitive-trait). + +> Sensitive data MUST NOT be exposed in things like exception messages or log output. Application of this trait SHOULD NOT affect wire logging (i.e., logging of all data transmitted to and from servers or clients). + +For this reason, Smithy runtime will never use `tracing` to emit events or open spans that include any sensitive data. This means that the customer can ingest all logs from `aws-smithy-http-server` and `aws-smithy-http-server-*` without fear of violating the sensitive trait. + +The Smithy runtime will not, and cannot, prevent the customer violating the sensitive trait within the operation handlers and custom middleware. It is the responsibility of the customer to not violate the sensitive contract of their own model, care must be taken. + +Smithy shapes can be sensitive while being coupled to the HTTP request/responses via the [HTTP binding traits](https://awslabs.github.io/smithy/2.0/spec/http-bindings.html). This poses a risk when ingesting events which naively capture request/response information. The instrumentation middleware provided by Smithy Rust respects the sensitive trait and will replace sensitive data in its span and event with `{redacted}`. This feature can be seen in the [Example](#example) above. For debugging purposes these redactions can be prevented using the `aws-smithy-http-server` feature flag, `unredacted-logging`. + +Some examples of inadvertently leaking sensitive information: + +- Ingesting tracing events and spans from third-party crates which do not respect sensitivity. + - An concrete example of this would be enabling events from `hyper` or `tokio`. +- Applying middleware which ingests events including HTTP payloads or any other part of the HTTP request/response which can be bound. diff --git a/design/src/rfcs/rfc0018_logging_sensitive.md b/design/src/rfcs/rfc0018_logging_sensitive.md index a38c067cc45..4ae6a27dd32 100644 --- a/design/src/rfcs/rfc0018_logging_sensitive.md +++ b/design/src/rfcs/rfc0018_logging_sensitive.md @@ -395,7 +395,12 @@ Code generation would be need to be used in order to produce the filtering crite ## Changes Checklist - [x] Implement and integrate code generated logging middleware. - - https://github.com/awslabs/smithy-rs/pull/1550 -- [ ] Add logging to `Router` implementation. -- [ ] Write developer guideline. -- [ ] Refactor `Router` to allow for better positioning described in [Middleware Position](#middleware-position). + - +- [x] Add logging to `Router` implementation. + - +- [x] Write developer guideline. + - +- [x] Refactor `Router` to allow for better positioning described in [Middleware Position](#middleware-position). + - + - + - diff --git a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/bin/pokemon-service-tls.rs b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/bin/pokemon-service-tls.rs index d52824b290a..1e86a6a0d63 100644 --- a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/bin/pokemon-service-tls.rs +++ b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/bin/pokemon-service-tls.rs @@ -40,8 +40,6 @@ use tokio_rustls::{ rustls::{Certificate, PrivateKey, ServerConfig}, TlsAcceptor, }; -use tower::ServiceBuilder; -use tower_http::trace::TraceLayer; #[derive(Parser, Debug)] #[clap(author, version, about, long_about = None)] @@ -82,11 +80,7 @@ pub async fn main() { // Setup shared state and middlewares. let shared_state = Arc::new(State::default()); - let app = app.layer( - ServiceBuilder::new() - .layer(TraceLayer::new_for_http()) - .layer(AddExtensionLayer::new(shared_state)), - ); + let app = app.layer(AddExtensionLayer::new(shared_state)); let addr: SocketAddr = format!("{}:{}", args.address, args.port) .parse() diff --git a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lambda.rs b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lambda.rs index dd863b5a276..17537ebab15 100644 --- a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lambda.rs +++ b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lambda.rs @@ -12,8 +12,6 @@ use pokemon_service::{ State, }; use pokemon_service_server_sdk::operation_registry::OperationRegistryBuilder; -use tower::ServiceBuilder; -use tower_http::trace::TraceLayer; #[tokio::main] pub async fn main() { @@ -37,11 +35,7 @@ pub async fn main() { // Setup shared state and middlewares. let shared_state = Arc::new(State::default()); - let app = app.layer( - ServiceBuilder::new() - .layer(TraceLayer::new_for_http()) - .layer(AddExtensionLayer::new(shared_state)), - ); + let app = app.layer(AddExtensionLayer::new(shared_state)); let handler = LambdaHandler::new(app); let lambda = lambda_http::run(handler); diff --git a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lib.rs b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lib.rs index 473c2571259..93213f73bf5 100644 --- a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lib.rs +++ b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lib.rs @@ -33,10 +33,7 @@ const PIKACHU_JAPANESE_FLAVOR_TEXT: &str = /// Setup `tracing::subscriber` to read the log level from RUST_LOG environment variable. pub fn setup_tracing() { - let format = tracing_subscriber::fmt::layer() - .with_ansi(true) - .with_line_number(true) - .with_level(true); + let format = tracing_subscriber::fmt::layer().pretty(); let filter = EnvFilter::try_from_default_env() .or_else(|_| EnvFilter::try_new("info")) .unwrap(); @@ -184,8 +181,11 @@ pub async fn get_storage( input: input::GetStorageInput, _state: Extension>, ) -> Result { + tracing::debug!("attempting to authenticate storage user"); + // We currently only support Ash and he has nothing stored if !(input.user == "ash" && input.passcode == "pikachu123") { + tracing::debug!("authentication failed"); return Err(error::GetStorageError::NotAuthorized(error::NotAuthorized {})); } Ok(output::GetStorageOutput { collection: vec![] }) diff --git a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/main.rs b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/main.rs index 2bae7c68f65..4122a49d6d2 100644 --- a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/main.rs +++ b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/main.rs @@ -13,8 +13,6 @@ use pokemon_service::{ State, }; use pokemon_service_server_sdk::operation_registry::OperationRegistryBuilder; -use tower::ServiceBuilder; -use tower_http::trace::TraceLayer; #[derive(Parser, Debug)] #[clap(author, version, about, long_about = None)] @@ -49,11 +47,7 @@ pub async fn main() { // Setup shared state and middlewares. let shared_state = Arc::new(State::default()); - let app = app.layer( - ServiceBuilder::new() - .layer(TraceLayer::new_for_http()) - .layer(AddExtensionLayer::new(shared_state)), - ); + let app = app.layer(AddExtensionLayer::new(shared_state)); // Start the [`hyper::Server`]. let bind: SocketAddr = format!("{}:{}", args.address, args.port) diff --git a/rust-runtime/aws-smithy-http-server/src/logging/layer.rs b/rust-runtime/aws-smithy-http-server/src/instrumentation/layer.rs similarity index 100% rename from rust-runtime/aws-smithy-http-server/src/logging/layer.rs rename to rust-runtime/aws-smithy-http-server/src/instrumentation/layer.rs diff --git a/rust-runtime/aws-smithy-http-server/src/logging/mod.rs b/rust-runtime/aws-smithy-http-server/src/instrumentation/mod.rs similarity index 97% rename from rust-runtime/aws-smithy-http-server/src/logging/mod.rs rename to rust-runtime/aws-smithy-http-server/src/instrumentation/mod.rs index 99f6f94869e..8a809bae8cc 100644 --- a/rust-runtime/aws-smithy-http-server/src/logging/mod.rs +++ b/rust-runtime/aws-smithy-http-server/src/instrumentation/mod.rs @@ -12,7 +12,7 @@ //! //! ``` //! # use std::convert::Infallible; -//! # use aws_smithy_http_server::logging::{*, sensitivity::{*, headers::*, uri::*}}; +//! # use aws_smithy_http_server::instrumentation::{*, sensitivity::{*, headers::*, uri::*}}; //! # use http::{Request, Response}; //! # use tower::{util::service_fn, Service}; //! # async fn service(request: Request<()>) -> Result, Infallible> { diff --git a/rust-runtime/aws-smithy-http-server/src/logging/plugin.rs b/rust-runtime/aws-smithy-http-server/src/instrumentation/plugin.rs similarity index 100% rename from rust-runtime/aws-smithy-http-server/src/logging/plugin.rs rename to rust-runtime/aws-smithy-http-server/src/instrumentation/plugin.rs diff --git a/rust-runtime/aws-smithy-http-server/src/logging/sensitivity/headers.rs b/rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/headers.rs similarity index 98% rename from rust-runtime/aws-smithy-http-server/src/logging/sensitivity/headers.rs rename to rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/headers.rs index b76da7c1e17..57e65eb4199 100644 --- a/rust-runtime/aws-smithy-http-server/src/logging/sensitivity/headers.rs +++ b/rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/headers.rs @@ -9,7 +9,7 @@ use std::fmt::{Debug, Display, Error, Formatter}; use http::{header::HeaderName, HeaderMap}; -use crate::logging::MakeFmt; +use crate::instrumentation::MakeFmt; use super::Sensitive; @@ -31,7 +31,7 @@ pub struct HeaderMarker { /// # Example /// /// ``` -/// # use aws_smithy_http_server::logging::sensitivity::headers::{SensitiveHeaders, HeaderMarker}; +/// # use aws_smithy_http_server::instrumentation::sensitivity::headers::{SensitiveHeaders, HeaderMarker}; /// # use http::header::HeaderMap; /// # let headers = HeaderMap::new(); /// // Headers with keys equal to "header-name" are sensitive diff --git a/rust-runtime/aws-smithy-http-server/src/logging/sensitivity/mod.rs b/rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/mod.rs similarity index 100% rename from rust-runtime/aws-smithy-http-server/src/logging/sensitivity/mod.rs rename to rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/mod.rs diff --git a/rust-runtime/aws-smithy-http-server/src/logging/sensitivity/request.rs b/rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/request.rs similarity index 98% rename from rust-runtime/aws-smithy-http-server/src/logging/sensitivity/request.rs rename to rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/request.rs index f2d3321b97f..87dfdcb8498 100644 --- a/rust-runtime/aws-smithy-http-server/src/logging/sensitivity/request.rs +++ b/rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/request.rs @@ -9,7 +9,7 @@ use std::fmt::{Debug, Error, Formatter}; use http::{header::HeaderName, HeaderMap}; -use crate::logging::{MakeFmt, MakeIdentity}; +use crate::instrumentation::{MakeFmt, MakeIdentity}; use super::{ headers::{HeaderMarker, MakeHeaders}, diff --git a/rust-runtime/aws-smithy-http-server/src/logging/sensitivity/response.rs b/rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/response.rs similarity index 98% rename from rust-runtime/aws-smithy-http-server/src/logging/sensitivity/response.rs rename to rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/response.rs index ebc90955a97..6d2212ab091 100644 --- a/rust-runtime/aws-smithy-http-server/src/logging/sensitivity/response.rs +++ b/rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/response.rs @@ -9,7 +9,7 @@ use std::fmt::{Debug, Error, Formatter}; use http::{header::HeaderName, HeaderMap}; -use crate::logging::{MakeFmt, MakeIdentity}; +use crate::instrumentation::{MakeFmt, MakeIdentity}; use super::{ headers::{HeaderMarker, MakeHeaders}, diff --git a/rust-runtime/aws-smithy-http-server/src/logging/sensitivity/sensitive.rs b/rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/sensitive.rs similarity index 95% rename from rust-runtime/aws-smithy-http-server/src/logging/sensitivity/sensitive.rs rename to rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/sensitive.rs index df48dbd3531..f61da00a02d 100644 --- a/rust-runtime/aws-smithy-http-server/src/logging/sensitivity/sensitive.rs +++ b/rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/sensitive.rs @@ -7,7 +7,7 @@ use std::fmt::{Debug, Display, Error, Formatter}; -use crate::logging::MakeFmt; +use crate::instrumentation::MakeFmt; use super::REDACTED; @@ -22,7 +22,7 @@ use super::REDACTED; /// # Example /// /// ``` -/// # use aws_smithy_http_server::logging::sensitivity::Sensitive; +/// # use aws_smithy_http_server::instrumentation::sensitivity::Sensitive; /// # let address = ""; /// tracing::debug!( /// name = %Sensitive("Alice"), diff --git a/rust-runtime/aws-smithy-http-server/src/logging/sensitivity/uri/label.rs b/rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/uri/label.rs similarity index 97% rename from rust-runtime/aws-smithy-http-server/src/logging/sensitivity/uri/label.rs rename to rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/uri/label.rs index d96c348abee..ca42a558eda 100644 --- a/rust-runtime/aws-smithy-http-server/src/logging/sensitivity/uri/label.rs +++ b/rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/uri/label.rs @@ -7,7 +7,7 @@ use std::fmt::{Debug, Display, Error, Formatter}; -use crate::logging::{sensitivity::Sensitive, MakeFmt}; +use crate::instrumentation::{sensitivity::Sensitive, MakeFmt}; /// A wrapper around a path [`&str`](str) which modifies the behavior of [`Display`]. Specific path segments are marked /// as sensitive by providing predicate over the segment index. This accommodates the [httpLabel trait] with @@ -18,7 +18,7 @@ use crate::logging::{sensitivity::Sensitive, MakeFmt}; /// # Example /// /// ``` -/// # use aws_smithy_http_server::logging::sensitivity::uri::Label; +/// # use aws_smithy_http_server::instrumentation::sensitivity::uri::Label; /// # use http::Uri; /// # let path = ""; /// // Path segment 2 is redacted and a trailing greedy label @@ -42,7 +42,7 @@ pub struct Label<'a, F> { /// The pattern, `/alpha/beta/{greedy+}/trail`, has segment index 2 and offset from the end of 6. /// /// ```rust -/// # use aws_smithy_http_server::logging::sensitivity::uri::GreedyLabel; +/// # use aws_smithy_http_server::instrumentation::sensitivity::uri::GreedyLabel; /// let greedy_label = GreedyLabel::new(2, 6); /// ``` #[derive(Clone, Debug)] @@ -177,7 +177,7 @@ where mod tests { use http::Uri; - use crate::logging::sensitivity::uri::{tests::EXAMPLES, GreedyLabel}; + use crate::instrumentation::sensitivity::uri::{tests::EXAMPLES, GreedyLabel}; use super::Label; diff --git a/rust-runtime/aws-smithy-http-server/src/logging/sensitivity/uri/mod.rs b/rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/uri/mod.rs similarity index 99% rename from rust-runtime/aws-smithy-http-server/src/logging/sensitivity/uri/mod.rs rename to rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/uri/mod.rs index 8438b1492a3..5b63d5303a2 100644 --- a/rust-runtime/aws-smithy-http-server/src/logging/sensitivity/uri/mod.rs +++ b/rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/uri/mod.rs @@ -15,7 +15,7 @@ use http::Uri; pub use label::*; pub use query::*; -use crate::logging::{MakeDisplay, MakeFmt, MakeIdentity}; +use crate::instrumentation::{MakeDisplay, MakeFmt, MakeIdentity}; /// A wrapper around [`&Uri`](Uri) which modifies the behavior of [`Display`]. Specific parts of the [`Uri`] as are /// marked as sensitive using the methods provided. diff --git a/rust-runtime/aws-smithy-http-server/src/logging/sensitivity/uri/query.rs b/rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/uri/query.rs similarity index 96% rename from rust-runtime/aws-smithy-http-server/src/logging/sensitivity/uri/query.rs rename to rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/uri/query.rs index 6c25fb1236b..34491c3ad11 100644 --- a/rust-runtime/aws-smithy-http-server/src/logging/sensitivity/uri/query.rs +++ b/rust-runtime/aws-smithy-http-server/src/instrumentation/sensitivity/uri/query.rs @@ -7,7 +7,7 @@ use std::fmt::{Debug, Display, Error, Formatter}; -use crate::logging::{sensitivity::Sensitive, MakeFmt}; +use crate::instrumentation::{sensitivity::Sensitive, MakeFmt}; /// Marks the sensitive data of a query string pair. #[derive(Debug, Default, PartialEq, Eq)] @@ -27,7 +27,7 @@ pub struct QueryMarker { /// # Example /// /// ``` -/// # use aws_smithy_http_server::logging::sensitivity::uri::{Query, QueryMarker}; +/// # use aws_smithy_http_server::instrumentation::sensitivity::uri::{Query, QueryMarker}; /// # let uri = ""; /// // Query string value with key "name" is redacted /// let uri = Query::new(&uri, |x| QueryMarker { key: false, value: x == "name" } ); @@ -119,7 +119,7 @@ where mod tests { use http::Uri; - use crate::logging::sensitivity::uri::tests::{ + use crate::instrumentation::sensitivity::uri::tests::{ ALL_KEYS_QUERY_STRING_EXAMPLES, ALL_PAIRS_QUERY_STRING_EXAMPLES, ALL_VALUES_QUERY_STRING_EXAMPLES, EXAMPLES, QUERY_STRING_EXAMPLES, X_QUERY_STRING_EXAMPLES, }; diff --git a/rust-runtime/aws-smithy-http-server/src/logging/service.rs b/rust-runtime/aws-smithy-http-server/src/instrumentation/service.rs similarity index 98% rename from rust-runtime/aws-smithy-http-server/src/logging/service.rs rename to rust-runtime/aws-smithy-http-server/src/instrumentation/service.rs index 8a35e08e45c..d358a1e7da1 100644 --- a/rust-runtime/aws-smithy-http-server/src/logging/service.rs +++ b/rust-runtime/aws-smithy-http-server/src/instrumentation/service.rs @@ -86,7 +86,7 @@ where /// # Example /// /// ``` -/// # use aws_smithy_http_server::logging::{sensitivity::{*, uri::*, headers::*}, *}; +/// # use aws_smithy_http_server::instrumentation::{sensitivity::{*, uri::*, headers::*}, *}; /// # use tower::{Service, service_fn}; /// # use http::{Request, Response}; /// # async fn f(request: Request<()>) -> Result, ()> { Ok(Response::new(())) } diff --git a/rust-runtime/aws-smithy-http-server/src/lib.rs b/rust-runtime/aws-smithy-http-server/src/lib.rs index 6e34fb1d093..79c963e0843 100644 --- a/rust-runtime/aws-smithy-http-server/src/lib.rs +++ b/rust-runtime/aws-smithy-http-server/src/lib.rs @@ -14,7 +14,7 @@ pub mod body; pub(crate) mod error; pub mod extension; #[doc(hidden)] -pub mod logging; +pub mod instrumentation; #[doc(hidden)] pub mod operation; #[doc(hidden)] From 49cc08da22a85342294b7aeb2978b41b6c6b0c15 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Wed, 28 Sep 2022 10:46:28 -0700 Subject: [PATCH 06/57] Move core tests from `codegen-client` into `codegen-core` (#1776) * Move `testutil` into `core` where possible * Move `rustlang` tests into `core` * Move remaining `util` tests to `core` * Move and refactor `TopLevelErrorGeneratorTest` to not require `RustCodegenPlugin` * Move protocols into `core` * Move `generator` tests into `core` * Move protocol ser/de tests into `core` * Suppress deprecation warning in `TopLevelErrorGeneratorTest` * Move `InlineFunctionNamerTest` into `core` * Move model transform tests into `core` * Rename `SymbolBuilderTest` to `SymbolVisitorTest` to match class under test * Move server classes out of client * Move core codegen tests into their own CI step --- .github/workflows/ci.yml | 1 + .../customize/glacier/TreeHashHeader.kt | 2 +- .../rustsdk/customize/s3/S3Decorator.kt | 6 +- .../rustsdk/AwsPresigningDecoratorTest.kt | 2 +- .../EndpointConfigCustomizationTest.kt | 6 +- .../rustsdk/RegionProviderConfigTest.kt | 4 +- .../rustsdk/SigV4SigningCustomizationTest.kt | 6 +- .../amazon/smithy/rustsdk/TestUtil.kt | 6 +- .../ec2/EC2MakePrimitivesOptionalTest.kt | 2 +- ci.mk | 4 + .../smithy/customize/RustCodegenDecorator.kt | 3 +- .../protocol/ProtocolTestGenerator.kt | 2 +- .../smithy/protocols/ClientProtocolLoader.kt | 83 +++++++++++- .../testutil/TestConfigCustomization.kt | 4 + .../codegen/client/testutil/TestHelpers.kt | 81 +----------- .../HttpVersionListGeneratorTest.kt | 6 +- .../ResiliencyConfigCustomizationTest.kt | 8 +- .../SmithyTypesPubUseGeneratorTest.kt | 4 +- .../client/smithy/CodegenVisitorTest.kt | 4 +- .../smithy/EventStreamSymbolProviderTest.kt | 6 +- .../StreamingShapeSymbolProviderTest.kt | 2 +- .../SymbolVisitorTest.kt} | 16 +-- .../generators/EndpointTraitBindingsTest.kt | 14 +- .../generators/PaginatorGeneratorTest.kt | 4 +- .../config/ServiceConfigGeneratorTest.kt | 8 +- .../error/TopLevelErrorGeneratorTest.kt | 64 --------- .../protocol/ProtocolTestGeneratorTest.kt | 10 +- .../client/smithy/protocols/AwsQueryTest.kt | 4 +- .../client/smithy/protocols/Ec2QueryTest.kt | 4 +- .../client/smithy/protocols/RestJsonTest.kt | 4 +- .../client/smithy/protocols/RestXmlTest.kt | 4 +- .../RemoveEventStreamOperationsTest.kt | 2 +- .../rustlang/{RustTypes.kt => RustType.kt} | 0 .../{RuntimeTypes.kt => RuntimeType.kt} | 0 .../codegen/core}/smithy/protocols/AwsJson.kt | 31 +---- .../core}/smithy/protocols/AwsQuery.kt | 30 +---- .../core}/smithy/protocols/Ec2Query.kt | 30 +---- .../core}/smithy/protocols/RestJson.kt | 31 +---- .../codegen/core}/smithy/protocols/RestXml.kt | 34 +---- .../rust/codegen/core}/testutil/Rust.kt | 2 +- .../rust/codegen/core/testutil/TestHelpers.kt | 121 ++++++++++++++++++ .../core}/rustlang/InlineDependencyTest.kt | 9 +- .../core/rustlang}/RustGenericsTest.kt | 6 +- .../core/rustlang/RustReservedWordsTest.kt | 5 +- .../codegen/core/rustlang/RustTypeTest.kt | 7 +- .../codegen/core}/rustlang/RustWriterTest.kt | 26 +--- .../core}/rustlang/UseDeclarationsTest.kt | 5 +- .../codegen/core}/rustlang/WritableTest.kt | 11 +- .../core}/smithy/CodegenDelegatorTest.kt | 3 +- .../codegen/core/smithy/RuntimeTypeTest.kt | 7 +- .../smithy/generators/BuilderGeneratorTest.kt | 10 +- .../generators/CargoTomlGeneratorTest.kt | 8 +- .../smithy}/generators/EnumGeneratorTest.kt | 10 +- .../smithy/generators/InstantiatorTest.kt | 14 +- .../generators/StructureGeneratorTest.kt | 13 +- .../smithy}/generators/UnionGeneratorTest.kt | 9 +- .../error}/CombinedErrorGeneratorTest.kt | 15 +-- .../error/TopLevelErrorGeneratorTest.kt | 108 ++++++++++++++++ .../http/RequestBindingGeneratorTest.kt | 22 ++-- .../http/ResponseBindingGeneratorTest.kt | 19 ++- .../protocols/InlineFunctionNamerTest.kt | 8 +- .../parse/AwsQueryParserGeneratorTest.kt | 19 ++- .../parse/Ec2QueryParserGeneratorTest.kt | 19 ++- .../parse/JsonParserGeneratorTest.kt | 19 ++- .../XmlBindingTraitParserGeneratorTest.kt | 19 ++- .../AwsQuerySerializerGeneratorTest.kt | 17 ++- .../Ec2QuerySerializerGeneratorTest.kt | 17 ++- .../serialize/JsonSerializerGeneratorTest.kt | 19 ++- .../XmlBindingTraitSerializerGeneratorTest.kt | 17 ++- .../transformers/EventStreamNormalizerTest.kt | 5 +- .../transformers/OperationNormalizerTest.kt | 7 +- .../transformers/RecursiveShapeBoxerTest.kt | 5 +- .../RecursiveShapesIntegrationTest.kt | 9 +- .../rust/codegen/core}/util/SyntheticsTest.kt | 7 +- .../smithy/PythonCodegenServerPlugin.kt | 2 +- .../smithy/PythonServerCodegenVisitor.kt | 2 +- .../PythonServerCodegenDecorator.kt | 2 +- .../generators/PythonServerModuleGenerator.kt | 2 +- .../PythonServerSymbolProviderTest.kt | 2 +- .../server/smithy/RustCodegenServerPlugin.kt | 1 - .../server}/smithy/ServerCodegenContext.kt | 2 +- .../server/smithy/ServerCodegenVisitor.kt | 2 - .../server}/smithy/ServerRustSettings.kt | 2 +- .../AdditionalErrorsDecorator.kt | 2 +- .../ServerRequiredCustomizations.kt | 2 +- .../generators/protocol/ServerProtocol.kt | 8 +- .../protocol/ServerProtocolTestGenerator.kt | 2 +- .../server/smithy/protocols/ServerAwsJson.kt | 6 +- .../ServerHttpBoundProtocolGenerator.kt | 2 +- .../smithy/protocols/ServerProtocolLoader.kt | 4 +- .../smithy/protocols/ServerRestJsonFactory.kt | 4 +- .../smithy/protocols/ServerRestXmlFactory.kt | 4 +- .../smithy/testutil/ServerTestHelpers.kt | 8 +- .../server/smithy/ServerCodegenVisitorTest.kt | 5 +- .../AdditionalErrorsDecoratorTest.kt | 2 +- .../ServerCombinedErrorGeneratorTest.kt | 10 +- .../generators/ServerEnumGeneratorTest.kt | 6 +- .../ServerHttpSensitivityGeneratorTest.kt | 10 +- .../ServerOperationRegistryGeneratorTest.kt | 2 +- .../smithy/protocols/EventStreamTestTools.kt | 20 +-- .../EventStreamUnmarshallerGeneratorTest.kt | 8 +- .../EventStreamMarshallerGeneratorTest.kt | 8 +- .../customize/CombinedCodegenDecoratorTest.kt | 2 +- .../scripts/check-client-codegen-unit-tests | 1 - .../scripts/check-core-codegen-unit-tests | 9 ++ 105 files changed, 621 insertions(+), 670 deletions(-) rename codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/{SymbolBuilderTest.kt => smithy/SymbolVisitorTest.kt} (97%) delete mode 100644 codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/error/TopLevelErrorGeneratorTest.kt rename codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/{RustTypes.kt => RustType.kt} (100%) rename codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/{RuntimeTypes.kt => RuntimeType.kt} (100%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/AwsJson.kt (82%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/AwsQuery.kt (73%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/Ec2Query.kt (71%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/RestJson.kt (80%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/RestXml.kt (69%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core}/testutil/Rust.kt (99%) create mode 100644 codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/rustlang/InlineDependencyTest.kt (71%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang}/RustGenericsTest.kt (92%) rename codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustReservedWordSymbolProviderTest.kt => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustReservedWordsTest.kt (92%) rename codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustTypesTest.kt => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustTypeTest.kt (92%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/rustlang/RustWriterTest.kt (80%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/rustlang/UseDeclarationsTest.kt (86%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/rustlang/WritableTest.kt (84%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/CodegenDelegatorTest.kt (92%) rename codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RuntimeTypesTest.kt => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeTypeTest.kt (93%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/BuilderGeneratorTest.kt (87%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/CargoTomlGeneratorTest.kt (84%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy}/generators/EnumGeneratorTest.kt (96%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/generators/InstantiatorTest.kt (94%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy}/generators/StructureGeneratorTest.kt (96%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy}/generators/UnionGeneratorTest.kt (92%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error}/CombinedErrorGeneratorTest.kt (86%) create mode 100644 codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGeneratorTest.kt rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy}/generators/http/RequestBindingGeneratorTest.kt (93%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy}/generators/http/ResponseBindingGeneratorTest.kt (85%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/InlineFunctionNamerTest.kt (89%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/parse/AwsQueryParserGeneratorTest.kt (78%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/parse/Ec2QueryParserGeneratorTest.kt (77%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/parse/JsonParserGeneratorTest.kt (90%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/parse/XmlBindingTraitParserGeneratorTest.kt (90%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/serialize/AwsQuerySerializerGeneratorTest.kt (87%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/serialize/Ec2QuerySerializerGeneratorTest.kt (86%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/serialize/JsonSerializerGeneratorTest.kt (87%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/protocols/serialize/XmlBindingTraitSerializerGeneratorTest.kt (87%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/transformers/EventStreamNormalizerTest.kt (89%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/transformers/OperationNormalizerTest.kt (93%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/transformers/RecursiveShapeBoxerTest.kt (91%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/smithy/transformers/RecursiveShapesIntegrationTest.kt (84%) rename {codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client => codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core}/util/SyntheticsTest.kt (89%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server}/smithy/ServerCodegenContext.kt (95%) rename {codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client => codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server}/smithy/ServerRustSettings.kt (98%) create mode 100755 tools/ci-build/scripts/check-core-codegen-unit-tests diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7a1e4749461..b4ab973ea79 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,6 +62,7 @@ jobs: - action: check-aws-sdk-adhoc-tests - action: check-client-codegen-integration-tests - action: check-client-codegen-unit-tests + - action: check-core-codegen-unit-tests - action: check-rust-runtimes - action: check-sdk-codegen-unit-tests - action: check-server-codegen-integration-tests diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/TreeHashHeader.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/TreeHashHeader.kt index f762ffe2e40..05f6e7471cc 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/TreeHashHeader.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/glacier/TreeHashHeader.kt @@ -7,7 +7,6 @@ package software.amazon.smithy.rustsdk.customize.glacier import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.testutil.TokioWithTestMacros import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate @@ -17,6 +16,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationCustomization import software.amazon.smithy.rust.codegen.core.smithy.customize.OperationSection import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError +import software.amazon.smithy.rust.codegen.core.testutil.TokioWithTestMacros import software.amazon.smithy.rustsdk.InlineAwsDependency val TreeHashDependencies = listOf( diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt index e99ef76e54b..86fa17c6004 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt @@ -16,8 +16,7 @@ import software.amazon.smithy.model.transform.ModelTransformer import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestXml -import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestXmlFactory +import software.amazon.smithy.rust.codegen.client.smithy.protocols.ClientRestXmlFactory import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.Writable @@ -31,6 +30,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsSection import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolMap +import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestXml import software.amazon.smithy.rust.codegen.core.smithy.traits.AllowInvalidXmlRoot import software.amazon.smithy.rust.codegen.core.util.letIf import software.amazon.smithy.rustsdk.AwsRuntimeType @@ -57,7 +57,7 @@ class S3Decorator : RustCodegenDecorator = currentProtocols.letIf(applies(serviceId)) { it + mapOf( - RestXmlTrait.ID to RestXmlFactory { protocolConfig -> + RestXmlTrait.ID to ClientRestXmlFactory { protocolConfig -> S3(protocolConfig) }, ) diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecoratorTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecoratorTest.kt index 7a1460bc1ec..e79617a7169 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecoratorTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/AwsPresigningDecoratorTest.kt @@ -14,7 +14,7 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.traits.HttpTrait -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.orNull import software.amazon.smithy.rustsdk.traits.PresignableTrait diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt index 11dd45f2bb1..d91f98267b0 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt @@ -15,16 +15,16 @@ import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCusto import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.client.testutil.stubConfigCustomization -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.runCommand internal class EndpointConfigCustomizationTest { diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/RegionProviderConfigTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/RegionProviderConfigTest.kt index c71ddb63834..8d69fb2c868 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/RegionProviderConfigTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/RegionProviderConfigTest.kt @@ -6,10 +6,10 @@ package software.amazon.smithy.rustsdk import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.rustSettings import software.amazon.smithy.rust.codegen.client.testutil.validateConfigCustomizations import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.rustSettings internal class RegionProviderConfigTest { @Test diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/SigV4SigningCustomizationTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/SigV4SigningCustomizationTest.kt index 8e792c452e6..bf934a0a3e8 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/SigV4SigningCustomizationTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/SigV4SigningCustomizationTest.kt @@ -7,10 +7,10 @@ package software.amazon.smithy.rustsdk import org.junit.jupiter.api.Test import software.amazon.smithy.aws.traits.auth.SigV4Trait -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.stubConfigProject -import software.amazon.smithy.rust.codegen.client.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.unitTest internal class SigV4SigningCustomizationTest { @Test diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt index 61d6558a1c4..fc0173cd50b 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt @@ -6,12 +6,12 @@ package software.amazon.smithy.rustsdk import software.amazon.smithy.model.Model -import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext -import software.amazon.smithy.rust.codegen.client.testutil.testRustSettings import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings import software.amazon.smithy.rust.codegen.core.smithy.RuntimeCrateLocation +import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.testRustSettings import java.io.File // In aws-sdk-codegen, the working dir when gradle runs tests is actually `./aws`. So, to find the smithy runtime, we need diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/customize/ec2/EC2MakePrimitivesOptionalTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/customize/ec2/EC2MakePrimitivesOptionalTest.kt index d7ec82737aa..51eba7fa861 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/customize/ec2/EC2MakePrimitivesOptionalTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/customize/ec2/EC2MakePrimitivesOptionalTest.kt @@ -9,7 +9,7 @@ import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.model.knowledge.NullableIndex import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.util.lookup internal class EC2MakePrimitivesOptionalTest { diff --git a/ci.mk b/ci.mk index df75378b8aa..c39d4167626 100644 --- a/ci.mk +++ b/ci.mk @@ -56,6 +56,10 @@ check-client-codegen-integration-tests: check-client-codegen-unit-tests: $(CI_ACTION) $@ $(ARGS) +.PHONY: check-core-codegen-unit-tests +check-core-codegen-unit-tests: + $(CI_ACTION) $@ $(ARGS) + .PHONY: check-rust-runtimes check-rust-runtimes: $(CI_ACTION) $@ $(ARGS) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt index 2b22ed040b4..bfaae9c8712 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customize/RustCodegenDecorator.kt @@ -65,8 +65,7 @@ interface RustCodegenDecorator { fun extras(codegenContext: C, rustCrate: RustCrate) {} - fun protocols(serviceId: ShapeId, currentProtocols: ProtocolMap): ProtocolMap = - currentProtocols + fun protocols(serviceId: ShapeId, currentProtocols: ProtocolMap): ProtocolMap = currentProtocols fun transformModel(service: ServiceShape, model: Model): Model = model diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt index 52fb86d933d..4bf70a2f7c2 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt @@ -19,7 +19,6 @@ import software.amazon.smithy.protocoltests.traits.HttpRequestTestCase import software.amazon.smithy.protocoltests.traits.HttpRequestTestsTrait import software.amazon.smithy.protocoltests.traits.HttpResponseTestCase import software.amazon.smithy.protocoltests.traits.HttpResponseTestsTrait -import software.amazon.smithy.rust.codegen.client.testutil.TokioTest import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata @@ -37,6 +36,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.generators.Instantiator import software.amazon.smithy.rust.codegen.core.smithy.generators.error.errorSymbol import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.core.testutil.TokioTest import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.findMemberWithTrait import software.amazon.smithy.rust.codegen.core.util.getTrait diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/ClientProtocolLoader.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/ClientProtocolLoader.kt index d97f52c26ec..ecfea77ff55 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/ClientProtocolLoader.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/ClientProtocolLoader.kt @@ -13,21 +13,92 @@ import software.amazon.smithy.aws.traits.protocols.RestJson1Trait import software.amazon.smithy.aws.traits.protocols.RestXmlTrait import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.core.smithy.protocols.AwsJson +import software.amazon.smithy.rust.codegen.core.smithy.protocols.AwsJsonVersion +import software.amazon.smithy.rust.codegen.core.smithy.protocols.AwsQueryProtocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Ec2QueryProtocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolLoader import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolMap +import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestJson +import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestXml class ClientProtocolLoader(supportedProtocols: ProtocolMap) : ProtocolLoader(supportedProtocols) { companion object { val DefaultProtocols = mapOf( - AwsJson1_0Trait.ID to AwsJsonFactory(AwsJsonVersion.Json10), - AwsJson1_1Trait.ID to AwsJsonFactory(AwsJsonVersion.Json11), - AwsQueryTrait.ID to AwsQueryFactory(), - Ec2QueryTrait.ID to Ec2QueryFactory(), - RestJson1Trait.ID to RestJsonFactory(), - RestXmlTrait.ID to RestXmlFactory(), + AwsJson1_0Trait.ID to ClientAwsJsonFactory(AwsJsonVersion.Json10), + AwsJson1_1Trait.ID to ClientAwsJsonFactory(AwsJsonVersion.Json11), + AwsQueryTrait.ID to ClientAwsQueryFactory(), + Ec2QueryTrait.ID to ClientEc2QueryFactory(), + RestJson1Trait.ID to ClientRestJsonFactory(), + RestXmlTrait.ID to ClientRestXmlFactory(), ) val Default = ClientProtocolLoader(DefaultProtocols) } } + +private val CLIENT_PROTOCOL_SUPPORT = ProtocolSupport( + /* Client protocol codegen enabled */ + requestSerialization = true, + requestBodySerialization = true, + responseDeserialization = true, + errorDeserialization = true, + /* Server protocol codegen disabled */ + requestDeserialization = false, + requestBodyDeserialization = false, + responseSerialization = false, + errorSerialization = false, +) + +private class ClientAwsJsonFactory(private val version: AwsJsonVersion) : + ProtocolGeneratorFactory { + override fun protocol(codegenContext: ClientCodegenContext): Protocol = AwsJson(codegenContext, version) + + override fun buildProtocolGenerator(codegenContext: ClientCodegenContext): HttpBoundProtocolGenerator = + HttpBoundProtocolGenerator(codegenContext, protocol(codegenContext)) + + override fun support(): ProtocolSupport = CLIENT_PROTOCOL_SUPPORT +} + +private class ClientAwsQueryFactory : ProtocolGeneratorFactory { + override fun protocol(codegenContext: ClientCodegenContext): Protocol = AwsQueryProtocol(codegenContext) + + override fun buildProtocolGenerator(codegenContext: ClientCodegenContext): HttpBoundProtocolGenerator = + HttpBoundProtocolGenerator(codegenContext, protocol(codegenContext)) + + override fun support(): ProtocolSupport = CLIENT_PROTOCOL_SUPPORT +} + +private class ClientRestJsonFactory : ProtocolGeneratorFactory { + override fun protocol(codegenContext: ClientCodegenContext): Protocol = RestJson(codegenContext) + + override fun buildProtocolGenerator(codegenContext: ClientCodegenContext): HttpBoundProtocolGenerator = + HttpBoundProtocolGenerator(codegenContext, RestJson(codegenContext)) + + override fun support(): ProtocolSupport = CLIENT_PROTOCOL_SUPPORT +} + +private class ClientEc2QueryFactory : ProtocolGeneratorFactory { + override fun protocol(codegenContext: ClientCodegenContext): Protocol = Ec2QueryProtocol(codegenContext) + + override fun buildProtocolGenerator(codegenContext: ClientCodegenContext): HttpBoundProtocolGenerator = + HttpBoundProtocolGenerator(codegenContext, protocol(codegenContext)) + + override fun support(): ProtocolSupport = CLIENT_PROTOCOL_SUPPORT +} + +class ClientRestXmlFactory( + private val generator: (CodegenContext) -> Protocol = { RestXml(it) }, +) : ProtocolGeneratorFactory { + override fun protocol(codegenContext: ClientCodegenContext): Protocol = generator(codegenContext) + + override fun buildProtocolGenerator(codegenContext: ClientCodegenContext): HttpBoundProtocolGenerator = + HttpBoundProtocolGenerator(codegenContext, protocol(codegenContext)) + + override fun support(): ProtocolSupport = CLIENT_PROTOCOL_SUPPORT +} diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestConfigCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestConfigCustomization.kt index d91ea1f6d67..7dd4d4ca358 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestConfigCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestConfigCustomization.kt @@ -12,6 +12,10 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.TestWriterDelegator +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.unitTest /** * Test helper to produce a valid config customization to test that a [ConfigCustomization] can be used in conjunction diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt index ffd625fe1b3..be6be79dee0 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestHelpers.kt @@ -6,43 +6,20 @@ package software.amazon.smithy.rust.codegen.client.testutil import software.amazon.smithy.model.Model -import software.amazon.smithy.model.knowledge.NullableIndex import software.amazon.smithy.model.node.ObjectNode import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenConfig import software.amazon.smithy.rust.codegen.client.smithy.ClientRustSettings import software.amazon.smithy.rust.codegen.client.smithy.RustCodegenPlugin -import software.amazon.smithy.rust.codegen.core.rustlang.Attribute -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo -import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope -import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget -import software.amazon.smithy.rust.codegen.core.smithy.CoreCodegenConfig import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeCrateLocation import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider -import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig -import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator -import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator -import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock -import software.amazon.smithy.rust.codegen.core.util.dq -import software.amazon.smithy.rust.codegen.core.util.letIf -import java.io.File - -val TestRuntimeConfig = - RuntimeConfig(runtimeCrateLocation = RuntimeCrateLocation.Path(File("../rust-runtime/").absolutePath)) -val TestSymbolVisitorConfig = SymbolVisitorConfig( - runtimeConfig = TestRuntimeConfig, - renameExceptions = true, - handleRustBoxing = true, - nullabilityCheckMode = NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1, -) +import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig +import software.amazon.smithy.rust.codegen.core.testutil.TestSymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.testutil.testRustSettings fun clientTestRustSettings( service: ShapeId = ShapeId.from("notrelevant#notrelevant"), @@ -70,30 +47,6 @@ fun clientTestRustSettings( customizationConfig, ) -fun testRustSettings( - service: ShapeId = ShapeId.from("notrelevant#notrelevant"), - moduleName: String = "test-module", - moduleVersion: String = "0.0.1", - moduleAuthors: List = listOf("notrelevant"), - moduleDescription: String = "not relevant", - moduleRepository: String? = null, - runtimeConfig: RuntimeConfig = TestRuntimeConfig, - codegenConfig: CoreCodegenConfig = CoreCodegenConfig(), - license: String? = null, - examplesUri: String? = null, -) = CoreRustSettings( - service, - moduleName, - moduleVersion, - moduleAuthors, - moduleDescription, - moduleRepository, - runtimeConfig, - codegenConfig, - license, - examplesUri, -) - fun testSymbolProvider(model: Model, serviceShape: ServiceShape? = null): RustSymbolProvider = RustCodegenPlugin.baseSymbolProvider( model, @@ -116,31 +69,3 @@ fun testCodegenContext( settings, codegenTarget, ) - -private const val SmithyVersion = "1.0" -fun String.asSmithyModel(sourceLocation: String? = null, smithyVersion: String = SmithyVersion): Model { - val processed = letIf(!this.startsWith("\$version")) { "\$version: ${smithyVersion.dq()}\n$it" } - return Model.assembler().discoverModels().addUnparsedModel(sourceLocation ?: "test.smithy", processed).assemble() - .unwrap() -} - -/** - * In tests, we frequently need to generate a struct, a builder, and an impl block to access said builder. - */ -fun StructureShape.renderWithModelBuilder(model: Model, symbolProvider: RustSymbolProvider, writer: RustWriter, forWhom: CodegenTarget = CodegenTarget.CLIENT) { - StructureGenerator(model, symbolProvider, writer, this).render(forWhom) - val modelBuilder = BuilderGenerator(model, symbolProvider, this) - modelBuilder.render(writer) - writer.implBlock(this, symbolProvider) { - modelBuilder.renderConvenienceMethod(this) - } -} - -val TokioWithTestMacros = CargoDependency( - "tokio", - CratesIo("1"), - features = setOf("macros", "test-util", "rt"), - scope = DependencyScope.Dev, -) - -val TokioTest = Attribute.Custom("tokio::test", listOf(TokioWithTestMacros.asType())) diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt index d36fdac0716..6b07db5cc43 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/HttpVersionListGeneratorTest.kt @@ -14,9 +14,6 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.config.Confi import software.amazon.smithy.rust.codegen.client.smithy.generators.config.ServiceConfig import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator import software.amazon.smithy.rust.codegen.client.testutil.AddRustTestsDecorator -import software.amazon.smithy.rust.codegen.client.testutil.TokioTest -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -24,6 +21,9 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.testutil.TokioTest +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.core.util.runCommand // If any of these tests fail, and you want to understand why, run them with logging: diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/ResiliencyConfigCustomizationTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/ResiliencyConfigCustomizationTest.kt index fc30f13dc87..2d2cf76916d 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/ResiliencyConfigCustomizationTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/ResiliencyConfigCustomizationTest.kt @@ -8,14 +8,14 @@ package software.amazon.smithy.rust.codegen.client.customizations import org.junit.jupiter.api.Test import software.amazon.smithy.rust.codegen.client.smithy.customizations.ResiliencyConfigCustomization import software.amazon.smithy.rust.codegen.client.smithy.customizations.ResiliencyReExportCustomization -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.rustSettings import software.amazon.smithy.rust.codegen.client.testutil.stubConfigProject import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.rustSettings internal class ResiliencyConfigCustomizationTest { private val baseModel = """ diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/SmithyTypesPubUseGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/SmithyTypesPubUseGeneratorTest.kt index 6450e40c74d..d402fb8acfd 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/SmithyTypesPubUseGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/customizations/SmithyTypesPubUseGeneratorTest.kt @@ -8,9 +8,9 @@ package software.amazon.smithy.rust.codegen.client.customizations import org.junit.jupiter.api.Test import software.amazon.smithy.model.Model import software.amazon.smithy.rust.codegen.client.smithy.customizations.pubUseTypes -import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel class SmithyTypesPubUseGeneratorTest { private fun emptyModel() = modelWithMember() diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitorTest.kt index 67b4987ac59..eccb9058d5b 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitorTest.kt @@ -13,8 +13,8 @@ import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodeg import software.amazon.smithy.rust.codegen.client.smithy.customize.NoOpEventStreamSigningDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCustomizations import software.amazon.smithy.rust.codegen.client.smithy.generators.client.FluentClientDecorator -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext import kotlin.io.path.createDirectory import kotlin.io.path.writeText diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProviderTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProviderTest.kt index 4f9fd822385..a6660f43876 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProviderTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/EventStreamSymbolProviderTest.kt @@ -10,14 +10,14 @@ import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig -import software.amazon.smithy.rust.codegen.client.testutil.TestSymbolVisitorConfig -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.rustlang.RustType import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig +import software.amazon.smithy.rust.codegen.core.testutil.TestSymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel class EventStreamSymbolProviderTest { @Test diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/StreamingShapeSymbolProviderTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/StreamingShapeSymbolProviderTest.kt index 584e097565a..6c0c3cdadf1 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/StreamingShapeSymbolProviderTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/StreamingShapeSymbolProviderTest.kt @@ -8,11 +8,11 @@ package software.amazon.smithy.rust.codegen.client.smithy import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.MemberShape -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.Default import software.amazon.smithy.rust.codegen.core.smithy.defaultValue import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.util.lookup internal class StreamingShapeSymbolProviderTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/SymbolBuilderTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/SymbolVisitorTest.kt similarity index 97% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/SymbolBuilderTest.kt rename to codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/SymbolVisitorTest.kt index 640cfc46fa7..e7e87a89a68 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/SymbolBuilderTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/SymbolVisitorTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client +package software.amazon.smithy.rust.codegen.client.smithy import io.kotest.matchers.collections.shouldContain import io.kotest.matchers.collections.shouldNotBeEmpty @@ -26,7 +26,6 @@ import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.ErrorTrait import software.amazon.smithy.model.traits.SparseTrait -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.rustlang.RustType import software.amazon.smithy.rust.codegen.core.rustlang.render @@ -35,8 +34,9 @@ import software.amazon.smithy.rust.codegen.core.smithy.Models import software.amazon.smithy.rust.codegen.core.smithy.Operations import software.amazon.smithy.rust.codegen.core.smithy.isOptional import software.amazon.smithy.rust.codegen.core.smithy.rustType +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel -class SymbolBuilderTest { +class SymbolVisitorTest { private fun Symbol.referenceClosure(): List { val referencedSymbols = this.references.map { it.symbol } return listOf(this) + referencedSymbols.flatMap { it.referenceClosure() } @@ -126,11 +126,11 @@ class SymbolBuilderTest { ) fun `creates primitives`(primitiveType: String, optional: Boolean, rustName: String) { val model = """ - namespace foo.bar - structure MyStruct { - quux: $primitiveType - } -""".asSmithyModel() + namespace foo.bar + structure MyStruct { + quux: $primitiveType + } + """.asSmithyModel() val member = model.expectShape(ShapeId.from("foo.bar#MyStruct\$quux")) val provider: SymbolProvider = testSymbolProvider(model) val memberSymbol = provider.toSymbol(member) diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt index 920faba4b96..d63b87e7ed1 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt @@ -15,14 +15,7 @@ import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodeg import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCustomizations import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator -import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.TokioTest -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.Visibility import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -31,6 +24,13 @@ import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError +import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.TokioTest +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.core.util.runCommand import kotlin.io.path.ExperimentalPathApi diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGeneratorTest.kt index 6b4366b4989..fd6fa27a3a1 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGeneratorTest.kt @@ -7,8 +7,8 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators import org.junit.jupiter.api.Test import software.amazon.smithy.rust.codegen.client.smithy.RustCodegenPlugin -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.core.util.runCommand internal class PaginatorGeneratorTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGeneratorTest.kt index 3afcc7d08a4..2d09a2dc2a8 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGeneratorTest.kt @@ -8,16 +8,16 @@ package software.amazon.smithy.rust.codegen.client.smithy.generators.config import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.ServiceShape -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.customize.NamedSectionGenerator +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.lookup internal class ServiceConfigGeneratorTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/error/TopLevelErrorGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/error/TopLevelErrorGeneratorTest.kt deleted file mode 100644 index 1cf32633b37..00000000000 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/error/TopLevelErrorGeneratorTest.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package software.amazon.smithy.rust.codegen.client.smithy.generators.error - -import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.smithy.RustCodegenPlugin -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext -import software.amazon.smithy.rust.codegen.core.util.runCommand -import kotlin.io.path.ExperimentalPathApi -import kotlin.io.path.createDirectory -import kotlin.io.path.writeText - -internal class TopLevelErrorGeneratorTest { - @ExperimentalPathApi - @Test - fun `top level errors are send + sync`() { - val model = """ - namespace com.example - - use aws.protocols#restJson1 - - @restJson1 - service HelloService { - operations: [SayHello], - version: "1" - } - - @http(uri: "/", method: "POST") - operation SayHello { - errors: [SorryBusy, CanYouRepeatThat, MeDeprecated] - - } - - @error("server") - structure SorryBusy { } - - @error("client") - structure CanYouRepeatThat { } - - @error("client") - @deprecated - structure MeDeprecated { } - """.asSmithyModel() - - val (pluginContext, testDir) = generatePluginContext(model) - val moduleName = pluginContext.settings.expectStringMember("module").value.replace('-', '_') - RustCodegenPlugin().execute(pluginContext) - testDir.resolve("tests").createDirectory() - testDir.resolve("tests/validate_errors.rs").writeText( - """ - fn check_send_sync() {} - #[test] - fn tl_errors_are_send_sync() { - check_send_sync::<$moduleName::Error>() - } - """, - ) - "cargo test".runCommand(testDir) - } -} diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt index ef563106885..57bd1ae2779 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGeneratorTest.kt @@ -14,9 +14,6 @@ import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.CodegenVisitor import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator -import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestJson -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.escape import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -32,6 +29,9 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.Proto import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolMap +import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestJson +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.core.util.CommandFailed import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.outputShape @@ -108,9 +108,7 @@ private class TestProtocolFactory( private val body: String, private val correctResponse: String, ) : ProtocolGeneratorFactory { - override fun protocol(codegenContext: ClientCodegenContext): Protocol { - return RestJson(codegenContext) - } + override fun protocol(codegenContext: ClientCodegenContext): Protocol = RestJson(codegenContext) override fun buildProtocolGenerator(codegenContext: ClientCodegenContext): ClientProtocolGenerator { return TestProtocolGenerator( diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsQueryTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsQueryTest.kt index 09b103df239..5445d403fa8 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsQueryTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsQueryTest.kt @@ -7,8 +7,8 @@ package software.amazon.smithy.rust.codegen.client.smithy.protocols import org.junit.jupiter.api.Test import software.amazon.smithy.rust.codegen.client.smithy.RustCodegenPlugin -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.core.util.runCommand class AwsQueryTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Ec2QueryTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Ec2QueryTest.kt index d7efcefa14e..80a5f9f2fdf 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Ec2QueryTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Ec2QueryTest.kt @@ -7,8 +7,8 @@ package software.amazon.smithy.rust.codegen.client.smithy.protocols import org.junit.jupiter.api.Test import software.amazon.smithy.rust.codegen.client.smithy.RustCodegenPlugin -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.core.util.runCommand class Ec2QueryTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestJsonTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestJsonTest.kt index 9790ecb71fa..0ac380f9833 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestJsonTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestJsonTest.kt @@ -7,8 +7,8 @@ package software.amazon.smithy.rust.codegen.client.smithy.protocols import org.junit.jupiter.api.Test import software.amazon.smithy.rust.codegen.client.smithy.RustCodegenPlugin -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.core.util.runCommand internal class RestJsonTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestXmlTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestXmlTest.kt index 4bf4f747aad..17400defb2c 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestXmlTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestXmlTest.kt @@ -7,8 +7,8 @@ package software.amazon.smithy.rust.codegen.client.smithy.protocols import org.junit.jupiter.api.Test import software.amazon.smithy.rust.codegen.client.smithy.RustCodegenPlugin -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.core.util.runCommand internal class RestXmlTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RemoveEventStreamOperationsTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RemoveEventStreamOperationsTest.kt index 39e5acde7dc..7873a74c2e1 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RemoveEventStreamOperationsTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RemoveEventStreamOperationsTest.kt @@ -11,8 +11,8 @@ import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenConfig -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.client.testutil.clientTestRustSettings +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import java.util.Optional internal class RemoveEventStreamOperationsTest { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustTypes.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt similarity index 100% rename from codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustTypes.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeTypes.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt similarity index 100% rename from codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeTypes.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsJson.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt similarity index 82% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsJson.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt index ae2d8e058ee..8c9588ada55 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsJson.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols +package software.amazon.smithy.rust.codegen.core.smithy.protocols import software.amazon.smithy.model.Model import software.amazon.smithy.model.pattern.UriPattern @@ -12,7 +12,6 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ToShapeId import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.asType @@ -20,18 +19,11 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.core.smithy.generators.serializationError -import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingDescriptor -import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver -import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpLocation -import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol -import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.JsonParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.JsonSerializerGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator -import software.amazon.smithy.rust.codegen.core.smithy.protocols.serializeFunctionName import software.amazon.smithy.rust.codegen.core.util.inputShape sealed class AwsJsonVersion { @@ -46,27 +38,6 @@ sealed class AwsJsonVersion { } } -class AwsJsonFactory(private val version: AwsJsonVersion) : - ProtocolGeneratorFactory { - override fun protocol(codegenContext: ClientCodegenContext): Protocol = AwsJson(codegenContext, version) - - override fun buildProtocolGenerator(codegenContext: ClientCodegenContext): HttpBoundProtocolGenerator = - HttpBoundProtocolGenerator(codegenContext, protocol(codegenContext)) - - override fun support(): ProtocolSupport = ProtocolSupport( - /* Client support */ - requestSerialization = true, - requestBodySerialization = true, - responseDeserialization = true, - errorDeserialization = true, - /* Server support */ - requestDeserialization = false, - requestBodyDeserialization = false, - responseSerialization = false, - errorSerialization = false, - ) -} - class AwsJsonHttpBindingResolver( private val model: Model, private val awsJsonVersion: AwsJsonVersion, diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsQuery.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt similarity index 73% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsQuery.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt index 4a95ea12699..d9d42244404 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/AwsQuery.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols +package software.amazon.smithy.rust.codegen.core.smithy.protocols import software.amazon.smithy.aws.traits.protocols.AwsQueryErrorTrait import software.amazon.smithy.model.Model @@ -12,7 +12,6 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ToShapeId import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.asType @@ -20,39 +19,12 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport -import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver -import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol -import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory -import software.amazon.smithy.rust.codegen.core.smithy.protocols.StaticHttpBindingResolver import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.AwsQueryParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.AwsQuerySerializerGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator import software.amazon.smithy.rust.codegen.core.util.getTrait -class AwsQueryFactory : ProtocolGeneratorFactory { - override fun protocol(codegenContext: ClientCodegenContext): Protocol = AwsQueryProtocol(codegenContext) - - override fun buildProtocolGenerator(codegenContext: ClientCodegenContext): HttpBoundProtocolGenerator = - HttpBoundProtocolGenerator(codegenContext, protocol(codegenContext)) - - override fun support(): ProtocolSupport { - return ProtocolSupport( - /* Client support */ - requestSerialization = true, - requestBodySerialization = true, - responseDeserialization = true, - errorDeserialization = true, - /* Server support */ - requestDeserialization = false, - requestBodyDeserialization = false, - responseSerialization = false, - errorSerialization = false, - ) - } -} - private val awsQueryHttpTrait = HttpTrait.builder() .code(200) .method("POST") diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Ec2Query.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt similarity index 71% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Ec2Query.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt index cd19cf2336e..3500dfcab2f 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/Ec2Query.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt @@ -3,13 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols +package software.amazon.smithy.rust.codegen.core.smithy.protocols import software.amazon.smithy.model.pattern.UriPattern import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.asType @@ -17,38 +16,11 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport -import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver -import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol -import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory -import software.amazon.smithy.rust.codegen.core.smithy.protocols.StaticHttpBindingResolver import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.Ec2QueryParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.Ec2QuerySerializerGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator -class Ec2QueryFactory : ProtocolGeneratorFactory { - override fun protocol(codegenContext: ClientCodegenContext): Protocol = Ec2QueryProtocol(codegenContext) - - override fun buildProtocolGenerator(codegenContext: ClientCodegenContext): HttpBoundProtocolGenerator = - HttpBoundProtocolGenerator(codegenContext, protocol(codegenContext)) - - override fun support(): ProtocolSupport { - return ProtocolSupport( - /* Client support */ - requestSerialization = true, - requestBodySerialization = true, - responseDeserialization = true, - errorDeserialization = true, - /* Server support */ - requestDeserialization = false, - requestBodyDeserialization = false, - responseSerialization = false, - errorSerialization = false, - ) - } -} - class Ec2QueryProtocol(private val codegenContext: CodegenContext) : Protocol { private val runtimeConfig = codegenContext.runtimeConfig private val ec2QueryErrors: RuntimeType = RuntimeType.ec2QueryErrors(runtimeConfig) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestJson.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt similarity index 80% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestJson.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt index 02f880d1b80..67edb3b7fa4 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestJson.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols +package software.amazon.smithy.rust.codegen.core.smithy.protocols import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.MemberShape @@ -14,19 +14,12 @@ import software.amazon.smithy.model.traits.JsonNameTrait import software.amazon.smithy.model.traits.MediaTypeTrait import software.amazon.smithy.model.traits.StreamingTrait import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport -import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver -import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpTraitHttpBindingResolver -import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol -import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolContentTypes -import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.JsonParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.JsonSerializerGenerator @@ -35,28 +28,6 @@ import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.outputShape -class RestJsonFactory : ProtocolGeneratorFactory { - override fun protocol(codegenContext: ClientCodegenContext): Protocol = RestJson(codegenContext) - - override fun buildProtocolGenerator(codegenContext: ClientCodegenContext): HttpBoundProtocolGenerator = - HttpBoundProtocolGenerator(codegenContext, RestJson(codegenContext)) - - override fun support(): ProtocolSupport { - return ProtocolSupport( - /* Client support */ - requestSerialization = true, - requestBodySerialization = true, - responseDeserialization = true, - errorDeserialization = true, - /* Server support */ - requestDeserialization = false, - requestBodyDeserialization = false, - responseSerialization = false, - errorSerialization = false, - ) - } -} - /** * This [HttpBindingResolver] implementation mostly delegates to the [HttpTraitHttpBindingResolver] class, since the * RestJson1 protocol can be almost entirely described by Smithy's HTTP binding traits diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestXml.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt similarity index 69% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestXml.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt index cb3a82674ae..b09092f4672 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/RestXml.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt @@ -3,12 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols +package software.amazon.smithy.rust.codegen.core.smithy.protocols import software.amazon.smithy.aws.traits.protocols.RestXmlTrait import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.traits.TimestampFormatTrait -import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.asType @@ -16,43 +15,12 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlockTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport -import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver -import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpTraitHttpBindingResolver -import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol -import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolContentTypes -import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.RestXmlParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.StructuredDataParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.XmlBindingTraitSerializerGenerator import software.amazon.smithy.rust.codegen.core.util.expectTrait -class RestXmlFactory( - private val generator: (ClientCodegenContext) -> Protocol = { RestXml(it) }, -) : ProtocolGeneratorFactory { - - override fun protocol(codegenContext: ClientCodegenContext): Protocol = generator(codegenContext) - - override fun buildProtocolGenerator(codegenContext: ClientCodegenContext): HttpBoundProtocolGenerator = - HttpBoundProtocolGenerator(codegenContext, protocol(codegenContext)) - - override fun support(): ProtocolSupport { - return ProtocolSupport( - /* Client support */ - requestSerialization = true, - requestBodySerialization = true, - responseDeserialization = true, - errorDeserialization = true, - /* Server support */ - requestDeserialization = false, - requestBodyDeserialization = false, - responseSerialization = false, - errorSerialization = false, - ) - } -} - open class RestXml(val codegenContext: CodegenContext) : Protocol { private val restXml = codegenContext.serviceShape.expectTrait() private val runtimeConfig = codegenContext.runtimeConfig diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt similarity index 99% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/Rust.kt rename to codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index 9340d0e27af..328eb4e1341 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.testutil +package software.amazon.smithy.rust.codegen.core.testutil import com.moandjiezana.toml.TomlWriter import org.intellij.lang.annotations.Language diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt new file mode 100644 index 00000000000..42d37b6679e --- /dev/null +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt @@ -0,0 +1,121 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rust.codegen.core.testutil + +import software.amazon.smithy.model.Model +import software.amazon.smithy.model.knowledge.NullableIndex +import software.amazon.smithy.model.shapes.ServiceShape +import software.amazon.smithy.model.shapes.ShapeId +import software.amazon.smithy.model.shapes.StructureShape +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute +import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency +import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo +import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope +import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolProvider +import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.asType +import software.amazon.smithy.rust.codegen.core.smithy.BaseSymbolMetadataProvider +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.CoreCodegenConfig +import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeCrateLocation +import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor +import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock +import software.amazon.smithy.rust.codegen.core.util.dq +import software.amazon.smithy.rust.codegen.core.util.letIf +import java.io.File + +val TestRuntimeConfig = + RuntimeConfig(runtimeCrateLocation = RuntimeCrateLocation.Path(File("../rust-runtime/").absolutePath)) +val TestSymbolVisitorConfig = SymbolVisitorConfig( + runtimeConfig = TestRuntimeConfig, + renameExceptions = true, + handleRustBoxing = true, + nullabilityCheckMode = NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1, +) + +fun testRustSettings( + service: ShapeId = ShapeId.from("notrelevant#notrelevant"), + moduleName: String = "test-module", + moduleVersion: String = "0.0.1", + moduleAuthors: List = listOf("notrelevant"), + moduleDescription: String = "not relevant", + moduleRepository: String? = null, + runtimeConfig: RuntimeConfig = TestRuntimeConfig, + codegenConfig: CoreCodegenConfig = CoreCodegenConfig(), + license: String? = null, + examplesUri: String? = null, +) = CoreRustSettings( + service, + moduleName, + moduleVersion, + moduleAuthors, + moduleDescription, + moduleRepository, + runtimeConfig, + codegenConfig, + license, + examplesUri, +) + +private const val SmithyVersion = "1.0" +fun String.asSmithyModel(sourceLocation: String? = null, smithyVersion: String = SmithyVersion): Model { + val processed = letIf(!this.startsWith("\$version")) { "\$version: ${smithyVersion.dq()}\n$it" } + return Model.assembler().discoverModels().addUnparsedModel(sourceLocation ?: "test.smithy", processed).assemble() + .unwrap() +} + +// Intentionally only visible to codegen-core since the other modules have their own symbol providers +internal fun testSymbolProvider(model: Model): RustSymbolProvider = SymbolVisitor( + model, + ServiceShape.builder().version("test").id("test#Service").build(), + TestSymbolVisitorConfig, +).let { BaseSymbolMetadataProvider(it, model, additionalAttributes = listOf(Attribute.NonExhaustive)) } + .let { RustReservedWordSymbolProvider(it, model) } + +// Intentionally only visible to codegen-core since the other modules have their own contexts +internal fun testCodegenContext( + model: Model, + serviceShape: ServiceShape? = null, + settings: CoreRustSettings = testRustSettings(), + codegenTarget: CodegenTarget = CodegenTarget.CLIENT, +): CodegenContext = CodegenContext( + model, + testSymbolProvider(model), + serviceShape + ?: model.serviceShapes.firstOrNull() + ?: ServiceShape.builder().version("test").id("test#Service").build(), + ShapeId.from("test#Protocol"), + settings, + codegenTarget, +) + +/** + * In tests, we frequently need to generate a struct, a builder, and an impl block to access said builder. + */ +fun StructureShape.renderWithModelBuilder(model: Model, symbolProvider: RustSymbolProvider, writer: RustWriter, forWhom: CodegenTarget = CodegenTarget.CLIENT) { + StructureGenerator(model, symbolProvider, writer, this).render(forWhom) + val modelBuilder = BuilderGenerator(model, symbolProvider, this) + modelBuilder.render(writer) + writer.implBlock(this, symbolProvider) { + modelBuilder.renderConvenienceMethod(this) + } +} + +val TokioWithTestMacros = CargoDependency( + "tokio", + CratesIo("1"), + features = setOf("macros", "test-util", "rt"), + scope = DependencyScope.Dev, +) + +val TokioTest = Attribute.Custom("tokio::test", listOf(TokioWithTestMacros.asType())) diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/InlineDependencyTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/InlineDependencyTest.kt similarity index 71% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/InlineDependencyTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/InlineDependencyTest.kt index 52103a35def..121578abd18 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/InlineDependencyTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/InlineDependencyTest.kt @@ -3,17 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.rustlang +package software.amazon.smithy.rust.codegen.core.rustlang import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.core.rustlang.InlineDependency -import software.amazon.smithy.rust.codegen.core.rustlang.RustModule -import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest internal class InlineDependencyTest { private fun makeDep(name: String) = InlineDependency(name, RustModule.private("module")) { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/RustGenericsTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustGenericsTest.kt similarity index 92% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/RustGenericsTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustGenericsTest.kt index 73fd5500e92..5b711dafa69 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/RustGenericsTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustGenericsTest.kt @@ -3,14 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.generators +package software.amazon.smithy.rust.codegen.core.rustlang import io.kotest.matchers.string.shouldContain import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.core.rustlang.GenericTypeArg -import software.amazon.smithy.rust.codegen.core.rustlang.RustGenerics -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.RuntimeType class RustGenericsTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustReservedWordSymbolProviderTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustReservedWordsTest.kt similarity index 92% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustReservedWordSymbolProviderTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustReservedWordsTest.kt index 36904eab7df..5f72e337653 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustReservedWordSymbolProviderTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustReservedWordsTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.rustlang +package software.amazon.smithy.rust.codegen.core.rustlang import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test @@ -11,11 +11,10 @@ import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.traits.EnumDefinition -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.MaybeRenamed import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.util.PANIC import software.amazon.smithy.rust.codegen.core.util.orNull import software.amazon.smithy.rust.codegen.core.util.toPascalCase diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustTypesTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustTypeTest.kt similarity index 92% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustTypesTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustTypeTest.kt index b9f36e3560f..0191ee5c940 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustTypesTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustTypeTest.kt @@ -3,16 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.rustlang +package software.amazon.smithy.rust.codegen.core.rustlang import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.core.rustlang.RustType -import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.render -import software.amazon.smithy.rust.codegen.core.rustlang.rustInlineTemplate internal class RustTypesTest { private fun forInputExpectOutput(t: Writable, expectedOutput: String) { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustWriterTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt similarity index 80% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustWriterTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt index a09066cc82a..e090bd385fb 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/RustWriterTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt @@ -3,35 +3,23 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.rustlang +package software.amazon.smithy.rust.codegen.core.rustlang import io.kotest.matchers.collections.shouldContain import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain import io.kotest.matchers.string.shouldContainOnlyOnce import org.junit.jupiter.api.Test -import software.amazon.smithy.codegen.core.SymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.SetShape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndRun -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.shouldCompile -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider -import software.amazon.smithy.rust.codegen.core.rustlang.Attribute -import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency -import software.amazon.smithy.rust.codegen.core.rustlang.RustType -import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.asType -import software.amazon.smithy.rust.codegen.core.rustlang.docs -import software.amazon.smithy.rust.codegen.core.rustlang.isEmpty -import software.amazon.smithy.rust.codegen.core.rustlang.rust -import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndRun +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.shouldCompile +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.util.lookup class RustWriterTest { @@ -61,7 +49,7 @@ class RustWriterTest { .assemble() .unwrap() - val provider: SymbolProvider = testSymbolProvider(model) + val provider = testSymbolProvider(model) val setSymbol = provider.toSymbol(set) val stringSymbol = provider.toSymbol(stringShape) sut.rustBlock("struct Test") { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/UseDeclarationsTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/UseDeclarationsTest.kt similarity index 86% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/UseDeclarationsTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/UseDeclarationsTest.kt index 0d88defcad3..c3f1abcddf8 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/UseDeclarationsTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/UseDeclarationsTest.kt @@ -3,12 +3,11 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.rustlang +package software.amazon.smithy.rust.codegen.core.rustlang import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.testutil.shouldCompile -import software.amazon.smithy.rust.codegen.core.rustlang.UseDeclarations +import software.amazon.smithy.rust.codegen.core.testutil.shouldCompile class UseDeclarationsTest { private fun useDecl() = UseDeclarations("test") diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/WritableTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/WritableTest.kt similarity index 84% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/WritableTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/WritableTest.kt index f770d5be611..67419a57284 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/rustlang/WritableTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/WritableTest.kt @@ -3,19 +3,10 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.rustlang +package software.amazon.smithy.rust.codegen.core.rustlang import io.kotest.matchers.string.shouldContain import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.core.rustlang.GenericTypeArg -import software.amazon.smithy.rust.codegen.core.rustlang.RustGenerics -import software.amazon.smithy.rust.codegen.core.rustlang.RustType -import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.join -import software.amazon.smithy.rust.codegen.core.rustlang.rustInlineTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate -import software.amazon.smithy.rust.codegen.core.rustlang.rustTypeParameters -import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType internal class RustTypeParametersTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenDelegatorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegatorTest.kt similarity index 92% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenDelegatorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegatorTest.kt index c2e47b6993a..5be3d0a898b 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenDelegatorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegatorTest.kt @@ -3,14 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy +package software.amazon.smithy.rust.codegen.core.smithy import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope.Compile -import software.amazon.smithy.rust.codegen.core.smithy.mergeDependencyFeatures class CodegenDelegatorTest { @Test diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RuntimeTypesTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeTypeTest.kt similarity index 93% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RuntimeTypesTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeTypeTest.kt index 074a2f83edf..1ae310088d9 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/RuntimeTypesTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeTypeTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy +package software.amazon.smithy.rust.codegen.core.smithy import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test @@ -14,11 +14,6 @@ import software.amazon.smithy.model.node.Node import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo import software.amazon.smithy.rust.codegen.core.rustlang.DependencyLocation import software.amazon.smithy.rust.codegen.core.rustlang.Local -import software.amazon.smithy.rust.codegen.core.smithy.CrateVersionMap -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig -import software.amazon.smithy.rust.codegen.core.smithy.RuntimeCrateLocation -import software.amazon.smithy.rust.codegen.core.smithy.crateLocation -import software.amazon.smithy.rust.codegen.core.smithy.defaultRuntimeCrateVersion import java.util.Optional class RuntimeTypesTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/BuilderGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGeneratorTest.kt similarity index 87% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/BuilderGeneratorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGeneratorTest.kt index a941f7218d1..fb10a12cc47 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/BuilderGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGeneratorTest.kt @@ -3,26 +3,22 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators +package software.amazon.smithy.rust.codegen.core.smithy.generators import org.junit.jupiter.api.Test import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.traits.EnumDefinition -import software.amazon.smithy.rust.codegen.client.generators.StructureGeneratorTest -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.smithy.Default import software.amazon.smithy.rust.codegen.core.smithy.MaybeRenamed import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig -import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator -import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator -import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock import software.amazon.smithy.rust.codegen.core.smithy.setDefault +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider internal class BuilderGeneratorTest { private val model = StructureGeneratorTest.model diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CargoTomlGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGeneratorTest.kt similarity index 84% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CargoTomlGeneratorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGeneratorTest.kt index c31aecfaf5e..a60f32c92e9 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CargoTomlGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGeneratorTest.kt @@ -3,15 +3,15 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators +package software.amazon.smithy.rust.codegen.core.smithy.generators import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.Version import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.CratesIo +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.unitTest class CargoTomlGeneratorTest { private val CargoMetadata: CargoDependency = CargoDependency("cargo_metadata", CratesIo("0.15.0")) diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/EnumGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGeneratorTest.kt similarity index 96% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/EnumGeneratorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGeneratorTest.kt index 031600f1aa2..90679f97735 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/EnumGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGeneratorTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.generators +package software.amazon.smithy.rust.codegen.core.smithy.generators import io.kotest.matchers.shouldBe import io.kotest.matchers.string.shouldContain @@ -11,13 +11,11 @@ import org.junit.jupiter.api.Nested import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.traits.EnumTrait -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.rust -import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator -import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumMemberModel +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.core.util.orNull diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/InstantiatorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/InstantiatorTest.kt similarity index 94% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/InstantiatorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/InstantiatorTest.kt index 6d47fff4cab..9bf232cc600 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/InstantiatorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/InstantiatorTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators +package software.amazon.smithy.rust.codegen.core.smithy.generators import org.junit.jupiter.api.Test import software.amazon.smithy.model.node.Node @@ -12,20 +12,18 @@ import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape -import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.raw import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget -import software.amazon.smithy.rust.codegen.core.smithy.generators.Instantiator -import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer +import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.lookup diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/StructureGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGeneratorTest.kt similarity index 96% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/StructureGeneratorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGeneratorTest.kt index 7f9b771a095..944c9a17382 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/StructureGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGeneratorTest.kt @@ -3,18 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.generators +package software.amazon.smithy.rust.codegen.core.smithy.generators import io.kotest.matchers.string.shouldContainInOrder import io.kotest.matchers.string.shouldNotContain import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter @@ -23,8 +18,12 @@ import software.amazon.smithy.rust.codegen.core.rustlang.docs import software.amazon.smithy.rust.codegen.core.rustlang.raw import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock -import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.lookup class StructureGeneratorTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/UnionGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGeneratorTest.kt similarity index 92% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/UnionGeneratorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGeneratorTest.kt index f770df48bc4..15a733b0d7b 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/UnionGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGeneratorTest.kt @@ -3,17 +3,16 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.generators +package software.amazon.smithy.rust.codegen.core.smithy.generators import io.kotest.matchers.string.shouldContain import org.junit.jupiter.api.Test import software.amazon.smithy.codegen.core.SymbolProvider -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.rust -import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.util.lookup class UnionGeneratorTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CombinedErrorGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGeneratorTest.kt similarity index 86% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CombinedErrorGeneratorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGeneratorTest.kt index 92f44feb442..24f0e85f9c3 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/CombinedErrorGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGeneratorTest.kt @@ -3,19 +3,18 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.generators +package software.amazon.smithy.rust.codegen.core.smithy.generators.error import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.RustModule -import software.amazon.smithy.rust.codegen.core.smithy.generators.error.CombinedErrorGenerator import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.lookup class CombinedErrorGeneratorTest { diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGeneratorTest.kt new file mode 100644 index 00000000000..d4b6d5efa9c --- /dev/null +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGeneratorTest.kt @@ -0,0 +1,108 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rust.codegen.core.smithy.generators.error + +import org.junit.jupiter.api.Test +import software.amazon.smithy.model.shapes.ServiceShape +import software.amazon.smithy.model.shapes.ShapeId +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings +import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules +import software.amazon.smithy.rust.codegen.core.smithy.RustCrate +import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.util.runCommand +import kotlin.io.path.ExperimentalPathApi +import kotlin.io.path.createDirectory +import kotlin.io.path.writeText + +internal class TopLevelErrorGeneratorTest { + @ExperimentalPathApi + @Test + fun `top level errors are send + sync`() { + val model = """ + namespace com.example + + use aws.protocols#restJson1 + + @restJson1 + service HelloService { + operations: [SayHello], + version: "1" + } + + @http(uri: "/", method: "POST") + operation SayHello { + input: EmptyStruct, + output: EmptyStruct, + errors: [SorryBusy, CanYouRepeatThat, MeDeprecated] + } + + structure EmptyStruct { } + + @error("server") + structure SorryBusy { } + + @error("client") + structure CanYouRepeatThat { } + + @error("client") + @deprecated + structure MeDeprecated { } + """.asSmithyModel() + + val (pluginContext, testDir) = generatePluginContext(model) + val moduleName = pluginContext.settings.expectStringMember("module").value.replace('-', '_') + val symbolProvider = testSymbolProvider(model) + val settings = CoreRustSettings.from(model, pluginContext.settings) + val codegenContext = CodegenContext( + model, + symbolProvider, + model.expectShape(ShapeId.from("com.example#HelloService")) as ServiceShape, + ShapeId.from("aws.protocols#restJson1"), + settings, + CodegenTarget.CLIENT, + ) + + val rustCrate = RustCrate( + pluginContext.fileManifest, + symbolProvider, + DefaultPublicModules, + codegenContext.settings.codegenConfig, + ) + + rustCrate.lib { writer -> + writer.rust("##![allow(deprecated)]") + } + rustCrate.withModule(RustModule.Error) { writer -> + for (shape in model.structureShapes) { + if (shape.id.namespace == "com.example") { + StructureGenerator(model, symbolProvider, writer, shape).render(CodegenTarget.CLIENT) + } + } + } + TopLevelErrorGenerator(codegenContext, model.operationShapes.toList()).render(rustCrate) + + testDir.resolve("tests").createDirectory() + testDir.resolve("tests/validate_errors.rs").writeText( + """ + fn check_send_sync() {} + #[test] + fn tl_errors_are_send_sync() { + check_send_sync::<$moduleName::Error>() + } + """, + ) + rustCrate.finalize(settings, model, emptyMap(), emptyList(), false) + + "cargo test".runCommand(testDir) + } +} diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/http/RequestBindingGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt similarity index 93% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/http/RequestBindingGeneratorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt index e2bbad162b4..b1eeab627b8 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/http/RequestBindingGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.generators.http +package software.amazon.smithy.rust.codegen.core.smithy.generators.http import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test @@ -11,24 +11,22 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.HttpTrait -import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestJson -import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder -import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.core.smithy.generators.http.RequestBindingGenerator -import software.amazon.smithy.rust.codegen.core.smithy.generators.http.uriFormatString import software.amazon.smithy.rust.codegen.core.smithy.generators.operationBuildError +import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestJson import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder +import software.amazon.smithy.rust.codegen.core.testutil.testCodegenContext +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.expectTrait diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/http/ResponseBindingGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/ResponseBindingGeneratorTest.kt similarity index 85% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/http/ResponseBindingGeneratorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/ResponseBindingGeneratorTest.kt index dd7af8de691..5a56ec35460 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/generators/http/ResponseBindingGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/ResponseBindingGeneratorTest.kt @@ -3,29 +3,28 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.generators.http +package software.amazon.smithy.rust.codegen.core.smithy.generators.http import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestJson -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder -import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext -import software.amazon.smithy.rust.codegen.core.smithy.generators.http.ResponseBindingGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpLocation import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpTraitHttpBindingResolver import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolContentTypes +import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestJson import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder +import software.amazon.smithy.rust.codegen.core.testutil.testCodegenContext +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.outputShape class ResponseBindingGeneratorTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/InlineFunctionNamerTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/InlineFunctionNamerTest.kt similarity index 89% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/InlineFunctionNamerTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/InlineFunctionNamerTest.kt index 623b4d1ac42..a988872b8bb 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/InlineFunctionNamerTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/InlineFunctionNamerTest.kt @@ -3,15 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols +package software.amazon.smithy.rust.codegen.core.smithy.protocols import io.kotest.assertions.withClue import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider -import software.amazon.smithy.rust.codegen.core.smithy.protocols.deserializeFunctionName -import software.amazon.smithy.rust.codegen.core.smithy.protocols.serializeFunctionName +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.util.lookup class InlineFunctionNamerTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/AwsQueryParserGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/AwsQueryParserGeneratorTest.kt similarity index 78% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/AwsQueryParserGeneratorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/AwsQueryParserGeneratorTest.kt index 638e4bc59d4..a655ef9ffbf 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/AwsQueryParserGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/AwsQueryParserGeneratorTest.kt @@ -3,24 +3,23 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.parse +package software.amazon.smithy.rust.codegen.core.smithy.protocols.parse import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder -import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.AwsQueryParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer +import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder +import software.amazon.smithy.rust.codegen.core.testutil.testCodegenContext +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.core.util.outputShape diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/Ec2QueryParserGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/Ec2QueryParserGeneratorTest.kt similarity index 77% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/Ec2QueryParserGeneratorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/Ec2QueryParserGeneratorTest.kt index aac9f12ed77..a4a10592adb 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/Ec2QueryParserGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/Ec2QueryParserGeneratorTest.kt @@ -3,24 +3,23 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.parse +package software.amazon.smithy.rust.codegen.core.smithy.protocols.parse import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder -import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.Ec2QueryParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer +import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder +import software.amazon.smithy.rust.codegen.core.testutil.testCodegenContext +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.core.util.outputShape diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/JsonParserGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGeneratorTest.kt similarity index 90% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/JsonParserGeneratorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGeneratorTest.kt index ad94eb2105a..81804625b7a 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/JsonParserGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGeneratorTest.kt @@ -3,28 +3,27 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.parse +package software.amazon.smithy.rust.codegen.core.smithy.protocols.parse import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.smithy.protocols.restJsonFieldName -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder -import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpTraitHttpBindingResolver import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolContentTypes -import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.JsonParserGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.restJsonFieldName import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder +import software.amazon.smithy.rust.codegen.core.testutil.testCodegenContext +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.core.util.outputShape diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/XmlBindingTraitParserGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGeneratorTest.kt similarity index 90% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/XmlBindingTraitParserGeneratorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGeneratorTest.kt index b5dea3f9fe3..ae1fdfc02f7 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/parse/XmlBindingTraitParserGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGeneratorTest.kt @@ -3,27 +3,26 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.parse +package software.amazon.smithy.rust.codegen.core.smithy.protocols.parse import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder -import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.XmlBindingTraitParserGenerator import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer +import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder +import software.amazon.smithy.rust.codegen.core.testutil.testCodegenContext +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.core.util.outputShape diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/AwsQuerySerializerGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/AwsQuerySerializerGeneratorTest.kt similarity index 87% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/AwsQuerySerializerGeneratorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/AwsQuerySerializerGeneratorTest.kt index 400d4c6b80a..88a32316ee1 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/AwsQuerySerializerGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/AwsQuerySerializerGeneratorTest.kt @@ -3,27 +3,26 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize +package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.CsvSource import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder -import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.AwsQuerySerializerGenerator import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder +import software.amazon.smithy.rust.codegen.core.testutil.testCodegenContext +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.lookup diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/Ec2QuerySerializerGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/Ec2QuerySerializerGeneratorTest.kt similarity index 86% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/Ec2QuerySerializerGeneratorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/Ec2QuerySerializerGeneratorTest.kt index 512fcd9aa53..6ae6fea2074 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/Ec2QuerySerializerGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/Ec2QuerySerializerGeneratorTest.kt @@ -3,25 +3,24 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize +package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder -import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.Ec2QuerySerializerGenerator import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder +import software.amazon.smithy.rust.codegen.core.testutil.testCodegenContext +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.lookup diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/JsonSerializerGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGeneratorTest.kt similarity index 87% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/JsonSerializerGeneratorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGeneratorTest.kt index be3341700a5..d9f16ff56fb 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/JsonSerializerGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGeneratorTest.kt @@ -3,28 +3,27 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize +package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.smithy.protocols.restJsonFieldName -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder -import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpTraitHttpBindingResolver import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolContentTypes -import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.JsonSerializerGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.restJsonFieldName import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder +import software.amazon.smithy.rust.codegen.core.testutil.testCodegenContext +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.lookup diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/XmlBindingTraitSerializerGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGeneratorTest.kt similarity index 87% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/XmlBindingTraitSerializerGeneratorTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGeneratorTest.kt index e352da919a8..d4cdc7740f2 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/serialize/XmlBindingTraitSerializerGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGeneratorTest.kt @@ -3,27 +3,26 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.protocols.serialize +package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder -import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpTraitHttpBindingResolver import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolContentTypes -import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.XmlBindingTraitSerializerGenerator import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder +import software.amazon.smithy.rust.codegen.core.testutil.testCodegenContext +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.lookup diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/EventStreamNormalizerTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/EventStreamNormalizerTest.kt similarity index 89% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/EventStreamNormalizerTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/EventStreamNormalizerTest.kt index 90564e81a58..0398180b8d6 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/EventStreamNormalizerTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/EventStreamNormalizerTest.kt @@ -3,15 +3,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.transformers +package software.amazon.smithy.rust.codegen.core.smithy.transformers import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.UnionShape -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticEventStreamUnionTrait -import software.amazon.smithy.rust.codegen.core.smithy.transformers.EventStreamNormalizer +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/OperationNormalizerTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/OperationNormalizerTest.kt similarity index 93% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/OperationNormalizerTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/OperationNormalizerTest.kt index 0fde36acbcd..8e1d922820d 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/OperationNormalizerTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/OperationNormalizerTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.transformers +package software.amazon.smithy.rust.codegen.core.smithy.transformers import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe @@ -11,11 +11,10 @@ import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticInputTrait import software.amazon.smithy.rust.codegen.core.smithy.traits.SyntheticOutputTrait -import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.util.orNull internal class OperationNormalizerTest { diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapeBoxerTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/RecursiveShapeBoxerTest.kt similarity index 91% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapeBoxerTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/RecursiveShapeBoxerTest.kt index 2327b3fa0c1..061814a73a6 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapeBoxerTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/RecursiveShapeBoxerTest.kt @@ -3,14 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.transformers +package software.amazon.smithy.rust.codegen.core.smithy.transformers import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.MemberShape -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.smithy.traits.RustBoxTrait -import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.lookup diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapesIntegrationTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/RecursiveShapesIntegrationTest.kt similarity index 84% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapesIntegrationTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/RecursiveShapesIntegrationTest.kt index 67b73e77c3e..bea21fd0833 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/transformers/RecursiveShapesIntegrationTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/RecursiveShapesIntegrationTest.kt @@ -3,20 +3,19 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy.transformers +package software.amazon.smithy.rust.codegen.core.smithy.transformers import io.kotest.matchers.string.shouldContain import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator -import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.util.CommandFailed import software.amazon.smithy.rust.codegen.core.util.lookup diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/util/SyntheticsTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/util/SyntheticsTest.kt similarity index 89% rename from codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/util/SyntheticsTest.kt rename to codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/util/SyntheticsTest.kt index 1feaf49662c..270183d05e8 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/util/SyntheticsTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/util/SyntheticsTest.kt @@ -3,17 +3,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.util +package software.amazon.smithy.rust.codegen.core.util import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.core.util.cloneOperation -import software.amazon.smithy.rust.codegen.core.util.orNull -import software.amazon.smithy.rust.codegen.core.util.rename +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel class SyntheticsTest { @Test diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonCodegenServerPlugin.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonCodegenServerPlugin.kt index 3a235ec5be0..a2fa85b72cf 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonCodegenServerPlugin.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonCodegenServerPlugin.kt @@ -11,7 +11,6 @@ import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.rust.codegen.client.smithy.EventStreamSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodegenDecorator import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWordSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.BaseSymbolMetadataProvider @@ -19,6 +18,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitor import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.server.python.smithy.customizations.DECORATORS +import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.server.smithy.customizations.ServerRequiredCustomizations import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator import java.util.logging.Level diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt index a3a5159d16e..6f824ef1f84 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt @@ -14,7 +14,6 @@ import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules @@ -26,6 +25,7 @@ import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerEnumGenerator import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerServiceGenerator import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerStructureGenerator +import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenVisitor import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/customizations/PythonServerCodegenDecorator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/customizations/PythonServerCodegenDecorator.kt index 9718d88f043..db4f71b301f 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/customizations/PythonServerCodegenDecorator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/customizations/PythonServerCodegenDecorator.kt @@ -6,7 +6,6 @@ package software.amazon.smithy.rust.codegen.server.python.smithy.customizations import software.amazon.smithy.model.neighbor.Walker -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.docs @@ -21,6 +20,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.ManifestCustom import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerRuntimeType import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerModuleGenerator +import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.server.smithy.customizations.AddInternalServerErrorToAllOperationsDecorator import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt index 2e0901778f8..9b2ca49b2bc 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt @@ -10,7 +10,6 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ResourceShape import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.Shape -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.asType @@ -19,6 +18,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerCargoDependency +import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext class PythonServerModuleGenerator( codegenContext: ServerCodegenContext, diff --git a/codegen-server/python/src/test/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerSymbolProviderTest.kt b/codegen-server/python/src/test/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerSymbolProviderTest.kt index e2ca3e8d29a..96439ac7870 100644 --- a/codegen-server/python/src/test/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerSymbolProviderTest.kt +++ b/codegen-server/python/src/test/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerSymbolProviderTest.kt @@ -8,9 +8,9 @@ package software.amazon.smithy.rust.codegen.server.python.smithy.generators import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.rustlang.RustType import software.amazon.smithy.rust.codegen.core.smithy.rustType +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerSymbolVisitor import software.amazon.smithy.rust.codegen.server.smithy.testutil.ServerTestSymbolVisitorConfig diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/RustCodegenServerPlugin.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/RustCodegenServerPlugin.kt index 42c81072c76..ac63fd9eebd 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/RustCodegenServerPlugin.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/RustCodegenServerPlugin.kt @@ -11,7 +11,6 @@ import software.amazon.smithy.codegen.core.ReservedWordSymbolProvider import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.rust.codegen.client.smithy.EventStreamSymbolProvider -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.StreamingShapeMetadataProvider import software.amazon.smithy.rust.codegen.client.smithy.StreamingShapeSymbolProvider import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodegenDecorator diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ServerCodegenContext.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenContext.kt similarity index 95% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ServerCodegenContext.kt rename to codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenContext.kt index ffa48f68fde..0cc39ac6470 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ServerCodegenContext.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenContext.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy +package software.amazon.smithy.rust.codegen.server.smithy import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt index 9e1e60980ab..1735a81bfd8 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt @@ -17,8 +17,6 @@ import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.transform.ModelTransformer -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.ServerRustSettings import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ServerRustSettings.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRustSettings.kt similarity index 98% rename from codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ServerRustSettings.kt rename to codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRustSettings.kt index 69404e96183..d9a83896000 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/ServerRustSettings.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerRustSettings.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package software.amazon.smithy.rust.codegen.client.smithy +package software.amazon.smithy.rust.codegen.server.smithy import software.amazon.smithy.model.Model import software.amazon.smithy.model.node.ObjectNode diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecorator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecorator.kt index 2d8ff6ed548..3f5e5cdab04 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecorator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecorator.kt @@ -13,10 +13,10 @@ import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.ErrorTrait import software.amazon.smithy.model.traits.RequiredTrait import software.amazon.smithy.model.transform.ModelTransformer -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.transformers.allErrors +import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator /** diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt index 4cd48a05c49..a8063cf898c 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/ServerRequiredCustomizations.kt @@ -5,7 +5,6 @@ package software.amazon.smithy.rust.codegen.server.smithy.customizations -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customizations.AllowLintsGenerator import software.amazon.smithy.rust.codegen.client.smithy.customizations.CrateVersionGenerator import software.amazon.smithy.rust.codegen.client.smithy.customizations.SmithyTypesPubUseGenerator @@ -14,6 +13,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.Feature import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization +import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator /** diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt index a85b59c24f5..651a47ac93c 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt @@ -7,10 +7,6 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators.protocol import software.amazon.smithy.model.knowledge.TopDownIndex import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsJson -import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsJsonVersion -import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestJson -import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestXml import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -20,7 +16,11 @@ import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.generators.http.RestRequestSpecGenerator +import software.amazon.smithy.rust.codegen.core.smithy.protocols.AwsJson +import software.amazon.smithy.rust.codegen.core.smithy.protocols.AwsJsonVersion import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestJson +import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestXml import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency import software.amazon.smithy.rust.codegen.server.smithy.ServerRuntimeType diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt index 08ecdc97950..7530438afc4 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt @@ -23,7 +23,6 @@ import software.amazon.smithy.protocoltests.traits.HttpRequestTestCase import software.amazon.smithy.protocoltests.traits.HttpRequestTestsTrait import software.amazon.smithy.protocoltests.traits.HttpResponseTestCase import software.amazon.smithy.protocoltests.traits.HttpResponseTestsTrait -import software.amazon.smithy.rust.codegen.client.testutil.TokioTest import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata @@ -43,6 +42,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.generators.Instantiator import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.core.smithy.transformers.allErrors +import software.amazon.smithy.rust.codegen.core.testutil.TokioTest import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.hasStreamingMember diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerAwsJson.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerAwsJson.kt index 66587f6c9ba..e82cea742a6 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerAwsJson.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerAwsJson.kt @@ -6,22 +6,22 @@ package software.amazon.smithy.rust.codegen.server.smithy.protocols import software.amazon.smithy.model.traits.ErrorTrait -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsJsonVersion -import software.amazon.smithy.rust.codegen.client.smithy.protocols.awsJsonFieldName import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.escape import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport +import software.amazon.smithy.rust.codegen.core.smithy.protocols.AwsJsonVersion import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingResolver import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory +import software.amazon.smithy.rust.codegen.core.smithy.protocols.awsJsonFieldName import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.JsonCustomization import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.JsonSection import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.JsonSerializerGenerator import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.StructuredDataSerializerGenerator import software.amazon.smithy.rust.codegen.core.util.hasTrait +import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerAwsJsonProtocol import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt index 5df9709e48b..47449ae0a5b 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt @@ -24,7 +24,6 @@ import software.amazon.smithy.model.traits.HttpErrorTrait import software.amazon.smithy.model.traits.HttpPayloadTrait import software.amazon.smithy.model.traits.HttpTrait import software.amazon.smithy.model.traits.MediaTypeTrait -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule @@ -74,6 +73,7 @@ import software.amazon.smithy.rust.codegen.core.util.outputShape import software.amazon.smithy.rust.codegen.core.util.toPascalCase import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency +import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.server.smithy.ServerRuntimeType import software.amazon.smithy.rust.codegen.server.smithy.generators.http.ServerRequestBindingGenerator import software.amazon.smithy.rust.codegen.server.smithy.generators.http.ServerResponseBindingGenerator diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerProtocolLoader.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerProtocolLoader.kt index 4fb304b499b..e52d9e3a3bc 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerProtocolLoader.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerProtocolLoader.kt @@ -9,10 +9,10 @@ import software.amazon.smithy.aws.traits.protocols.AwsJson1_0Trait import software.amazon.smithy.aws.traits.protocols.AwsJson1_1Trait import software.amazon.smithy.aws.traits.protocols.RestJson1Trait import software.amazon.smithy.aws.traits.protocols.RestXmlTrait -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsJsonVersion +import software.amazon.smithy.rust.codegen.core.smithy.protocols.AwsJsonVersion import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolLoader import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolMap +import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator class ServerProtocolLoader(supportedProtocols: ProtocolMap) : diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestJsonFactory.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestJsonFactory.kt index 39f1e9947d8..ee7e609ccce 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestJsonFactory.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestJsonFactory.kt @@ -5,11 +5,11 @@ package software.amazon.smithy.rust.codegen.server.smithy.protocols -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestJson import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory +import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestJson +import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerRestJsonProtocol /** diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestXmlFactory.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestXmlFactory.kt index 96e6b06a0fd..5bc9cb705e6 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestXmlFactory.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestXmlFactory.kt @@ -5,11 +5,11 @@ package software.amazon.smithy.rust.codegen.server.smithy.protocols -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestXml import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory +import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestXml +import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerRestXmlProtocol /* diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt index 8972fd02969..5c648e6fe47 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt @@ -10,15 +10,15 @@ import software.amazon.smithy.model.knowledge.NullableIndex import software.amazon.smithy.model.node.ObjectNode import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenConfig -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.ServerRustSettings -import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig +import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig import software.amazon.smithy.rust.codegen.server.smithy.RustCodegenServerPlugin +import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenConfig +import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext +import software.amazon.smithy.rust.codegen.server.smithy.ServerRustSettings // These are the settings we default to if the user does not override them in their `smithy-build.json`. val ServerTestSymbolVisitorConfig = SymbolVisitorConfig( diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitorTest.kt index 3b496f1d286..bbb697d93ef 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitorTest.kt @@ -8,10 +8,9 @@ package software.amazon.smithy.rust.codegen.server.smithy import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodegenDecorator -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.generatePluginContext +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.server.smithy.customizations.ServerRequiredCustomizations import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator import kotlin.io.path.createDirectory diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecoratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecoratorTest.kt index 0727a2154a9..406a1dbfea7 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecoratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/customizations/AdditionalErrorsDecoratorTest.kt @@ -9,8 +9,8 @@ import io.kotest.matchers.shouldBe import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ServiceShape -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.util.lookup class AdditionalErrorsDecoratorTest { diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerCombinedErrorGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerCombinedErrorGeneratorTest.kt index 1406573d894..c96fabb5692 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerCombinedErrorGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerCombinedErrorGeneratorTest.kt @@ -7,15 +7,15 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.StructureShape -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.generators.error.ServerCombinedErrorGenerator import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverTestSymbolProvider diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerEnumGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerEnumGeneratorTest.kt index 85f4b2e3f3d..a07447a715f 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerEnumGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerEnumGeneratorTest.kt @@ -8,10 +8,10 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import io.kotest.matchers.string.shouldNotContain import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.StringShape -import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest import software.amazon.smithy.rust.codegen.core.util.expectTrait import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverTestSymbolProvider diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt index aba8b71da39..cfc0e0d35cc 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt @@ -8,14 +8,14 @@ package software.amazon.smithy.rust.codegen.server.smithy.generators import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import software.amazon.smithy.model.traits.HttpTrait -import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate +import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGeneratorTest.kt index 3f3de45222e..dd249d6e7c4 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationRegistryGeneratorTest.kt @@ -9,8 +9,8 @@ import io.kotest.matchers.string.shouldContain import org.junit.jupiter.api.Test import software.amazon.smithy.model.knowledge.TopDownIndex import software.amazon.smithy.model.shapes.ServiceShape -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerProtocolLoader diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/EventStreamTestTools.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/EventStreamTestTools.kt index 6a7227c658c..3e551f239ec 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/EventStreamTestTools.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/EventStreamTestTools.kt @@ -16,16 +16,6 @@ import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.ErrorTrait -import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsJson -import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsJsonVersion -import software.amazon.smithy.rust.codegen.client.smithy.protocols.AwsQueryProtocol -import software.amazon.smithy.rust.codegen.client.smithy.protocols.Ec2QueryProtocol -import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestJson -import software.amazon.smithy.rust.codegen.client.smithy.protocols.RestXml -import software.amazon.smithy.rust.codegen.client.testutil.TestWorkspace -import software.amazon.smithy.rust.codegen.client.testutil.TestWriterDelegator -import software.amazon.smithy.rust.codegen.client.testutil.asSmithyModel -import software.amazon.smithy.rust.codegen.client.testutil.renderWithModelBuilder import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter @@ -39,9 +29,19 @@ import software.amazon.smithy.rust.codegen.core.smithy.generators.error.Combined import software.amazon.smithy.rust.codegen.core.smithy.generators.error.ServerCombinedErrorGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.implBlock import software.amazon.smithy.rust.codegen.core.smithy.generators.renderUnknownVariant +import software.amazon.smithy.rust.codegen.core.smithy.protocols.AwsJson +import software.amazon.smithy.rust.codegen.core.smithy.protocols.AwsJsonVersion +import software.amazon.smithy.rust.codegen.core.smithy.protocols.AwsQueryProtocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.Ec2QueryProtocol import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol +import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestJson +import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestXml import software.amazon.smithy.rust.codegen.core.smithy.transformers.EventStreamNormalizer import software.amazon.smithy.rust.codegen.core.smithy.transformers.OperationNormalizer +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.TestWriterDelegator +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.lookup import software.amazon.smithy.rust.codegen.core.util.outputShape diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/parse/EventStreamUnmarshallerGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/parse/EventStreamUnmarshallerGeneratorTest.kt index bce3bfab2dd..419df695983 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/parse/EventStreamUnmarshallerGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/parse/EventStreamUnmarshallerGeneratorTest.kt @@ -8,14 +8,14 @@ package software.amazon.smithy.rust.codegen.server.smithy.protocols.parse import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ArgumentsSource import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.testRustSettings -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.protocols.parse.EventStreamUnmarshallerGenerator +import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.testRustSettings +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.server.smithy.protocols.EventStreamTestModels import software.amazon.smithy.rust.codegen.server.smithy.protocols.EventStreamTestTools diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt index 9fbbe47f504..15dc788d4dd 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt @@ -8,15 +8,15 @@ package software.amazon.smithy.rust.codegen.server.smithy.protocols.serialize import org.junit.jupiter.params.ParameterizedTest import org.junit.jupiter.params.provider.ArgumentsSource import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.testutil.TestRuntimeConfig -import software.amazon.smithy.rust.codegen.client.testutil.compileAndTest -import software.amazon.smithy.rust.codegen.client.testutil.testRustSettings -import software.amazon.smithy.rust.codegen.client.testutil.unitTest import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.DependencyScope import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize.EventStreamMarshallerGenerator +import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.testRustSettings +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.server.smithy.protocols.EventStreamTestModels import software.amazon.smithy.rust.codegen.server.smithy.protocols.EventStreamTestTools diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/customize/CombinedCodegenDecoratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/customize/CombinedCodegenDecoratorTest.kt index 8277de48af2..8287f2d2ce4 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/customize/CombinedCodegenDecoratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/smithy/customize/CombinedCodegenDecoratorTest.kt @@ -8,11 +8,11 @@ package software.amazon.smithy.rust.codegen.smithy.customize import io.kotest.matchers.collections.shouldContainExactly import org.junit.jupiter.api.Test import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext -import software.amazon.smithy.rust.codegen.client.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.client.smithy.customize.CombinedCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.customize.RequiredCustomizations import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.ClientProtocolGenerator +import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.server.smithy.customizations.ServerRequiredCustomizations import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolGenerator diff --git a/tools/ci-build/scripts/check-client-codegen-unit-tests b/tools/ci-build/scripts/check-client-codegen-unit-tests index baa7b76ebf4..b62678703ca 100755 --- a/tools/ci-build/scripts/check-client-codegen-unit-tests +++ b/tools/ci-build/scripts/check-client-codegen-unit-tests @@ -6,5 +6,4 @@ set -eux cd smithy-rs -./gradlew codegen-core:test ./gradlew codegen-client:test diff --git a/tools/ci-build/scripts/check-core-codegen-unit-tests b/tools/ci-build/scripts/check-core-codegen-unit-tests new file mode 100755 index 00000000000..2cb33ab127b --- /dev/null +++ b/tools/ci-build/scripts/check-core-codegen-unit-tests @@ -0,0 +1,9 @@ +#!/bin/bash +# +# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. +# SPDX-License-Identifier: Apache-2.0 +# + +set -eux +cd smithy-rs +./gradlew codegen-core:test From a11ea2a0083985d5bbf48fae5f139d8bf618af22 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Wed, 28 Sep 2022 13:08:08 -0700 Subject: [PATCH 07/57] Fix changelog entry (#1781) --- CHANGELOG.next.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 90fb4b69f77..e6e9fac7ec4 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -10,7 +10,7 @@ # references = ["smithy-rs#920"] # meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"} # author = "rcoh" -[[rust-runtime]] +[[smithy-rs]] message = "Pokémon Service example code now runs clippy during build." references = ["smithy-rs#1727"] meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "server" } From 4cfac14d49f8cdbacd0158c5e1d279bb62f41e53 Mon Sep 17 00:00:00 2001 From: kastolars <31855040+kastolars@users.noreply.github.com> Date: Thu, 29 Sep 2022 11:43:07 -0500 Subject: [PATCH 08/57] Getters added to ConfigImpl (#1761) --- CHANGELOG.next.toml | 6 ++ .../smithy/rustsdk/AwsEndpointDecorator.kt | 62 ++++++++++--------- .../smithy/rustsdk/CredentialProviders.kt | 50 ++++++++------- .../amazon/smithy/rustsdk/RegionDecorator.kt | 40 +++++++----- .../IdempotencyTokenProviderCustomization.kt | 14 ++++- .../testutil/TestConfigCustomization.kt | 9 ++- .../config/ServiceConfigGeneratorTest.kt | 10 ++- .../inlineable/src/idempotency_token.rs | 9 +++ 8 files changed, 127 insertions(+), 73 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index e6e9fac7ec4..4129e447106 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -93,3 +93,9 @@ message = "Paginators now stop on encountering a duplicate token by default rath references = ["aws-sdk-rust#620", "smithy-rs#1748"] meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "client"} author = "jdisanti" + +[[aws-sdk-rust]] +message = "The client Config now has getters for every value that it holds." +references = ["smithy-rs#1747"] +meta = { "breaking" = false, "tada" = false, "bug" = true } +author = "kastolars" diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt index af3ae09c6a3..4c69d140dbe 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt @@ -109,24 +109,28 @@ class EndpointConfigCustomization( "aws_types" to awsTypes(runtimeConfig).asType(), ) - override fun section(section: ServiceConfig): Writable = - writable { - when (section) { - is ServiceConfig.ConfigStruct -> rustTemplate( - "pub (crate) endpoint_resolver: std::sync::Arc>,", - *codegenScope, - ) - - is ServiceConfig.ConfigImpl -> emptySection - is ServiceConfig.BuilderStruct -> - rustTemplate( - "endpoint_resolver: Option>>,", - *codegenScope, - ) - - ServiceConfig.BuilderImpl -> - rustTemplate( - """ + override fun section(section: ServiceConfig): Writable = writable { + when (section) { + is ServiceConfig.ConfigStruct -> rustTemplate( + "pub (crate) endpoint_resolver: std::sync::Arc>,", + *codegenScope, + ) + is ServiceConfig.ConfigImpl -> emptySection +// TODO(https://github.com/awslabs/smithy-rs/issues/1780): Uncomment once endpoints 2.0 project is completed +// rustTemplate( +// """ +// /// Returns the endpoint resolver. +// pub fn endpoint_resolver(&self) -> std::sync::Arc> { +// self.endpoint_resolver.clone() +// } +// """, +// *codegenScope, +// ) + is ServiceConfig.BuilderStruct -> + rustTemplate("endpoint_resolver: Option>>,", *codegenScope) + ServiceConfig.BuilderImpl -> + rustTemplate( + """ /// Overrides the endpoint resolver to use when making requests. /// /// When unset, the client will used a generated endpoint resolver based on the endpoint metadata @@ -154,24 +158,24 @@ class EndpointConfigCustomization( self } """, - *codegenScope, - ) + *codegenScope, + ) - ServiceConfig.BuilderBuild -> { - val resolverGenerator = EndpointResolverGenerator(codegenContext, endpointData) - rustTemplate( - """ + ServiceConfig.BuilderBuild -> { + val resolverGenerator = EndpointResolverGenerator(codegenContext, endpointData) + rustTemplate( + """ endpoint_resolver: self.endpoint_resolver.unwrap_or_else(|| std::sync::Arc::new(#{EndpointShim}::from_resolver(#{Resolver}())) ), """, - *codegenScope, "Resolver" to resolverGenerator.resolver(), - ) - } - - else -> emptySection + *codegenScope, "Resolver" to resolverGenerator.resolver(), + ) } + + else -> emptySection } + } } // This is an experiment in a slightly different way to create runtime types. All code MAY be refactored to use this pattern diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt index 47e74d3ad0f..304195588ce 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CredentialProviders.kt @@ -64,24 +64,26 @@ class CredentialProviderConfig(runtimeConfig: RuntimeConfig) : ConfigCustomizati "DefaultProvider" to defaultProvider, ) - override fun section(section: ServiceConfig) = - writable { - when (section) { - is ServiceConfig.ConfigStruct -> rustTemplate( - """pub(crate) credentials_provider: #{credentials}::SharedCredentialsProvider,""", - *codegenScope, - ) - - is ServiceConfig.ConfigImpl -> emptySection - is ServiceConfig.BuilderStruct -> - rustTemplate( - "credentials_provider: Option<#{credentials}::SharedCredentialsProvider>,", - *codegenScope, - ) - - ServiceConfig.BuilderImpl -> { - rustTemplate( - """ + override fun section(section: ServiceConfig) = writable { + when (section) { + is ServiceConfig.ConfigStruct -> rustTemplate( + """pub(crate) credentials_provider: #{credentials}::SharedCredentialsProvider,""", + *codegenScope, + ) + is ServiceConfig.ConfigImpl -> rustTemplate( + """ + /// Returns the credentials provider. + pub fn credentials_provider(&self) -> #{credentials}::SharedCredentialsProvider { + self.credentials_provider.clone() + } + """, + *codegenScope, + ) + is ServiceConfig.BuilderStruct -> + rustTemplate("credentials_provider: Option<#{credentials}::SharedCredentialsProvider>,", *codegenScope) + ServiceConfig.BuilderImpl -> { + rustTemplate( + """ /// Sets the credentials provider for this service pub fn credentials_provider(mut self, credentials_provider: impl #{credentials}::ProvideCredentials + 'static) -> Self { self.credentials_provider = Some(#{credentials}::SharedCredentialsProvider::new(credentials_provider)); @@ -94,16 +96,16 @@ class CredentialProviderConfig(runtimeConfig: RuntimeConfig) : ConfigCustomizati self } """, - *codegenScope, - ) - } - - ServiceConfig.BuilderBuild -> rustTemplate( - "credentials_provider: self.credentials_provider.unwrap_or_else(|| #{credentials}::SharedCredentialsProvider::new(#{DefaultProvider})),", *codegenScope, ) } + + ServiceConfig.BuilderBuild -> rustTemplate( + "credentials_provider: self.credentials_provider.unwrap_or_else(|| #{credentials}::SharedCredentialsProvider::new(#{DefaultProvider})),", + *codegenScope, + ) } + } } class CredentialsProviderFeature(private val runtimeConfig: RuntimeConfig) : OperationCustomization() { diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt index 3a6aaf40a66..d57d379f2cf 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/RegionDecorator.kt @@ -105,17 +105,23 @@ class RegionProviderConfig(codegenContext: CodegenContext) : ConfigCustomization private val region = region(codegenContext.runtimeConfig) private val moduleUseName = codegenContext.moduleUseName() private val codegenScope = arrayOf("Region" to region.member("Region")) - override fun section(section: ServiceConfig) = - writable { - when (section) { - is ServiceConfig.ConfigStruct -> rustTemplate("pub(crate) region: Option<#{Region}>,", *codegenScope) - is ServiceConfig.ConfigImpl -> emptySection - is ServiceConfig.BuilderStruct -> - rustTemplate("region: Option<#{Region}>,", *codegenScope) - - ServiceConfig.BuilderImpl -> - rustTemplate( - """ + override fun section(section: ServiceConfig) = writable { + when (section) { + is ServiceConfig.ConfigStruct -> rustTemplate("pub(crate) region: Option<#{Region}>,", *codegenScope) + is ServiceConfig.ConfigImpl -> rustTemplate( + """ + /// Returns the AWS region, if it was provided. + pub fn region(&self) -> Option<&#{Region}> { + self.region.as_ref() + } + """, + *codegenScope, + ) + is ServiceConfig.BuilderStruct -> + rustTemplate("region: Option<#{Region}>,", *codegenScope) + ServiceConfig.BuilderImpl -> + rustTemplate( + """ /// Sets the AWS region to use when making requests. /// /// ## Examples @@ -132,15 +138,15 @@ class RegionProviderConfig(codegenContext: CodegenContext) : ConfigCustomization self } """, - *codegenScope, - ) - - ServiceConfig.BuilderBuild -> rustTemplate( - """region: self.region,""", *codegenScope, ) - } + + ServiceConfig.BuilderBuild -> rustTemplate( + """region: self.region,""", + *codegenScope, + ) } + } } class RegionConfigPlugin : OperationCustomization() { diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/IdempotencyTokenProviderCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/IdempotencyTokenProviderCustomization.kt index 59c983bdd42..320c1ee0114 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/IdempotencyTokenProviderCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/IdempotencyTokenProviderCustomization.kt @@ -20,7 +20,19 @@ class IdempotencyTokenProviderCustomization : NamedSectionGenerator writable { rust("pub (crate) make_token: #T::IdempotencyTokenProvider,", RuntimeType.IdempotencyToken) } - ServiceConfig.ConfigImpl -> emptySection + ServiceConfig.ConfigImpl -> writable { + rust( + """ + /// Returns a copy of the idempotency token provider. + /// If a random token provider was configured, + /// a newly-randomized token provider will be returned. + pub fn make_token(&self) -> #T::IdempotencyTokenProvider { + self.make_token.clone() + } + """, + RuntimeType.IdempotencyToken, + ) + } ServiceConfig.BuilderStruct -> writable { rust("make_token: Option<#T::IdempotencyTokenProvider>,", RuntimeType.IdempotencyToken) } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestConfigCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestConfigCustomization.kt index 7dd4d4ca358..3a239facab4 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestConfigCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestConfigCustomization.kt @@ -26,7 +26,14 @@ fun stubConfigCustomization(name: String): ConfigCustomization { override fun section(section: ServiceConfig): Writable = writable { when (section) { ServiceConfig.ConfigStruct -> rust("_$name: u64,") - ServiceConfig.ConfigImpl -> emptySection + ServiceConfig.ConfigImpl -> rust( + """ + ##[allow(missing_docs)] + pub fn $name(&self) -> u64 { + self._$name + } + """, + ) ServiceConfig.BuilderStruct -> rust("_$name: Option,") ServiceConfig.BuilderImpl -> rust( """ diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGeneratorTest.kt index 2d09a2dc2a8..b2002a953ac 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGeneratorTest.kt @@ -83,7 +83,15 @@ internal class ServiceConfigGeneratorTest { return when (section) { ServiceConfig.ConfigStructAdditionalDocs -> emptySection ServiceConfig.ConfigStruct -> writable { rust("config_field: u64,") } - ServiceConfig.ConfigImpl -> emptySection + ServiceConfig.ConfigImpl -> writable { + rust( + """ + pub fn config_field(&self) -> u64 { + self.config_field + } + """, + ) + } ServiceConfig.BuilderStruct -> writable { rust("config_field: Option") } ServiceConfig.BuilderImpl -> emptySection ServiceConfig.BuilderBuild -> writable { rust("config_field: self.config_field.unwrap_or_default(),") } diff --git a/rust-runtime/inlineable/src/idempotency_token.rs b/rust-runtime/inlineable/src/idempotency_token.rs index b62fb903270..9d55f46db52 100644 --- a/rust-runtime/inlineable/src/idempotency_token.rs +++ b/rust-runtime/inlineable/src/idempotency_token.rs @@ -85,3 +85,12 @@ impl IdempotencyTokenProvider { } } } + +impl Clone for IdempotencyTokenProvider { + fn clone(&self) -> Self { + match &self.inner { + Inner::Static(token) => IdempotencyTokenProvider::fixed(token), + Inner::Random(_) => IdempotencyTokenProvider::random(), + } + } +} From 4c5cbc39384f0d949d7693eb87b5853fe72629cd Mon Sep 17 00:00:00 2001 From: Luca Palmieri Date: Fri, 30 Sep 2022 12:30:47 +0100 Subject: [PATCH 09/57] Fix a few rendering issues in the design docs (#1787) * Fix backtick fences to render code block * Render list as a list instead of a code block. * Indent further to get nested code block. * Remove `ignore` descriptors. --- design/src/smithy/aggregate_shapes.md | 24 ++++++++++++------------ design/src/smithy/recursive_shapes.md | 2 +- design/src/transport/operation.md | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/design/src/smithy/aggregate_shapes.md b/design/src/smithy/aggregate_shapes.md index e411277bf50..0f63a2e5ea1 100644 --- a/design/src/smithy/aggregate_shapes.md +++ b/design/src/smithy/aggregate_shapes.md @@ -28,10 +28,10 @@ Smithy `structure` becomes a `struct` in Rust. Backwards compatibility & usabili 2. All structs are marked `#[non_exhaustive]` 3. All structs derive `Debug` & `PartialEq`. Structs **do not** derive `Eq` because a `float` member may be added in the future. 4. Struct fields are public. Public struct fields allow for [split borrows](https://doc.rust-lang.org/nomicon/borrow-splitting.html). When working with output objects this significantly improves ergonomics, especially with optional fields. - ```rust,ignore - let out = dynamo::ListTablesOutput::new(); - out.some_field.unwrap(); // <- partial move, impossible with an accessor - ``` + ```rust + let out = dynamo::ListTablesOutput::new(); + out.some_field.unwrap(); // <- partial move, impossible with an accessor + ``` 5. Builders are generated for structs that provide ergonomic and backwards compatible constructors. A builder for a struct is always available via the convenience method `SomeStruct::builder()` 6. Structures manually implement debug: In order to support the [sensitive trait](https://awslabs.github.io/smithy/1.0/spec/core/documentation-traits.html#sensitive-trait), a `Debug` implementation for structures is manually generated. @@ -52,7 +52,7 @@ long ReadIOs long WriteIOs ``` **Rust Output**: -```rust,ignore +```rust ///

Contains I/O usage metrics for a command that was invoked.

#[non_exhaustive] #[derive(std::clone::Clone, std::cmp::PartialEq)] @@ -118,12 +118,12 @@ impl IOUsage { ## Union Smithy `Union` is modeled as `enum` in Rust. - 1. Generated `enum`s must be marked `#[non_exhaustive]`. - 2. Generated `enum`s must provide an `Unknown` variant. If parsing receives an unknown input that doesn't match any of the given union variants, `Unknown` should be constructed. [Tracking Issue](https://github.com/awslabs/smithy-rs/issues/185). - 1. Union members (enum variants) are **not** nullable, because Smithy union members cannot contain null values. - 2. When union members contain references to other shapes, we generate a wrapping variant (see below). - 3. Union members do not require `#[non_exhaustive]`, because changing the shape targeted by a union member is not backwards compatible. - 4. `is_variant` and `as_variant` helper functions are generated to improve ergonomics. +1. Generated `enum`s must be marked `#[non_exhaustive]`. +2. Generated `enum`s must provide an `Unknown` variant. If parsing receives an unknown input that doesn't match any of the given union variants, `Unknown` should be constructed. [Tracking Issue](https://github.com/awslabs/smithy-rs/issues/185). +3. Union members (enum variants) are **not** nullable, because Smithy union members cannot contain null values. +4. When union members contain references to other shapes, we generate a wrapping variant (see below). +5. Union members do not require `#[non_exhaustive]`, because changing the shape targeted by a union member is not backwards compatible. +6. `is_variant` and `as_variant` helper functions are generated to improve ergonomics. ### Generated Union Example The union generated for a simplified `dynamodb::AttributeValue` @@ -149,7 +149,7 @@ list BoolList { } ``` **Rust**: -```rust,ignore +```rust #[non_exhaustive] #[derive(std::clone::Clone, std::cmp::PartialEq, std::fmt::Debug)] pub enum AttributeValue { diff --git a/design/src/smithy/recursive_shapes.md b/design/src/smithy/recursive_shapes.md index 61f4ec7b53e..1697fb0ddbe 100644 --- a/design/src/smithy/recursive_shapes.md +++ b/design/src/smithy/recursive_shapes.md @@ -13,7 +13,7 @@ struct IntermediateStructure { } ``` -```rust,ignore +```text | 3 | struct TopStructure { | ^^^^^^^^^^^^^^^^^^^ recursive type has infinite size diff --git a/design/src/transport/operation.md b/design/src/transport/operation.md index 9ca8a4dfc95..332e6076577 100644 --- a/design/src/transport/operation.md +++ b/design/src/transport/operation.md @@ -16,7 +16,7 @@ This section details the flow of a request through the SDK until a response is r A customer interacts with the SDK builders to construct an input. The `build()` method on an input returns an `Operation`. This codifies the base HTTP request & all the configuration and middleware layers required to modify and dispatch the request. -```rust,ignore +```rust pub struct Operation { request: Request, response_handler: H, @@ -37,7 +37,7 @@ By using a property bag, we can define the `Operation` in Smithy core. AWS speci In order to construct an operation, the generated code injects appropriate middleware & configuration via the configuration property bag. It does this by reading the configuration properties out of the service config, copying them as necessary, and loading them into the `Request`: -```rust,ignore +```rust // This is approximately the generated code, I've cleaned a few things up for readability. pub fn build(self, config: &dynamodb::config::Config) -> Operation { let op = BatchExecuteStatement::new(BatchExecuteStatementInput { From 368e13f23d88cb801b6e48c308070df21adef0df Mon Sep 17 00:00:00 2001 From: Luca Palmieri Date: Fri, 30 Sep 2022 13:44:13 +0100 Subject: [PATCH 10/57] Amend the example of generated code in the design docs to match current behaviour (#1789) * Amend the example of generated code in the design docs to match current behaviour. * A few more capitalization issues. --- design/src/smithy/aggregate_shapes.md | 30 ++++++++++++++------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/design/src/smithy/aggregate_shapes.md b/design/src/smithy/aggregate_shapes.md index 0f63a2e5ea1..627ea875b36 100644 --- a/design/src/smithy/aggregate_shapes.md +++ b/design/src/smithy/aggregate_shapes.md @@ -56,23 +56,23 @@ long WriteIOs ///

Contains I/O usage metrics for a command that was invoked.

#[non_exhaustive] #[derive(std::clone::Clone, std::cmp::PartialEq)] -pub struct IOUsage { +pub struct IoUsage { ///

The number of read I/O requests that the command made.

pub read_i_os: i64, ///

The number of write I/O requests that the command made.

pub write_i_os: i64, } -impl std::fmt::Debug for IOUsage { +impl std::fmt::Debug for IoUsage { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - let mut formatter = f.debug_struct("IOUsage"); + let mut formatter = f.debug_struct("IoUsage"); formatter.field("read_i_os", &self.read_i_os); formatter.field("write_i_os", &self.write_i_os); formatter.finish() } } -/// See [`IOUsage`](crate::model::IOUsage) +/// See [`IoUsage`](crate::model::IoUsage) pub mod io_usage { - /// A builder for [`IOUsage`](crate::model::IOUsage) + /// A builder for [`IoUsage`](crate::model::IoUsage) #[non_exhaustive] #[derive(Debug, Clone, Default)] pub struct Builder { @@ -85,8 +85,9 @@ pub mod io_usage { self.read_i_os = Some(inp); self } - pub fn set_read_i_os(mut self, inp: i64) -> Self { - self.read_i_os = Some(inp); + ///

The number of read I/O requests that the command made.

+ pub fn set_read_i_os(mut self, inp: Option) -> Self { + self.read_i_os = inp; self } ///

The number of write I/O requests that the command made.

@@ -94,21 +95,22 @@ pub mod io_usage { self.write_i_os = Some(inp); self } - pub fn set_write_i_os(mut self, inp: i64) -> Self { - self.write_i_os = Some(inp); + ///

The number of write I/O requests that the command made.

+ pub fn set_write_i_os(mut self, inp: Option) -> Self { + self.write_i_os = inp; self } - /// Consumes the builder and constructs a [`IOUsage`](crate::model::IOUsage) - pub fn build(self) -> crate::model::IOUsage { - crate::model::IOUsage { + /// Consumes the builder and constructs a [`IoUsage`](crate::model::IoUsage) + pub fn build(self) -> crate::model::IoUsage { + crate::model::IoUsage { read_i_os: self.read_i_os.unwrap_or_default(), write_i_os: self.write_i_os.unwrap_or_default(), } } } } -impl IOUsage { - /// Creates a new builder-style object to manufacture [`IOUsage`](crate::model::IOUsage) +impl IoUsage { + /// Creates a new builder-style object to manufacture [`IoUsage`](crate::model::IoUsage) pub fn builder() -> crate::model::io_usage::Builder { crate::model::io_usage::Builder::default() } From aea63544e1160543d7692e17f88da63930195bb8 Mon Sep 17 00:00:00 2001 From: Luca Palmieri Date: Fri, 30 Sep 2022 16:50:42 +0100 Subject: [PATCH 11/57] Update MSRV policy state in the README (#1790) * Update MSRV policy state in the README * Beautify --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5f6146743ce..0cf99e8d25f 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Setup 1. `./gradlew` will setup gradle for you. JDK 17 is required. 2. Running tests requires a working Rust installation. See [Rust docs](https://www.rust-lang.org/learn/get-started) for -installation instructions on your platform. Minimum supported Rust version is the latest released Rust version, although older versions may work. +installation instructions on your platform. The MSRV (**M**inimum **S**upported **R**ust **V**ersion) for the crates in this project is `stable-2`, i.e. the current `stable` Rust version and the prior two versions. Older versions may work. Development ----------- From 89a6e5894aebb81efa1305c41188d7ded3b3c43b Mon Sep 17 00:00:00 2001 From: Matteo Bigoi <1781140+crisidev@users.noreply.github.com> Date: Fri, 30 Sep 2022 18:40:31 +0100 Subject: [PATCH 12/57] Add LukeMathWalker and jjant to the contributor list (#1791) --- tools/changelogger/smithy-rs-maintainers.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/changelogger/smithy-rs-maintainers.txt b/tools/changelogger/smithy-rs-maintainers.txt index 8af0f8655e4..2aa2e7b5a9b 100644 --- a/tools/changelogger/smithy-rs-maintainers.txt +++ b/tools/changelogger/smithy-rs-maintainers.txt @@ -5,6 +5,8 @@ david-perez drganjoo hlbarber jdisanti +jjant +LukeMathWalker rcoh unexge velfi From 7fb7e177d02ee15ba5e4ab69021ac1236a974858 Mon Sep 17 00:00:00 2001 From: Burak Date: Mon, 3 Oct 2022 15:03:17 +0100 Subject: [PATCH 13/57] Simplify Python Pokemon service (#1773) * Simplify Python Pokemon service * Use `threading.Lock` instead of `multiprocessing.Lock` Co-authored-by: Matteo Bigoi <1781140+crisidev@users.noreply.github.com> * Explain why we need to pass `force=True` * Add comment about synchronization of `Context` class Co-authored-by: Matteo Bigoi <1781140+crisidev@users.noreply.github.com> --- .../examples/pokemon_service.py | 34 +++++++++++-------- .../src/server.rs | 8 ++++- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/rust-runtime/aws-smithy-http-server-python/examples/pokemon_service.py b/rust-runtime/aws-smithy-http-server-python/examples/pokemon_service.py index 288c1bf0f21..9264b31dcb9 100644 --- a/rust-runtime/aws-smithy-http-server-python/examples/pokemon_service.py +++ b/rust-runtime/aws-smithy-http-server-python/examples/pokemon_service.py @@ -6,7 +6,7 @@ import itertools import logging import random -import threading +from threading import Lock from dataclasses import dataclass from typing import List, Optional @@ -30,22 +30,18 @@ # fast logging handler, Tracingandler based on Rust tracing crate. logging.basicConfig(handlers=[TracingHandler(level=logging.DEBUG).handler()]) - -# A slightly more atomic counter using a threading lock. -class FastWriteCounter: +class SafeCounter: def __init__(self): - self._number_of_read = 0 - self._counter = itertools.count() - self._read_lock = threading.Lock() + self._val = 0 + self._lock = Lock() def increment(self): - next(self._counter) + with self._lock: + self._val += 1 def value(self): - with self._read_lock: - value = next(self._counter) - self._number_of_read - self._number_of_read += 1 - return value + with self._lock: + return self._val ########################################################### @@ -65,7 +61,12 @@ def value(self): # * def operation(input: OperationInput, state: State) -> OperationOutput # * async def operation(input: OperationInput, state: State) -> OperationOutput # -# NOTE: protection of the data inside the context class is up to the developer +# Synchronization: +# Instance of `Context` class will be cloned for every worker and all state kept in `Context` +# will be specific to that process. There is no protection provided by default, +# it is up to you to have synchronization between processes. +# If you really want to share state between different processes you need to use `multiprocessing` primitives: +# https://docs.python.org/3/library/multiprocessing.html#sharing-state-between-processes @dataclass class Context: # In our case it simulates an in-memory database containing the description of Pikachu in multiple @@ -90,7 +91,7 @@ class Context: ), ] } - _calls_count = FastWriteCounter() + _calls_count = SafeCounter() _radio_database = [ "https://ia800107.us.archive.org/33/items/299SoundEffectCollection/102%20Palette%20Town%20Theme.mp3", "https://ia600408.us.archive.org/29/items/PocketMonstersGreenBetaLavenderTownMusicwwwFlvtoCom/Pocket%20Monsters%20Green%20Beta-%20Lavender%20Town%20Music-%5Bwww_flvto_com%5D.mp3", @@ -228,4 +229,7 @@ async def stream_pokemon_radio(_: StreamPokemonRadioInput, context: Context): ########################################################### # Run the server. ########################################################### -app.run(workers=1) +def main(): + app.run(workers=1) + +main() diff --git a/rust-runtime/aws-smithy-http-server-python/src/server.rs b/rust-runtime/aws-smithy-http-server-python/src/server.rs index 94680ce3bfe..fdff93b3981 100644 --- a/rust-runtime/aws-smithy-http-server-python/src/server.rs +++ b/rust-runtime/aws-smithy-http-server-python/src/server.rs @@ -426,7 +426,13 @@ event_loop.add_signal_handler(signal.SIGINT, // Forcing the multiprocessing start method to fork is a workaround for it. // https://github.com/pytest-dev/pytest-flask/issues/104#issuecomment-577908228 #[cfg(target_os = "macos")] - mp.call_method1("set_start_method", ("fork",))?; + mp.call_method( + "set_start_method", + ("fork",), + // We need to pass `force=True` to prevent `context has already been set` exception, + // see https://github.com/pytorch/pytorch/issues/3492 + Some(vec![("force", true)].into_py_dict(py)), + )?; let address = address.unwrap_or_else(|| String::from("127.0.0.1")); let port = port.unwrap_or(13734); From 39c0096c33417d44f125a042c112b3c16918098a Mon Sep 17 00:00:00 2001 From: david-perez Date: Mon, 3 Oct 2022 18:19:56 +0200 Subject: [PATCH 14/57] Remove unnecessary call to upgrade to a server protocol for `ServerServiceGeneratorV2` (#1805) The protocol `ServerServiceGenerator` hosts is already typed as a `ServerProtocol`. --- .../codegen/server/smithy/generators/ServerServiceGenerator.kt | 3 +-- .../codegen/server/smithy/protocols/ServerRestJsonFactory.kt | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt index a9670d013b3..ecb56283ac2 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt @@ -89,10 +89,9 @@ open class ServerServiceGenerator( rustCrate.withModule( RustModule("service", RustMetadata(visibility = Visibility.PUBLIC, additionalAttributes = listOf(Attribute.DocHidden)), null), ) { writer -> - val serverProtocol = ServerProtocol.fromCoreProtocol(protocol) ServerServiceGeneratorV2( codegenContext, - serverProtocol, + protocol, ).render(writer) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestJsonFactory.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestJsonFactory.kt index ee7e609ccce..d3d0fea6312 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestJsonFactory.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerRestJsonFactory.kt @@ -8,7 +8,6 @@ package software.amazon.smithy.rust.codegen.server.smithy.protocols import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol import software.amazon.smithy.rust.codegen.core.smithy.protocols.ProtocolGeneratorFactory -import software.amazon.smithy.rust.codegen.core.smithy.protocols.RestJson import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerRestJsonProtocol @@ -17,7 +16,7 @@ import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.Ser * with RestJson1 specific configurations. */ class ServerRestJsonFactory : ProtocolGeneratorFactory { - override fun protocol(codegenContext: ServerCodegenContext): Protocol = RestJson(codegenContext) + override fun protocol(codegenContext: ServerCodegenContext): Protocol = ServerRestJsonProtocol(codegenContext) override fun buildProtocolGenerator(codegenContext: ServerCodegenContext): ServerHttpBoundProtocolGenerator = ServerHttpBoundProtocolGenerator(codegenContext, ServerRestJsonProtocol(codegenContext)) From 917d0a62b50bd03734747648b87ecb665e213c6a Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Tue, 4 Oct 2022 17:15:22 +0100 Subject: [PATCH 15/57] Do not generate public empty modules (#1803) * Mark `operation_handler` module as private in the generated server code since it does not contain any public type. Tune the visibility of the 'operation' module based on the rendering context * Add changelog.next entry. * Rename `operationModule` to `operation`. * Ensure that `operation` is added to the list of public modules for the generated client. * Remove DefaultModules from codegen-core * Fix Python server. * Expose TestDefaultPublicModules. --- CHANGELOG.next.toml | 10 ++++++++++ .../codegen/client/smithy/CodegenVisitor.kt | 14 ++++++++++++-- .../client/CustomizableOperationGenerator.kt | 3 ++- .../rust/codegen/core/rustlang/RustModule.kt | 12 +++++++++++- .../codegen/core/smithy/CodegenDelegator.kt | 12 ------------ .../smithy/rust/codegen/core/testutil/Rust.kt | 17 +++++++++++++++-- .../error/TopLevelErrorGeneratorTest.kt | 4 ++-- .../python/smithy/PythonServerCodegenVisitor.kt | 4 ++-- .../server/smithy/ServerCodegenVisitor.kt | 12 ++++++++++-- .../smithy/generators/ServerServiceGenerator.kt | 5 ++--- 10 files changed, 66 insertions(+), 27 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 4129e447106..18d9fa6ff17 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -10,6 +10,16 @@ # references = ["smithy-rs#920"] # meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"} # author = "rcoh" + +[[smithy-rs]] +message = """ +Mark `operation` and `operation_handler` modules as private in the generated server crate. +Both modules did not contain any public types, therefore there should be no actual breakage when updating. +""" +references = ["smithy-rs#1803"] +meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server"} +author = "LukeMathWalker" + [[smithy-rs]] message = "Pokémon Service example code now runs clippy during build." references = ["smithy-rs#1727"] diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt index 0e66b6ba3d7..f7c68c6583a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt @@ -23,7 +23,8 @@ import software.amazon.smithy.rust.codegen.client.smithy.generators.protocol.Cli import software.amazon.smithy.rust.codegen.client.smithy.protocols.ClientProtocolLoader import software.amazon.smithy.rust.codegen.client.smithy.transformers.AddErrorMessage import software.amazon.smithy.rust.codegen.client.smithy.transformers.RemoveEventStreamOperations -import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.Visibility import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig @@ -81,10 +82,19 @@ class CodegenVisitor( symbolProvider = RustCodegenPlugin.baseSymbolProvider(model, service, symbolVisitorConfig) codegenContext = ClientCodegenContext(model, symbolProvider, service, protocol, settings) + + val clientPublicModules = setOf( + RustModule.Error, + RustModule.Model, + RustModule.Input, + RustModule.Output, + RustModule.Config, + RustModule.operation(Visibility.PUBLIC), + ).associateBy { it.name } rustCrate = RustCrate( context.fileManifest, symbolProvider, - DefaultPublicModules, + clientPublicModules, codegenContext.settings.codegenConfig, ) protocolGenerator = protocolGeneratorFactory.buildProtocolGenerator(codegenContext) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt index d3d43563fd5..f954f79496b 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt @@ -10,6 +10,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.GenericTypeArg import software.amazon.smithy.rust.codegen.core.rustlang.RustGenerics import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Visibility import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.docs import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -34,7 +35,7 @@ class CustomizableOperationGenerator( private val smithyTypes = CargoDependency.SmithyTypes(runtimeConfig).asType() fun render(crate: RustCrate) { - crate.withModule(RustModule.Operation) { writer -> + crate.withModule(RustModule.operation(Visibility.PUBLIC)) { writer -> writer.docs("Operation customization and supporting types") writer.rust("pub mod customize;") } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt index 0ec62243d15..8cfbcb206c4 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt @@ -23,8 +23,18 @@ data class RustModule(val name: String, val rustMetadata: RustMetadata, val docu fun private(name: String, documentation: String? = null): RustModule = default(name, visibility = Visibility.PRIVATE, documentation = documentation) + /* Common modules used across client, server and tests */ val Config = public("config", documentation = "Configuration for the service.") val Error = public("error", documentation = "All error types that operations can return.") - val Operation = public("operation", documentation = "All operations that this crate can perform.") + val Model = public("model", documentation = "Data structures used by operation inputs/outputs.") + val Input = public("input", documentation = "Input structures for operations.") + val Output = public("output", documentation = "Output structures for operations.") + + /** + * Helper method to generate the `operation` Rust module. + * Its visibility depends on the generation context (client or server). + */ + fun operation(visibility: Visibility): RustModule = + default("operation", visibility = visibility, documentation = "All operations that this crate can perform.") } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt index 53473cb6716..32ba37f3d33 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt @@ -170,18 +170,6 @@ open class RustCrate( } } -/** - * Allowlist of modules that will be exposed publicly in generated crates - */ -val DefaultPublicModules = setOf( - RustModule.Error, - RustModule.Operation, - RustModule.public("model", documentation = "Data structures used by operation inputs/outputs."), - RustModule.public("input", documentation = "Input structures for operations."), - RustModule.public("output", documentation = "Output structures for operations."), - RustModule.Config, -).associateBy { it.name } - /** * Finalize all the writers by: * - inlining inline dependencies that have been used diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index 328eb4e1341..b45b014c0e8 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -18,11 +18,11 @@ import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.traits.EnumDefinition import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustDependency +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.raw import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock import software.amazon.smithy.rust.codegen.core.smithy.CoreCodegenConfig -import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules import software.amazon.smithy.rust.codegen.core.smithy.MaybeRenamed import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RustCrate @@ -189,6 +189,14 @@ fun RustWriter.unitTest( return rustBlock("fn $name()", *args, block = block) } +val DefaultTestPublicModules = setOf( + RustModule.Error, + RustModule.Model, + RustModule.Input, + RustModule.Output, + RustModule.Config, +).associateBy { it.name } + /** * WriterDelegator used for test purposes * @@ -199,7 +207,12 @@ class TestWriterDelegator( symbolProvider: RustSymbolProvider, val codegenConfig: CoreCodegenConfig, ) : - RustCrate(fileManifest, symbolProvider, DefaultPublicModules, codegenConfig) { + RustCrate( + fileManifest, + symbolProvider, + DefaultTestPublicModules, + codegenConfig, + ) { val baseDir: Path = fileManifest.baseDir fun generatedFiles(): List = fileManifest.files.toList().sorted() diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGeneratorTest.kt index d4b6d5efa9c..b17e48cd921 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGeneratorTest.kt @@ -13,9 +13,9 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings -import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.generators.StructureGenerator +import software.amazon.smithy.rust.codegen.core.testutil.DefaultTestPublicModules import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.testutil.generatePluginContext import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider @@ -75,7 +75,7 @@ internal class TopLevelErrorGeneratorTest { val rustCrate = RustCrate( pluginContext.fileManifest, symbolProvider, - DefaultPublicModules, + DefaultTestPublicModules, codegenContext.settings.codegenConfig, ) diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt index 6f824ef1f84..c4e07d60d91 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt @@ -16,7 +16,6 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget -import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig import software.amazon.smithy.rust.codegen.core.smithy.generators.BuilderGenerator @@ -25,6 +24,7 @@ import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerEnumGenerator import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerServiceGenerator import software.amazon.smithy.rust.codegen.server.python.smithy.generators.PythonServerStructureGenerator +import software.amazon.smithy.rust.codegen.server.smithy.DefaultServerPublicModules import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenVisitor import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol @@ -69,7 +69,7 @@ class PythonServerCodegenVisitor( codegenContext = ServerCodegenContext(model, symbolProvider, service, protocol, settings) // Override `rustCrate` which carries the symbolProvider. - rustCrate = RustCrate(context.fileManifest, symbolProvider, DefaultPublicModules, settings.codegenConfig) + rustCrate = RustCrate(context.fileManifest, symbolProvider, DefaultServerPublicModules, settings.codegenConfig) // Override `protocolGenerator` which carries the symbolProvider. protocolGenerator = protocolGeneratorFactory.buildProtocolGenerator(codegenContext) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt index 1735a81bfd8..db93c5cfffe 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt @@ -18,9 +18,9 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.transform.ModelTransformer import software.amazon.smithy.rust.codegen.client.smithy.customize.RustCodegenDecorator +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings -import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig @@ -42,6 +42,14 @@ import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.Ser import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerProtocolLoader import java.util.logging.Logger +val DefaultServerPublicModules = setOf( + RustModule.Error, + RustModule.Model, + RustModule.Input, + RustModule.Output, + RustModule.Config, +).associateBy { it.name } + /** * Entrypoint for server-side code generation. This class will walk the in-memory model and * generate all the needed types by calling the accept() function on the available shapes. @@ -92,7 +100,7 @@ open class ServerCodegenVisitor( settings, ) - rustCrate = RustCrate(context.fileManifest, symbolProvider, DefaultPublicModules, settings.codegenConfig) + rustCrate = RustCrate(context.fileManifest, symbolProvider, DefaultServerPublicModules, settings.codegenConfig) protocolGenerator = protocolGeneratorFactory.buildProtocolGenerator(codegenContext) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt index ecb56283ac2..a002a167ea6 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt @@ -13,7 +13,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Visibility import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext -import software.amazon.smithy.rust.codegen.core.smithy.DefaultPublicModules import software.amazon.smithy.rust.codegen.core.smithy.RustCrate import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol @@ -41,7 +40,7 @@ open class ServerServiceGenerator( * which assigns a symbol location to each shape. */ fun render() { - rustCrate.withModule(DefaultPublicModules["operation"]!!) { writer -> + rustCrate.withModule(RustModule.operation(Visibility.PRIVATE)) { writer -> ServerProtocolTestGenerator(codegenContext, protocolSupport, protocolGenerator).render(writer) } @@ -52,7 +51,7 @@ open class ServerServiceGenerator( } } } - rustCrate.withModule(RustModule.public("operation_handler", "Operation handlers definition and implementation.")) { writer -> + rustCrate.withModule(RustModule.private("operation_handler", "Operation handlers definition and implementation.")) { writer -> renderOperationHandler(writer, operations) } rustCrate.withModule( From 38c32b792e55a937d6beb0d33b00100e3090caa1 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Tue, 4 Oct 2022 11:09:19 -0700 Subject: [PATCH 16/57] Update tool dependencies (#1808) --- tools/changelogger/Cargo.lock | 241 ++++++++-------- tools/ci-cdk/canary-runner/Cargo.lock | 376 ++++++++++++------------ tools/crate-hasher/Cargo.lock | 82 +++--- tools/echo-server/Cargo.lock | 138 +++++---- tools/publisher/Cargo.lock | 396 ++++++++++++-------------- tools/sdk-lints/Cargo.lock | 204 +++++++------ tools/sdk-sync/Cargo.lock | 274 +++++++++--------- tools/sdk-versioner/Cargo.lock | 229 +++++++-------- 8 files changed, 944 insertions(+), 996 deletions(-) diff --git a/tools/changelogger/Cargo.lock b/tools/changelogger/Cargo.lock index 9196d86eed9..24955c08d87 100644 --- a/tools/changelogger/Cargo.lock +++ b/tools/changelogger/Cargo.lock @@ -4,33 +4,24 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anyhow" -version = "1.0.58" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "async-trait" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96cf8829f67d2eab0b2dfa42c5d0ef737e0724e4a82b01b3e292456202b19716" +checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" dependencies = [ "proc-macro2", "quote", @@ -68,15 +59,15 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bumpalo" -version = "3.10.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" +checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" [[package]] name = "bytes" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" [[package]] name = "cc" @@ -108,9 +99,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.15" +version = "3.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44bbe24bbd31a185bc2c4f7c2abe80bea13a20d57ee4e55be70ac512bdc76417" +checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" dependencies = [ "atty", "bitflags", @@ -125,9 +116,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.2.15" +version = "3.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ba52acd3b0a5c33aeada5cdaa3267cdc7c594a98731d4268cdc1532f4264cb4" +checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" dependencies = [ "heck", "proc-macro-error", @@ -163,9 +154,9 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "ctor" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" +checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb" dependencies = [ "quote", "syn", @@ -218,46 +209,45 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" dependencies = [ - "matches", "percent-encoding", ] [[package]] name = "futures-channel" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" +checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" [[package]] name = "futures-sink" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" +checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" [[package]] name = "futures-task" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" [[package]] name = "futures-util" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" dependencies = [ "futures-core", "futures-task", @@ -267,9 +257,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" dependencies = [ "bytes", "fnv", @@ -329,9 +319,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" @@ -378,11 +368,10 @@ dependencies = [ [[package]] name = "idna" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" dependencies = [ - "matches", "unicode-bidi", "unicode-normalization", ] @@ -414,15 +403,15 @@ checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" [[package]] name = "itoa" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" [[package]] name = "js-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -435,9 +424,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.134" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" [[package]] name = "log" @@ -448,12 +437,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "matches" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" - [[package]] name = "memchr" version = "2.5.0" @@ -526,15 +509,15 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" [[package]] name = "openssl" -version = "0.10.41" +version = "0.10.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" +checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" dependencies = [ "bitflags", "cfg-if", @@ -564,9 +547,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.75" +version = "0.9.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" +checksum = "5230151e44c0f05157effb743e8d517472843121cf9243e8b81393edb5acd9ce" dependencies = [ "autocfg", "cc", @@ -586,9 +569,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.2.0" +version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" +checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" [[package]] name = "output_vt100" @@ -601,9 +584,9 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pin-project-lite" @@ -625,14 +608,14 @@ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" [[package]] name = "pretty_assertions" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89f989ac94207d048d92db058e4f6ec7342b0971fc58d1271ca148b799b3563" +checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755" dependencies = [ - "ansi_term", "ctor", "diff", "output_vt100", + "yansi", ] [[package]] @@ -661,18 +644,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.42" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b" +checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -714,9 +697,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.11" +version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" +checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" dependencies = [ "base64", "bytes", @@ -730,10 +713,10 @@ dependencies = [ "hyper-tls", "ipnet", "js-sys", - "lazy_static", "log", "mime", "native-tls", + "once_cell", "percent-encoding", "pin-project-lite", "serde", @@ -751,9 +734,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "schannel" @@ -767,9 +750,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.6.1" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" +checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" dependencies = [ "bitflags", "core-foundation", @@ -790,24 +773,24 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" [[package]] name = "serde" -version = "1.0.140" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.140" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2122636b9fe3b81f1cb25099fcf2d3f542cdb1d45940d56c713158884a05da" +checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" dependencies = [ "proc-macro2", "quote", @@ -816,9 +799,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ "itoa", "ryu", @@ -864,9 +847,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.4.4" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" dependencies = [ "libc", "winapi", @@ -880,9 +863,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.98" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2" dependencies = [ "proc-macro2", "quote", @@ -914,15 +897,15 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" [[package]] name = "time" -version = "0.3.11" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72c91f41dcb2f096c05f0873d667dceec1087ce5bcf984ec8ffb19acddbb3217" +checksum = "d634a985c4d4238ec39cacaed2e7ae552fbd3c476b552c1deac3021b7d7eaf0c" dependencies = [ "libc", "num_threads", @@ -945,16 +928,15 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.20.1" +version = "1.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" dependencies = [ "autocfg", "bytes", "libc", "memchr", "mio", - "once_cell", "pin-project-lite", "socket2", "winapi", @@ -972,9 +954,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45" +checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" dependencies = [ "bytes", "futures-core", @@ -1002,9 +984,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.35" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" +checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" dependencies = [ "cfg-if", "pin-project-lite", @@ -1025,9 +1007,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7" +checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" dependencies = [ "once_cell", ] @@ -1046,28 +1028,27 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" [[package]] name = "unicode-normalization" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" dependencies = [ "tinyvec", ] [[package]] name = "url" -version = "2.2.2" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" dependencies = [ "form_urlencoded", "idna", - "matches", "percent-encoding", ] @@ -1101,9 +1082,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1111,9 +1092,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", @@ -1126,9 +1107,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.32" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" +checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" dependencies = [ "cfg-if", "js-sys", @@ -1138,9 +1119,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1148,9 +1129,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -1161,15 +1142,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "web-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" dependencies = [ "js-sys", "wasm-bindgen", @@ -1257,3 +1238,9 @@ checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ "winapi", ] + +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" diff --git a/tools/ci-cdk/canary-runner/Cargo.lock b/tools/ci-cdk/canary-runner/Cargo.lock index dc3e65808ef..3bdfd38331a 100644 --- a/tools/ci-cdk/canary-runner/Cargo.lock +++ b/tools/ci-cdk/canary-runner/Cargo.lock @@ -10,13 +10,22 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "ansi_term" version = "0.12.1" @@ -28,9 +37,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.58" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "async-recursion" @@ -45,9 +54,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96cf8829f67d2eab0b2dfa42c5d0ef737e0724e4a82b01b3e292456202b19716" +checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" dependencies = [ "proc-macro2", "quote", @@ -92,7 +101,7 @@ dependencies = [ "http", "hyper", "ring", - "time 0.3.11", + "time 0.3.15", "tokio", "tower", "tracing", @@ -277,7 +286,7 @@ dependencies = [ "percent-encoding", "regex", "ring", - "time 0.3.11", + "time 0.3.15", "tracing", ] @@ -413,7 +422,7 @@ dependencies = [ "itoa", "num-integer", "ryu", - "time 0.3.11", + "time 0.3.15", ] [[package]] @@ -461,18 +470,18 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "block-buffer" -version = "0.10.2" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf7fe51849ea569fd452f37822f606a5cabb684dc918707a0193fd4664ff324" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" dependencies = [ "generic-array", ] [[package]] name = "bumpalo" -version = "3.10.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" +checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" [[package]] name = "byteorder" @@ -488,9 +497,9 @@ checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8" [[package]] name = "bytes-utils" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1934a3ef9cac8efde4966a92781e77713e1ba329f1d42e446c7d7eba340d8ef1" +checksum = "e47d3a8076e283f3acd27400535992edb3ba4b5bb72f8891ad8fbe7932a7d4b9" dependencies = [ "bytes", "either", @@ -538,23 +547,25 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.19" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" dependencies = [ - "libc", + "iana-time-zone", + "js-sys", "num-integer", "num-traits", "serde", "time 0.1.44", + "wasm-bindgen", "winapi", ] [[package]] name = "clap" -version = "3.2.17" +version = "3.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29e724a68d9319343bb3328c9cc2dfde263f4b3142ee1059a9980580171c954b" +checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" dependencies = [ "atty", "bitflags", @@ -569,9 +580,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.2.17" +version = "3.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "13547f7012c01ab4a0e8f8967730ada8f9fdf419e8b6c792788f39cf4e46eefa" +checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" dependencies = [ "heck", "proc-macro-error", @@ -607,9 +618,9 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "cpufeatures" -version = "0.2.2" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" dependencies = [ "libc", ] @@ -644,12 +655,11 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" dependencies = [ "cfg-if", - "once_cell", ] [[package]] @@ -673,9 +683,9 @@ dependencies = [ [[package]] name = "ctor" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" +checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb" dependencies = [ "quote", "syn", @@ -689,9 +699,9 @@ checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" [[package]] name = "digest" -version = "0.10.3" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2fb860ca6fafa5552fb6d0e816a69c8e49f0908bf524e30a90d97c85892d506" +checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" dependencies = [ "block-buffer", "crypto-common", @@ -699,15 +709,15 @@ dependencies = [ [[package]] name = "dyn-clone" -version = "1.0.8" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d07a982d1fb29db01e5a59b1918e03da4df7297eaeee7686ac45542fd4e59c8" +checksum = "4f94fa09c2aeea5b8839e414b7b841bf429fd25b9c522116ac97ee87856d88b2" [[package]] name = "either" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "encoding_rs" @@ -770,9 +780,9 @@ dependencies = [ [[package]] name = "futures" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e" +checksum = "7f21eda599937fba36daeb58a22e8f5cee2d14c4a17b5b7739c7c8e5e3b8230c" dependencies = [ "futures-channel", "futures-core", @@ -785,9 +795,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" dependencies = [ "futures-core", "futures-sink", @@ -795,15 +805,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" +checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" [[package]] name = "futures-executor" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6" +checksum = "9ff63c23854bee61b6e9cd331d523909f238fc7636290b96826e9cfa5faa00ab" dependencies = [ "futures-core", "futures-task", @@ -812,15 +822,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" +checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" [[package]] name = "futures-macro" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512" +checksum = "42cd15d1c7456c04dbdf7e88bcd69760d74f3a798d6444e16974b505b0e62f17" dependencies = [ "proc-macro2", "quote", @@ -829,21 +839,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" +checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" [[package]] name = "futures-task" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" [[package]] name = "futures-util" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" dependencies = [ "futures-channel", "futures-core", @@ -859,9 +869,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.14.5" +version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" dependencies = [ "typenum", "version_check", @@ -880,9 +890,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" dependencies = [ "bytes", "fnv", @@ -948,15 +958,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" - -[[package]] -name = "httpdate" -version = "0.3.2" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" @@ -978,7 +982,7 @@ dependencies = [ "http", "http-body", "httparse", - "httpdate 1.0.2", + "httpdate", "itoa", "pin-project-lite", "socket2", @@ -1040,13 +1044,26 @@ dependencies = [ "base64 0.13.0", "bytes", "http", - "httpdate 0.3.2", + "httpdate", "language-tags", "mime", "percent-encoding", "unicase", ] +[[package]] +name = "iana-time-zone" +version = "0.1.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd911b35d940d2bd0bea0f9100068e5b97b51a1cbe13d13382f132e0365257a0" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "js-sys", + "wasm-bindgen", + "winapi", +] + [[package]] name = "idna" version = "0.2.3" @@ -1085,15 +1102,15 @@ checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" [[package]] name = "itoa" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" [[package]] name = "js-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -1126,15 +1143,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.134" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" [[package]] name = "lock_api" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ "autocfg", "scopeguard", @@ -1167,9 +1184,9 @@ checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" [[package]] name = "md-5" -version = "0.10.1" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658646b21e0b72f7866c7038ab086d3d5e1cd6271f060fd37defb241949d0582" +checksum = "6365506850d44bff6e2fbcb5176cf63650e48bd45ef2fe2665ae1570e0f4b9ca" dependencies = [ "digest", ] @@ -1198,9 +1215,9 @@ dependencies = [ [[package]] name = "miniz_oxide" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" +checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" dependencies = [ "adler", ] @@ -1316,15 +1333,15 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" [[package]] name = "openssl" -version = "0.10.41" +version = "0.10.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" +checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" dependencies = [ "bitflags", "cfg-if", @@ -1354,9 +1371,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.75" +version = "0.9.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" +checksum = "5230151e44c0f05157effb743e8d517472843121cf9243e8b81393edb5acd9ce" dependencies = [ "autocfg", "cc", @@ -1386,9 +1403,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.2.0" +version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" +checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" [[package]] name = "output_vt100" @@ -1441,18 +1458,18 @@ checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" [[package]] name = "pin-project" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78203e83c48cffbe01e4a2d35d566ca4de445d79a85372fc64e378bfc812a260" +checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "710faf75e1b33345361201d36d04e98ac1ed8909151a017ed384700836104c74" +checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" dependencies = [ "proc-macro2", "quote", @@ -1485,14 +1502,14 @@ checksum = "eb9f9e6e233e5c4a35559a617bf40a4ec447db2e84c20b55a6f83167b7e57872" [[package]] name = "pretty_assertions" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89f989ac94207d048d92db058e4f6ec7342b0971fc58d1271ca148b799b3563" +checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755" dependencies = [ - "ansi_term", "ctor", "diff", "output_vt100", + "yansi", ] [[package]] @@ -1521,18 +1538,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.42" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b" +checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -1560,9 +1577,9 @@ dependencies = [ [[package]] name = "rand_core" -version = "0.6.3" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d34f1408f55294453790c48b2f1ebbb1c5b4b7563eb1f418bcfcfdbb06ebb4e7" +checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ "getrandom", ] @@ -1613,9 +1630,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.10" +version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46a1f7aa4f35e5e8b4160449f51afc758f0ce6454315a9fa7d0d113e958c41eb" +checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" dependencies = [ "base64 0.13.0", "bytes", @@ -1630,11 +1647,11 @@ dependencies = [ "hyper-tls", "ipnet", "js-sys", - "lazy_static", "log", "mime", "mime_guess", "native-tls", + "once_cell", "percent-encoding", "pin-project-lite", "rustls 0.20.6", @@ -1645,6 +1662,7 @@ dependencies = [ "tokio", "tokio-native-tls", "tokio-rustls 0.23.4", + "tower-service", "url", "wasm-bindgen", "wasm-bindgen-futures", @@ -1791,18 +1809,18 @@ dependencies = [ [[package]] name = "rustls-pemfile" -version = "0.3.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ee86d63972a7c661d1536fefe8c3c8407321c3df668891286de28abcd087360" +checksum = "0864aeff53f8c05aa08d86e5ef839d3dfcf07aeba2db32f12db0ef716e87bd55" dependencies = [ "base64 0.13.0", ] [[package]] name = "ryu" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "schannel" @@ -1816,9 +1834,9 @@ dependencies = [ [[package]] name = "schemars" -version = "0.8.10" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1847b767a3d62d95cbf3d8a9f0e421cf57a0d8aa4f411d4b16525afb0284d4ed" +checksum = "2a5fb6c61f29e723026dc8e923d94c694313212abbecbbe5f55a7748eec5b307" dependencies = [ "bytes", "chrono", @@ -1832,9 +1850,9 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.10" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af4d7e1b012cb3d9129567661a63755ea4b8a7386d339dc945ae187e403c6743" +checksum = "f188d036977451159430f3b8dc82ec76364a42b7e289c2b18a9a18f4470058e9" dependencies = [ "proc-macro2", "quote", @@ -1870,9 +1888,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.6.1" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" +checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" dependencies = [ "bitflags", "core-foundation", @@ -1893,24 +1911,24 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" [[package]] name = "serde" -version = "1.0.140" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.140" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2122636b9fe3b81f1cb25099fcf2d3f542cdb1d45940d56c713158884a05da" +checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" dependencies = [ "proc-macro2", "quote", @@ -1930,9 +1948,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ "itoa", "ryu", @@ -1953,9 +1971,9 @@ dependencies = [ [[package]] name = "sha1" -version = "0.10.1" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c77f4e7f65455545c2153c1253d25056825e77ee2533f0e41deb65a93a34852f" +checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" dependencies = [ "cfg-if", "cpufeatures", @@ -1964,9 +1982,9 @@ dependencies = [ [[package]] name = "sha2" -version = "0.10.2" +version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55deaec60f81eefe3cce0dc50bda92d6d8e88f2a27df7c5033b42afeb1ed2676" +checksum = "82e6b795fe2e3b1e845bafcb27aa35405c4d47cdfc92af5fc8d3002f76cebdc0" dependencies = [ "cfg-if", "cpufeatures", @@ -2013,9 +2031,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "smithy-rs-tool-common" @@ -2036,9 +2054,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.4.4" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" dependencies = [ "libc", "winapi", @@ -2058,9 +2076,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.98" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2" dependencies = [ "proc-macro2", "quote", @@ -2069,9 +2087,9 @@ dependencies = [ [[package]] name = "task-local-extensions" -version = "0.1.1" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36794203e10c86e5998179e260869d156e0674f02d5451b4a3fb9fd86d02aaab" +checksum = "4167afbec18ae012de40f8cf1b9bf48420abb390678c34821caa07d924941cc4" dependencies = [ "tokio", ] @@ -2101,24 +2119,24 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" [[package]] name = "thiserror" -version = "1.0.31" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.31" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" dependencies = [ "proc-macro2", "quote", @@ -2147,9 +2165,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.11" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72c91f41dcb2f096c05f0873d667dceec1087ce5bcf984ec8ffb19acddbb3217" +checksum = "d634a985c4d4238ec39cacaed2e7ae552fbd3c476b552c1deac3021b7d7eaf0c" dependencies = [ "libc", "num_threads", @@ -2172,9 +2190,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.20.1" +version = "1.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" dependencies = [ "autocfg", "bytes", @@ -2182,7 +2200,6 @@ dependencies = [ "memchr", "mio", "num_cpus", - "once_cell", "parking_lot", "pin-project-lite", "signal-hook-registry", @@ -2236,9 +2253,9 @@ dependencies = [ [[package]] name = "tokio-stream" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "df54d54117d6fdc4e4fea40fe1e4e566b3505700e148a6827e59b34b0d2600d9" +checksum = "f6edf2d6bc038a43d31353570e27270603f4648d18f5ed10c0e179abe43255af" dependencies = [ "futures-core", "pin-project-lite", @@ -2247,9 +2264,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45" +checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" dependencies = [ "bytes", "futures-core", @@ -2299,9 +2316,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.35" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" +checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" dependencies = [ "cfg-if", "log", @@ -2323,9 +2340,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7" +checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" dependencies = [ "once_cell", "valuable", @@ -2403,15 +2420,15 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" [[package]] name = "unicode-normalization" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" dependencies = [ "tinyvec", ] @@ -2424,22 +2441,21 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.2.2" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +checksum = "22fe195a4f217c25b25cb5058ced57059824a678474874038dc88d211bf508d3" dependencies = [ "form_urlencoded", "idna", - "matches", "percent-encoding", "serde", ] [[package]] name = "urlencoding" -version = "2.1.0" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b90931029ab9b034b300b797048cf23723400aa757e8a2bfb9d748102f9821" +checksum = "e8db7427f936968176eaa7cdf81b7f98b980b18495ec28f1b5791ac3bfe3eea9" [[package]] name = "uuid" @@ -2489,9 +2505,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -2499,9 +2515,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", @@ -2514,9 +2530,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.32" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" +checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" dependencies = [ "cfg-if", "js-sys", @@ -2526,9 +2542,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2536,9 +2552,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -2549,15 +2565,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "web-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" dependencies = [ "js-sys", "wasm-bindgen", @@ -2585,9 +2601,9 @@ dependencies = [ [[package]] name = "webpki-roots" -version = "0.22.4" +version = "0.22.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1c760f0d366a6c24a02ed7816e23e691f5d92291f94d15e836006fd11b04daf" +checksum = "368bfe657969fb01238bb756d351dcade285e0f6fcbd36dcb23359a5169975be" dependencies = [ "webpki 0.22.0", ] @@ -2681,6 +2697,12 @@ version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "114ba2b24d2167ef6d67d7d04c8cc86522b87f490025f39f0303b7db5bf5e3d8" +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + [[package]] name = "zeroize" version = "1.5.7" diff --git a/tools/crate-hasher/Cargo.lock b/tools/crate-hasher/Cargo.lock index ba5b5d323d9..9fed13f46b9 100644 --- a/tools/crate-hasher/Cargo.lock +++ b/tools/crate-hasher/Cargo.lock @@ -10,27 +10,18 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anyhow" -version = "1.0.58" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "atty" @@ -120,9 +111,9 @@ dependencies = [ [[package]] name = "cpufeatures" -version = "0.2.2" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" dependencies = [ "libc", ] @@ -152,19 +143,18 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" dependencies = [ "cfg-if", - "once_cell", ] [[package]] name = "ctor" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" +checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb" dependencies = [ "quote", "syn", @@ -221,9 +211,9 @@ checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" [[package]] name = "generic-array" -version = "0.14.5" +version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" dependencies = [ "typenum", "version_check", @@ -305,9 +295,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.134" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" [[package]] name = "log" @@ -326,18 +316,18 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "miniz_oxide" -version = "0.5.3" +version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f5c75688da582b8ffc1f1799e9db273f32133c49e048f614d22ec3256773ccc" +checksum = "96590ba8f175222643a85693f33d26e9c8a015f599c216509b1a6894af675d34" dependencies = [ "adler", ] [[package]] name = "once_cell" -version = "1.13.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" [[package]] name = "opaque-debug" @@ -347,9 +337,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "os_str_bytes" -version = "6.2.0" +version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" +checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" [[package]] name = "output_vt100" @@ -362,14 +352,14 @@ dependencies = [ [[package]] name = "pretty_assertions" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89f989ac94207d048d92db058e4f6ec7342b0971fc58d1271ca148b799b3563" +checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755" dependencies = [ - "ansi_term", "ctor", "diff", "output_vt100", + "yansi", ] [[package]] @@ -398,18 +388,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.42" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b" +checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -526,9 +516,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.98" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2" dependencies = [ "proc-macro2", "quote", @@ -567,9 +557,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" [[package]] name = "thread_local" @@ -588,9 +578,9 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "unicode-ident" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" [[package]] name = "version_check" @@ -691,3 +681,9 @@ checksum = "6d1526bbe5aaeb5eb06885f4d987bcdfa5e23187055de9b83fe00156a821fabc" dependencies = [ "libc", ] + +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" diff --git a/tools/echo-server/Cargo.lock b/tools/echo-server/Cargo.lock index 06c5576118b..2efeb1952ff 100644 --- a/tools/echo-server/Cargo.lock +++ b/tools/echo-server/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96cf8829f67d2eab0b2dfa42c5d0ef737e0724e4a82b01b3e292456202b19716" +checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" dependencies = [ "proc-macro2", "quote", @@ -30,9 +30,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "axum" -version = "0.5.13" +version = "0.5.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6b9496f0c1d1afb7a2af4338bbe1d969cddfead41d87a9fb3aaa6d0bbc7af648" +checksum = "c9e3356844c4d6a6d6467b8da2cffb4a2820be256f50a3a386c9d152bab31043" dependencies = [ "async-trait", "axum-core", @@ -61,9 +61,9 @@ dependencies = [ [[package]] name = "axum-core" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4f44a0e6200e9d11a1cdc989e4b358f6e3d354fbf48478f345a17f4e43f8635" +checksum = "d9f0c0a60006f2a293d82d571f635042a72edf927539b7685bd62d361963839b" dependencies = [ "async-trait", "bytes", @@ -71,6 +71,8 @@ dependencies = [ "http", "http-body", "mime", + "tower-layer", + "tower-service", ] [[package]] @@ -81,9 +83,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bytes" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" [[package]] name = "cfg-if" @@ -111,46 +113,45 @@ checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] name = "form_urlencoded" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" dependencies = [ - "matches", "percent-encoding", ] [[package]] name = "futures-channel" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" +checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" [[package]] name = "futures-sink" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" +checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" [[package]] name = "futures-task" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" [[package]] name = "futures-util" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" dependencies = [ "futures-core", "futures-task", @@ -160,9 +161,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" dependencies = [ "bytes", "fnv", @@ -222,9 +223,9 @@ checksum = "0bfe8eed0a9285ef776bb792479ea3834e8b94e13d615c2f66d03dd50a435a29" [[package]] name = "httparse" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" @@ -268,9 +269,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" [[package]] name = "lazy_static" @@ -280,15 +281,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.134" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" [[package]] name = "lock_api" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ "autocfg", "scopeguard", @@ -312,12 +313,6 @@ dependencies = [ "regex-automata", ] -[[package]] -name = "matches" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" - [[package]] name = "matchit" version = "0.5.0" @@ -360,9 +355,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" [[package]] name = "parking_lot" @@ -389,24 +384,24 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pin-project" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78203e83c48cffbe01e4a2d35d566ca4de445d79a85372fc64e378bfc812a260" +checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.0.11" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "710faf75e1b33345361201d36d04e98ac1ed8909151a017ed384700836104c74" +checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" dependencies = [ "proc-macro2", "quote", @@ -427,18 +422,18 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "proc-macro2" -version = "1.0.42" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b" +checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -478,9 +473,9 @@ checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" [[package]] name = "ryu" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "scopeguard" @@ -490,15 +485,15 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "serde" -version = "1.0.140" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" [[package]] name = "serde_json" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ "itoa", "ryu", @@ -546,15 +541,15 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "socket2" -version = "0.4.4" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" dependencies = [ "libc", "winapi", @@ -562,9 +557,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.98" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2" dependencies = [ "proc-macro2", "quote", @@ -588,9 +583,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.20.1" +version = "1.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" dependencies = [ "autocfg", "bytes", @@ -598,7 +593,6 @@ dependencies = [ "memchr", "mio", "num_cpus", - "once_cell", "parking_lot", "pin-project-lite", "signal-hook-registry", @@ -620,9 +614,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45" +checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" dependencies = [ "bytes", "futures-core", @@ -681,9 +675,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.35" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" +checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" dependencies = [ "cfg-if", "log", @@ -705,9 +699,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7" +checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" dependencies = [ "once_cell", "valuable", @@ -750,9 +744,9 @@ checksum = "59547bce71d9c38b83d9c0e92b6066c4253371f15005def0c30d9657f50c7642" [[package]] name = "unicode-ident" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" [[package]] name = "valuable" diff --git a/tools/publisher/Cargo.lock b/tools/publisher/Cargo.lock index cdc9f45f8e2..91c73c8b415 100644 --- a/tools/publisher/Cargo.lock +++ b/tools/publisher/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] @@ -22,9 +22,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.58" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "async-recursion" @@ -39,9 +39,9 @@ dependencies = [ [[package]] name = "async-trait" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96cf8829f67d2eab0b2dfa42c5d0ef737e0724e4a82b01b3e292456202b19716" +checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" dependencies = [ "proc-macro2", "quote", @@ -77,59 +77,35 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" -[[package]] -name = "block-buffer" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" -dependencies = [ - "block-padding", - "byte-tools", - "byteorder", - "generic-array 0.12.4", -] - [[package]] name = "block-buffer" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" dependencies = [ - "generic-array 0.14.5", + "generic-array", ] [[package]] -name = "block-padding" -version = "0.1.5" +name = "block-buffer" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +checksum = "69cce20737498f97b993470a6e536b8523f0af7892a4f928cceb1ac5e52ebe7e" dependencies = [ - "byte-tools", + "generic-array", ] [[package]] name = "bumpalo" -version = "3.10.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" - -[[package]] -name = "byte-tools" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" - -[[package]] -name = "byteorder" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" [[package]] name = "bytes" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" [[package]] name = "cargo_toml" @@ -156,9 +132,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.19" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" dependencies = [ "num-integer", "num-traits", @@ -237,9 +213,9 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "cpufeatures" -version = "0.2.2" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59a6001667ab124aebae2a495118e11d30984c3a653e99d86d58971708cf5e4b" +checksum = "28d997bd5e24a5928dd43e46dc529867e207907fe0b239c3477d924f7f2ca320" dependencies = [ "libc", ] @@ -261,11 +237,21 @@ dependencies = [ "url", ] +[[package]] +name = "crypto-common" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3" +dependencies = [ + "generic-array", + "typenum", +] + [[package]] name = "ctor" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" +checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb" dependencies = [ "quote", "syn", @@ -291,20 +277,21 @@ checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" [[package]] name = "digest" -version = "0.8.1" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" dependencies = [ - "generic-array 0.12.4", + "generic-array", ] [[package]] name = "digest" -version = "0.9.0" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3dd60d1080a57a05ab032377049e0591415d2b31afd7028356dbf3cc6dcb066" +checksum = "adfbc57365a37acbd2ebf2b64d7e69bb766e2fea813521ed536f5d0520dcf86c" dependencies = [ - "generic-array 0.14.5", + "block-buffer 0.10.3", + "crypto-common", ] [[package]] @@ -322,12 +309,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "fake-simd" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" - [[package]] name = "fastrand" version = "1.8.0" @@ -360,19 +341,18 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" dependencies = [ - "matches", "percent-encoding", ] [[package]] name = "futures" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f73fe65f54d1e12b726f517d3e2135ca3125a437b6d998caf1962961f7172d9e" +checksum = "7f21eda599937fba36daeb58a22e8f5cee2d14c4a17b5b7739c7c8e5e3b8230c" dependencies = [ "futures-channel", "futures-core", @@ -385,9 +365,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" dependencies = [ "futures-core", "futures-sink", @@ -395,15 +375,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" +checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" [[package]] name = "futures-executor" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9420b90cfa29e327d0429f19be13e7ddb68fa1cccb09d65e5706b8c7a749b8a6" +checksum = "9ff63c23854bee61b6e9cd331d523909f238fc7636290b96826e9cfa5faa00ab" dependencies = [ "futures-core", "futures-task", @@ -412,15 +392,15 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc4045962a5a5e935ee2fdedaa4e08284547402885ab326734432bed5d12966b" +checksum = "bbf4d2a7a308fd4578637c0b17c7e1c7ba127b8f6ba00b29f717e9655d85eb68" [[package]] name = "futures-macro" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33c1e13800337f4d4d7a316bf45a567dbcb6ffe087f16424852d97e97a91f512" +checksum = "42cd15d1c7456c04dbdf7e88bcd69760d74f3a798d6444e16974b505b0e62f17" dependencies = [ "proc-macro2", "quote", @@ -429,21 +409,21 @@ dependencies = [ [[package]] name = "futures-sink" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" +checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" [[package]] name = "futures-task" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" [[package]] name = "futures-util" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" dependencies = [ "futures-channel", "futures-core", @@ -459,18 +439,9 @@ dependencies = [ [[package]] name = "generic-array" -version = "0.12.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffdf9f34f1447443d37393cc6c2b8313aebddcd96906caf34e54c68d8e57d7bd" -dependencies = [ - "typenum", -] - -[[package]] -name = "generic-array" -version = "0.14.5" +version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd48d33ec7f05fbfa152300fdad764757cbded343c1aa1cff2fbaf4134851803" +checksum = "bff49e947297f3312447abdca79f45f4738097cc82b06e72054d2223f601f1b9" dependencies = [ "typenum", "version_check", @@ -478,9 +449,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" dependencies = [ "bytes", "fnv", @@ -497,9 +468,9 @@ dependencies = [ [[package]] name = "handlebars" -version = "4.3.3" +version = "4.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "360d9740069b2f6cbb63ce2dbaa71a20d3185350cbb990d7bebeb9318415eb17" +checksum = "56b224eaa4987c03c30b251de7ef0c15a6a59f34222905850dbc3026dfb24d5f" dependencies = [ "log", "pest", @@ -560,9 +531,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" @@ -609,11 +580,10 @@ dependencies = [ [[package]] name = "idna" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" dependencies = [ - "matches", "unicode-bidi", "unicode-normalization", ] @@ -645,15 +615,15 @@ checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" [[package]] name = "itoa" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" [[package]] name = "js-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -666,15 +636,15 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.134" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" [[package]] name = "lock_api" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "327fa5b6a6940e4699ec49a9beae1ea4845c6bab9314e4f84ac68742139d8c53" +checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" dependencies = [ "autocfg", "scopeguard", @@ -689,12 +659,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "maplit" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" - [[package]] name = "matchers" version = "0.1.0" @@ -704,12 +668,6 @@ dependencies = [ "regex-automata", ] -[[package]] -name = "matches" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" - [[package]] name = "memchr" version = "2.5.0" @@ -783,15 +741,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" - -[[package]] -name = "opaque-debug" -version = "0.2.3" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" [[package]] name = "opaque-debug" @@ -801,9 +753,9 @@ checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" [[package]] name = "openssl" -version = "0.10.41" +version = "0.10.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" +checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" dependencies = [ "bitflags", "cfg-if", @@ -833,9 +785,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.75" +version = "0.9.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" +checksum = "5230151e44c0f05157effb743e8d517472843121cf9243e8b81393edb5acd9ce" dependencies = [ "autocfg", "cc", @@ -846,9 +798,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.2.0" +version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" +checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" [[package]] name = "output_vt100" @@ -884,24 +836,25 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pest" -version = "2.1.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10f4872ae94d7b90ae48754df22fd42ad52ce740b8f370b03da4835417403e53" +checksum = "dbc7bc69c062e492337d74d59b120c274fd3d261b6bf6d3207d499b4b379c41a" dependencies = [ + "thiserror", "ucd-trie", ] [[package]] name = "pest_derive" -version = "2.1.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "833d1ae558dc601e9a60366421196a8d94bc0ac980476d0b67e1d0988d72b2d0" +checksum = "60b75706b9642ebcb34dab3bc7750f811609a0eb1dd8b88c2d15bf628c1c65b2" dependencies = [ "pest", "pest_generator", @@ -909,9 +862,9 @@ dependencies = [ [[package]] name = "pest_generator" -version = "2.1.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99b8db626e31e5b81787b9783425769681b347011cc59471e33ea46d2ea0cf55" +checksum = "f4f9272122f5979a6511a749af9db9bfc810393f63119970d7085fed1c4ea0db" dependencies = [ "pest", "pest_meta", @@ -922,13 +875,13 @@ dependencies = [ [[package]] name = "pest_meta" -version = "2.1.3" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54be6e404f5317079812fc8f9f5279de376d8856929e21c184ecf6bbd692a11d" +checksum = "4c8717927f9b79515e565a64fe46c38b8cd0427e64c40680b14a7365ab09ac8d" dependencies = [ - "maplit", + "once_cell", "pest", - "sha-1", + "sha1", ] [[package]] @@ -951,14 +904,14 @@ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" [[package]] name = "pretty_assertions" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89f989ac94207d048d92db058e4f6ec7342b0971fc58d1271ca148b799b3563" +checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755" dependencies = [ - "ansi_term", "ctor", "diff", "output_vt100", + "yansi", ] [[package]] @@ -987,9 +940,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.42" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b" +checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" dependencies = [ "unicode-ident", ] @@ -1024,9 +977,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -1077,9 +1030,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.11" +version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" +checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" dependencies = [ "base64", "bytes", @@ -1093,10 +1046,10 @@ dependencies = [ "hyper-tls", "ipnet", "js-sys", - "lazy_static", "log", "mime", "native-tls", + "once_cell", "percent-encoding", "pin-project-lite", "serde", @@ -1114,9 +1067,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "schannel" @@ -1136,9 +1089,9 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" [[package]] name = "security-framework" -version = "2.6.1" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" +checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" dependencies = [ "bitflags", "core-foundation", @@ -1159,24 +1112,24 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" [[package]] name = "serde" -version = "1.0.140" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.140" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2122636b9fe3b81f1cb25099fcf2d3f542cdb1d45940d56c713158884a05da" +checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" dependencies = [ "proc-macro2", "quote", @@ -1185,9 +1138,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ "itoa", "ryu", @@ -1207,15 +1160,14 @@ dependencies = [ ] [[package]] -name = "sha-1" -version = "0.8.2" +name = "sha1" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7d94d0bede923b3cea61f3f1ff57ff8cdfd77b400fb8f9998949e0cf04163df" +checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" dependencies = [ - "block-buffer 0.7.3", - "digest 0.8.1", - "fake-simd", - "opaque-debug 0.2.3", + "cfg-if", + "cpufeatures", + "digest 0.10.5", ] [[package]] @@ -1228,7 +1180,7 @@ dependencies = [ "cfg-if", "cpufeatures", "digest 0.9.0", - "opaque-debug 0.3.0", + "opaque-debug", ] [[package]] @@ -1270,9 +1222,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "smithy-rs-tool-common" @@ -1293,9 +1245,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.4.4" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" dependencies = [ "libc", "winapi", @@ -1309,9 +1261,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.98" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2" dependencies = [ "proc-macro2", "quote", @@ -1353,24 +1305,24 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" [[package]] name = "thiserror" -version = "1.0.31" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd829fe32373d27f76265620b5309d0340cb8550f523c1dda251d6298069069a" +checksum = "10deb33631e3c9018b9baf9dcbbc4f737320d2b576bac10f6aefa048fa407e3e" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.31" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0396bc89e626244658bef819e22d0cc459e795a5ebe878e6ec336d1674a8d79a" +checksum = "982d17546b47146b28f7c22e3d08465f6b8903d0ea13c1660d9d84a6e7adcdbb" dependencies = [ "proc-macro2", "quote", @@ -1403,9 +1355,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.20.1" +version = "1.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" dependencies = [ "autocfg", "bytes", @@ -1413,7 +1365,6 @@ dependencies = [ "memchr", "mio", "num_cpus", - "once_cell", "parking_lot", "pin-project-lite", "signal-hook-registry", @@ -1445,9 +1396,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45" +checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" dependencies = [ "bytes", "futures-core", @@ -1475,9 +1426,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.35" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" +checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" dependencies = [ "cfg-if", "pin-project-lite", @@ -1498,9 +1449,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7" +checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" dependencies = [ "once_cell", "valuable", @@ -1549,9 +1500,9 @@ checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" [[package]] name = "ucd-trie" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89570599c4fe5585de2b388aab47e99f7fa4e9238a1399f707a02e356058141c" +checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" [[package]] name = "unicode-bidi" @@ -1561,34 +1512,33 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" [[package]] name = "unicode-normalization" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" dependencies = [ "tinyvec", ] [[package]] name = "unicode-width" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3ed742d4ea2bd1176e236172c8429aaf54486e7ac098db29ffe6529e0ce50973" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" [[package]] name = "url" -version = "2.2.2" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" dependencies = [ "form_urlencoded", "idna", - "matches", "percent-encoding", ] @@ -1628,9 +1578,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1638,9 +1588,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", @@ -1653,9 +1603,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.32" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" +checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" dependencies = [ "cfg-if", "js-sys", @@ -1665,9 +1615,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1675,9 +1625,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -1688,15 +1638,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "web-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" dependencies = [ "js-sys", "wasm-bindgen", @@ -1785,6 +1735,12 @@ dependencies = [ "winapi", ] +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" + [[package]] name = "zeroize" version = "1.5.7" diff --git a/tools/sdk-lints/Cargo.lock b/tools/sdk-lints/Cargo.lock index 76fa4a0bcf9..4d1a68488a0 100644 --- a/tools/sdk-lints/Cargo.lock +++ b/tools/sdk-lints/Cargo.lock @@ -4,24 +4,24 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] [[package]] name = "anyhow" -version = "1.0.58" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "async-trait" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96cf8829f67d2eab0b2dfa42c5d0ef737e0724e4a82b01b3e292456202b19716" +checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" dependencies = [ "proc-macro2", "quote", @@ -59,15 +59,15 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bumpalo" -version = "3.10.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" +checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" [[package]] name = "bytes" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" [[package]] name = "cargo_toml" @@ -188,46 +188,45 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" dependencies = [ - "matches", "percent-encoding", ] [[package]] name = "futures-channel" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" +checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" [[package]] name = "futures-sink" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" +checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" [[package]] name = "futures-task" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" [[package]] name = "futures-util" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" dependencies = [ "futures-core", "futures-task", @@ -237,9 +236,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" dependencies = [ "bytes", "fnv", @@ -299,9 +298,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" @@ -348,11 +347,10 @@ dependencies = [ [[package]] name = "idna" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" dependencies = [ - "matches", "unicode-bidi", "unicode-normalization", ] @@ -384,15 +382,15 @@ checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" [[package]] name = "itoa" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" [[package]] name = "js-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -405,9 +403,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.134" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" [[package]] name = "log" @@ -418,12 +416,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "matches" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" - [[package]] name = "memchr" version = "2.5.0" @@ -468,15 +460,15 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" [[package]] name = "openssl" -version = "0.10.41" +version = "0.10.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" +checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" dependencies = [ "bitflags", "cfg-if", @@ -506,9 +498,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.75" +version = "0.9.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" +checksum = "5230151e44c0f05157effb743e8d517472843121cf9243e8b81393edb5acd9ce" dependencies = [ "autocfg", "cc", @@ -519,15 +511,15 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.2.0" +version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" +checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" [[package]] name = "percent-encoding" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pin-project-lite" @@ -573,18 +565,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.42" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b" +checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -626,9 +618,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.11" +version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" +checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" dependencies = [ "base64", "bytes", @@ -642,10 +634,10 @@ dependencies = [ "hyper-tls", "ipnet", "js-sys", - "lazy_static", "log", "mime", "native-tls", + "once_cell", "percent-encoding", "pin-project-lite", "serde", @@ -663,9 +655,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "schannel" @@ -692,9 +684,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.6.1" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" +checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" dependencies = [ "bitflags", "core-foundation", @@ -715,24 +707,24 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" [[package]] name = "serde" -version = "1.0.140" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.140" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2122636b9fe3b81f1cb25099fcf2d3f542cdb1d45940d56c713158884a05da" +checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" dependencies = [ "proc-macro2", "quote", @@ -741,9 +733,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ "itoa", "ryu", @@ -789,9 +781,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.4.4" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" dependencies = [ "libc", "winapi", @@ -805,9 +797,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.98" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2" dependencies = [ "proc-macro2", "quote", @@ -839,9 +831,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" [[package]] name = "tinyvec" @@ -860,16 +852,15 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.20.1" +version = "1.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" dependencies = [ "autocfg", "bytes", "libc", "memchr", "mio", - "once_cell", "pin-project-lite", "socket2", "winapi", @@ -887,9 +878,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45" +checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" dependencies = [ "bytes", "futures-core", @@ -917,9 +908,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.35" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" +checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" dependencies = [ "cfg-if", "pin-project-lite", @@ -940,9 +931,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7" +checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" dependencies = [ "once_cell", ] @@ -961,28 +952,27 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" [[package]] name = "unicode-normalization" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" dependencies = [ "tinyvec", ] [[package]] name = "url" -version = "2.2.2" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" dependencies = [ "form_urlencoded", "idna", - "matches", "percent-encoding", ] @@ -1016,9 +1006,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1026,9 +1016,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", @@ -1041,9 +1031,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.32" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" +checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" dependencies = [ "cfg-if", "js-sys", @@ -1053,9 +1043,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1063,9 +1053,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -1076,15 +1066,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "web-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" dependencies = [ "js-sys", "wasm-bindgen", diff --git a/tools/sdk-sync/Cargo.lock b/tools/sdk-sync/Cargo.lock index 76a2e6db56e..4bbe7ee9156 100644 --- a/tools/sdk-sync/Cargo.lock +++ b/tools/sdk-sync/Cargo.lock @@ -4,13 +4,22 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "ansi_term" version = "0.12.1" @@ -22,15 +31,15 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.58" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "async-trait" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96cf8829f67d2eab0b2dfa42c5d0ef737e0724e4a82b01b3e292456202b19716" +checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" dependencies = [ "proc-macro2", "quote", @@ -68,15 +77,15 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bumpalo" -version = "3.10.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" +checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" [[package]] name = "bytes" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" [[package]] name = "bytesize" @@ -98,11 +107,11 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.19" +version = "0.4.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "670ad68c9088c2a963aaa298cb369688cf3f9465ce5e2d4ca10e6e0098a1ce73" +checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1" dependencies = [ - "libc", + "iana-time-zone", "num-integer", "num-traits", "winapi", @@ -186,33 +195,31 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.10" +version = "0.9.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "045ebe27666471bb549370b4b0b3e51b07f56325befa4284db65fc89c02511b1" +checksum = "f916dfc5d356b0ed9dae65f1db9fc9770aa2851d2662b988ccf4fe3516e86348" dependencies = [ "autocfg", "cfg-if", "crossbeam-utils", "memoffset", - "once_cell", "scopeguard", ] [[package]] name = "crossbeam-utils" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51887d4adc7b564537b15adcfb307936f8075dfcd5f00dde9a9f1d29383682bc" +checksum = "edbafec5fa1f196ca66527c1b12c2ec4745ca14b50f1ad8f9f6f720b55d11fac" dependencies = [ "cfg-if", - "once_cell", ] [[package]] name = "ctor" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" +checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb" dependencies = [ "quote", "syn", @@ -238,9 +245,9 @@ checksum = "1435fa1053d8b2fbbe9be7e97eca7f33d37b28409959813daefc1446a14247f1" [[package]] name = "either" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f107b87b6afc2a64fd13cac55fe06d6c8859f12d4b14cbcdd2c67d0976781be" +checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" [[package]] name = "encoding_rs" @@ -292,11 +299,10 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" dependencies = [ - "matches", "percent-encoding", ] @@ -308,36 +314,36 @@ checksum = "85dcb89d2b10c5f6133de2efd8c11959ce9dbb46a2f7a4cab208c4eeda6ce1ab" [[package]] name = "futures-channel" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" +checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" [[package]] name = "futures-sink" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" +checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" [[package]] name = "futures-task" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" [[package]] name = "futures-util" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" dependencies = [ "futures-core", "futures-task", @@ -362,9 +368,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "h2" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" dependencies = [ "bytes", "fnv", @@ -424,9 +430,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" @@ -471,13 +477,25 @@ dependencies = [ "tokio-native-tls", ] +[[package]] +name = "iana-time-zone" +version = "0.1.50" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd911b35d940d2bd0bea0f9100068e5b97b51a1cbe13d13382f132e0365257a0" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "js-sys", + "wasm-bindgen", + "winapi", +] + [[package]] name = "idna" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" dependencies = [ - "matches", "unicode-bidi", "unicode-normalization", ] @@ -509,24 +527,24 @@ checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" [[package]] name = "itertools" -version = "0.10.3" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" +checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" dependencies = [ "either", ] [[package]] name = "itoa" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" [[package]] name = "js-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -539,9 +557,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.134" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" [[package]] name = "log" @@ -561,12 +579,6 @@ dependencies = [ "regex-automata", ] -[[package]] -name = "matches" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" - [[package]] name = "memchr" version = "2.5.0" @@ -698,15 +710,15 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" [[package]] name = "openssl" -version = "0.10.41" +version = "0.10.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" +checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" dependencies = [ "bitflags", "cfg-if", @@ -736,9 +748,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.75" +version = "0.9.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" +checksum = "5230151e44c0f05157effb743e8d517472843121cf9243e8b81393edb5acd9ce" dependencies = [ "autocfg", "cc", @@ -749,9 +761,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.2.0" +version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" +checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" [[package]] name = "output_vt100" @@ -764,9 +776,9 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pin-project-lite" @@ -818,14 +830,14 @@ dependencies = [ [[package]] name = "pretty_assertions" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89f989ac94207d048d92db058e4f6ec7342b0971fc58d1271ca148b799b3563" +checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755" dependencies = [ - "ansi_term", "ctor", "diff", "output_vt100", + "yansi", ] [[package]] @@ -854,18 +866,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.42" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b" +checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -940,9 +952,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.11" +version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" +checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" dependencies = [ "base64", "bytes", @@ -956,10 +968,10 @@ dependencies = [ "hyper-tls", "ipnet", "js-sys", - "lazy_static", "log", "mime", "native-tls", + "once_cell", "percent-encoding", "pin-project-lite", "serde", @@ -977,9 +989,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "schannel" @@ -1022,9 +1034,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.6.1" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" +checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" dependencies = [ "bitflags", "core-foundation", @@ -1045,24 +1057,24 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" [[package]] name = "serde" -version = "1.0.140" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.140" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2122636b9fe3b81f1cb25099fcf2d3f542cdb1d45940d56c713158884a05da" +checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" dependencies = [ "proc-macro2", "quote", @@ -1071,9 +1083,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ "itoa", "ryu", @@ -1112,9 +1124,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.9.0" +version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" +checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" [[package]] name = "smithy-rs-tool-common" @@ -1134,9 +1146,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.4.4" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" dependencies = [ "libc", "winapi", @@ -1150,9 +1162,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.98" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2" dependencies = [ "proc-macro2", "quote", @@ -1161,9 +1173,9 @@ dependencies = [ [[package]] name = "systemstat" -version = "0.1.11" +version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f5dc96f7634f46ac7e485b8c051f5b89ec8ee5cc023236dd12fe4ae2fb52f80" +checksum = "91a3cae256f8af5246c2daad51ff29c32de4b4b0b0222063920af445fa3e12ab" dependencies = [ "bytesize", "chrono", @@ -1204,9 +1216,9 @@ checksum = "507e9898683b6c43a9aa55b64259b721b52ba226e0f3779137e50ad114a4c90b" [[package]] name = "textwrap" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" [[package]] name = "thread_local" @@ -1234,16 +1246,15 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.20.1" +version = "1.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" dependencies = [ "autocfg", "bytes", "libc", "memchr", "mio", - "once_cell", "pin-project-lite", "socket2", "winapi", @@ -1261,9 +1272,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45" +checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" dependencies = [ "bytes", "futures-core", @@ -1291,9 +1302,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.35" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" +checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" dependencies = [ "cfg-if", "pin-project-lite", @@ -1314,9 +1325,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7" +checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" dependencies = [ "once_cell", "valuable", @@ -1365,28 +1376,27 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" [[package]] name = "unicode-normalization" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" dependencies = [ "tinyvec", ] [[package]] name = "url" -version = "2.2.2" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" dependencies = [ "form_urlencoded", "idna", - "matches", "percent-encoding", ] @@ -1426,9 +1436,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1436,9 +1446,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", @@ -1451,9 +1461,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.32" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" +checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" dependencies = [ "cfg-if", "js-sys", @@ -1463,9 +1473,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1473,9 +1483,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -1486,15 +1496,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "web-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" dependencies = [ "js-sys", "wasm-bindgen", @@ -1582,3 +1592,9 @@ checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ "winapi", ] + +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" diff --git a/tools/sdk-versioner/Cargo.lock b/tools/sdk-versioner/Cargo.lock index 80233a0aa0b..00fdd6c9973 100644 --- a/tools/sdk-versioner/Cargo.lock +++ b/tools/sdk-versioner/Cargo.lock @@ -4,33 +4,24 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "b4f55bd91a0978cbfd91c457a164bab8b4001c833b7f323132c0a4e1922dd44e" dependencies = [ "memchr", ] -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anyhow" -version = "1.0.58" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "async-trait" -version = "0.1.56" +version = "0.1.57" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96cf8829f67d2eab0b2dfa42c5d0ef737e0724e4a82b01b3e292456202b19716" +checksum = "76464446b8bc32758d7e88ee1a804d9914cd9b1cb264c029899680b0be29826f" dependencies = [ "proc-macro2", "quote", @@ -68,15 +59,15 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bumpalo" -version = "3.10.0" +version = "3.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37ccbd214614c6783386c1af30caf03192f17891059cecc394b4fb119e363de3" +checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d" [[package]] name = "bytes" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f0b3de4a0c5e67e16066a0715723abd91edc2f9001d09c46e1dca929351e130e" +checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db" [[package]] name = "cc" @@ -147,9 +138,9 @@ checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc" [[package]] name = "ctor" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f877be4f7c9f246b183111634f75baa039715e3f46ce860677d3b19a69fb229c" +checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb" dependencies = [ "quote", "syn", @@ -202,46 +193,45 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fc25a87fa4fd2094bffb06925852034d90a17f0d1e05197d4956d3555752191" +checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" dependencies = [ - "matches", "percent-encoding", ] [[package]] name = "futures-channel" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3083ce4b914124575708913bca19bfe887522d6e2e6d0952943f5eac4a74010" +checksum = "30bdd20c28fadd505d0fd6712cdfcb0d4b5648baf45faef7f852afb2399bb050" dependencies = [ "futures-core", ] [[package]] name = "futures-core" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c09fd04b7e4073ac7156a9539b57a484a8ea920f79c7c675d05d289ab6110d3" +checksum = "4e5aa3de05362c3fb88de6531e6296e85cde7739cccad4b9dfeeb7f6ebce56bf" [[package]] name = "futures-sink" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21163e139fa306126e6eedaf49ecdb4588f939600f0b1e770f4205ee4b7fa868" +checksum = "21b20ba5a92e727ba30e72834706623d94ac93a725410b6a6b6fbc1b07f7ba56" [[package]] name = "futures-task" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "57c66a976bf5909d801bbef33416c41372779507e7a6b3a5e25e4749c58f776a" +checksum = "a6508c467c73851293f390476d4491cf4d227dbabcd4170f3bb6044959b294f1" [[package]] name = "futures-util" -version = "0.3.21" +version = "0.3.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8b7abd5d659d9b90c8cba917f6ec750a74e2dc23902ef9cd4cc8c8b22e6036a" +checksum = "44fb6cb1be61cc1d2e43b262516aafcf63b241cffdb1d3fa115f91d9c7b09c90" dependencies = [ "futures-core", "futures-task", @@ -251,9 +241,9 @@ dependencies = [ [[package]] name = "h2" -version = "0.3.13" +version = "0.3.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37a82c6d637fc9515a4694bbf1cb2457b79d81ce52b3108bdeea58b07dd34a57" +checksum = "5ca32592cf21ac7ccab1825cd87f6c9b3d9022c44d086172ed0966bec8af30be" dependencies = [ "bytes", "fnv", @@ -313,9 +303,9 @@ dependencies = [ [[package]] name = "httparse" -version = "1.7.1" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "496ce29bb5a52785b44e0f7ca2847ae0bb839c9bd28f69acac9b99d461c0c04c" +checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" [[package]] name = "httpdate" @@ -362,11 +352,10 @@ dependencies = [ [[package]] name = "idna" -version = "0.2.3" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" dependencies = [ - "matches", "unicode-bidi", "unicode-normalization", ] @@ -398,15 +387,15 @@ checksum = "879d54834c8c76457ef4293a689b2a8c59b076067ad77b15efafbb05f92a592b" [[package]] name = "itoa" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" [[package]] name = "js-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "258451ab10b34f8af53416d1fdab72c22e805f0c92a1136d59470ec0b11138b2" +checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47" dependencies = [ "wasm-bindgen", ] @@ -419,9 +408,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.126" +version = "0.2.134" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "329c933548736bc49fd575ee68c89e8be4d260064184389a5b77517cddd99ffb" [[package]] name = "log" @@ -432,12 +421,6 @@ dependencies = [ "cfg-if", ] -[[package]] -name = "matches" -version = "0.1.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3e378b66a060d48947b590737b30a1be76706c8dd7b8ba0f2fe3989c68a853f" - [[package]] name = "memchr" version = "2.5.0" @@ -482,15 +465,15 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" [[package]] name = "openssl" -version = "0.10.41" +version = "0.10.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "618febf65336490dfcf20b73f885f5651a0c89c64c2d4a8c3662585a70bf5bd0" +checksum = "12fc0523e3bd51a692c8850d075d74dc062ccf251c0110668cbd921917118a13" dependencies = [ "bitflags", "cfg-if", @@ -520,9 +503,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.75" +version = "0.9.76" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5f9bd0c2710541a3cda73d6f9ac4f1b240de4ae261065d309dbe73d9dceb42f" +checksum = "5230151e44c0f05157effb743e8d517472843121cf9243e8b81393edb5acd9ce" dependencies = [ "autocfg", "cc", @@ -533,9 +516,9 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.2.0" +version = "6.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "648001efe5d5c0102d8cea768e348da85d90af8ba91f0bea908f157951493cd4" +checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" [[package]] name = "output_vt100" @@ -548,9 +531,9 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4fd5641d01c8f18a23da7b6fe29298ff4b55afcccdf78973b24cf3175fee32e" +checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" [[package]] name = "pin-project-lite" @@ -572,14 +555,14 @@ checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae" [[package]] name = "pretty_assertions" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89f989ac94207d048d92db058e4f6ec7342b0971fc58d1271ca148b799b3563" +checksum = "a25e9bcb20aa780fd0bb16b72403a9064d6b3f22f026946029acb941a50af755" dependencies = [ - "ansi_term", "ctor", "diff", "output_vt100", + "yansi", ] [[package]] @@ -608,18 +591,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.42" +version = "1.0.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b" +checksum = "94e2ef8dbfc347b10c094890f778ee2e36ca9bb4262e86dc99cd217e35f3470b" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.20" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] @@ -661,9 +644,9 @@ dependencies = [ [[package]] name = "reqwest" -version = "0.11.11" +version = "0.11.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b75aa69a3f06bbcc66ede33af2af253c6f7a86b1ca0033f60c580a27074fbf92" +checksum = "431949c384f4e2ae07605ccaa56d1d9d2ecdb5cadd4f9577ccfab29f2e5149fc" dependencies = [ "base64", "bytes", @@ -677,10 +660,10 @@ dependencies = [ "hyper-tls", "ipnet", "js-sys", - "lazy_static", "log", "mime", "native-tls", + "once_cell", "percent-encoding", "pin-project-lite", "serde", @@ -698,9 +681,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "schannel" @@ -726,9 +709,9 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.6.1" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dc14f172faf8a0194a3aded622712b0de276821addc574fa54fc0a1167e10dc" +checksum = "2bc1bb97804af6631813c55739f771071e0f2ed33ee20b68c86ec505d906356c" dependencies = [ "bitflags", "core-foundation", @@ -749,24 +732,24 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.12" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2333e6df6d6598f2b1974829f853c2b4c5f4a6e503c10af918081aa6f8564e1" +checksum = "e25dfac463d778e353db5be2449d1cce89bd6fd23c9f1ea21310ce6e5a1b29c4" [[package]] name = "serde" -version = "1.0.140" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03" +checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.140" +version = "1.0.145" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f2122636b9fe3b81f1cb25099fcf2d3f542cdb1d45940d56c713158884a05da" +checksum = "81fa1584d3d1bcacd84c277a0dfe21f5b0f6accf4a23d04d4c6d61f1af522b4c" dependencies = [ "proc-macro2", "quote", @@ -775,9 +758,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82c2c1fdcd807d1098552c5b9a36e425e42e9fbd7c6a37a8425f390f781f7fa7" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ "itoa", "ryu", @@ -823,9 +806,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.4.4" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66d72b759436ae32898a2af0a14218dbf55efde3feeb170eb623637db85ee1e0" +checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd" dependencies = [ "libc", "winapi", @@ -839,9 +822,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.98" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +checksum = "e90cde112c4b9690b8cbe810cba9ddd8bc1d7472e2cae317b69e9438c1cba7d2" dependencies = [ "proc-macro2", "quote", @@ -873,9 +856,9 @@ dependencies = [ [[package]] name = "textwrap" -version = "0.15.0" +version = "0.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" +checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" [[package]] name = "tinyvec" @@ -894,16 +877,15 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c" [[package]] name = "tokio" -version = "1.20.1" +version = "1.21.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581" +checksum = "a9e03c497dc955702ba729190dc4aac6f2a0ce97f913e5b1b5912fc5039d9099" dependencies = [ "autocfg", "bytes", "libc", "memchr", "mio", - "once_cell", "pin-project-lite", "socket2", "winapi", @@ -921,9 +903,9 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc463cd8deddc3770d20f9852143d50bf6094e640b485cb2e189a2099085ff45" +checksum = "0bb2e075f03b3d66d8d8785356224ba688d2906a371015e225beeb65ca92c740" dependencies = [ "bytes", "futures-core", @@ -951,9 +933,9 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.35" +version = "0.1.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a400e31aa60b9d44a52a8ee0343b5b18566b03a8321e0d321f695cf56e940160" +checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" dependencies = [ "cfg-if", "pin-project-lite", @@ -974,9 +956,9 @@ dependencies = [ [[package]] name = "tracing-core" -version = "0.1.28" +version = "0.1.29" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b7358be39f2f274f322d2aaed611acc57f382e8eb1e5b48cb9ae30933495ce7" +checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" dependencies = [ "once_cell", ] @@ -995,28 +977,27 @@ checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" [[package]] name = "unicode-ident" -version = "1.0.2" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" [[package]] name = "unicode-normalization" -version = "0.1.21" +version = "0.1.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "854cbdc4f7bc6ae19c820d44abdc3277ac3e1b2b93db20a636825d9322fb60e6" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" dependencies = [ "tinyvec", ] [[package]] name = "url" -version = "2.2.2" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507c383b2d33b5fc35d1861e77e6b383d158b2da5e14fe51b83dfedf6fd578c" +checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" dependencies = [ "form_urlencoded", "idna", - "matches", "percent-encoding", ] @@ -1050,9 +1031,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc7652e3f6c4706c8d9cd54832c4a4ccb9b5336e2c3bd154d5cccfbf1c1f5f7d" +checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268" dependencies = [ "cfg-if", "wasm-bindgen-macro", @@ -1060,9 +1041,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "662cd44805586bd52971b9586b1df85cdbbd9112e4ef4d8f41559c334dc6ac3f" +checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142" dependencies = [ "bumpalo", "log", @@ -1075,9 +1056,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.32" +version = "0.4.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa76fb221a1f8acddf5b54ace85912606980ad661ac7a503b4570ffd3a624dad" +checksum = "23639446165ca5a5de86ae1d8896b737ae80319560fbaa4c2887b7da6e7ebd7d" dependencies = [ "cfg-if", "js-sys", @@ -1087,9 +1068,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602" +checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -1097,9 +1078,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da" +checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c" dependencies = [ "proc-macro2", "quote", @@ -1110,15 +1091,15 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.82" +version = "0.2.83" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6598dd0bd3c7d51095ff6531a5b23e02acdc81804e30d8f07afb77b7215a140a" +checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f" [[package]] name = "web-sys" -version = "0.3.59" +version = "0.3.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed055ab27f941423197eb86b2035720b1a3ce40504df082cac2ecc6ed73335a1" +checksum = "bcda906d8be16e728fd5adc5b729afad4e444e106ab28cd1c7256e54fa61510f" dependencies = [ "js-sys", "wasm-bindgen", @@ -1206,3 +1187,9 @@ checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" dependencies = [ "winapi", ] + +[[package]] +name = "yansi" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" From 6322569ea7e1f0a43e380b859c1cfabfcab92a5d Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Tue, 4 Oct 2022 16:14:35 -0700 Subject: [PATCH 17/57] Add GitHub Action to update `aws-sdk-rust/next` branch (#1774) --- .github/workflows/update-sdk-next.yml | 55 +++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/update-sdk-next.yml diff --git a/.github/workflows/update-sdk-next.yml b/.github/workflows/update-sdk-next.yml new file mode 100644 index 00000000000..e21b6433fd4 --- /dev/null +++ b/.github/workflows/update-sdk-next.yml @@ -0,0 +1,55 @@ +# This workflow updates the `next` branch with freshly generated +# code from the latest smithy-rs and models that reside in aws-sdk-rust. +name: Update `aws-sdk-rust/next` +on: + workflow_dispatch: + +jobs: + update-next: + name: Update `next` + runs-on: ubuntu-latest + steps: + - name: Check out `smithy-rs` + uses: actions/checkout@v3 + with: + repository: awslabs/smithy-rs + ref: main + path: smithy-rs + - name: Check out `aws-sdk-rust` + uses: actions/checkout@v3 + with: + repository: awslabs/aws-sdk-rust + ref: main + path: aws-sdk-rust + token: ${{ secrets.RELEASE_AUTOMATION_BOT_PAT }} + - name: Set up JDK + uses: actions/setup-java@v1 + with: + java-version: 11 + # Rust is only used to `rustfmt` the generated code; doesn't need to match MSRV + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - name: Delete old SDK + run: | + - name: Generate a fresh SDK + run: | + WORKSPACE="$(pwd)" + cd smithy-rs + ./gradlew aws:sdk:assemble --info -Paws.sdk.models.path="${WORKSPACE}/aws-sdk-rust/aws-models" + - name: Update `aws-sdk-rust/next` + run: | + set -eux + cd aws-sdk-rust + git checkout origin/main -b next + + # Delete the old SDK + rm -rf sdk examples + rm -f versions.toml Cargo.toml index.md + + # Copy in the new SDK + mv ../smithy-rs/aws/sdk/build/aws-sdk/* . + git add . + git -c 'user.name=AWS SDK Rust Bot' -c 'user.email=aws-sdk-rust-primary@amazon.com' commit -m 'Update `aws-sdk-rust/next`' --allow-empty + git push origin next:next --force From 4ba6063f259333d19b13759c2ff4e42d44ec7627 Mon Sep 17 00:00:00 2001 From: david-perez Date: Wed, 5 Oct 2022 13:49:06 +0200 Subject: [PATCH 18/57] =?UTF-8?q?Move=20all=20binaries=20in=20the=20Pok?= =?UTF-8?q?=C3=A9mon=20service=20example=20under=20`src/bin`=20(#1788)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We're currently being inconsistent in that only the TLS example is under `src/bin`, but the other two are under `src/`. --- .../examples/pokemon-service/Cargo.toml | 18 ++++++++++-------- .../pokemon-service-lambda.rs} | 0 .../src/{main.rs => bin/pokemon-service.rs} | 0 3 files changed, 10 insertions(+), 8 deletions(-) rename rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/{lambda.rs => bin/pokemon-service-lambda.rs} (100%) rename rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/{main.rs => bin/pokemon-service.rs} (100%) diff --git a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/Cargo.toml b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/Cargo.toml index 81821cd46d5..82162950a1e 100644 --- a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/Cargo.toml +++ b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/Cargo.toml @@ -8,22 +8,21 @@ description = "A smithy Rust service to retrieve information about Pokémon." default-run = "pokemon-service" [[bin]] -name = "pokemon-service-tls" -path = "src/bin/pokemon-service-tls.rs" +name = "pokemon-service" +path = "src/bin/pokemon-service.rs" [[bin]] -name = "pokemon-service" -path = "src/main.rs" +name = "pokemon-service-tls" +path = "src/bin/pokemon-service-tls.rs" [[bin]] name = "pokemon-service-lambda" -path = "src/lambda.rs" +path = "src/bin/pokemon-service-lambda.rs" [dependencies] async-stream = "0.3" clap = { version = "~3.2.1", features = ["derive"] } hyper = {version = "0.14.12", features = ["server"] } -lambda_http = "0.6.0" rand = "0.8" tokio = "1.20.1" tower = "0.4" @@ -31,12 +30,15 @@ tower-http = { version = "0.3", features = ["trace"] } tracing = "0.1" tracing-subscriber = { version = "0.3.15", features = ["env-filter"] } -# These dependencies are only required for `pokemon-service-tls`. +# These dependencies are only required for the `pokemon-service-tls` program. tls-listener = { version = "0.5.1", features = ["rustls", "hyper-h2"] } tokio-rustls = "0.23.4" rustls-pemfile = "1.0.1" futures-util = "0.3" +# This dependency is only required for the `pokemon-service-lambda` program. +lambda_http = "0.6.0" + # Local paths aws-smithy-http-server = { path = "../../" } pokemon-service-server-sdk = { path = "../pokemon-service-server-sdk/" } @@ -47,7 +49,7 @@ home = "0.5" serial_test = "0.7.0" wrk-api-bench = "0.0.7" -# These dependencies are only required for testing `pokemon-service-tls`. +# This dependency is only required for testing the `pokemon-service-tls` program. hyper-rustls = { version = "0.23.0", features = ["http2"] } # Local paths diff --git a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lambda.rs b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/bin/pokemon-service-lambda.rs similarity index 100% rename from rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lambda.rs rename to rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/bin/pokemon-service-lambda.rs diff --git a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/main.rs b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/bin/pokemon-service.rs similarity index 100% rename from rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/main.rs rename to rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/bin/pokemon-service.rs From d953a4466fe2d5737dc01685bbe78ca7026f8e14 Mon Sep 17 00:00:00 2001 From: Harry Barber <106155934+hlbarber@users.noreply.github.com> Date: Wed, 5 Oct 2022 18:10:43 +0100 Subject: [PATCH 19/57] Add Server section to the Book (#1813) * Move docs to server folder * Index the Server folder * Fix markdown lints * Add basic overview.md to server folder --- design/src/SUMMARY.md | 16 ++++-- .../src/{docs => server}/code_generation.md | 6 +-- .../src/{docs => server}/instrumentation.md | 0 design/src/server/overview.md | 7 +++ .../src/{docs => server}/pokemon_service.md | 52 +++++++++---------- 5 files changed, 47 insertions(+), 34 deletions(-) rename design/src/{docs => server}/code_generation.md (99%) rename design/src/{docs => server}/instrumentation.md (100%) create mode 100644 design/src/server/overview.md rename design/src/{docs => server}/pokemon_service.md (89%) diff --git a/design/src/SUMMARY.md b/design/src/SUMMARY.md index 4e4fd2f7eba..f104234efc6 100644 --- a/design/src/SUMMARY.md +++ b/design/src/SUMMARY.md @@ -1,4 +1,5 @@ # Summary + - [Design Overview](./overview.md) - [Tenets](./tenets.md) - [Design FAQ](./faq.md) @@ -7,11 +8,16 @@ - [HTTP Middleware](transport/middleware.md) - [Smithy](./smithy/overview.md) - - [Simple Shapes](./smithy/simple_shapes.md) - - [Recursive Shapes](./smithy/recursive_shapes.md) - - [Aggregate Shapes](./smithy/aggregate_shapes.md) - - [Endpoint Resolution](smithy/endpoint.md) - - [Backwards Compatibility](smithy/backwards-compat.md) + - [Simple Shapes](./smithy/simple_shapes.md) + - [Recursive Shapes](./smithy/recursive_shapes.md) + - [Aggregate Shapes](./smithy/aggregate_shapes.md) + - [Endpoint Resolution](smithy/endpoint.md) + - [Backwards Compatibility](smithy/backwards-compat.md) + +- [Server](./server/overview.md) + - [Generating Common Service Code](./server/code_generation.md) + - [Generating the Pokémon Service](./server/pokemon_service.md) + - [Instrumentation](./server/instrumentation.md) - [RFCs](./rfcs/overview.md) - [RFC-0001: Sharing configuration between multiple clients](./rfcs/rfc0001_shared_config.md) diff --git a/design/src/docs/code_generation.md b/design/src/server/code_generation.md similarity index 99% rename from design/src/docs/code_generation.md rename to design/src/server/code_generation.md index f0a8bd3793c..20da6c46c61 100644 --- a/design/src/docs/code_generation.md +++ b/design/src/server/code_generation.md @@ -1,9 +1,9 @@ -## Generating common service code +# Generating Common Service Code How a service is constructed and how to plug in new business logic is described in [Pokémon Service][1]. This document introduces the project and how code is being generated. It is written for developers who want to start contributing to `smithy-rs`. -### Folder structure +## Folder structure The project is divided in: @@ -15,7 +15,7 @@ which contains common functions used by other crates, [copied into][2] the sourc `/rust-runtime` crates ("runtime crates") are added to a crate's dependency only when used. If a model uses event streams, it will depend on [`aws-smithy-eventstream`][3]. -### Generating code +## Generating code `smithy-rs`'s entry points are Smithy code-generation plugins, and is not a command. One entry point is in [RustCodegenPlugin::execute][4] and inherits from `SmithyBuildPlugin` in [smithy-build][5]. Code generation is in Kotlin and shared common, non-Rust specific code with the [`smithy` Java repository][6]. They plug into the [Smithy gradle][7] plugin, which is a gradle plugin. diff --git a/design/src/docs/instrumentation.md b/design/src/server/instrumentation.md similarity index 100% rename from design/src/docs/instrumentation.md rename to design/src/server/instrumentation.md diff --git a/design/src/server/overview.md b/design/src/server/overview.md new file mode 100644 index 00000000000..2b023112c5a --- /dev/null +++ b/design/src/server/overview.md @@ -0,0 +1,7 @@ +# Smithy Server + +Smithy Rust provides the ability to generate a server whose operations are provided by the customer. + +- [Generating Common Service Code](./code_generation.md) +- [Generating the Pokémon Service](./pokemon_service.md) +- [Instrumentation](./instrumentation.md) diff --git a/design/src/docs/pokemon_service.md b/design/src/server/pokemon_service.md similarity index 89% rename from design/src/docs/pokemon_service.md rename to design/src/server/pokemon_service.md index d1209696b6d..6842bcf5c4c 100644 --- a/design/src/docs/pokemon_service.md +++ b/design/src/server/pokemon_service.md @@ -1,4 +1,4 @@ -## Code generating the Pokémon Service +# Generating the Pokémon Service This is an overview of client and server of the Pokémon service. It introduces: @@ -10,7 +10,7 @@ All the code shown and linked to is from the repository at this commit: [db48039 The Smithy model used to generate the code snippets is: [Pokémon][2] -### Building the service +## Building the service The entry point of a service is [main.rs][3] @@ -59,37 +59,37 @@ let app: Router = OperationRegistryBuilder::default() Each of these operations is a function that can take any of these signatures. -1. If the operation is not fallible and does not share any state: +1. If the operation is not fallible and does not share any state: -```rust -pub async fn health_check_operation(_input: input::HealthCheckOperationInput) -> output::HealthCheckOperationOutput {...} -``` + ```rust + pub async fn health_check_operation(_input: input::HealthCheckOperationInput) -> output::HealthCheckOperationOutput {...} + ``` -2. If the operation is fallible and does not share any state: +2. If the operation is fallible and does not share any state: -```rust -pub async fn capture_pokemon( - mut input: input::CapturePokemonOperationInput, -) -> Result {...} -``` + ```rust + pub async fn capture_pokemon( + mut input: input::CapturePokemonOperationInput, + ) -> Result {...} + ``` -3. If the operation is not fallible and shares some state: +3. If the operation is not fallible and shares some state: -```rust -pub async fn get_server_statistics( - _input: input::GetServerStatisticsInput, - state: Extension>, -) -> output::GetServerStatisticsOutput {...} -``` + ```rust + pub async fn get_server_statistics( + _input: input::GetServerStatisticsInput, + state: Extension>, + ) -> output::GetServerStatisticsOutput {...} + ``` -4. If the operation is fallible and shares some state: +4. If the operation is fallible and shares some state: -```rust -pub async fn get_storage( - input: input::GetStorageInput, - _state: Extension>, -) -> Result {...} -``` + ```rust + pub async fn get_storage( + input: input::GetStorageInput, + _state: Extension>, + ) -> Result {...} + ``` All of these are operations which implementors define; they are the business logic of the application. The rest is code generated. From 1b2b42d6aed42caacdbd1281ea531e5ce913164c Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Thu, 6 Oct 2022 10:17:47 +0100 Subject: [PATCH 20/57] Support 32bits targets (#1811) * Replace AtomicU64 with AtomicUsize to prevent compilation issues on 32 bits platforms. * Make sure that Rust tests compile on MacOS. * Add CHANGELOG next entry. --- CHANGELOG.next.toml | 16 ++++++++++++++++ rust-runtime/aws-smithy-client/src/never.rs | 6 +++--- .../aws-smithy-http-server-python/src/socket.rs | 8 ++++++++ .../examples/pokemon-service/src/lib.rs | 4 ++-- 4 files changed, 29 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 18d9fa6ff17..60a2386ebf4 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -11,6 +11,22 @@ # meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"} # author = "rcoh" +[[smithy-rs]] +message = """ +Replace all usages of `AtomicU64` with `AtomicUsize` to support 32bit targets. +""" +references = ["smithy-rs#1811"] +meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "server"} +author = "LukeMathWalker" + +[[smithy-rs]] +message = """ +Replace all usages of `AtomicU64` with `AtomicUsize` to support 32bit targets. +""" +references = ["smithy-rs#1811"] +meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client"} +author = "LukeMathWalker" + [[smithy-rs]] message = """ Mark `operation` and `operation_handler` modules as private in the generated server crate. diff --git a/rust-runtime/aws-smithy-client/src/never.rs b/rust-runtime/aws-smithy-client/src/never.rs index 57d3f288a0d..7989800d6bd 100644 --- a/rust-runtime/aws-smithy-client/src/never.rs +++ b/rust-runtime/aws-smithy-client/src/never.rs @@ -10,7 +10,7 @@ use http::Uri; use aws_smithy_async::future::never::Never; use std::marker::PhantomData; -use std::sync::atomic::{AtomicU64, Ordering}; +use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; use std::task::{Context, Poll}; @@ -27,7 +27,7 @@ use tower::BoxError; #[derive(Debug)] pub struct NeverService { _resp: PhantomData<(Req, Resp, Err)>, - invocations: Arc, + invocations: Arc, } impl Clone for NeverService { @@ -55,7 +55,7 @@ impl NeverService { } /// Returns the number of invocations made to this service - pub fn num_calls(&self) -> u64 { + pub fn num_calls(&self) -> usize { self.invocations.load(Ordering::SeqCst) } } diff --git a/rust-runtime/aws-smithy-http-server-python/src/socket.rs b/rust-runtime/aws-smithy-http-server-python/src/socket.rs index 5922c5920db..df0e151078f 100644 --- a/rust-runtime/aws-smithy-http-server-python/src/socket.rs +++ b/rust-runtime/aws-smithy-http-server-python/src/socket.rs @@ -73,6 +73,14 @@ impl PySocket { } #[cfg(test)] +// `is_listener` on `Socket` is only available on certain platforms. +// In particular, this fails to compile on MacOS. +#[cfg(any( + target_os = "android", + target_os = "freebsd", + target_os = "fuchsia", + target_os = "linux", +))] mod tests { use super::*; diff --git a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lib.rs b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lib.rs index 93213f73bf5..b309d49cd8a 100644 --- a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lib.rs +++ b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/lib.rs @@ -10,7 +10,7 @@ use std::{ collections::HashMap, convert::TryInto, - sync::{atomic::AtomicU64, Arc}, + sync::{atomic::AtomicUsize, Arc}, }; use async_stream::stream; @@ -108,7 +108,7 @@ struct PokemonTranslations { #[derive(Debug)] pub struct State { pokemons_translations: HashMap, - call_count: AtomicU64, + call_count: AtomicUsize, } impl Default for State { From e78da5598a2d94d23fd18e30492a20ce3603f844 Mon Sep 17 00:00:00 2001 From: Kevin Park Date: Thu, 6 Oct 2022 20:10:14 -0400 Subject: [PATCH 21/57] Fix regression: Use `connect_timeout` and `read_timeout` again (#1822) (#1823) --- CHANGELOG.next.toml | 6 ++++++ aws/rust-runtime/aws-config/src/imds/client.rs | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 60a2386ebf4..02caa3a3502 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -125,3 +125,9 @@ message = "The client Config now has getters for every value that it holds." references = ["smithy-rs#1747"] meta = { "breaking" = false, "tada" = false, "bug" = true } author = "kastolars" + +[[aws-sdk-rust]] +message = "Fix regression where `connect_timeout` and `read_timeout` fields are unused in the IMDS client" +references = ["smithy-rs#1822"] +meta = { "breaking" = false, "tada" = false, "bug" = true } +author = "kevinpark1217" diff --git a/aws/rust-runtime/aws-config/src/imds/client.rs b/aws/rust-runtime/aws-config/src/imds/client.rs index 10e6d419abf..f853e7bc909 100644 --- a/aws/rust-runtime/aws-config/src/imds/client.rs +++ b/aws/rust-runtime/aws-config/src/imds/client.rs @@ -556,8 +556,8 @@ impl Builder { pub async fn build(self) -> Result { let config = self.config.unwrap_or_default(); let timeout_config = TimeoutConfig::builder() - .connect_timeout(DEFAULT_CONNECT_TIMEOUT) - .read_timeout(DEFAULT_READ_TIMEOUT) + .connect_timeout(self.connect_timeout.unwrap_or(DEFAULT_CONNECT_TIMEOUT)) + .read_timeout(self.read_timeout.unwrap_or(DEFAULT_READ_TIMEOUT)) .build(); let connector_settings = ConnectorSettings::from_timeout_config(&timeout_config); let connector = expect_connector(config.connector(&connector_settings)); From 238cf8b434107e82c86d9d4d4c3b51d8cb00872f Mon Sep 17 00:00:00 2001 From: Julian Antonielli Date: Fri, 7 Oct 2022 14:44:11 +0100 Subject: [PATCH 22/57] Fix @sensitive handling in Display implementations on error shapes (#1802) * Use `Sensitive` wrapper in Debug impl for structures * Fix using the wrong import path for `Sensitive` * Use redactMemberIfNecessary * Fix display implementation on errors to respect @sensitive trait * Don't use Sensitive type just yet * Add entry in changelog * Improve redaction of sensitive error message * Use correct flags in changelog * Run ktlint --- CHANGELOG.next.toml | 8 +++++++- .../smithy/generators/StructureGenerator.kt | 3 ++- .../smithy/generators/error/ErrorGenerator.kt | 12 ++++++++++-- .../smithy/rust/codegen/core/util/Smithy.kt | 19 ++++++++++++------- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 02caa3a3502..ae179af55e0 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -36,6 +36,12 @@ references = ["smithy-rs#1803"] meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server"} author = "LukeMathWalker" +[[smithy-rs]] +message = "Sensitive fields in errors now respect @sensitive trait and are properly redacted." +references = ["smithy-rs#1802"] +meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "all" } +author = "jjant" + [[smithy-rs]] message = "Pokémon Service example code now runs clippy during build." references = ["smithy-rs#1727"] @@ -117,7 +123,7 @@ author = "jdisanti" [[smithy-rs]] message = "Paginators now stop on encountering a duplicate token by default rather than panic. This behavior can be customized by toggling the `stop_on_duplicate_token` property on the paginator before calling `send`." references = ["aws-sdk-rust#620", "smithy-rs#1748"] -meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "client"} +meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "client" } author = "jdisanti" [[aws-sdk-rust]] diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt index 5bf6e0a6b88..f216f236d47 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt @@ -63,7 +63,7 @@ open class StructureGenerator( fun render(forWhom: CodegenTarget = CodegenTarget.CLIENT) { renderStructure() errorTrait?.also { errorTrait -> - ErrorGenerator(symbolProvider, writer, shape, errorTrait).render(forWhom) + ErrorGenerator(model, symbolProvider, writer, shape, errorTrait).render(forWhom) } } @@ -109,6 +109,7 @@ open class StructureGenerator( members.forEach { member -> val memberName = symbolProvider.toMemberName(member) val fieldValue = member.redactIfNecessary(model, "self.$memberName") + rust( "formatter.field(${memberName.dq()}, &$fieldValue);", ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ErrorGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ErrorGenerator.kt index 8f9382b5acc..07f9315b858 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ErrorGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/ErrorGenerator.kt @@ -5,6 +5,7 @@ package software.amazon.smithy.rust.codegen.core.smithy.generators.error +import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.traits.ErrorTrait import software.amazon.smithy.model.traits.RetryableTrait @@ -19,10 +20,12 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType.Companion.StdError import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.isOptional +import software.amazon.smithy.rust.codegen.core.util.REDACTION import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.errorMessageMember import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.letIf +import software.amazon.smithy.rust.codegen.core.util.shouldRedact sealed class ErrorKind { abstract fun writable(runtimeConfig: RuntimeConfig): Writable @@ -60,6 +63,7 @@ fun StructureShape.modeledRetryKind(errorTrait: ErrorTrait): ErrorKind? { } class ErrorGenerator( + private val model: Model, private val symbolProvider: RustSymbolProvider, private val writer: RustWriter, private val shape: StructureShape, @@ -118,8 +122,12 @@ class ErrorGenerator( } write("write!(f, ${errorDesc.dq()})?;") messageShape?.let { - ifSet(it, symbolProvider.toSymbol(it), "&self.message") { field -> - write("""write!(f, ": {}", $field)?;""") + if (it.shouldRedact(model)) { + write("""write!(f, ": {}", $REDACTION)?;""") + } else { + ifSet(it, symbolProvider.toSymbol(it), "&self.message") { field -> + write("""write!(f, ": {}", $field)?;""") + } } } write("Ok(())") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/util/Smithy.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/util/Smithy.kt index 448107af0c8..291dd30e313 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/util/Smithy.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/util/Smithy.kt @@ -84,14 +84,19 @@ fun ServiceShape.hasEventStreamOperations(model: Model): Boolean = operations.an model.expectShape(id, OperationShape::class.java).isEventStream(model) } -fun Shape.redactIfNecessary(model: Model, safeToPrint: String): String = +fun Shape.shouldRedact(model: Model): Boolean = when (this) { - is MemberShape -> model.expectShape(this.target).redactIfNecessary(model, safeToPrint) - else -> if (this.hasTrait()) { - "*** Sensitive Data Redacted ***".dq() - } else { - safeToPrint - } + is MemberShape -> model.expectShape(this.target).shouldRedact(model) + else -> this.hasTrait() + } + +const val REDACTION = "\"*** Sensitive Data Redacted ***\"" + +fun Shape.redactIfNecessary(model: Model, safeToPrint: String): String = + if (this.shouldRedact(model)) { + REDACTION + } else { + safeToPrint } /* From 78022d69efd70504c6ab539a6bd0ce1e9aedbd32 Mon Sep 17 00:00:00 2001 From: Harry Barber <106155934+hlbarber@users.noreply.github.com> Date: Mon, 10 Oct 2022 14:29:37 +0100 Subject: [PATCH 23/57] Remove Protocol enum (#1829) * Remove Protocol enum * Update Python implementation --- CHANGELOG.next.toml | 12 ++ .../generators/PythonApplicationGenerator.kt | 42 ++++-- .../PythonServerOperationHandlerGenerator.kt | 4 +- .../PythonServerServiceGenerator.kt | 4 +- .../ServerOperationHandlerGenerator.kt | 16 +-- .../generators/ServerServiceGenerator.kt | 4 +- .../protocol/ServerProtocolGenerator.kt | 3 +- .../protocol/ServerProtocolTestGenerator.kt | 3 +- .../ServerHttpBoundProtocolGenerator.kt | 39 +---- .../src/error.rs | 77 ++++++---- .../src/middleware/handler.rs | 67 ++++----- .../src/middleware/layer.rs | 67 +++------ .../src/server.rs | 3 - .../aws-smithy-http-server/src/extension.rs | 2 +- .../aws-smithy-http-server/src/protocols.rs | 9 -- .../src/runtime_error.rs | 134 +++++++++--------- 16 files changed, 226 insertions(+), 260 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index ae179af55e0..b303a4b601c 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -137,3 +137,15 @@ message = "Fix regression where `connect_timeout` and `read_timeout` fields are references = ["smithy-rs#1822"] meta = { "breaking" = false, "tada" = false, "bug" = true } author = "kevinpark1217" + +[[smithy-rs]] +message = "Remove `Protocol` enum, removing an obstruction to extending smithy to third-party protocols." +references = ["smithy-rs#1829"] +meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" } +author = "hlbarber" + +[[smithy-rs]] +message = "Convert the `protocol` argument on `PyMiddlewares::new` constructor to a type parameter." +references = ["smithy-rs#1829"] +meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" } +author = "hlbarber" diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt index 1f3e3e197a6..c032ea9102f 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt @@ -23,6 +23,7 @@ import software.amazon.smithy.rust.codegen.core.util.outputShape import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerCargoDependency import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency +import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol /** * Generates a Python compatible application and server that can be configured from Python. @@ -62,13 +63,13 @@ import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency */ class PythonApplicationGenerator( codegenContext: CodegenContext, + private val protocol: ServerProtocol, private val operations: List, ) { private val symbolProvider = codegenContext.symbolProvider private val libName = "lib${codegenContext.settings.moduleName.toSnakeCase()}" private val runtimeConfig = codegenContext.runtimeConfig private val model = codegenContext.model - private val protocol = codegenContext.protocol private val codegenScope = arrayOf( "SmithyPython" to PythonServerCargoDependency.SmithyHttpServerPython(runtimeConfig).asType(), @@ -88,6 +89,7 @@ class PythonApplicationGenerator( fun render(writer: RustWriter) { renderPyApplicationRustDocs(writer) renderAppStruct(writer) + renderAppDefault(writer) renderAppClone(writer) renderPyAppTrait(writer) renderAppImpl(writer) @@ -98,7 +100,7 @@ class PythonApplicationGenerator( writer.rustTemplate( """ ##[#{pyo3}::pyclass] - ##[derive(Debug, Default)] + ##[derive(Debug)] pub struct App { handlers: #{HashMap}, middlewares: #{SmithyPython}::PyMiddlewares, @@ -128,6 +130,25 @@ class PythonApplicationGenerator( ) } + private fun renderAppDefault(writer: RustWriter) { + writer.rustTemplate( + """ + impl Default for App { + fn default() -> Self { + Self { + handlers: Default::default(), + middlewares: #{SmithyPython}::PyMiddlewares::new::<#{Protocol}>(vec![]), + context: None, + workers: #{parking_lot}::Mutex::new(vec![]), + } + } + } + """, + "Protocol" to protocol.markerStruct(), + *codegenScope, + ) + } + private fun renderAppImpl(writer: RustWriter) { writer.rustBlockTemplate( """ @@ -165,20 +186,17 @@ class PythonApplicationGenerator( rustTemplate( """ let middleware_locals = pyo3_asyncio::TaskLocals::new(event_loop); - use #{SmithyPython}::PyApp; - let service = #{tower}::ServiceBuilder::new().layer( - #{SmithyPython}::PyMiddlewareLayer::new( - self.middlewares.clone(), - self.protocol(), - middleware_locals - )?, - ); + let service = #{tower}::ServiceBuilder::new() + .layer( + #{SmithyPython}::PyMiddlewareLayer::<#{Protocol}>::new(self.middlewares.clone(), middleware_locals), + ); let router: #{SmithyServer}::routing::Router = router .build() .expect("Unable to build operation registry") .into(); Ok(router.layer(service)) """, + "Protocol" to protocol.markerStruct(), *codegenScope, ) } @@ -186,7 +204,6 @@ class PythonApplicationGenerator( } private fun renderPyAppTrait(writer: RustWriter) { - val protocol = protocol.toString().replace("#", "##") writer.rustTemplate( """ impl #{SmithyPython}::PyApp for App { @@ -202,9 +219,6 @@ class PythonApplicationGenerator( fn middlewares(&mut self) -> &mut #{SmithyPython}::PyMiddlewares { &mut self.middlewares } - fn protocol(&self) -> &'static str { - "$protocol" - } } """, *codegenScope, diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt index 6f814d7ee3a..076a7570143 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerOperationHandlerGenerator.kt @@ -16,6 +16,7 @@ import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerCargoDependency import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency import software.amazon.smithy.rust.codegen.server.smithy.generators.ServerOperationHandlerGenerator +import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol /** * The Rust code responsible to run the Python business logic on the Python interpreter @@ -33,8 +34,9 @@ import software.amazon.smithy.rust.codegen.server.smithy.generators.ServerOperat */ class PythonServerOperationHandlerGenerator( codegenContext: CodegenContext, + protocol: ServerProtocol, private val operations: List, -) : ServerOperationHandlerGenerator(codegenContext, operations) { +) : ServerOperationHandlerGenerator(codegenContext, protocol, operations) { private val symbolProvider = codegenContext.symbolProvider private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerServiceGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerServiceGenerator.kt index ce1bf6a36f0..56e119a87e7 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerServiceGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerServiceGenerator.kt @@ -34,12 +34,12 @@ class PythonServerServiceGenerator( } override fun renderOperationHandler(writer: RustWriter, operations: List) { - PythonServerOperationHandlerGenerator(context, operations).render(writer) + PythonServerOperationHandlerGenerator(context, protocol, operations).render(writer) } override fun renderExtras(operations: List) { rustCrate.withModule(RustModule.public("python_server_application", "Python server and application implementation.")) { writer -> - PythonApplicationGenerator(context, operations) + PythonApplicationGenerator(context, protocol, operations) .render(writer) } } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt index 38e1a114095..5a3c93b2be9 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationHandlerGenerator.kt @@ -19,9 +19,9 @@ import software.amazon.smithy.rust.codegen.core.smithy.transformers.operationErr import software.amazon.smithy.rust.codegen.core.util.hasStreamingMember import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.outputShape -import software.amazon.smithy.rust.codegen.core.util.toPascalCase import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency import software.amazon.smithy.rust.codegen.server.smithy.ServerRuntimeType +import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocol import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerHttpBoundProtocolGenerator /** @@ -29,12 +29,11 @@ import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerHttpBou */ open class ServerOperationHandlerGenerator( codegenContext: CodegenContext, + val protocol: ServerProtocol, private val operations: List, ) { private val serverCrate = "aws_smithy_http_server" - private val service = codegenContext.serviceShape private val model = codegenContext.model - private val protocol = codegenContext.protocol private val symbolProvider = codegenContext.symbolProvider private val runtimeConfig = codegenContext.runtimeConfig private val codegenScope = arrayOf( @@ -83,11 +82,8 @@ open class ServerOperationHandlerGenerator( Ok(v) => v, Err(extension_not_found_rejection) => { let extension = $serverCrate::extension::RuntimeErrorExtension::new(extension_not_found_rejection.to_string()); - let runtime_error = $serverCrate::runtime_error::RuntimeError { - protocol: #{SmithyHttpServer}::protocols::Protocol::${protocol.name.toPascalCase()}, - kind: extension_not_found_rejection.into(), - }; - let mut response = runtime_error.into_response(); + let runtime_error = $serverCrate::runtime_error::RuntimeError::from(extension_not_found_rejection); + let mut response = #{SmithyHttpServer}::response::IntoResponse::<#{Protocol}>::into_response(runtime_error); response.extensions_mut().insert(extension); return response.map($serverCrate::body::boxed); } @@ -109,7 +105,8 @@ open class ServerOperationHandlerGenerator( let input_wrapper = match $inputWrapperName::from_request(&mut req).await { Ok(v) => v, Err(runtime_error) => { - return runtime_error.into_response().map($serverCrate::body::boxed); + let response = #{SmithyHttpServer}::response::IntoResponse::<#{Protocol}>::into_response(runtime_error); + return response.map($serverCrate::body::boxed); } }; $callImpl @@ -120,6 +117,7 @@ open class ServerOperationHandlerGenerator( response.map(#{SmithyHttpServer}::body::boxed) } """, + "Protocol" to protocol.markerStruct(), *codegenScope, ) } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt index a002a167ea6..2e659adc263 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt @@ -29,7 +29,7 @@ open class ServerServiceGenerator( private val rustCrate: RustCrate, private val protocolGenerator: ServerProtocolGenerator, private val protocolSupport: ProtocolSupport, - private val protocol: ServerProtocol, + val protocol: ServerProtocol, private val codegenContext: CodegenContext, ) { private val index = TopDownIndex.of(codegenContext.model) @@ -107,7 +107,7 @@ open class ServerServiceGenerator( // Render operations handler. open fun renderOperationHandler(writer: RustWriter, operations: List) { - ServerOperationHandlerGenerator(codegenContext, operations).render(writer) + ServerOperationHandlerGenerator(codegenContext, protocol, operations).render(writer) } // Render operations registry. diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolGenerator.kt index f46ade2f662..6428e8dba06 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolGenerator.kt @@ -11,11 +11,10 @@ import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.MakeOperationGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolTraitImplGenerator -import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol open class ServerProtocolGenerator( codegenContext: CodegenContext, - protocol: Protocol, + val protocol: ServerProtocol, makeOperationGenerator: MakeOperationGenerator, private val traitGenerator: ProtocolTraitImplGenerator, ) : ProtocolGenerator(codegenContext, protocol, makeOperationGenerator, traitGenerator) { diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt index 7530438afc4..f4b3bab27af 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt @@ -452,8 +452,9 @@ class ServerProtocolTestGenerator( """ let mut http_request = #{SmithyHttpServer}::request::RequestParts::new(http_request); let rejection = super::$operationName::from_request(&mut http_request).await.expect_err("request was accepted but we expected it to be rejected"); - let http_response = rejection.into_response(); + let http_response = #{SmithyHttpServer}::response::IntoResponse::<#{Protocol}>::into_response(rejection); """, + "Protocol" to protocolGenerator.protocol.markerStruct(), *codegenScope, ) checkResponse(this, testCase.response) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt index 47449ae0a5b..952a0dc73a8 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt @@ -70,7 +70,6 @@ import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.isStreaming import software.amazon.smithy.rust.codegen.core.util.outputShape -import software.amazon.smithy.rust.codegen.core.util.toPascalCase import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext @@ -177,10 +176,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( rustTemplate( """ if ! #{SmithyHttpServer}::protocols::accept_header_classifier(req, ${contentType.dq()}) { - return Err(#{RuntimeError} { - protocol: #{SmithyHttpServer}::protocols::Protocol::${codegenContext.protocol.name.toPascalCase()}, - kind: #{SmithyHttpServer}::runtime_error::RuntimeErrorKind::NotAcceptable, - }) + return Err(#{RuntimeError}::NotAcceptable) } """, *codegenScope, @@ -200,10 +196,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( rustTemplate( """ if #{SmithyHttpServer}::protocols::content_type_header_classifier(req, $expectedRequestContentType).is_err() { - return Err(#{RuntimeError} { - protocol: #{SmithyHttpServer}::protocols::Protocol::${codegenContext.protocol.name.toPascalCase()}, - kind: #{SmithyHttpServer}::runtime_error::RuntimeErrorKind::UnsupportedMediaType, - }) + return Err(#{RuntimeError}::UnsupportedMediaType) } """, *codegenScope, @@ -230,12 +223,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( #{parse_request}(req) .await .map($inputName) - .map_err( - |err| #{RuntimeError} { - protocol: #{SmithyHttpServer}::protocols::Protocol::${codegenContext.protocol.name.toPascalCase()}, - kind: err.into() - } - ) + .map_err(Into::into) } } @@ -282,12 +270,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( Self::Output(o) => { match #{serialize_response}(o) { Ok(response) => response, - Err(e) => { - #{RuntimeError} { - protocol: #{SmithyHttpServer}::protocols::Protocol::${codegenContext.protocol.name.toPascalCase()}, - kind: e.into() - }.into_response() - } + Err(e) => #{SmithyHttpServer}::response::IntoResponse::<#{Marker}>::into_response(#{RuntimeError}::from(e)) } }, Self::Error(err) => { @@ -296,12 +279,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( response.extensions_mut().insert(#{SmithyHttpServer}::extension::ModeledErrorExtension::new(err.name())); response }, - Err(e) => { - #{RuntimeError} { - protocol: #{SmithyHttpServer}::protocols::Protocol::${codegenContext.protocol.name.toPascalCase()}, - kind: e.into() - }.into_response() - } + Err(e) => #{SmithyHttpServer}::response::IntoResponse::<#{Marker}>::into_response(#{RuntimeError}::from(e)) } } } @@ -346,12 +324,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( """ match #{serialize_response}(self.0) { Ok(response) => response, - Err(e) => { - #{RuntimeError} { - protocol: #{SmithyHttpServer}::protocols::Protocol::${codegenContext.protocol.name.toPascalCase()}, - kind: e.into() - }.into_response() - } + Err(e) => #{SmithyHttpServer}::response::IntoResponse::<#{Marker}>::into_response(#{RuntimeError}::from(e)) } """.trimIndent() diff --git a/rust-runtime/aws-smithy-http-server-python/src/error.rs b/rust-runtime/aws-smithy-http-server-python/src/error.rs index 519e75501a6..a6396fa969d 100644 --- a/rust-runtime/aws-smithy-http-server-python/src/error.rs +++ b/rust-runtime/aws-smithy-http-server-python/src/error.rs @@ -5,8 +5,14 @@ //! Python error definition. -use aws_smithy_http_server::protocols::Protocol; -use aws_smithy_http_server::{body::to_boxed, response::Response}; +use aws_smithy_http_server::{ + body::{to_boxed, BoxBody}, + proto::{ + aws_json_10::AwsJson10, aws_json_11::AwsJson11, rest_json_1::AwsRestJson1, + rest_xml::AwsRestXml, + }, + response::IntoResponse, +}; use aws_smithy_types::date_time::{ConversionError, DateTimeParseError}; use pyo3::{create_exception, exceptions::PyException as BasePyException, prelude::*, PyErr}; use thiserror::Error; @@ -62,39 +68,50 @@ impl From for PyMiddlewareException { } } -impl PyMiddlewareException { - /// Convert the exception into a [Response], following the [Protocol] specification. - pub(crate) fn into_response(self, protocol: Protocol) -> Response { - let body = to_boxed(match protocol { - Protocol::RestJson1 => self.json_body(), - Protocol::RestXml => self.xml_body(), - // See https://awslabs.github.io/smithy/1.0/spec/aws/aws-json-1_0-protocol.html#empty-body-serialization - Protocol::AwsJson10 => self.json_body(), - // See https://awslabs.github.io/smithy/1.0/spec/aws/aws-json-1_1-protocol.html#empty-body-serialization - Protocol::AwsJson11 => self.json_body(), - }); +impl IntoResponse for PyMiddlewareException { + fn into_response(self) -> http::Response { + http::Response::builder() + .status(self.status_code) + .header("Content-Type", "application/json") + .header("X-Amzn-Errortype", "MiddlewareException") + .body(to_boxed(self.json_body())) + .expect("invalid HTTP response for `MiddlewareException`; please file a bug report under https://github.com/awslabs/smithy-rs/issues") + } +} - let mut builder = http::Response::builder(); - builder = builder.status(self.status_code); +impl IntoResponse for PyMiddlewareException { + fn into_response(self) -> http::Response { + http::Response::builder() + .status(self.status_code) + .header("Content-Type", "application/xml") + .body(to_boxed(self.xml_body())) + .expect("invalid HTTP response for `MiddlewareException`; please file a bug report under https://github.com/awslabs/smithy-rs/issues") + } +} - match protocol { - Protocol::RestJson1 => { - builder = builder - .header("Content-Type", "application/json") - .header("X-Amzn-Errortype", "MiddlewareException"); - } - Protocol::RestXml => builder = builder.header("Content-Type", "application/xml"), - Protocol::AwsJson10 => { - builder = builder.header("Content-Type", "application/x-amz-json-1.0") - } - Protocol::AwsJson11 => { - builder = builder.header("Content-Type", "application/x-amz-json-1.1") - } - } +impl IntoResponse for PyMiddlewareException { + fn into_response(self) -> http::Response { + http::Response::builder() + .status(self.status_code) + .header("Content-Type", "application/x-amz-json-1.0") + // See https://awslabs.github.io/smithy/1.0/spec/aws/aws-json-1_0-protocol.html#empty-body-serialization + .body(to_boxed(self.json_body())) + .expect("invalid HTTP response for `MiddlewareException`; please file a bug report under https://github.com/awslabs/smithy-rs/issues") + } +} - builder.body(body).expect("invalid HTTP response for `MiddlewareException`; please file a bug report under https://github.com/awslabs/smithy-rs/issues") +impl IntoResponse for PyMiddlewareException { + fn into_response(self) -> http::Response { + http::Response::builder() + .status(self.status_code) + .header("Content-Type", "application/x-amz-json-1.1") + // See https://awslabs.github.io/smithy/1.0/spec/aws/aws-json-1_1-protocol.html#empty-body-serialization + .body(to_boxed(self.json_body())) + .expect("invalid HTTP response for `MiddlewareException`; please file a bug report under https://github.com/awslabs/smithy-rs/issues") } +} +impl PyMiddlewareException { /// Serialize the body into a JSON object. fn json_body(&self) -> String { let mut out = String::new(); diff --git a/rust-runtime/aws-smithy-http-server-python/src/middleware/handler.rs b/rust-runtime/aws-smithy-http-server-python/src/middleware/handler.rs index 00f99312e85..20a4104925e 100644 --- a/rust-runtime/aws-smithy-http-server-python/src/middleware/handler.rs +++ b/rust-runtime/aws-smithy-http-server-python/src/middleware/handler.rs @@ -4,11 +4,10 @@ */ //! Execute Python middleware handlers. -use aws_smithy_http_server::body::Body; +use aws_smithy_http_server::{body::Body, body::BoxBody, response::IntoResponse}; use http::Request; use pyo3::prelude::*; -use aws_smithy_http_server::protocols::Protocol; use pyo3_asyncio::TaskLocals; use crate::{PyMiddlewareException, PyRequest, PyResponse}; @@ -36,18 +35,27 @@ pub struct PyMiddlewareHandler { /// Structure holding the list of Python middlewares that will be executed by this server. /// /// Middlewares are executed one after each other inside the [crate::PyMiddlewareLayer] Tower layer. -#[derive(Debug, Clone, Default)] -pub struct PyMiddlewares(Vec); +#[derive(Debug, Clone)] +pub struct PyMiddlewares { + handlers: Vec, + into_response: fn(PyMiddlewareException) -> http::Response, +} impl PyMiddlewares { /// Create a new instance of `PyMiddlewareHandlers` from a list of heandlers. - pub fn new(handlers: Vec) -> Self { - Self(handlers) + pub fn new

(handlers: Vec) -> Self + where + PyMiddlewareException: IntoResponse

, + { + Self { + handlers, + into_response: PyMiddlewareException::into_response, + } } /// Add a new handler to the list. pub fn push(&mut self, handler: PyMiddlewareHandler) { - self.0.push(handler); + self.handlers.push(handler); } /// Execute a single middleware handler. @@ -114,13 +122,9 @@ impl PyMiddlewares { /// and return a protocol specific error, with the option of setting the HTTP return code. /// * Middleware raising any other exception will immediately terminate the request handling and /// return a protocol specific error, with HTTP status code 500. - pub fn run( - &mut self, - mut request: Request, - protocol: Protocol, - locals: TaskLocals, - ) -> PyFuture { - let handlers = self.0.clone(); + pub fn run(&mut self, mut request: Request, locals: TaskLocals) -> PyFuture { + let handlers = self.handlers.clone(); + let into_response = self.into_response; // Run all Python handlers in a loop. Box::pin(async move { tracing::debug!("Executing Python middleware stack"); @@ -152,7 +156,7 @@ impl PyMiddlewares { tracing::debug!( "Middleware `{name}` returned an error, exit middleware loop" ); - return Err(e.into_response(protocol)); + return Err((into_response)(e)); } } } @@ -166,6 +170,7 @@ impl PyMiddlewares { #[cfg(test)] mod tests { + use aws_smithy_http_server::proto::rest_json_1::AwsRestJson1; use http::HeaderValue; use hyper::body::to_bytes; use pretty_assertions::assert_eq; @@ -175,7 +180,7 @@ mod tests { #[tokio::test] async fn request_middleware_chain_keeps_headers_changes() -> PyResult<()> { let locals = crate::tests::initialize(); - let mut middlewares = PyMiddlewares(vec![]); + let mut middlewares = PyMiddlewares::new::(vec![]); Python::with_gil(|py| { let middleware = PyModule::new(py, "middleware").unwrap(); @@ -212,11 +217,7 @@ def second_middleware(request: Request): })?; let result = middlewares - .run( - Request::builder().body(Body::from("")).unwrap(), - Protocol::RestJson1, - locals, - ) + .run(Request::builder().body(Body::from("")).unwrap(), locals) .await .unwrap(); assert_eq!( @@ -229,7 +230,7 @@ def second_middleware(request: Request): #[tokio::test] async fn request_middleware_return_response() -> PyResult<()> { let locals = crate::tests::initialize(); - let mut middlewares = PyMiddlewares(vec![]); + let mut middlewares = PyMiddlewares::new::(vec![]); Python::with_gil(|py| { let middleware = PyModule::new(py, "middleware").unwrap(); @@ -252,11 +253,7 @@ def middleware(request: Request): })?; let result = middlewares - .run( - Request::builder().body(Body::from("")).unwrap(), - Protocol::RestJson1, - locals, - ) + .run(Request::builder().body(Body::from("")).unwrap(), locals) .await .unwrap_err(); assert_eq!(result.status(), 200); @@ -268,7 +265,7 @@ def middleware(request: Request): #[tokio::test] async fn request_middleware_raise_middleware_exception() -> PyResult<()> { let locals = crate::tests::initialize(); - let mut middlewares = PyMiddlewares(vec![]); + let mut middlewares = PyMiddlewares::new::(vec![]); Python::with_gil(|py| { let middleware = PyModule::new(py, "middleware").unwrap(); @@ -291,11 +288,7 @@ def middleware(request: Request): })?; let result = middlewares - .run( - Request::builder().body(Body::from("")).unwrap(), - Protocol::RestJson1, - locals, - ) + .run(Request::builder().body(Body::from("")).unwrap(), locals) .await .unwrap_err(); assert_eq!(result.status(), 503); @@ -311,7 +304,7 @@ def middleware(request: Request): #[tokio::test] async fn request_middleware_raise_python_exception() -> PyResult<()> { let locals = crate::tests::initialize(); - let mut middlewares = PyMiddlewares(vec![]); + let mut middlewares = PyMiddlewares::new::(vec![]); Python::with_gil(|py| { let middleware = PyModule::from_code( @@ -333,11 +326,7 @@ def middleware(request): })?; let result = middlewares - .run( - Request::builder().body(Body::from("")).unwrap(), - Protocol::RestJson1, - locals, - ) + .run(Request::builder().body(Body::from("")).unwrap(), locals) .await .unwrap_err(); assert_eq!(result.status(), 500); diff --git a/rust-runtime/aws-smithy-http-server-python/src/middleware/layer.rs b/rust-runtime/aws-smithy-http-server-python/src/middleware/layer.rs index 73508541a2d..6c1cb6bce01 100644 --- a/rust-runtime/aws-smithy-http-server-python/src/middleware/layer.rs +++ b/rust-runtime/aws-smithy-http-server-python/src/middleware/layer.rs @@ -5,69 +5,52 @@ //! Tower layer implementation of Python middleware handling. use std::{ + marker::PhantomData, pin::Pin, task::{Context, Poll}, }; use aws_smithy_http_server::{ body::{Body, BoxBody}, - protocols::Protocol, + response::IntoResponse, }; use futures::{ready, Future}; use http::{Request, Response}; use pin_project_lite::pin_project; -use pyo3::PyResult; use pyo3_asyncio::TaskLocals; use tower::{Layer, Service}; -use crate::{error::PyException, middleware::PyFuture, PyMiddlewares}; +use crate::{middleware::PyFuture, PyMiddlewareException, PyMiddlewares}; /// Tower [Layer] implementation of Python middleware handling. /// /// Middleware stored in the `handlers` attribute will be executed, in order, /// inside an async Tower middleware. #[derive(Debug, Clone)] -pub struct PyMiddlewareLayer { +pub struct PyMiddlewareLayer

{ handlers: PyMiddlewares, - protocol: Protocol, locals: TaskLocals, + _protocol: PhantomData

, } -impl PyMiddlewareLayer { - pub fn new( - handlers: PyMiddlewares, - protocol: &str, - locals: TaskLocals, - ) -> PyResult { - let protocol = match protocol { - "aws.protocols#restJson1" => Protocol::RestJson1, - "aws.protocols#restXml" => Protocol::RestXml, - "aws.protocols#awsjson10" => Protocol::AwsJson10, - "aws.protocols#awsjson11" => Protocol::AwsJson11, - _ => { - return Err(PyException::new_err(format!( - "Protocol {protocol} is not supported" - ))) - } - }; - Ok(Self { +impl

PyMiddlewareLayer

{ + pub fn new(handlers: PyMiddlewares, locals: TaskLocals) -> Self { + Self { handlers, - protocol, locals, - }) + _protocol: PhantomData, + } } } -impl Layer for PyMiddlewareLayer { +impl Layer for PyMiddlewareLayer

+where + PyMiddlewareException: IntoResponse

, +{ type Service = PyMiddlewareService; fn layer(&self, inner: S) -> Self::Service { - PyMiddlewareService::new( - inner, - self.handlers.clone(), - self.protocol, - self.locals.clone(), - ) + PyMiddlewareService::new(inner, self.handlers.clone(), self.locals.clone()) } } @@ -76,21 +59,14 @@ impl Layer for PyMiddlewareLayer { pub struct PyMiddlewareService { inner: S, handlers: PyMiddlewares, - protocol: Protocol, locals: TaskLocals, } impl PyMiddlewareService { - pub fn new( - inner: S, - handlers: PyMiddlewares, - protocol: Protocol, - locals: TaskLocals, - ) -> PyMiddlewareService { + pub fn new(inner: S, handlers: PyMiddlewares, locals: TaskLocals) -> PyMiddlewareService { Self { inner, handlers, - protocol, locals, } } @@ -113,7 +89,7 @@ where let clone = self.inner.clone(); // See https://docs.rs/tower/latest/tower/trait.Service.html#be-careful-when-cloning-inner-services let inner = std::mem::replace(&mut self.inner, clone); - let run = self.handlers.run(req, self.protocol, self.locals.clone()); + let run = self.handlers.run(req, self.locals.clone()); ResponseFuture { middleware: State::Running { run }, @@ -184,6 +160,7 @@ mod tests { use super::*; use aws_smithy_http_server::body::to_boxed; + use aws_smithy_http_server::proto::rest_json_1::AwsRestJson1; use pyo3::prelude::*; use tower::{Service, ServiceBuilder, ServiceExt}; @@ -197,7 +174,7 @@ mod tests { #[tokio::test] async fn request_middlewares_are_chained_inside_layer() -> PyResult<()> { let locals = crate::tests::initialize(); - let mut middlewares = PyMiddlewares::new(vec![]); + let mut middlewares = PyMiddlewares::new::(vec![]); Python::with_gil(|py| { let middleware = PyModule::new(py, "middleware").unwrap(); @@ -234,11 +211,7 @@ def second_middleware(request: Request): })?; let mut service = ServiceBuilder::new() - .layer(PyMiddlewareLayer::new( - middlewares, - "aws.protocols#restJson1", - locals, - )?) + .layer(PyMiddlewareLayer::::new(middlewares, locals)) .service_fn(echo); let request = Request::get("/").body(Body::empty()).unwrap(); diff --git a/rust-runtime/aws-smithy-http-server-python/src/server.rs b/rust-runtime/aws-smithy-http-server-python/src/server.rs index fdff93b3981..6a4ac559c29 100644 --- a/rust-runtime/aws-smithy-http-server-python/src/server.rs +++ b/rust-runtime/aws-smithy-http-server-python/src/server.rs @@ -63,8 +63,6 @@ pub trait PyApp: Clone + pyo3::IntoPy { fn middlewares(&mut self) -> &mut PyMiddlewares; - fn protocol(&self) -> &'static str; - /// Handle the graceful termination of Python workers by looping through all the /// active workers and calling `terminate()` on them. If termination fails, this /// method will try to `kill()` any failed worker. @@ -385,7 +383,6 @@ event_loop.add_signal_handler(signal.SIGINT, /// fn context(&self) -> &Option { todo!() } /// fn handlers(&mut self) -> &mut HashMap { todo!() } /// fn middlewares(&mut self) -> &mut PyMiddlewares { todo!() } - /// fn protocol(&self) -> &'static str { "proto1" } /// } /// /// #[pymethods] diff --git a/rust-runtime/aws-smithy-http-server/src/extension.rs b/rust-runtime/aws-smithy-http-server/src/extension.rs index d0b4c1cdd99..736dfd0c448 100644 --- a/rust-runtime/aws-smithy-http-server/src/extension.rs +++ b/rust-runtime/aws-smithy-http-server/src/extension.rs @@ -131,7 +131,7 @@ impl Deref for ModeledErrorExtension { } /// Extension type used to store the _name_ of the [`crate::runtime_error::RuntimeError`] that -/// occurred during request handling (see [`crate::runtime_error::RuntimeErrorKind::name`]). +/// occurred during request handling (see [`crate::runtime_error::RuntimeError::name`]). /// These are _unmodeled_ errors; the operation handler was not invoked. #[derive(Debug, Clone)] pub struct RuntimeErrorExtension(String); diff --git a/rust-runtime/aws-smithy-http-server/src/protocols.rs b/rust-runtime/aws-smithy-http-server/src/protocols.rs index 1707e33cf78..6b22e9dd1bf 100644 --- a/rust-runtime/aws-smithy-http-server/src/protocols.rs +++ b/rust-runtime/aws-smithy-http-server/src/protocols.rs @@ -7,15 +7,6 @@ use crate::rejection::MissingContentTypeReason; use crate::request::RequestParts; -/// Supported protocols. -#[derive(Debug, Clone, Copy, PartialEq)] -pub enum Protocol { - RestJson1, - RestXml, - AwsJson10, - AwsJson11, -} - /// When there are no modeled inputs, /// a request body is empty and the content-type request header must not be set pub fn content_type_header_empty_body_no_modeled_input( diff --git a/rust-runtime/aws-smithy-http-server/src/runtime_error.rs b/rust-runtime/aws-smithy-http-server/src/runtime_error.rs index b8a4e71e0aa..e8174f0f08c 100644 --- a/rust-runtime/aws-smithy-http-server/src/runtime_error.rs +++ b/rust-runtime/aws-smithy-http-server/src/runtime_error.rs @@ -11,7 +11,7 @@ //! the framework, `RuntimeError` is surfaced to clients in HTTP responses: indeed, it implements //! [`RuntimeError::into_response`]. Rejections can be "grouped" and converted into a //! specific `RuntimeError` kind: for example, all request rejections due to serialization issues -//! can be conflated under the [`RuntimeErrorKind::Serialization`] enum variant. +//! can be conflated under the [`RuntimeError::Serialization`] enum variant. //! //! The HTTP response representation of the specific `RuntimeError` can be protocol-specific: for //! example, the runtime error in the RestJson1 protocol sets the `X-Amzn-Errortype` header. @@ -21,15 +21,17 @@ //! and converts into the corresponding `RuntimeError`, and then it uses the its //! [`RuntimeError::into_response`] method to render and send a response. +use http::StatusCode; + +use crate::extension::RuntimeErrorExtension; use crate::proto::aws_json_10::AwsJson10; use crate::proto::aws_json_11::AwsJson11; use crate::proto::rest_json_1::AwsRestJson1; use crate::proto::rest_xml::AwsRestXml; -use crate::protocols::Protocol; -use crate::response::{IntoResponse, Response}; +use crate::response::IntoResponse; #[derive(Debug)] -pub enum RuntimeErrorKind { +pub enum RuntimeError { /// Request failed to deserialize or response failed to serialize. Serialization(crate::Error), /// As of writing, this variant can only occur upon failure to extract an @@ -43,13 +45,22 @@ pub enum RuntimeErrorKind { /// String representation of the runtime error type. /// Used as the value of the `X-Amzn-Errortype` header in RestJson1. /// Used as the value passed to construct an [`crate::extension::RuntimeErrorExtension`]. -impl RuntimeErrorKind { +impl RuntimeError { pub fn name(&self) -> &'static str { match self { - RuntimeErrorKind::Serialization(_) => "SerializationException", - RuntimeErrorKind::InternalFailure(_) => "InternalFailureException", - RuntimeErrorKind::NotAcceptable => "NotAcceptableException", - RuntimeErrorKind::UnsupportedMediaType => "UnsupportedMediaTypeException", + Self::Serialization(_) => "SerializationException", + Self::InternalFailure(_) => "InternalFailureException", + Self::NotAcceptable => "NotAcceptableException", + Self::UnsupportedMediaType => "UnsupportedMediaTypeException", + } + } + + pub fn status_code(&self) -> StatusCode { + match self { + Self::Serialization(_) => StatusCode::BAD_REQUEST, + Self::InternalFailure(_) => StatusCode::INTERNAL_SERVER_ERROR, + Self::NotAcceptable => StatusCode::NOT_ACCEPTABLE, + Self::UnsupportedMediaType => StatusCode::UNSUPPORTED_MEDIA_TYPE, } } } @@ -58,104 +69,93 @@ pub struct InternalFailureException; impl IntoResponse for InternalFailureException { fn into_response(self) -> http::Response { - RuntimeError::internal_failure_from_protocol(Protocol::AwsJson10).into_response() + IntoResponse::::into_response(RuntimeError::InternalFailure(crate::Error::new(String::new()))) } } impl IntoResponse for InternalFailureException { fn into_response(self) -> http::Response { - RuntimeError::internal_failure_from_protocol(Protocol::AwsJson11).into_response() + IntoResponse::::into_response(RuntimeError::InternalFailure(crate::Error::new(String::new()))) } } impl IntoResponse for InternalFailureException { fn into_response(self) -> http::Response { - RuntimeError::internal_failure_from_protocol(Protocol::RestJson1).into_response() + IntoResponse::::into_response(RuntimeError::InternalFailure(crate::Error::new(String::new()))) } } impl IntoResponse for InternalFailureException { fn into_response(self) -> http::Response { - RuntimeError::internal_failure_from_protocol(Protocol::RestXml).into_response() + IntoResponse::::into_response(RuntimeError::InternalFailure(crate::Error::new(String::new()))) } } -#[derive(Debug)] -pub struct RuntimeError { - pub protocol: Protocol, - pub kind: RuntimeErrorKind, +impl IntoResponse for RuntimeError { + fn into_response(self) -> http::Response { + http::Response::builder() + .status(self.status_code()) + .header("Content-Type", "application/json") + .header("X-Amzn-Errortype", self.name()) + .extension(RuntimeErrorExtension::new(self.name().to_string())) + // See https://awslabs.github.io/smithy/1.0/spec/aws/aws-json-1_1-protocol.html#empty-body-serialization + .body(crate::body::to_boxed("{}")) + .expect("invalid HTTP response for `RuntimeError`; please file a bug report under https://github.com/awslabs/smithy-rs/issues") + } } -impl

IntoResponse

for RuntimeError { +impl IntoResponse for RuntimeError { fn into_response(self) -> http::Response { - self.into_response() + http::Response::builder() + .status(self.status_code()) + .header("Content-Type", "application/xml") + .extension(RuntimeErrorExtension::new(self.name().to_string())) + .body(crate::body::to_boxed("")) + .expect("invalid HTTP response for `RuntimeError`; please file a bug report under https://github.com/awslabs/smithy-rs/issues") } } -impl RuntimeError { - pub fn internal_failure_from_protocol(protocol: Protocol) -> Self { - RuntimeError { - protocol, - kind: RuntimeErrorKind::InternalFailure(crate::Error::new(String::new())), - } +impl IntoResponse for RuntimeError { + fn into_response(self) -> http::Response { + http::Response::builder() + .status(self.status_code()) + .header("Content-Type", "application/x-amz-json-1.0") + .extension(RuntimeErrorExtension::new(self.name().to_string())) + // See https://awslabs.github.io/smithy/1.0/spec/aws/aws-json-1_0-protocol.html#empty-body-serialization + .body(crate::body::to_boxed("")) + .expect("invalid HTTP response for `RuntimeError`; please file a bug report under https://github.com/awslabs/smithy-rs/issues") } +} - pub fn into_response(self) -> Response { - let status_code = match self.kind { - RuntimeErrorKind::Serialization(_) => http::StatusCode::BAD_REQUEST, - RuntimeErrorKind::InternalFailure(_) => http::StatusCode::INTERNAL_SERVER_ERROR, - RuntimeErrorKind::NotAcceptable => http::StatusCode::NOT_ACCEPTABLE, - RuntimeErrorKind::UnsupportedMediaType => http::StatusCode::UNSUPPORTED_MEDIA_TYPE, - }; - - let body = crate::body::to_boxed(match self.protocol { - Protocol::RestJson1 => "{}", - Protocol::RestXml => "", - // See https://awslabs.github.io/smithy/1.0/spec/aws/aws-json-1_0-protocol.html#empty-body-serialization - Protocol::AwsJson10 => "", +impl IntoResponse for RuntimeError { + fn into_response(self) -> http::Response { + http::Response::builder() + .status(self.status_code()) + .header("Content-Type", "application/x-amz-json-1.1") + .extension(RuntimeErrorExtension::new(self.name().to_string())) // See https://awslabs.github.io/smithy/1.0/spec/aws/aws-json-1_1-protocol.html#empty-body-serialization - Protocol::AwsJson11 => "", - }); - - let mut builder = http::Response::builder(); - builder = builder.status(status_code); - - match self.protocol { - Protocol::RestJson1 => { - builder = builder - .header("Content-Type", "application/json") - .header("X-Amzn-Errortype", self.kind.name()); - } - Protocol::RestXml => builder = builder.header("Content-Type", "application/xml"), - Protocol::AwsJson10 => builder = builder.header("Content-Type", "application/x-amz-json-1.0"), - Protocol::AwsJson11 => builder = builder.header("Content-Type", "application/x-amz-json-1.1"), - } - - builder = builder.extension(crate::extension::RuntimeErrorExtension::new(String::from( - self.kind.name(), - ))); - - builder.body(body).expect("invalid HTTP response for `RuntimeError`; please file a bug report under https://github.com/awslabs/smithy-rs/issues") + .body(crate::body::to_boxed("")) + .expect("invalid HTTP response for `RuntimeError`; please file a bug report under https://github.com/awslabs/smithy-rs/issues") } } -impl From for RuntimeErrorKind { +impl From for RuntimeError { fn from(err: crate::rejection::RequestExtensionNotFoundRejection) -> Self { - RuntimeErrorKind::InternalFailure(crate::Error::new(err)) + Self::InternalFailure(crate::Error::new(err)) } } -impl From for RuntimeErrorKind { +impl From for RuntimeError { fn from(err: crate::rejection::ResponseRejection) -> Self { - RuntimeErrorKind::Serialization(crate::Error::new(err)) + Self::Serialization(crate::Error::new(err)) } } -impl From for RuntimeErrorKind { +impl From for RuntimeError { fn from(err: crate::rejection::RequestRejection) -> Self { match err { - crate::rejection::RequestRejection::MissingContentType(_reason) => RuntimeErrorKind::UnsupportedMediaType, - _ => RuntimeErrorKind::Serialization(crate::Error::new(err)), + crate::rejection::RequestRejection::MissingContentType(_reason) => Self::UnsupportedMediaType, + _ => Self::Serialization(crate::Error::new(err)), } } } From 9db14463c133efd871d9c2b784d879fe3a7084c2 Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Mon, 10 Oct 2022 16:10:16 +0100 Subject: [PATCH 24/57] Update version to 0.50.0. (#1834) --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index ec1cba26861..7969ecbf08d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ rust.msrv=1.61.0 org.gradle.jvmargs=-Xmx1024M # Version number to use for the generated runtime crates -smithy.rs.runtime.crate.version=0.49.0 +smithy.rs.runtime.crate.version=0.50.0 kotlin.code.style=official From b547045a5ad9ae2129d020b241e6b725755552b3 Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Mon, 10 Oct 2022 18:50:37 +0100 Subject: [PATCH 25/57] Add a new CI job to check that smithy-rs compiles on 32bit Linux-based targets (#1812) * Replace AtomicU64 with AtomicUsize to prevent compilation issues on 32 bits platforms. * Make sure that Rust tests compile on MacOS. * Add CHANGELOG next entry. * Add a new CI job to check that smithy-rs compiles on 32bit Linux-based targets. * No trailing commas pretty please. * Point cross at the manifest explicitly. * Skip crates with a Python dependency. Exercise all features. * Install required dependencies. * Do not fail fast, we want to see the result on all platforms. * Set paths for both commands. * Openssl must be installed inside the cross Docker container, not on the host machine. * Fix connector setup if `rustls` feature is not enabled. * Restrict feature set on powerpc. * Pass openssl env variables to the cross Docker container * Split in two commands. * Enable debug level logs. * Remove openssl feature (temporarily). * Raise verbosity. * Trigger CI * `native-tls`, here we go again. * Clean up. * Trigger CI * Trigger CI * Add pkg-config. * Change include path to include arch * Trigger CI * Allow workflow_dispatch on ci-pr to enable triggering this CI workflow from the GitHub web interface. * Trigger CI? Why are you doing this to me GitHub? * Trigger CI? Are you alive GitHub? * Fix env variables for openssl * Use features only for rust-runtime crates. * Check all feature combinations for aws-smithy-client * Dry-up env variables. * A rogue `echo` was missing * Feature-gate doc tests based on the features they require. * Put .github folder under shared ownership. * Fix docs. * Fix feature selection for doctest. * We are using methods that are only available if rustls is enabled - adjust feature gates accordingly. * Remove workflow dispatch trigger. --- .github/workflows/ci.yml | 64 +++++++++++++++++++ CODEOWNERS | 1 + rust-runtime/aws-smithy-client/additional-ci | 3 + rust-runtime/aws-smithy-client/src/builder.rs | 2 +- .../aws-smithy-client/src/hyper_ext.rs | 29 +++++++-- 5 files changed, 94 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b4ab973ea79..92f145542f2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -143,6 +143,69 @@ jobs: popd &>/dev/null done + # We make sure that Smithy-rs can be compiled on platforms that are not natively supported by GitHub actions. + # We do not run tests on those platforms (yet) because it'd require a more complicated setup involving architecture + # emulation via QEMU, likely to cause a significant degradation on CI completion time. + test-exotic-platform-support: + name: Exotic platform support + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - target: i686-unknown-linux-gnu + non_aws_features: --all-features + aws_excludes: '' + # We only test `native-tls` here because `rustls` depends on `ring` which in turn does not support powerpc + # as a target platform (see https://github.com/briansmith/ring/issues/389) + # We also exclude all first-party crates that have a non-optional dependency on `ring`. + - target: powerpc-unknown-linux-gnu + non_aws_features: --features native-tls + aws_excludes: --exclude aws-inlineable --exclude aws-sigv4 --exclude aws-sig-auth + env: + CROSS_CONFIG: Cross.toml + OPENSSL_LIB_DIR: /usr/lib/i386-linux-gnu + OPENSSL_INCLUDE_DIR: /usr/include/i386-linux-gnu + steps: + - name: Checkout + uses: actions/checkout@v1 + # Pinned to the commit hash of v1.3.0 + - uses: Swatinem/rust-cache@842ef286fff290e445b90b4002cc9807c3669641 + with: + sharedKey: ${{ runner.os }}-${{ env.rust_version }}-${{ github.job }}-${{ matrix.target }} + target-dir: ./target + - uses: actions-rs/toolchain@v1 + with: + toolchain: ${{ env.rust_version }} + components: ${{ env.rust_toolchain_components }} + profile: minimal + override: true + target: ${{ matrix.target }} + - name: Configure cross + shell: bash + run: | + cat > Cross.toml << EOF + [build] + pre-build = ["dpkg --add-architecture i386", "apt-get update && apt-get install --assume-yes pkg-config:i386 libssl-dev:i386"] + [build.env] + passthrough = [ + "OPENSSL_LIB_DIR", + "OPENSSL_INCLUDE_DIR", + ] + EOF + - name: Build rust-runtime crates + uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --target ${{ matrix.target }} --manifest-path "rust-runtime/Cargo.toml" --exclude aws-smithy-http-server-python --workspace ${{ matrix.non_aws_features }} + - name: Build AWS rust-runtime crates + uses: actions-rs/cargo@v1 + with: + use-cross: true + command: build + args: --target ${{ matrix.target }} --manifest-path "aws/rust-runtime/Cargo.toml" ${{ matrix.aws_excludes }} --workspace + # This job is split out from the rest since it is not required to pass for merge check-sdk-examples: name: Check SDK Examples @@ -166,6 +229,7 @@ jobs: - test-codegen - test-sdk - test-rust-windows + - test-exotic-platform-support # Run this job even if its dependency jobs fail if: always() runs-on: ubuntu-latest diff --git a/CODEOWNERS b/CODEOWNERS index 19506644ac7..20265881e68 100644 --- a/CODEOWNERS +++ b/CODEOWNERS @@ -7,6 +7,7 @@ /rust-runtime/aws-smithy-http-server/ @awslabs/smithy-rs-server # Shared ownership +/.github/ @awslabs/rust-sdk-owners @awslabs/smithy-rs-server /CHANGELOG.md @awslabs/rust-sdk-owners @awslabs/smithy-rs-server /CHANGELOG.next.toml @awslabs/rust-sdk-owners @awslabs/smithy-rs-server /README.md @awslabs/rust-sdk-owners @awslabs/smithy-rs-server diff --git a/rust-runtime/aws-smithy-client/additional-ci b/rust-runtime/aws-smithy-client/additional-ci index c1fd7ce4066..fde542e9fc1 100755 --- a/rust-runtime/aws-smithy-client/additional-ci +++ b/rust-runtime/aws-smithy-client/additional-ci @@ -10,3 +10,6 @@ set -e echo "### Checking for duplicate dependency versions in the normal dependency graph with all features enabled" cargo tree -d --edges normal --all-features + +echo "### Testing every combination of features (excluding --all-features)" +cargo hack test --feature-powerset --exclude-all-features diff --git a/rust-runtime/aws-smithy-client/src/builder.rs b/rust-runtime/aws-smithy-client/src/builder.rs index 017ae04e7be..4a1b62fb854 100644 --- a/rust-runtime/aws-smithy-client/src/builder.rs +++ b/rust-runtime/aws-smithy-client/src/builder.rs @@ -135,7 +135,7 @@ impl Builder<(), M, R> { let with_https = |b: Builder<_, M, R>| b.rustls_connector(connector_settings); // If we are compiling this function & rustls is not enabled, then native-tls MUST be enabled #[cfg(not(feature = "rustls"))] - let with_https = |b: Builder<_, M, R>| b.native_tls_connector(); + let with_https = |b: Builder<_, M, R>| b.native_tls_connector(connector_settings); with_https(self) } diff --git a/rust-runtime/aws-smithy-client/src/hyper_ext.rs b/rust-runtime/aws-smithy-client/src/hyper_ext.rs index 18acf755262..27caf43ad37 100644 --- a/rust-runtime/aws-smithy-client/src/hyper_ext.rs +++ b/rust-runtime/aws-smithy-client/src/hyper_ext.rs @@ -17,7 +17,20 @@ //! with `rustls` will be constructed during client creation. However, if you are creating a Smithy //! [`Client`](crate::Client), directly, use the `dyn_https_https()` method to match that default behavior: //! -//! ```no_run +#![cfg_attr( + not(all( + any(feature = "rustls", feature = "native-tls"), + feature = "client-hyper" + )), + doc = "```no_run,ignore" +)] +#![cfg_attr( + all( + any(feature = "rustls", feature = "native-tls"), + feature = "client-hyper" + ), + doc = "```no_run" +)] //! use aws_smithy_client::Client; //! //! let client = Client::builder() @@ -34,7 +47,11 @@ //! A use case for where you may want to use the [`Adapter`] is when settings Hyper client settings //! that aren't otherwise exposed by the `Client` builder interface. //! -//! ```no_run +#![cfg_attr( + not(all(feature = "rustls", feature = "client-hyper")), + doc = "```no_run,ignore" +)] +#![cfg_attr(all(feature = "rustls", feature = "client-hyper"), doc = "```no_run")] //! use std::time::Duration; //! use aws_smithy_client::{Client, conns, hyper_ext}; //! use aws_smithy_client::erase::DynConnector; @@ -186,7 +203,11 @@ fn find_source<'a, E: Error + 'static>(err: &'a (dyn Error + 'static)) -> Option /// Construct a HyperAdapter with the default HTTP implementation (rustls). This can be useful when you want to share a Hyper connector /// between multiple Smithy clients. /// -/// ```no_run +#[cfg_attr( + not(all(feature = "rustls", feature = "client-hyper")), + doc = "```no_run,ignore" +)] +#[cfg_attr(all(feature = "rustls", feature = "client-hyper"), doc = "```no_run")] /// use tower::layer::util::Identity; /// use aws_smithy_client::{conns, hyper_ext}; /// use aws_smithy_client::erase::DynConnector; @@ -428,7 +449,7 @@ mod timeout_middleware { fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let (timeout_future, kind, &mut duration) = match self.project() { MaybeTimeoutFutureProj::NoTimeout { future } => { - return future.poll(cx).map_err(|err| err.into()) + return future.poll(cx).map_err(|err| err.into()); } MaybeTimeoutFutureProj::Timeout { timeout, From eb6ffe35206a4866ccd2456dc5d001173984ed75 Mon Sep 17 00:00:00 2001 From: Burak Date: Tue, 11 Oct 2022 12:03:44 +0100 Subject: [PATCH 26/57] Lambda support for Python servers (#1807) * Allow running Python servers with Lambda handler * Fix doctests * Add `Running servers on AWS Lambda` section to docs * Remove empty spaces from `README` to make linter happy * Rename `run_lambda_server` to `run_lambda_handler` * Add more comments to example `Dockerfile` * Fix capitalization of logs * Preserve original formatting of `PythonApplicationGenerator.kt` --- .../generators/PythonApplicationGenerator.kt | 60 +++++++++-------- .../aws-smithy-http-server-python/Cargo.toml | 1 + .../aws-smithy-http-server-python/README.md | 67 +++++++++++++++++++ .../src/server.rs | 59 ++++++++++++---- 4 files changed, 145 insertions(+), 42 deletions(-) diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt index c032ea9102f..9fd367617a8 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt @@ -92,7 +92,6 @@ class PythonApplicationGenerator( renderAppDefault(writer) renderAppClone(writer) renderPyAppTrait(writer) - renderAppImpl(writer) renderPyMethods(writer) } @@ -149,17 +148,35 @@ class PythonApplicationGenerator( ) } - private fun renderAppImpl(writer: RustWriter) { + private fun renderPyAppTrait(writer: RustWriter) { writer.rustBlockTemplate( """ - impl App + impl #{SmithyPython}::PyApp for App """, *codegenScope, ) { + rustTemplate( + """ + fn workers(&self) -> &#{parking_lot}::Mutex> { + &self.workers + } + fn context(&self) -> &Option<#{pyo3}::PyObject> { + &self.context + } + fn handlers(&mut self) -> &mut #{HashMap} { + &mut self.handlers + } + fn middlewares(&mut self) -> &mut #{SmithyPython}::PyMiddlewares { + &mut self.middlewares + } + """, + *codegenScope, + ) + rustBlockTemplate( """ - /// Dynamically codegenerate the routes, allowing to build the Smithy [#{SmithyServer}::routing::Router]. - pub fn build_router(&mut self, event_loop: &#{pyo3}::PyAny) -> #{pyo3}::PyResult<#{SmithyServer}::routing::Router> + // Dynamically codegenerate the routes, allowing to build the Smithy [#{SmithyServer}::routing::Router]. + fn build_router(&mut self, event_loop: &#{pyo3}::PyAny) -> #{pyo3}::PyResult<#{SmithyServer}::routing::Router> """, *codegenScope, ) { @@ -203,28 +220,6 @@ class PythonApplicationGenerator( } } - private fun renderPyAppTrait(writer: RustWriter) { - writer.rustTemplate( - """ - impl #{SmithyPython}::PyApp for App { - fn workers(&self) -> &#{parking_lot}::Mutex> { - &self.workers - } - fn context(&self) -> &Option<#{pyo3}::PyObject> { - &self.context - } - fn handlers(&mut self) -> &mut #{HashMap} { - &mut self.handlers - } - fn middlewares(&mut self) -> &mut #{SmithyPython}::PyMiddlewares { - &mut self.middlewares - } - } - """, - *codegenScope, - ) - } - private fun renderPyMethods(writer: RustWriter) { writer.rustBlockTemplate( """ @@ -264,6 +259,15 @@ class PythonApplicationGenerator( use #{SmithyPython}::PyApp; self.run_server(py, address, port, backlog, workers) } + /// Lambda entrypoint: start the server on Lambda. + ##[pyo3(text_signature = "(${'$'}self)")] + pub fn run_lambda( + &mut self, + py: #{pyo3}::Python, + ) -> #{pyo3}::PyResult<()> { + use #{SmithyPython}::PyApp; + self.run_lambda_handler(py) + } /// Build the router and start a single worker. ##[pyo3(text_signature = "(${'$'}self, socket, worker_number)")] pub fn start_worker( @@ -274,7 +278,7 @@ class PythonApplicationGenerator( ) -> pyo3::PyResult<()> { use #{SmithyPython}::PyApp; let event_loop = self.configure_python_event_loop(py)?; - let router = self.build_router(event_loop)?; + let router = self.build_and_configure_router(py, event_loop)?; self.start_hyper_worker(py, socket, event_loop, router, worker_number) } """, diff --git a/rust-runtime/aws-smithy-http-server-python/Cargo.toml b/rust-runtime/aws-smithy-http-server-python/Cargo.toml index b77292c3243..d666c30dadd 100644 --- a/rust-runtime/aws-smithy-http-server-python/Cargo.toml +++ b/rust-runtime/aws-smithy-http-server-python/Cargo.toml @@ -22,6 +22,7 @@ bytes = "1.2" futures = "0.3" http = "0.2" hyper = { version = "0.14.20", features = ["server", "http1", "http2", "tcp", "stream"] } +lambda_http = "0.6.0" num_cpus = "1.13.1" parking_lot = "0.12.1" pin-project-lite = "0.2" diff --git a/rust-runtime/aws-smithy-http-server-python/README.md b/rust-runtime/aws-smithy-http-server-python/README.md index da3dc2c1316..c8a7e728c32 100644 --- a/rust-runtime/aws-smithy-http-server-python/README.md +++ b/rust-runtime/aws-smithy-http-server-python/README.md @@ -2,6 +2,73 @@ Server libraries for smithy-rs generated servers, targeting pure Python business logic. +## Running servers on AWS Lambda + +`aws-smithy-http-server-python` supports running your services on [AWS Lambda](https://aws.amazon.com/lambda/). + +You need to use `run_lambda` method instead of `run` method to start +the [custom runtime](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html) +instead of the [Hyper](https://hyper.rs/) HTTP server. + +In your `app.py`: + +```diff +from libpokemon_service_server_sdk import App +from libpokemon_service_server_sdk.error import ResourceNotFoundException + +# ... + +# Get the number of requests served by this server. +@app.get_server_statistics +def get_server_statistics( + _: GetServerStatisticsInput, context: Context +) -> GetServerStatisticsOutput: + calls_count = context.get_calls_count() + logging.debug("The service handled %d requests", calls_count) + return GetServerStatisticsOutput(calls_count=calls_count) + +# ... + +-app.run() ++app.run_lambda() +``` + +`aws-smithy-http-server-python` comes with a +[custom runtime](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html) +so you should run your service without any provided runtimes. +You can achieve that with a `Dockerfile` similar to this: + +```dockerfile +# You can use any image that has your desired Python version +FROM public.ecr.aws/lambda/python:3.8-x86_64 + +# Copy your application code to `LAMBDA_TASK_ROOT` +COPY app.py ${LAMBDA_TASK_ROOT} +# When you build your Server SDK for your service you get a shared library +# that is importable in Python. You need to copy that shared library to same folder +# with your application code, so it can be imported by your application. +# Note that you need to build your library for Linux, +# if you are on a different platform you can consult to +# https://pyo3.rs/latest/building_and_distribution.html#cross-compiling +# for cross compiling. +COPY lib_pokemon_service_server_sdk.so ${LAMBDA_TASK_ROOT} + +# You can install your application's dependencies using file `requirements.txt` +# from your project folder, if you have any. +# COPY requirements.txt . +# RUN pip3 install -r requirements.txt --target "${LAMBDA_TASK_ROOT}" + +# Create a symlink for your application's entrypoint, +# so we can use `/app.py` to refer it +RUN ln -s ${LAMBDA_TASK_ROOT}/app.py /app.py + +# By default `public.ecr.aws/lambda/python` images comes with Python runtime, +# we need to override `ENTRYPOINT` and `CMD` to not call that runtime and +# instead run directly your service and it will start our custom runtime. +ENTRYPOINT [ "/var/lang/bin/python3.8" ] +CMD [ "/app.py" ] +``` + This crate is part of the [AWS SDK for Rust](https://awslabs.github.io/aws-sdk-rust/) and the [smithy-rs](https://github.com/awslabs/smithy-rs) code generator. In most cases, it should not be used directly. diff --git a/rust-runtime/aws-smithy-http-server-python/src/server.rs b/rust-runtime/aws-smithy-http-server-python/src/server.rs index 6a4ac559c29..d9d68ff2c37 100644 --- a/rust-runtime/aws-smithy-http-server-python/src/server.rs +++ b/rust-runtime/aws-smithy-http-server-python/src/server.rs @@ -6,7 +6,10 @@ use std::{collections::HashMap, ops::Deref, process, thread}; -use aws_smithy_http_server::{routing::Router, AddExtensionLayer}; +use aws_smithy_http_server::{ + routing::{LambdaHandler, Router}, + AddExtensionLayer, +}; use parking_lot::Mutex; use pyo3::{prelude::*, types::IntoPyDict}; use signal_hook::{consts::*, iterator::Signals}; @@ -63,6 +66,9 @@ pub trait PyApp: Clone + pyo3::IntoPy { fn middlewares(&mut self) -> &mut PyMiddlewares; + /// Build the app's `Router` using given `event_loop`. + fn build_router(&mut self, event_loop: &pyo3::PyAny) -> pyo3::PyResult; + /// Handle the graceful termination of Python workers by looping through all the /// active workers and calling `terminate()` on them. If termination fails, this /// method will try to `kill()` any failed worker. @@ -212,9 +218,6 @@ event_loop.add_signal_handler(signal.SIGINT, router: Router, worker_number: isize, ) -> PyResult<()> { - // Create the `PyState` object from the Python context object. - let context = self.context().clone().unwrap_or_else(|| py.None()); - // let state = PyState::new(context); // Clone the socket. let borrow = socket.try_borrow_mut()?; let held_socket: &PySocket = &*borrow; @@ -231,19 +234,14 @@ event_loop.add_signal_handler(signal.SIGINT, .thread_name(format!("smithy-rs-tokio[{worker_number}]")) .build() .expect("Unable to start a new tokio runtime for this process"); - // Register operations into a Router, add middleware and start the `hyper` server, - // all inside a [tokio] blocking function. rt.block_on(async move { - tracing::debug!("Add middlewares to Rust Python router"); - let app = - router.layer(ServiceBuilder::new().layer(AddExtensionLayer::new(context))); let server = hyper::Server::from_tcp( raw_socket .try_into() .expect("Unable to convert socket2::Socket into std::net::TcpListener"), ) .expect("Unable to create hyper server from shared socket") - .serve(app.into_make_service()); + .serve(router.into_make_service()); tracing::debug!("Started hyper server from shared socket"); // Run forever-ish... @@ -374,15 +372,12 @@ event_loop.add_signal_handler(signal.SIGINT, /// #[derive(Debug, Clone)] /// pub struct App {}; /// - /// impl App { - /// pub fn build_router(&mut self, event_loop: &PyAny) -> PyResult { todo!() } - /// } - /// /// impl PyApp for App { /// fn workers(&self) -> &Mutex> { todo!() } /// fn context(&self) -> &Option { todo!() } /// fn handlers(&mut self) -> &mut HashMap { todo!() } /// fn middlewares(&mut self) -> &mut PyMiddlewares { todo!() } + /// fn build_router(&mut self, event_loop: &PyAny) -> PyResult { todo!() } /// } /// /// #[pymethods] @@ -457,4 +452,40 @@ event_loop.add_signal_handler(signal.SIGINT, self.block_on_rust_signals(); Ok(()) } + + /// Lambda main entrypoint: start the handler on Lambda. + /// + /// Unlike the `run_server`, `run_lambda_handler` does not spawns other processes, + /// it starts the Lambda handler on the current process. + fn run_lambda_handler(&mut self, py: Python) -> PyResult<()> { + let event_loop = self.configure_python_event_loop(py)?; + let app = self.build_and_configure_router(py, event_loop)?; + let rt = runtime::Builder::new_multi_thread() + .enable_all() + .build() + .expect("unable to start a new tokio runtime for this process"); + rt.block_on(async move { + let handler = LambdaHandler::new(app); + let lambda = lambda_http::run(handler); + tracing::debug!("starting lambda handler"); + if let Err(err) = lambda.await { + tracing::error!(error = %err, "unable to start lambda handler"); + } + }); + Ok(()) + } + + // Builds the router and adds necessary layers to it. + fn build_and_configure_router( + &mut self, + py: Python, + event_loop: &pyo3::PyAny, + ) -> pyo3::PyResult { + let app = self.build_router(event_loop)?; + // Create the `PyState` object from the Python context object. + let context = self.context().clone().unwrap_or_else(|| py.None()); + tracing::debug!("add middlewares to rust python router"); + let app = app.layer(ServiceBuilder::new().layer(AddExtensionLayer::new(context))); + Ok(app) + } } From 4255eb384786cdde79637d914abf7e47aab89055 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Tue, 11 Oct 2022 09:33:51 -0700 Subject: [PATCH 27/57] Remove unused generic from customizable ops (#1835) Co-authored-by: Zelda Hessler --- .../smithy/generators/client/CustomizableOperationGenerator.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt index f954f79496b..c6e4d7a0e71 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt @@ -110,7 +110,7 @@ class CustomizableOperationGenerator( } /// Convenience for `map_request` where infallible direct mutation of request is acceptable - pub fn mutate_request(self, f: impl FnOnce(&mut #{HttpRequest})) -> Self { + pub fn mutate_request(self, f: impl FnOnce(&mut #{HttpRequest})) -> Self { self.map_request(|mut req| { f(&mut req); Result::<_, Infallible>::Ok(req) From 057fe971b8273884667dace35d8103443fdbcc9c Mon Sep 17 00:00:00 2001 From: ethyi <37843741+ethyi@users.noreply.github.com> Date: Tue, 11 Oct 2022 10:15:07 -0700 Subject: [PATCH 28/57] Update with flexible zeroize version (#1817) --- CHANGELOG.next.toml | 6 ++++++ aws/rust-runtime/aws-types/Cargo.toml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index b303a4b601c..781d528fc41 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -149,3 +149,9 @@ message = "Convert the `protocol` argument on `PyMiddlewares::new` constructor t references = ["smithy-rs#1829"] meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" } author = "hlbarber" + +[[smithy-rs]] +message = "Update aws-types zeroize to flexible version to prevent downstream version conflicts." +references = ["smithy-rs#1817"] +meta = { "breaking" = false, "tada" = false, "bug" = true } +author = "ethyi" \ No newline at end of file diff --git a/aws/rust-runtime/aws-types/Cargo.toml b/aws/rust-runtime/aws-types/Cargo.toml index 86c2293b309..54b599ed29f 100644 --- a/aws/rust-runtime/aws-types/Cargo.toml +++ b/aws/rust-runtime/aws-types/Cargo.toml @@ -16,7 +16,7 @@ aws-smithy-types = { path = "../../../rust-runtime/aws-smithy-types" } aws-smithy-client = { path = "../../../rust-runtime/aws-smithy-client" } aws-smithy-http = { path = "../../../rust-runtime/aws-smithy-http" } tracing = "0.1" -zeroize = "1.4.1" +zeroize = "1" http = "0.2.6" [dev-dependencies] From 94a991cd649f4f43c3eb50611e34a9964020282e Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Tue, 11 Oct 2022 11:09:04 -0700 Subject: [PATCH 29/57] Remove `handleRustBoxing` config from `SymbolVisitor` (#1824) --- .../smithy/rust/codegen/client/smithy/CodegenVisitor.kt | 1 - .../smithy/rust/codegen/core/smithy/SymbolVisitor.kt | 8 +------- .../codegen/core/smithy/generators/StructureGenerator.kt | 2 +- .../smithy/rust/codegen/core/testutil/TestHelpers.kt | 1 - .../server/python/smithy/PythonServerCodegenVisitor.kt | 1 - .../rust/codegen/server/smithy/ServerCodegenVisitor.kt | 1 - .../codegen/server/smithy/testutil/ServerTestHelpers.kt | 1 - 7 files changed, 2 insertions(+), 13 deletions(-) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt index f7c68c6583a..4a7e6cae11b 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt @@ -69,7 +69,6 @@ class CodegenVisitor( SymbolVisitorConfig( runtimeConfig = settings.runtimeConfig, renameExceptions = settings.codegenConfig.renameExceptions, - handleRustBoxing = true, nullabilityCheckMode = NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1, ) val baseModel = baselineTransform(context.model) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt index 3b2024faed7..d72bafb5b97 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt @@ -65,7 +65,6 @@ val SimpleShapes: Map, RustType> = mapOf( data class SymbolVisitorConfig( val runtimeConfig: RuntimeConfig, val renameExceptions: Boolean, - val handleRustBoxing: Boolean, val nullabilityCheckMode: NullableIndex.CheckMode, ) @@ -328,13 +327,8 @@ open class SymbolVisitor( override fun memberShape(shape: MemberShape): Symbol { val target = model.expectShape(shape.target) - val targetSymbol = this.toSymbol(target) // Handle boxing first so we end up with Option>, not Box> - return targetSymbol.letIf(config.handleRustBoxing) { - handleRustBoxing(it, shape) - }.let { - handleOptionality(it, shape) - } + return handleOptionality(handleRustBoxing(toSymbol(target), shape), shape) } override fun timestampShape(shape: TimestampShape?): Symbol { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt index f216f236d47..96f508c5d03 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt @@ -152,7 +152,7 @@ open class StructureGenerator( writer.renderMemberDoc(member, memberSymbol) writer.deprecatedShape(member) memberSymbol.expectRustMetadata().render(writer) - writer.write("$memberName: #T,", symbolProvider.toSymbol(member)) + writer.write("$memberName: #T,", memberSymbol) } open fun renderStructure() { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt index 42d37b6679e..848762ff183 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt @@ -39,7 +39,6 @@ val TestRuntimeConfig = val TestSymbolVisitorConfig = SymbolVisitorConfig( runtimeConfig = TestRuntimeConfig, renameExceptions = true, - handleRustBoxing = true, nullabilityCheckMode = NullableIndex.CheckMode.CLIENT_ZERO_VALUE_V1, ) diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt index c4e07d60d91..0edc5a0878c 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt @@ -48,7 +48,6 @@ class PythonServerCodegenVisitor( SymbolVisitorConfig( runtimeConfig = settings.runtimeConfig, renameExceptions = false, - handleRustBoxing = true, nullabilityCheckMode = NullableIndex.CheckMode.SERVER, ) val baseModel = baselineTransform(context.model) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt index db93c5cfffe..712d930b424 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt @@ -75,7 +75,6 @@ open class ServerCodegenVisitor( SymbolVisitorConfig( runtimeConfig = settings.runtimeConfig, renameExceptions = false, - handleRustBoxing = true, nullabilityCheckMode = NullableIndex.CheckMode.SERVER, ) val baseModel = baselineTransform(context.model) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt index 5c648e6fe47..4159e732c79 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt @@ -24,7 +24,6 @@ import software.amazon.smithy.rust.codegen.server.smithy.ServerRustSettings val ServerTestSymbolVisitorConfig = SymbolVisitorConfig( runtimeConfig = TestRuntimeConfig, renameExceptions = false, - handleRustBoxing = true, nullabilityCheckMode = NullableIndex.CheckMode.SERVER, ) From bf3fbc2e1dd77847f67e796251116a7cd00ae550 Mon Sep 17 00:00:00 2001 From: Harry Barber <106155934+hlbarber@users.noreply.github.com> Date: Tue, 11 Oct 2022 19:40:49 +0100 Subject: [PATCH 30/57] Add "Anatomy of a Service" documentation (#1782) * Rust documentation improvements * Add "Anatomy of a Service" documentation --- .../generators/ServerServiceGeneratorV2.kt | 4 +- design/src/SUMMARY.md | 1 + design/src/server/anatomy.md | 880 ++++++++++++++++++ design/src/server/overview.md | 1 + .../examples/pokemon-service/src/plugin.rs | 32 +- .../src/operation/mod.rs | 4 +- .../aws-smithy-http-server/src/plugin.rs | 25 +- .../aws-smithy-http-server/src/routers/mod.rs | 4 +- 8 files changed, 922 insertions(+), 29 deletions(-) create mode 100644 design/src/server/anatomy.md diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt index 9486b47488a..d63ed4cd734 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGeneratorV2.kt @@ -113,7 +113,7 @@ class ServerServiceGeneratorV2( """ /// Sets the [`$structName`](crate::operation_shape::$structName) operation. /// - /// This should be a closure satisfying the [`Handler`](#{SmithyHttpServer}::operation::Handler) trait. + /// This should be an async function satisfying the [`Handler`](#{SmithyHttpServer}::operation::Handler) trait. /// See the [operation module documentation](#{SmithyHttpServer}::operation) for more information. pub fn $fieldName(self, value: H) -> $builderName<#{HandlerSetterGenerics:W}> where @@ -312,7 +312,7 @@ class ServerServiceGeneratorV2( #{SmithyHttpServer}::routing::IntoMakeService::new(self) } - /// Applies a layer uniformly to all routes. + /// Applies a [`Layer`](#{Tower}::Layer) uniformly to all routes. pub fn layer(self, layer: &L) -> $serviceName where L: #{Tower}::Layer diff --git a/design/src/SUMMARY.md b/design/src/SUMMARY.md index f104234efc6..5a25cb39da8 100644 --- a/design/src/SUMMARY.md +++ b/design/src/SUMMARY.md @@ -18,6 +18,7 @@ - [Generating Common Service Code](./server/code_generation.md) - [Generating the Pokémon Service](./server/pokemon_service.md) - [Instrumentation](./server/instrumentation.md) + - [RFCs](./rfcs/overview.md) - [RFC-0001: Sharing configuration between multiple clients](./rfcs/rfc0001_shared_config.md) diff --git a/design/src/server/anatomy.md b/design/src/server/anatomy.md new file mode 100644 index 00000000000..7c14ecd15e6 --- /dev/null +++ b/design/src/server/anatomy.md @@ -0,0 +1,880 @@ +# The Anatomy of a Service + +What is [Smithy](https://awslabs.github.io/smithy/2.0/index.html)? At a high-level, it's a grammar for specifying services while leaving the business logic undefined. A [Smithy Service](https://awslabs.github.io/smithy/2.0/spec/service-types.html#service) specifies a collection of function signatures in the form of [Operations](https://awslabs.github.io/smithy/2.0/spec/service-types.html#operation), their purpose is to encapsulate business logic. A Smithy implementation should, for each Smithy Service, provide a builder, which accepts functions conforming to said signatures, and returns a service subject to the semantics specified by the model. + +This survey is disinterested in the actual Kotlin implementation of the code generator, and instead focuses on the structure of the generated Rust code and how it relates to the Smithy model. The intended audience is new contributors and users interested in internal details. + +During the survey we will use the [`pokemon.smithy`](https://github.com/awslabs/smithy-rs/blob/main/codegen-core/common-test-models/pokemon.smithy) model as a reference: + +```smithy +/// A Pokémon species forms the basis for at least one Pokémon. +@title("Pokémon Species") +resource PokemonSpecies { + identifiers: { + name: String + }, + read: GetPokemonSpecies, +} + +/// A users current Pokémon storage. +resource Storage { + identifiers: { + user: String + }, + read: GetStorage, +} + +/// The Pokémon Service allows you to retrieve information about Pokémon species. +@title("Pokémon Service") +@restJson1 +service PokemonService { + version: "2021-12-01", + resources: [PokemonSpecies, Storage], + operations: [ + GetServerStatistics, + DoNothing, + CapturePokemon, + CheckHealth + ], +} +``` + +Smithy Rust will use this model to produce the following API: + +```rust +// A handler for the `GetPokemonSpecies` operation (the `PokemonSpecies` resource). +async fn get_pokemon_species(input: GetPokemonSpeciesInput) -> Result { + /* implementation */ +} + +// Apply a `tower::Layer` to a handler. +let get_pokemon_species_op = GetPokemonSpecies::from_handler(get_pokemon_species).layer(/* some `tower::Layer` */); + +// Use the service builder to create `PokemonService`. +let pokemon_service = PokemonService::builder() + // Pass the handler directly to the service builder... + .get_pokemon_species(get_pokemon_species) + // ...or pass the layered handler. + .get_pokemon_species_operation(get_pokemon_species_op) + /* other operation setters */ + .build(); +``` + +## Operations + +A [Smithy Operation](https://awslabs.github.io/smithy/2.0/spec/service-types.html#operation) specifies the input, output, and possible errors of an API operation. One might characterize a Smithy Operation as syntax for specifying a function type. + +We represent this in Rust using the [`OperationShape`](https://github.com/awslabs/smithy-rs/blob/4c5cbc39384f0d949d7693eb87b5853fe72629cd/rust-runtime/aws-smithy-http-server/src/operation/shape.rs#L8-L22) trait: + +```rust +pub trait OperationShape { + /// The name of the operation. + const NAME: &'static str; + + /// The operation input. + type Input; + /// The operation output. + type Output; + /// The operation error. [`Infallible`](std::convert::Infallible) in the case where no error + /// exists. + type Error; +} +``` + +For each Smithy Operation shape, + +```smithy +/// Retrieve information about a Pokémon species. +@readonly +@http(uri: "/pokemon-species/{name}", method: "GET") +operation GetPokemonSpecies { + input: GetPokemonSpeciesInput, + output: GetPokemonSpeciesOutput, + errors: [ResourceNotFoundException], +} +``` + +the following implementation is generated + +```rust +/// Retrieve information about a Pokémon species. +pub struct GetPokemonSpecies; + +impl OperationShape for GetPokemonSpecies { + const NAME: &'static str = "com.aws.example#GetPokemonSpecies"; + + type Input = GetPokemonSpeciesInput; + type Output = GetPokemonSpeciesOutput; + type Error = GetPokemonSpeciesError; +} +``` + +where `GetPokemonSpeciesInput`, `GetPokemonSpeciesOutput` are both generated from the Smithy structures and `GetPokemonSpeciesError` is an enum generated from the `errors: [ResourceNotFoundException]`. + +Note that the `GetPokemonSpecies` marker structure is a zero-sized type (ZST), and therefore does not allocate - only existing in the type system as a way to hang operation specific data on. + +The following nomenclature will aid us in our survey. We describe a `tower::Service` as a "model service" if its request and response are Smithy structures, as defined by the `OperationShape` trait - the `GetPokemonSpeciesInput`, `GetPokemonSpeciesOutput`, and `GetPokemonSpeciesError` described above. Similarly, we describe a `tower::Service` as a "HTTP service" if its request and response are [`http`](https://github.com/hyperium/http) structures - `http::Request` and `http::Response`. + +In contrast to the marker ZSTs above, the [`Operation`](https://github.com/awslabs/smithy-rs/blob/4c5cbc39384f0d949d7693eb87b5853fe72629cd/rust-runtime/aws-smithy-http-server/src/operation/mod.rs#L192-L198) structure holds the actual runtime behavior of an operation, which is specified, during construction, by the customer. + +```rust +/// A Smithy operation, represented by a [`Service`](tower::Service) `S` and a [`Layer`](tower::Layer) `L`. +/// +/// The `L` is held and applied lazily during [`Upgradable::upgrade`]. +pub struct Operation { + inner: S, + layer: L, +} +``` + +The `S` here is a model service, this is specified during construction of the `Operation`. The constructors exist on the marker ZSTs as an extension trait to `OperationShape`, namely [`OperationShapeExt`](https://github.com/awslabs/smithy-rs/blob/4c5cbc39384f0d949d7693eb87b5853fe72629cd/rust-runtime/aws-smithy-http-server/src/operation/shape.rs#L24-L45): + +```rust +/// An extension trait over [`OperationShape`]. +pub trait OperationShapeExt: OperationShape { + /// Creates a new [`Operation`] for well-formed [`Handler`]s. + fn from_handler(handler: H) -> Operation> + where + H: Handler, + Self: Sized, + { + Operation::from_handler(handler) + } + + /// Creates a new [`Operation`] for well-formed [`Service`](tower::Service)s. + fn from_service(svc: S) -> Operation> + where + S: OperationService, + Self: Sized, + { + Operation::from_service(svc) + } +} +``` + +Observe that there are two constructors provided: `from_handler` which takes a `H: Handler` and `from_service` which takes a `S: OperationService`. In both cases `Self` is passed as a parameter to the traits - this constrains `handler: H` and `svc: S` to the signature given by the implementation of `OperationShape` on `Self`. + +The [`Handler`](https://github.com/awslabs/smithy-rs/blob/4c5cbc39384f0d949d7693eb87b5853fe72629cd/rust-runtime/aws-smithy-http-server/src/operation/handler.rs#L21-L29) and [`OperationService`](https://github.com/awslabs/smithy-rs/blob/4c5cbc39384f0d949d7693eb87b5853fe72629cd/rust-runtime/aws-smithy-http-server/src/operation/operation_service.rs#L15-L29) both serve a similar purpose - they provide a common interface for converting to a model service `S`. + +- The `Handler` trait covers all async functions taking `GetPokemonSpeciesInput` and asynchronously returning a `Result`. +- The `OperationService` trait covers all `tower::Service`s with request `GetPokemonSpeciesInput`, response `GetPokemonSpeciesOutput` and error `GetPokemonSpeciesOutput`. + +The `from_handler` constructor is used in the following way: + +```rust +async fn get_pokemon_service(input: GetPokemonServiceInput) -> Result { + /* Handler logic */ +} + +let operation = GetPokemonService::from_handler(get_pokemon_service); +``` + +Alternatively, `from_service` constructor: + +```rust +struct Svc { + /* ... */ +} + +impl Service for Svc { + type Response = GetPokemonServiceOutput; + type Error = GetPokemonServiceError; + + /* ... */ +} + +let svc: Svc = /* ... */; +let operation = GetPokemonService::from_service(svc); +``` + +To summarize, the `S`, in `Operation`, is a _model service_ constructed from a `Handler` or a `OperationService` subject to the constraints of an `OperationShape`. More detailed information on these conversions is provided in the [Handler and OperationService section](https://github.com/awslabs/smithy-rs/blob/39c0096c33417d44f125a042c112b3c16918098a/rust-runtime/aws-smithy-http-server/src/operation/mod.rs#L50-L100) Rust docs. + +Now, what about the `L` in `Operation`? The `L` is a [`tower::Layer`](https://docs.rs/tower/latest/tower/layer/trait.Layer.html), or colloquially "middleware", that is applied to a _HTTP service_. Note that this means that `L` is _not_ applied directly to `S`. We can append to `L` using the `Operation::layer` method: + +```rust +impl Operation { + /// Applies a [`Layer`] to the operation _after_ it has been upgraded via [`Operation::upgrade`]. + pub fn layer(self, layer: NewL) -> Operation> { + Operation { + inner: self.inner, + layer: Stack::new(self.layer, layer), + } + } +} +``` + +where [`tower::layer::util::Stack`](https://docs.rs/tower/latest/tower/layer/util/struct.Stack.html) is used to chains layers together. + +A typical use of this might be: + +```rust +let operation = GetPokemonSpecies::from_handler(handler).layer(RequestBodyLimitLayer::new(500)); +``` + +where [`RequestBodyLimitLayer`](https://docs.rs/tower-http/latest/tower_http/limit/struct.RequestBodyLimitLayer.html) limits the size of the HTTP request body to the `GetPokemonSpecies` operation. + +As mentioned, `L` is applied _after_ the `Operation` has been "upgraded" to a HTTP service. The procedure of upgrading a model service to a HTTP service is described in the [Upgrading a Model Service](#upgrading-a-model-service) section below. + +## Serialization and Deserialization + +A [Smithy protocol](https://awslabs.github.io/smithy/2.0/spec/protocol-traits.html#serialization-and-protocol-traits) specifies the serialization/deserialization scheme - how a HTTP request is transformed into a modelled input and a modelled output to a HTTP response. The is formalized using the [`FromRequest`](https://github.com/awslabs/smithy-rs/blob/4c5cbc39384f0d949d7693eb87b5853fe72629cd/rust-runtime/aws-smithy-http-server/src/request.rs#L156-L164) and [`IntoResponse`](https://github.com/awslabs/smithy-rs/blob/4c5cbc39384f0d949d7693eb87b5853fe72629cd/rust-runtime/aws-smithy-http-server/src/response.rs#L40-L44) traits: + +```rust +/// Provides a protocol aware extraction from a [`Request`]. This consumes the +/// [`Request`], in contrast to [`FromParts`]. +pub trait FromRequest: Sized { + type Rejection: IntoResponse; + type Future: Future>; + + /// Extracts `self` from a [`Request`] asynchronously. + fn from_request(request: http::Request) -> Self::Future; +} + +/// A protocol aware function taking `self` to [`http::Response`]. +pub trait IntoResponse { + /// Performs a conversion into a [`http::Response`]. + fn into_response(self) -> http::Response; +} +``` + +Note that both traits are parameterized by `Protocol`. These [protocols](https://awslabs.github.io/smithy/2.0/aws/protocols/index.html) exist as ZST marker structs: + +```rust +/// [AWS REST JSON 1.0 Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-restjson1-protocol.html). +pub struct AwsRestJson1; + +/// [AWS REST XML Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-restxml-protocol.html). +pub struct AwsRestXml; + +/// [AWS JSON 1.0 Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-json-1_0-protocol.html). +pub struct AwsJson10; + +/// [AWS JSON 1.1 Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-json-1_1-protocol.html). +pub struct AwsJson11; +``` + +## Upgrading a Model Service + +We can "upgrade" a model service to a HTTP service using `FromRequest` and `IntoResponse` described in the prior section: + +```mermaid +stateDiagram-v2 + direction LR + HttpService: HTTP Service + [*] --> from_request: HTTP Request + state HttpService { + direction LR + ModelService: Model Service + from_request --> ModelService: Model Input + ModelService --> into_response: Model Output + } + into_response --> [*]: HTTP Response +``` + +This is formalized by the [`Upgrade`](https://github.com/awslabs/smithy-rs/blob/4c5cbc39384f0d949d7693eb87b5853fe72629cd/rust-runtime/aws-smithy-http-server/src/operation/upgrade.rs#L76-L84) HTTP service. The `tower::Service` implementation is approximately: + +```rust +impl Service for Upgrade +where + // `Op` is used to specify the operation shape + Op: OperationShape, + // Smithy input must convert from a HTTP request + Op::Input: FromRequest

, + // Smithy output must convert into a HTTP response + Op::Output: IntoResponse

, + // Smithy error must convert into a HTTP response + OpError: IntoResponse

, + + // The signature of the inner service is correct + S: Service, + + async fn call(&mut self, request: http::Request) -> http::Response { + let model_request = match ::from_request(request).await { + Ok(ok) => ok, + Err(err) => return err.into_response() + }; + let model_response = self.model_service.call(model_request).await; + model_response.into_response() + } +``` + +When we `GetPokemonService::from_handler` or `GetPokemonService::from_service`, the model service produced, `S`, will meet the constraints above. + +There is an associated `Layer`, `UpgradeLayer` which constructs `Upgrade` from a service. + +The upgrade procedure is finalized by the application of the `Layer` `L`, referenced in `Operation`. In this way the entire upgrade procedure takes an `Operation` and returns a HTTP service. + +```mermaid +stateDiagram-v2 + direction LR + [*] --> S: HTTP Request + state L { + state Upgrade { + S + } + } + S --> [*]: HTTP Response +``` + +Note that the `S` and `L` are specified by logic written, in Rust, by the customer, whereas `Upgrade`/`UpgradeLayer` is specified entirely by Smithy model via the protocol, [HTTP bindings](https://awslabs.github.io/smithy/2.0/spec/http-bindings.html), etc. + +The procedure of taking a struct and transforming it into a HTTP service is formalized by the [`Upgradable`](https://github.com/awslabs/smithy-rs/blob/4c5cbc39384f0d949d7693eb87b5853fe72629cd/rust-runtime/aws-smithy-http-server/src/operation/upgrade.rs#L222-L229) trait: + +```rust +impl Upgradable for Operation +where + // `Op` is used to specify the operation shape + Op: OperationShape, + + // Smithy input must convert from a HTTP request + Op::Input: FromRequest

, + // Smithy output must convert into a HTTP response + Op::Output: IntoResponse

, + // Smithy error must convert into a HTTP response + Op::Error: IntoResponse

, + + // The signature of the inner service is correct + S: Service + Clone, + + // The modified Layer applies correctly to `Upgrade` + L: Layer>, + + // The signature of the output is correct + L::Service: Service, Response = http::Response>, +{ + type Service = L::Service; + + /// Takes the [`Operation`](Operation), then applies [`UpgradeLayer`] to `S`, then finally applies the `L`. + /// + /// The composition is made explicit in the method constraints and return type. + fn upgrade(self) -> Self::Service { + let Operation { inner, layer } = self; + let layer = Stack::new(UpgradeLayer::new(), layer); + layer.layer(inner) + } +} +``` + +Why do we need a trait for this? Why not simply write an `upgrade` method on `Operation`? The reason is that we might _not_ want to supply an `Operation` to the service builder, instead we might want to supply something that overrides the typical upgrade procedure. + +Below we give an example of a ZST which can be provided to the builder, which also satisfies `Upgradable` and returns a `MissingFailure` `tower::Service`. This `MissingFailure` service simply returns a status code 500. + +```rust +/// A marker struct indicating an [`Operation`] has not been set in a builder. +/// +/// This _does_ implement [`Upgradable`] but produces a [`Service`] which always returns an internal failure message. +pub struct FailOnMissingOperation; + +impl Upgradable for FailOnMissingOperation +where + InternalFailureException: IntoResponse

, +{ + type Service = MissingFailure

; + + fn upgrade(self, _plugin: &Pl) -> Self::Service { + MissingFailure { _protocol: PhantomData } + } +} +``` + +We go into more detail on how the `Upgradable` trait is used in conjunction with builders in the [Builders](#builders) section below. + +## Routers + +Different protocols supported by Smithy enjoy different routing mechanisms, for example, [AWS JSON 1.0](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-json-1_0-protocol.html#protocol-behaviors) uses the `X-Amz-Target` header to select an operation, whereas [AWS REST XML](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-restxml-protocol.html) uses the [HTTP label trait](https://awslabs.github.io/smithy/2.0/spec/http-bindings.html#httplabel-trait). + +Despite their differences, all routing mechanisms satisfy a common interface. This is formalized using the `Router` trait: + +```rust +/// An interface for retrieving an inner [`Service`] given a [`http::Request`]. +pub trait Router { + type Service; + type Error; + + /// Matches a [`http::Request`] to a target [`Service`]. + fn match_route(&self, request: &http::Request) -> Result; +} +``` + +which provides the ability to determine an inner HTTP service from a collection using a `&http::Request`. + +Types which implement the `Router` trait are converted to a HTTP service via the `RoutingService` struct: + +```rust +/// A [`Service`] using a [`Router`] `R` to redirect messages to specific routes. +/// +/// The `Protocol` parameter is used to determine the serialization of errors. +pub struct RoutingService { + router: R, + _protocol: PhantomData, +} + +impl Service for RoutingService +where + R: Router, + R::Service: Service, + R::Error: IntoResponse

+ Error, +{ + type Response = http::Response; + type Error = /* implementation detail */; + + async fn call(&mut self, req: http::Request) -> Result { + match self.router.match_route(&req) { + // Successfully routed, use the routes `Service::call`. + Ok(ok) => ok.oneshot(req).await, + // Failed to route, use the `R::Error`s `IntoResponse

`. + Err(error) => { + debug!(%error, "failed to route"); + Err(Box::new(error.into_response())) + } + } + } +} +``` + +The `RouterService` is the final piece necessary to form a functioning composition - it is used to aggregate together the HTTP services, created via the upgrade procedure, into a single HTTP service which can be presented to the customer. + +```mermaid +stateDiagram +state in <> + direction LR + [*] --> in + state RouterService { + direction LR + in --> ServiceA + in --> ServiceB + in --> ServiceC + } + ServiceA --> [*] + ServiceB --> [*] + ServiceC --> [*] +``` + +## Builders + +The service builder is the primary public API, it can be generated for every [Smithy Service](https://awslabs.github.io/smithy/2.0/spec/service-types.html). At a high-level, the purpose of a service builder is to take a function for each Smithy Operation, whose signature is constrained by the Smithy model, and produce a single HTTP service. + +```rust +/// The service builder for [`PokemonService`]. +/// +/// Constructed via [`PokemonService::builder`]. +pub struct PokemonServiceBuilder { + capture_pokemon_operation: Op1, + empty_operation: Op2, + get_pokemon_species: Op3, + get_server_statistics: Op4, + get_storage: Op5, + health_check_operation: Op6, +} +``` + +The builder has one generic type parameter for each [Smithy Operation](https://awslabs.github.io/smithy/2.0/spec/service-types.html#operation) in the [Smithy Service](https://awslabs.github.io/smithy/2.0/spec/service-types.html#service). Each setter switches the type of the `Op{N}` type parameter: + +```rust + /// Sets the [`GetPokemonSpecies`](crate::operation_shape::GetPokemonSpecies) operation. + /// + /// This should be an [`Operation`](aws_smithy_http_server::operation::Operation) created from + /// [`GetPokemonSpecies`](crate::operation_shape::GetPokemonSpecies) using either + /// [`OperationShape::from_handler`](aws_smithy_http_server::operation::OperationShapeExt::from_handler) or + /// [`OperationShape::from_service`](aws_smithy_http_server::operation::OperationShapeExt::from_service). + pub fn get_pokemon_species_operation( + self, + value: NewOp, + ) -> PokemonServiceBuilder< + Op1, + Op2, + NewOp, + Op4, + Op5, + Op6, + > { + PokemonServiceBuilder { + capture_pokemon_operation: self.capture_pokemon_operation, + empty_operation: self.empty_operation, + get_pokemon_species: value, + get_server_statistics: self.get_server_statistics, + get_storage: self.get_storage, + health_check_operation: self.health_check_operation, + } + } + + /// Sets the [`GetPokemonSpecies`](crate::operation_shape::GetPokemonSpecies) operation. + /// + /// This should be an async function satisfying the [`Handler`](aws_smithy_http_server::operation::Handler) trait. + /// See the [operation module documentation](aws_smithy_http_server::operation) for more information. + pub fn get_pokemon_species( + self, + value: H, + ) -> PokemonServiceBuilder< + Op1, + Op2, + Operation>, + Op4, + Op5, + Op6, + > + where + H: Handler, + { + self.get_pokemon_species_operation(GetPokemonSpecies::from_handler(value)) + } +``` + +To finalize the build and construct the complete service, `PokemonService`, each builder has a `build` method whose bounds list out all the requirements for composition: + +```rust + /// Constructs a [`PokemonService`] from the arguments provided to the builder. + pub fn build(self) -> PokemonService + where + Op1: Upgradable, + Op1::Service: tower::Service, + + Op2: Upgradable, + Op2::Service: tower::Service, + + /* ... */ + + Op6: Upgradable, + Op6::Service: tower::Service, +``` + +Notice the general form: `Op{N}` must upgrade to a HTTP service. + +We provide two builder constructors: + +```rust + /// Constructs a builder for [`PokemonService`]. + pub fn builder() -> PokemonServiceBuilder< + MissingOperation, + MissingOperation, + MissingOperation, + MissingOperation, + MissingOperation, + MissingOperation, + > { + PokemonServiceBuilder { + check_health: MissingOperation, + do_nothing: MissingOperation, + get_pokemon_species: MissingOperation, + get_server_statistics: MissingOperation, + capture_pokemon: MissingOperation, + get_storage: MissingOperation, + } + } + + /// Constructs an unchecked builder for [`PokemonService`]. + /// + /// This will not enforce that all operations are set, however if an unset operation is used at runtime + /// it will return status code 500 and log an error. + pub fn unchecked_builder() -> PokemonServiceBuilder< + FailOnMissingOperation, + FailOnMissingOperation, + FailOnMissingOperation, + FailOnMissingOperation, + FailOnMissingOperation, + FailOnMissingOperation, + > { + PokemonServiceBuilder { + check_health: FailOnMissingOperation, + do_nothing: FailOnMissingOperation, + get_pokemon_species: FailOnMissingOperation, + get_server_statistics: FailOnMissingOperation, + capture_pokemon: FailOnMissingOperation, + get_storage: FailOnMissingOperation, + } + } +``` + +The `builder` constructor provides a `PokemonServiceBuilder` where `build` cannot be called until all operations are set because `MissingOperation` purposefully doesn't implement `Upgradable`. In contrast, the `unchecked_builder` which sets all `Op{N}` to `FailOnMissingOperation` can be immediately built, however any unset operations are upgraded into a service which always returns status code 500, as noted in [Upgrading a Model Service](#upgrading-a-model-service). + +The build method then proceeds as follows: + +1. Upgrade all `Op{N}` to a HTTP service via their `Upgradable::upgrade` method. +2. Type erase them via [`Route`](https://github.com/awslabs/smithy-rs/blob/4c5cbc39384f0d949d7693eb87b5853fe72629cd/rust-runtime/aws-smithy-http-server/src/routing/route.rs#L49-L52) (basically amounts to `Box`ing them). +3. Pair each of them with their routing information and collect them all into a `Router`. +4. Transform the `Router` implementation into a HTTP service via `RouterService`. +5. Wrap the `RouterService` in a newtype given by the service name, `PokemonService`. + +```rust + /// Constructs a [`PokemonService`] from the arguments provided to the builder. + pub fn build(self) -> PokemonService + where + Op1: Upgradable, + Op1::Service: tower::Service, + + Op2: Upgradable, + Op2::Service: tower::Service, + + /* ... */ +{ + let router = RestRouter::from_iter([ + ( + /* `CheckHealth` (Op1) routing information */, + Route::new(self.check_health.upgrade()) + ), + ( + /* `DoNothing` (Op2) routing information */, + Route::new(self.do_nothing.upgrade()) + ), + /* ... */ + ]); + PokemonService { + router: RoutingService::new(router) + } +} +``` + +where + +```rust +/// The Pokémon Service allows you to retrieve information about Pokémon species. +#[derive(Clone)] +pub struct PokemonService { + router: RoutingService, AwsRestJson1>, +} +``` + +## Plugins + + +There are a variety of places in which the customer can apply middleware. During the build: + +- For a specific operation, for example `GetPokemonSpecies`, the model service can be wrapped by a `Layer` before passing it to `GetPokemonSpecies::from_service` constructor. +- The `Operation::layer` method can be used to apply a `Layer` to a specific operation _after_ it's been upgraded. + +After the build is finalized: + +- The entire `PokemonService` HTTP service can be wrapped by a `Layer`. +- Every `Route` in the `Router` can be wrapped by a `Layer` using `PokemonService::layer`. + +Although this provides a reasonably "complete" API, it can be cumbersome in some use cases. Suppose a customer wants to log the operation name when a request is routed to said operation. Writing a `Layer`, `NameLogger`, to log an operation name is simple, however with the current API the customer is forced to do the following + +```rust +let get_pokemon_species = GetPokemonSpecies::from_handler(/* handler */).layer(NameLogger::new("GetPokemonSpecies")); +let get_storage = GetStorage::from_handler(/* handler */).layer(NameLogger::new("GetStorage")); +let do_nothing = DoNothing::from_handler(/* handler */).layer(NameLogger::new("DoNothing")); +/* Repeat for every route... */ +``` + +Note that `PokemonService::layer` cannot be used here because it applies a _single_ layer uniformly across all `Route`s stored in the `Router`. + +```rust +impl PokemonService { + /// Applies a [`Layer`](tower::Layer) uniformly to all routes. + pub fn layer(self, layer: &L) -> PokemonService + where + L: Layer, + { + PokemonService { + router: self.router.map(|s| s.layer(layer)), + } + } +} +``` + +The plugin system solves the general problem of modifying `Operation` prior to the upgrade procedure in a way parameterized by the protocol and operation marker structures. This parameterization removes the excessive boiler plate above. + +The central trait is [`Plugin`](https://github.com/awslabs/smithy-rs/blob/4c5cbc39384f0d949d7693eb87b5853fe72629cd/rust-runtime/aws-smithy-http-server/src/plugin.rs#L31-L41): + +```rust +/// A mapping from one [`Operation`] to another. Used to modify the behavior of +/// [`Upgradable`](crate::operation::Upgradable) and therefore the resulting service builder, +/// +/// The generics `Protocol` and `Op` allow the behavior to be parameterized. +/// +/// Every service builder enjoys [`Pluggable`] and therefore can be provided with a [`Plugin`] using +/// [`Pluggable::apply`]. +pub trait Plugin { + type Service; + type Layer; + + /// Maps an [`Operation`] to another. + fn map(&self, input: Operation) -> Operation; +} +``` + +The `Upgradable::upgrade` method on `Operation`, previously presented in [Upgrading a Model Service](#upgrading-a-model-service), is more accurately: + +```rust + /// Takes the [`Operation`](Operation), applies [`Plugin`], then applies [`UpgradeLayer`] to + /// the modified `S`, then finally applies the modified `L`. + /// + /// The composition is made explicit in the method constraints and return type. + fn upgrade(self, plugin: &Pl) -> Self::Service { + let Operation { inner, layer } = plugin.map(self); + let layer = Stack::new(UpgradeLayer::new(), layer); + layer.layer(inner) + } +``` + +```mermaid +stateDiagram-v2 + direction TB + Op1: Operation#60;S1, L1#62; + state Op1 { + direction LR + [*] --> S1 : HTTP Request + S1 --> [*]: HTTP Response + state L1 { + Upgrade1 : Upgrade + state Upgrade1 { + S1 + } + } + + } + + Op2: Operation#60;S2, L2#62; + state Op2 { + direction LR + [*] --> S2: HTTP Request + S2 --> [*]: HTTP Response + state L2 { + Upgrade2 : Upgrade + state Upgrade2 { + S2 + } + } + } + + Op1 --> Op2 : Plugin#colon;#colon;map +``` + +An example `Plugin` implementation can be found in [aws-smithy-http-server/examples/pokemon-service/src/plugin.rs](https://github.com/awslabs/smithy-rs/blob/main/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/plugin.rs). + +The service builder implements the [`Pluggable`](https://github.com/awslabs/smithy-rs/blob/4c5cbc39384f0d949d7693eb87b5853fe72629cd/rust-runtime/aws-smithy-http-server/src/plugin.rs#L8-L29) trait, which allows them to apply plugins to service builders: + +```rust +/// Provides a standard interface for applying [`Plugin`]s to a service builder. This is implemented automatically for +/// all builders. +/// +/// As [`Plugin`]s modify the way in which [`Operation`]s are [`upgraded`](crate::operation::Upgradable) we can use +/// [`Pluggable`] as a foundation to write extension traits which are implemented for all service builders. +/// +/// # Example +/// +/// ``` +/// # struct PrintPlugin; +/// # use aws_smithy_http_server::plugin::Pluggable; +/// trait PrintExt: Pluggable { +/// fn print(self) -> Self::Output where Self: Sized { +/// self.apply(PrintPlugin) +/// } +/// } +/// +/// impl PrintExt for Builder where Builder: Pluggable {} +/// ``` +pub trait Pluggable { + type Output; + + /// Applies a [`Plugin`] to the service builder. + fn apply(self, plugin: NewPlugin) -> Self::Output; +} +``` + +As seen in the `Pluggable` documentation, third-parties can use extension traits over `Pluggable` to extend the API of builders. In addition to all the `Op{N}` the service builder also holds a `Pl`: + +```rust +/// The service builder for [`PokemonService`]. +/// +/// Constructed via [`PokemonService::builder`]. +pub struct PokemonServiceBuilder { + capture_pokemon_operation: Op1, + empty_operation: Op2, + get_pokemon_species: Op3, + get_server_statistics: Op4, + get_storage: Op5, + health_check_operation: Op6, + + plugin: Pl +} +``` + +which allows the following `Pluggable` implementation to be generated: + +```rust +impl Pluggable for PokemonServiceBuilder +{ + type Output = PokemonServiceBuilder>; + fn apply(self, plugin: NewPl) -> Self::Output { + PokemonServiceBuilder { + capture_pokemon_operation: self.capture_pokemon_operation, + empty_operation: self.empty_operation, + /* ... */, + + plugin: PluginStack::new(self.plugin, plugin), + } + } +} +``` + +Here `PluginStack` works in a similar way to [`tower::layer::util::Stack`](https://docs.rs/tower/latest/tower/layer/util/struct.Stack.html) - allowing users to stack a new plugin rather than replacing the currently set one. + +## Accessing Unmodelled Data + +An additional omitted detail is that we provide an "escape hatch" allowing `Handler`s and `OperationService`s to accept data that isn't modelled. In addition to accepting `Op::Input` they can accept additional arguments which implement the [`FromParts`](https://github.com/awslabs/smithy-rs/blob/4c5cbc39384f0d949d7693eb87b5853fe72629cd/rust-runtime/aws-smithy-http-server/src/request.rs#L114-L121) trait: + +```rust +use http::request::Parts; + +/// Provides a protocol aware extraction from a [`Request`]. This borrows the +/// [`Parts`], in contrast to [`FromRequest`]. +pub trait FromParts: Sized { + type Rejection: IntoResponse; + + /// Extracts `self` from a [`Parts`] synchronously. + fn from_parts(parts: &mut Parts) -> Result; +} +``` + +This differs from `FromRequest` trait, introduced in [Serialization and Deserialization](#serialization-and-deserialization), as it's synchronous and has non-consuming access to [`Parts`](https://docs.rs/http/0.2.8/http/request/struct.Parts.html), rather than the entire [Request](https://docs.rs/http/0.2.8/http/request/struct.Request.html). + +```rust +pub struct Parts { + pub method: Method, + pub uri: Uri, + pub version: Version, + pub headers: HeaderMap, + pub extensions: Extensions, + /* private fields */ +} +``` + +This is commonly used to access types stored within [`Extensions`](https://docs.rs/http/0.2.8/http/struct.Extensions.html) which have been inserted by a middleware. An `Extension` struct implements `FromParts` to support this use case: + +```rust +/// Generic extension type stored in and extracted from [request extensions]. +/// +/// This is commonly used to share state across handlers. +/// +/// If the extension is missing it will reject the request with a `500 Internal +/// Server Error` response. +/// +/// [request extensions]: https://docs.rs/http/latest/http/struct.Extensions.html +#[derive(Debug, Clone)] +pub struct Extension(pub T); + +impl FromParts for Extension +where + T: Clone + Send + Sync + 'static, +{ + type Rejection = MissingExtension; + + fn from_parts(parts: &mut http::request::Parts) -> Result { + parts.extensions.remove::().map(Extension).ok_or(MissingExtension) + } +} + +/// The extension has not been added to the [`Request`](http::Request) or has been previously removed. +#[derive(Debug, Error)] +#[error("the `Extension` is not present in the `http::Request`")] +pub struct MissingExtension; + +impl IntoResponse for MissingExtension { + fn into_response(self) -> http::Response { + let mut response = http::Response::new(empty()); + *response.status_mut() = StatusCode::INTERNAL_SERVER_ERROR; + response + } +} +``` diff --git a/design/src/server/overview.md b/design/src/server/overview.md index 2b023112c5a..8957eb45d0a 100644 --- a/design/src/server/overview.md +++ b/design/src/server/overview.md @@ -5,3 +5,4 @@ Smithy Rust provides the ability to generate a server whose operations are provi - [Generating Common Service Code](./code_generation.md) - [Generating the Pokémon Service](./pokemon_service.md) - [Instrumentation](./instrumentation.md) + diff --git a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/plugin.rs b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/plugin.rs index 6c76df56133..cb05ef2e4e9 100644 --- a/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/plugin.rs +++ b/rust-runtime/aws-smithy-http-server/examples/pokemon-service/src/plugin.rs @@ -3,7 +3,13 @@ * SPDX-License-Identifier: Apache-2.0 */ -use aws_smithy_http_server::plugin::Plugin; +use aws_smithy_http_server::{ + operation::{Operation, OperationShape}, + plugin::{Pluggable, Plugin}, +}; +use tower::{layer::util::Stack, Layer, Service}; + +use std::task::{Context, Poll}; /// A [`Service`](tower::Service) that adds a print log. #[derive(Clone, Debug)] @@ -12,15 +18,15 @@ pub struct PrintService { name: &'static str, } -impl tower::Service for PrintService +impl Service for PrintService where - S: tower::Service, + S: Service, { type Response = S::Response; type Error = S::Error; type Future = S::Future; - fn poll_ready(&mut self, cx: &mut std::task::Context<'_>) -> std::task::Poll> { + fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll> { self.inner.poll_ready(cx) } @@ -35,7 +41,7 @@ where pub struct PrintLayer { name: &'static str, } -impl tower::Layer for PrintLayer { +impl Layer for PrintLayer { type Service = PrintService; fn layer(&self, service: S) -> Self::Service { @@ -46,26 +52,24 @@ impl tower::Layer for PrintLayer { } } -/// A [`Plugin`]() for a service builder to add a [`PrintLayer`] over operations. +/// A [`Plugin`] for a service builder to add a [`PrintLayer`] over operations. #[derive(Debug)] pub struct PrintPlugin; + impl Plugin for PrintPlugin where - Op: aws_smithy_http_server::operation::OperationShape, + Op: OperationShape, { type Service = S; - type Layer = tower::layer::util::Stack; + type Layer = Stack; - fn map( - &self, - input: aws_smithy_http_server::operation::Operation, - ) -> aws_smithy_http_server::operation::Operation { + fn map(&self, input: Operation) -> Operation { input.layer(PrintLayer { name: Op::NAME }) } } /// An extension to service builders to add the `print()` function. -pub trait PrintExt: aws_smithy_http_server::plugin::Pluggable { +pub trait PrintExt: Pluggable { /// Causes all operations to print the operation name when called. /// /// This works by applying the [`PrintPlugin`]. @@ -77,4 +81,4 @@ pub trait PrintExt: aws_smithy_http_server::plugin::Pluggable { } } -impl PrintExt for Builder where Builder: aws_smithy_http_server::plugin::Pluggable {} +impl PrintExt for Builder where Builder: Pluggable {} diff --git a/rust-runtime/aws-smithy-http-server/src/operation/mod.rs b/rust-runtime/aws-smithy-http-server/src/operation/mod.rs index 5fec3a2f155..ddfab157d69 100644 --- a/rust-runtime/aws-smithy-http-server/src/operation/mod.rs +++ b/rust-runtime/aws-smithy-http-server/src/operation/mod.rs @@ -49,7 +49,7 @@ //! //! ## [`Handler`] //! -//! The [`Handler`] trait is implemented by all closures which accept [`OperationShape::Input`] as their first +//! The [`Handler`] trait is implemented by all async functions which accept [`OperationShape::Input`] as their first //! argument, the remaining arguments implement [`FromParts`](crate::request::FromParts), and return either //! [`OperationShape::Output`] when [`OperationShape::Error`] is [`Infallible`](std::convert::Infallible) or //! [`Result`]<[`OperationShape::Output`],[`OperationShape::Error`]>. The following are examples of closures which @@ -191,7 +191,7 @@ pub use upgrade::*; /// A Smithy operation, represented by a [`Service`](tower::Service) `S` and a [`Layer`](tower::Layer) `L`. /// -/// The `L` is held and applied lazily during [`Operation::upgrade`]. +/// The `L` is held and applied lazily during [`Upgradable::upgrade`]. pub struct Operation { inner: S, layer: L, diff --git a/rust-runtime/aws-smithy-http-server/src/plugin.rs b/rust-runtime/aws-smithy-http-server/src/plugin.rs index 8ba1f5747a6..206a0d7fea7 100644 --- a/rust-runtime/aws-smithy-http-server/src/plugin.rs +++ b/rust-runtime/aws-smithy-http-server/src/plugin.rs @@ -5,9 +5,11 @@ use crate::operation::Operation; -/// Provides a standard interface for applying [`Plugin`]s to a service builder. This is implemented automatically for all builders. -/// As [`Plugin`]s modify the way in which [`Operation`]s are [`upgraded`](crate::operation::Upgradable) we can use [`Pluggable`] as a foundation -/// to write extension traits for all builders. +/// Provides a standard interface for applying [`Plugin`]s to a service builder. This is implemented automatically for +/// all builders. +/// +/// As [`Plugin`]s modify the way in which [`Operation`]s are [`upgraded`](crate::operation::Upgradable) we can use +/// [`Pluggable`] as a foundation to write extension traits which are implemented for all service builders. /// /// # Example /// @@ -19,29 +21,34 @@ use crate::operation::Operation; /// self.apply(PrintPlugin) /// } /// } +/// /// impl PrintExt for Builder where Builder: Pluggable {} /// ``` pub trait Pluggable { type Output; - /// A service builder applies this `plugin`. + /// Applies a [`Plugin`] to the service builder. fn apply(self, plugin: NewPlugin) -> Self::Output; } -/// Maps one [`Operation`] to another, -/// parameterised by the protocol `P` and operation shape `Op` to allow for plugin behaviour to be specialised accordingly. +/// A mapping from one [`Operation`] to another. Used to modify the behavior of +/// [`Upgradable`](crate::operation::Upgradable) and therefore the resulting service builder, /// -/// This is passed to [`Pluggable::apply`] to modify the behaviour of the builder. -pub trait Plugin { +/// The generics `Protocol` and `Op` allow the behavior to be parameterized. +/// +/// Every service builder enjoys [`Pluggable`] and therefore can be provided with a [`Plugin`] using +/// [`Pluggable::apply`]. +pub trait Plugin { type Service; type Layer; - /// Map an [`Operation`] to another. + /// Maps an [`Operation`] to another. fn map(&self, input: Operation) -> Operation; } /// An [`Plugin`] that maps an `input` [`Operation`] to itself. pub struct IdentityPlugin; + impl Plugin for IdentityPlugin { type Service = S; type Layer = L; diff --git a/rust-runtime/aws-smithy-http-server/src/routers/mod.rs b/rust-runtime/aws-smithy-http-server/src/routers/mod.rs index abefe0ba32d..ecffe36e0cd 100644 --- a/rust-runtime/aws-smithy-http-server/src/routers/mod.rs +++ b/rust-runtime/aws-smithy-http-server/src/routers/mod.rs @@ -46,9 +46,9 @@ pub trait Router { fn match_route(&self, request: &http::Request) -> Result; } -/// A [`Service`] using the a [`Router`] `R` to redirect messages to specific routes. +/// A [`Service`] using the [`Router`] `R` to redirect messages to specific routes. /// -/// The `Protocol` parameter is used to determine +/// The `Protocol` parameter is used to determine the serialization of errors. pub struct RoutingService { router: R, _protocol: PhantomData, From 046edd54ab71b242895c9dddecfe642dde0309d6 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Tue, 11 Oct 2022 12:46:13 -0700 Subject: [PATCH 31/57] Remove `cargo-check-external-types` (#1820) This tool now has its own repository: https://github.com/awslabs/cargo-check-external-types --- tools/Dockerfile | 5 +- tools/cargo-check-external-types/Cargo.lock | 630 ------------------ tools/cargo-check-external-types/Cargo.toml | 27 - tools/cargo-check-external-types/LICENSE | 175 ----- tools/cargo-check-external-types/README.md | 61 -- .../cargo-check-external-types/additional-ci | 10 - tools/cargo-check-external-types/src/cargo.rs | 121 ---- .../cargo-check-external-types/src/config.rs | 144 ---- tools/cargo-check-external-types/src/error.rs | 276 -------- tools/cargo-check-external-types/src/lib.rs | 22 - tools/cargo-check-external-types/src/main.rs | 232 ------- tools/cargo-check-external-types/src/path.rs | 93 --- .../cargo-check-external-types/src/visitor.rs | 579 ---------------- .../test-workspace/.gitignore | 1 - .../test-workspace/Cargo.toml | 2 - .../test-workspace/external-lib/Cargo.toml | 7 - .../test-workspace/external-lib/src/lib.rs | 42 -- .../test-workspace/test-crate/Cargo.toml | 8 - .../test-workspace/test-crate/src/lib.rs | 159 ----- .../test-crate/src/test_union.rs | 24 - .../test-reexports-crate/Cargo.toml | 8 - .../test-reexports-crate/src/lib.rs | 16 - .../allow-some-types-expected-output.txt | 39 -- .../tests/allow-some-types.toml | 6 - .../tests/default-config-expected-output.txt | 369 ---------- .../tests/integration_test.rs | 77 --- ...t-format-markdown-table-expected-output.md | 44 -- .../tests/test-reexports-expected-output.md | 57 -- tools/ci-build/scripts/check-tools | 1 - 29 files changed, 3 insertions(+), 3232 deletions(-) delete mode 100644 tools/cargo-check-external-types/Cargo.lock delete mode 100644 tools/cargo-check-external-types/Cargo.toml delete mode 100644 tools/cargo-check-external-types/LICENSE delete mode 100644 tools/cargo-check-external-types/README.md delete mode 100755 tools/cargo-check-external-types/additional-ci delete mode 100644 tools/cargo-check-external-types/src/cargo.rs delete mode 100644 tools/cargo-check-external-types/src/config.rs delete mode 100644 tools/cargo-check-external-types/src/error.rs delete mode 100644 tools/cargo-check-external-types/src/lib.rs delete mode 100644 tools/cargo-check-external-types/src/main.rs delete mode 100644 tools/cargo-check-external-types/src/path.rs delete mode 100644 tools/cargo-check-external-types/src/visitor.rs delete mode 100644 tools/cargo-check-external-types/test-workspace/.gitignore delete mode 100644 tools/cargo-check-external-types/test-workspace/Cargo.toml delete mode 100644 tools/cargo-check-external-types/test-workspace/external-lib/Cargo.toml delete mode 100644 tools/cargo-check-external-types/test-workspace/external-lib/src/lib.rs delete mode 100644 tools/cargo-check-external-types/test-workspace/test-crate/Cargo.toml delete mode 100644 tools/cargo-check-external-types/test-workspace/test-crate/src/lib.rs delete mode 100644 tools/cargo-check-external-types/test-workspace/test-crate/src/test_union.rs delete mode 100644 tools/cargo-check-external-types/test-workspace/test-reexports-crate/Cargo.toml delete mode 100644 tools/cargo-check-external-types/test-workspace/test-reexports-crate/src/lib.rs delete mode 100644 tools/cargo-check-external-types/tests/allow-some-types-expected-output.txt delete mode 100644 tools/cargo-check-external-types/tests/allow-some-types.toml delete mode 100644 tools/cargo-check-external-types/tests/default-config-expected-output.txt delete mode 100644 tools/cargo-check-external-types/tests/integration_test.rs delete mode 100644 tools/cargo-check-external-types/tests/output-format-markdown-table-expected-output.md delete mode 100644 tools/cargo-check-external-types/tests/test-reexports-expected-output.md diff --git a/tools/Dockerfile b/tools/Dockerfile index 1e61c92387a..9d8c0b963b7 100644 --- a/tools/Dockerfile +++ b/tools/Dockerfile @@ -51,6 +51,7 @@ ARG cargo_deny_version=0.12.2 ARG cargo_udeps_version=0.1.29 ARG cargo_hack_version=0.5.14 ARG cargo_minimal_versions_version=0.1.4 +ARG cargo_check_external_types_version=0.1.4 ENV RUSTUP_HOME=/opt/rustup \ CARGO_HOME=/opt/cargo \ PATH=/opt/cargo/bin/:${PATH} \ @@ -97,14 +98,14 @@ RUN set -eux; \ cargo install cargo-deny --locked --version ${cargo_deny_version}; \ cargo +${rust_nightly_version} install cargo-udeps --locked --version ${cargo_udeps_version}; \ cargo install cargo-hack --locked --version ${cargo_hack_version}; \ - cargo install cargo-minimal-versions --version ${cargo_minimal_versions_version}; \ + cargo install cargo-minimal-versions --locked --version ${cargo_minimal_versions_version}; \ + cargo install cargo-check-external-types --locked --version ${cargo_check_external_types_version}; \ if [[ "${checkout_smithy_rs_tools}" == "true" ]]; then \ git clone https://github.com/awslabs/smithy-rs.git; \ cd smithy-rs; \ git checkout ${smithy_rs_commit_hash}; \ fi; \ cargo install --locked --path tools/publisher; \ - cargo install --locked --path tools/cargo-check-external-types; \ cargo install --locked --path tools/changelogger; \ cargo install --locked --path tools/crate-hasher; \ cargo install --locked --path tools/sdk-lints; \ diff --git a/tools/cargo-check-external-types/Cargo.lock b/tools/cargo-check-external-types/Cargo.lock deleted file mode 100644 index b35e21c09dc..00000000000 --- a/tools/cargo-check-external-types/Cargo.lock +++ /dev/null @@ -1,630 +0,0 @@ -# This file is automatically @generated by Cargo. -# It is not intended for manual editing. -version = 3 - -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - -[[package]] -name = "anyhow" -version = "1.0.62" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1485d4d2cc45e7b201ee3767015c96faa5904387c9d87c6efdd0fb511f12d305" - -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi", - "libc", - "winapi", -] - -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - -[[package]] -name = "camino" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88ad0e1e3e88dd237a156ab9f571021b8a158caa0ae44b1968a241efb5144c1e" -dependencies = [ - "serde", -] - -[[package]] -name = "cargo-check-external-types" -version = "0.1.3" -dependencies = [ - "anyhow", - "cargo_metadata", - "clap", - "owo-colors", - "pest", - "pretty_assertions", - "rustdoc-types", - "serde", - "serde_json", - "test_bin", - "toml", - "tracing", - "tracing-attributes", - "tracing-subscriber", - "wildmatch", -] - -[[package]] -name = "cargo-platform" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbdb825da8a5df079a43676dbe042702f1707b1109f713a01420fbb4cc71fa27" -dependencies = [ - "serde", -] - -[[package]] -name = "cargo_metadata" -version = "0.14.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4acbb09d9ee8e23699b9634375c72795d095bf268439da88562cf9b501f181fa" -dependencies = [ - "camino", - "cargo-platform", - "semver", - "serde", - "serde_json", -] - -[[package]] -name = "cfg-if" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" - -[[package]] -name = "clap" -version = "3.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" -dependencies = [ - "atty", - "bitflags", - "clap_derive", - "clap_lex", - "indexmap", - "lazy_static", - "strsim", - "termcolor", - "textwrap", -] - -[[package]] -name = "clap_derive" -version = "3.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "clap_lex" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" -dependencies = [ - "os_str_bytes", -] - -[[package]] -name = "ctor" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb" -dependencies = [ - "quote", - "syn", -] - -[[package]] -name = "diff" -version = "0.1.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8" - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "heck" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "indexmap" -version = "1.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" -dependencies = [ - "autocfg", - "hashbrown", -] - -[[package]] -name = "is_ci" -version = "1.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "616cde7c720bb2bb5824a224687d8f77bfd38922027f01d825cd7453be5099fb" - -[[package]] -name = "itoa" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" - -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - -[[package]] -name = "libc" -version = "0.2.132" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" - -[[package]] -name = "log" -version = "0.4.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" -dependencies = [ - "cfg-if", -] - -[[package]] -name = "matchers" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8263075bb86c5a1b1427b5ae862e8889656f126e9f77c484496e8b47cf5c5558" -dependencies = [ - "regex-automata", -] - -[[package]] -name = "once_cell" -version = "1.13.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "074864da206b4973b84eb91683020dbefd6a8c3f0f38e054d93954e891935e4e" - -[[package]] -name = "os_str_bytes" -version = "6.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" - -[[package]] -name = "output_vt100" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "628223faebab4e3e40667ee0b2336d34a5b960ff60ea743ddfdbcf7770bcfb66" -dependencies = [ - "winapi", -] - -[[package]] -name = "owo-colors" -version = "3.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f" -dependencies = [ - "supports-color", -] - -[[package]] -name = "pest" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b0560d531d1febc25a3c9398a62a71256c0178f2e3443baedd9ad4bb8c9deb4" -dependencies = [ - "thiserror", - "ucd-trie", -] - -[[package]] -name = "pin-project-lite" -version = "0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" - -[[package]] -name = "pretty_assertions" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c89f989ac94207d048d92db058e4f6ec7342b0971fc58d1271ca148b799b3563" -dependencies = [ - "ansi_term", - "ctor", - "diff", - "output_vt100", -] - -[[package]] -name = "proc-macro-error" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2", - "quote", - "syn", - "version_check", -] - -[[package]] -name = "proc-macro-error-attr" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2", - "quote", - "version_check", -] - -[[package]] -name = "proc-macro2" -version = "1.0.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" -dependencies = [ - "unicode-ident", -] - -[[package]] -name = "quote" -version = "1.0.21" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" -dependencies = [ - "proc-macro2", -] - -[[package]] -name = "regex" -version = "1.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c4eb3267174b8c6c2f654116623910a0fef09c4753f8dd83db29c48a0df988b" -dependencies = [ - "regex-syntax", -] - -[[package]] -name = "regex-automata" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" -dependencies = [ - "regex-syntax", -] - -[[package]] -name = "regex-syntax" -version = "0.6.27" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3f87b73ce11b1619a3c6332f45341e0047173771e8b8b73f87bfeefb7b56244" - -[[package]] -name = "rustdoc-types" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3a260c376ebec8b6fcd30f518b253772873c5dd8564b45e384aad8a79c62aa6" -dependencies = [ - "serde", -] - -[[package]] -name = "ryu" -version = "1.0.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" - -[[package]] -name = "semver" -version = "1.0.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f6841e709003d68bb2deee8c343572bf446003ec20a583e76f7b15cebf3711" -dependencies = [ - "serde", -] - -[[package]] -name = "serde" -version = "1.0.144" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" -dependencies = [ - "serde_derive", -] - -[[package]] -name = "serde_derive" -version = "1.0.144" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "serde_json" -version = "1.0.85" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" -dependencies = [ - "itoa", - "ryu", - "serde", -] - -[[package]] -name = "sharded-slab" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "smallvec" -version = "1.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1" - -[[package]] -name = "strsim" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" - -[[package]] -name = "supports-color" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4872ced36b91d47bae8a214a683fe54e7078875b399dfa251df346c9b547d1f9" -dependencies = [ - "atty", - "is_ci", -] - -[[package]] -name = "syn" -version = "1.0.99" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - -[[package]] -name = "termcolor" -version = "1.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" -dependencies = [ - "winapi-util", -] - -[[package]] -name = "test_bin" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e7a7de15468c6e65dd7db81cf3822c1ec94c71b2a3c1a976ea8e4696c91115c" - -[[package]] -name = "textwrap" -version = "0.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" - -[[package]] -name = "thiserror" -version = "1.0.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5f6586b7f764adc0231f4c79be7b920e766bb2f3e51b3661cdb263828f19994" -dependencies = [ - "thiserror-impl", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "thread_local" -version = "1.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180" -dependencies = [ - "once_cell", -] - -[[package]] -name = "toml" -version = "0.5.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d82e1a7758622a465f8cee077614c73484dac5b836c02ff6a40d5d1010324d7" -dependencies = [ - "serde", -] - -[[package]] -name = "tracing" -version = "0.1.36" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2fce9567bd60a67d08a16488756721ba392f24f29006402881e43b19aac64307" -dependencies = [ - "cfg-if", - "pin-project-lite", - "tracing-attributes", - "tracing-core", -] - -[[package]] -name = "tracing-attributes" -version = "0.1.22" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] -name = "tracing-core" -version = "0.1.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aeea4303076558a00714b823f9ad67d58a3bbda1df83d8827d21193156e22f7" -dependencies = [ - "once_cell", - "valuable", -] - -[[package]] -name = "tracing-log" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" -dependencies = [ - "lazy_static", - "log", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60db860322da191b40952ad9affe65ea23e7dd6a5c442c2c42865810c6ab8e6b" -dependencies = [ - "ansi_term", - "matchers", - "once_cell", - "regex", - "sharded-slab", - "smallvec", - "thread_local", - "tracing", - "tracing-core", - "tracing-log", -] - -[[package]] -name = "ucd-trie" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89570599c4fe5585de2b388aab47e99f7fa4e9238a1399f707a02e356058141c" - -[[package]] -name = "unicode-ident" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4f5b37a154999a8f3f98cc23a628d850e154479cd94decf3414696e12e31aaf" - -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - -[[package]] -name = "version_check" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" - -[[package]] -name = "wildmatch" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee583bdc5ff1cf9db20e9db5bb3ff4c3089a8f6b8b31aff265c9aba85812db86" - -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - -[[package]] -name = "winapi-util" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" -dependencies = [ - "winapi", -] - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/tools/cargo-check-external-types/Cargo.toml b/tools/cargo-check-external-types/Cargo.toml deleted file mode 100644 index bc888d25925..00000000000 --- a/tools/cargo-check-external-types/Cargo.toml +++ /dev/null @@ -1,27 +0,0 @@ -[package] -name = "cargo-check-external-types" -version = "0.1.3" -authors = ["AWS Rust SDK Team ", "John DiSanti "] -description = "Static analysis tool to detect external types exposed in a library's public API." -edition = "2021" -license = "Apache-2.0" -repository = "https://github.com/awslabs/smithy-rs" - -[dependencies] -anyhow = "1" -cargo_metadata = "0.14" -clap = { version = "~3.1.18", features = ["derive"] } -owo-colors = { version = "3", features = ["supports-colors"] } -pest = "2" # For pretty error formatting -rustdoc-types = "0.12" -serde = { version = "1", features = ["derive"] } -serde_json = "1" -toml = "0.5" -tracing = "0.1" -tracing-attributes = "0.1" -tracing-subscriber = { version = "0.3.15", features = ["env-filter"] } -wildmatch = "2" - -[dev-dependencies] -pretty_assertions = "1.1" -test_bin = "0.4" diff --git a/tools/cargo-check-external-types/LICENSE b/tools/cargo-check-external-types/LICENSE deleted file mode 100644 index 67db8588217..00000000000 --- a/tools/cargo-check-external-types/LICENSE +++ /dev/null @@ -1,175 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. diff --git a/tools/cargo-check-external-types/README.md b/tools/cargo-check-external-types/README.md deleted file mode 100644 index 820d4c95c6b..00000000000 --- a/tools/cargo-check-external-types/README.md +++ /dev/null @@ -1,61 +0,0 @@ -cargo-check-external-types -========================== - -Static analysis tool that detects external types used in a Rust library's public API. -Configuration can be provided to allow certain external types so that this tool can -be used in continuous integration so that types don't unintentionally make it into -the library's API. It can also output a Markdown table of the external types it found. - -Example Output --------------- - -The test suite has a Rust library that [relies on some external types](test-workspace/test-crate/src/lib.rs). -When the tool is run against this library without any configuration, -[it emits errors](tests/default-config-expected-output.txt) -for each occurrence of an external type in the public API. - -When [a config file](tests/allow-some-types.toml) is provided, -the allowed external types [no longer show up in the output](tests/allow-some-types-expected-output.txt). - -When the output format is set to `markdown-table`, then -a [table of external types](tests/output-format-markdown-table-expected-output.md) is output. - -How to Use ----------- - -_Important:_ This tool requires a nightly build of Rust to be installed since it relies on rustdoc JSON output. -It was last tested against nightly-2022-07-25. - -To install, run the following from this README path: - -```bash -cargo install --locked cargo-check-external-types -``` - -Then, in your library crate path, run: -```bash -cargo +nightly check-external-types -``` - -This will produce errors if any external types are used in a public API at all. That's not terribly useful -on its own, so the tool can be given a config file to allow certain types. For example, we can allow -any type in `bytes` with: - -```toml -allowed_external_types = [ - "bytes::*", -] -``` - -Save that file somewhere in your project (in this example, we choose the name `external-types.toml`), and then -run the command with: - -```bash -cargo +nightly check-external-types --config external-types.toml -``` - -License -------- - -This tool is distributed under the terms of Apache License Version 2.0. -See the [LICENSE](LICENSE) file for more information. diff --git a/tools/cargo-check-external-types/additional-ci b/tools/cargo-check-external-types/additional-ci deleted file mode 100755 index 66816d0d60a..00000000000 --- a/tools/cargo-check-external-types/additional-ci +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -# -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: Apache-2.0 - -set -e -cd "$(dirname "$0")" - -cargo clippy -cargo "+${RUST_NIGHTLY_VERSION}" test diff --git a/tools/cargo-check-external-types/src/cargo.rs b/tools/cargo-check-external-types/src/cargo.rs deleted file mode 100644 index 4cc7b144a33..00000000000 --- a/tools/cargo-check-external-types/src/cargo.rs +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -use crate::here; -use anyhow::{bail, Context, Result}; -use rustdoc_types::{Crate, FORMAT_VERSION}; -use serde::Deserialize; -use std::fs; -use std::path::PathBuf; -use std::process::{Command, Output}; - -#[derive(Deserialize)] -struct CrateFormatVersion { - format_version: u32, -} - -/// Runs the `cargo rustdoc` command required to produce Rustdoc's JSON output with a nightly compiler. -pub struct CargoRustDocJson { - /// Name of the crate (as specified in the Cargo.toml file) - crate_name: String, - /// Path of the crate to examine - crate_path: PathBuf, - /// Expected `target/` directory where the output will be - target_path: PathBuf, - /// Features to enable - features: Vec, -} - -impl CargoRustDocJson { - pub fn new( - crate_name: impl Into, - crate_path: impl Into, - target_path: impl Into, - features: Vec, - ) -> Self { - CargoRustDocJson { - crate_name: crate_name.into(), - crate_path: crate_path.into(), - target_path: target_path.into(), - features, - } - } - - pub fn run(&self) -> Result { - let cargo = std::env::var("CARGO") - .ok() - .unwrap_or_else(|| "cargo".to_string()); - - let mut command = Command::new(&cargo); - command.current_dir(&self.crate_path).arg("rustdoc"); - if !self.features.is_empty() { - command.arg("--no-default-features").arg("--features"); - command.arg(&self.features.join(",")); - } - command - .arg("--") - .arg("--document-private-items") - .arg("-Z") - .arg("unstable-options") - .arg("--output-format") - .arg("json"); - let output = command - .output() - .context(here!("failed to run nightly rustdoc"))?; - handle_failure("rustdoc", &output)?; - - let output_file_name = self - .target_path - .canonicalize() - .context(here!())? - .join(format!("doc/{}.json", self.crate_name.replace('-', "_"))); - - let json = fs::read_to_string(output_file_name).context(here!())?; - let format_version: CrateFormatVersion = serde_json::from_str(&json) - .context("Failed to find `format_version` in rustdoc JSON output.") - .context(here!())?; - if format_version.format_version != FORMAT_VERSION { - bail!( - "The version of rustdoc being used produces JSON format version {0}, but \ - this tool requires format version {1}. This can happen if the locally \ - installed version of rustdoc doesn't match the rustdoc JSON types from \ - the `rustdoc-types` crate.\n\n\ - If this occurs with the latest Rust nightly and the latest version of this \ - tool, then this is a bug, and the tool needs to be upgraded to the latest \ - format version.\n\n\ - Otherwise, you'll need to determine a Rust nightly version that matches \ - this tool's supported format version (or vice versa).", - format_version.format_version, - FORMAT_VERSION - ); - } - let package: Crate = serde_json::from_str(&json) - .context("Failed to parse rustdoc output.") - .context(here!())?; - Ok(package) - } -} - -pub fn handle_failure(operation_name: &str, output: &Output) -> Result<(), anyhow::Error> { - if !output.status.success() { - return Err(capture_error(operation_name, output)); - } - Ok(()) -} - -pub fn capture_error(operation_name: &str, output: &Output) -> anyhow::Error { - let message = format!( - "Failed to {name}:\nStatus: {status}\nStdout: {stdout}\nStderr: {stderr}\n", - name = operation_name, - status = if let Some(code) = output.status.code() { - format!("{}", code) - } else { - "Killed by signal".to_string() - }, - stdout = String::from_utf8_lossy(&output.stdout), - stderr = String::from_utf8_lossy(&output.stderr) - ); - anyhow::Error::msg(message) -} diff --git a/tools/cargo-check-external-types/src/config.rs b/tools/cargo-check-external-types/src/config.rs deleted file mode 100644 index fa74e3c076f..00000000000 --- a/tools/cargo-check-external-types/src/config.rs +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -use serde::de::{SeqAccess, Visitor}; -use serde::{Deserialize, Deserializer}; -use std::fmt; -use wildmatch::WildMatch; - -/// Struct reprepsentation of the TOML config files that specify which external types are allowed. -#[derive(Debug, Deserialize)] -pub struct Config { - /// Whether or not to allow types from `alloc`. Defaults to true. - #[serde(default = "default_allow_std")] - pub allow_alloc: bool, - - /// Whether or not to allow types from `core`. Defaults to true. - #[serde(default = "default_allow_std")] - pub allow_core: bool, - - /// Whether or not to allow types from `std`. Defaults to true. - #[serde(default = "default_allow_std")] - pub allow_std: bool, - - /// List of globs for allowed external types - /// - /// For example, to allow every type in a crate: - /// ```toml - /// allowed_external_types = [ - /// "crate_name::*" - /// ] - /// ``` - /// - /// Or, to selectively allow just a module of that crate - /// ```toml - /// allowed_external_types = [ - /// "crate_name::path::to_module::*" - /// ] - /// ``` - #[serde(deserialize_with = "deserialize_vec_wild_match")] - pub allowed_external_types: Vec, -} - -impl Config { - /// Returns true if the given `type_name` is allowed by this config for the given `root_crate_name`. - pub fn allows_type(&self, root_crate_name: &str, type_name: &str) -> bool { - let type_crate_name = &type_name[0..type_name.find("::").unwrap_or(type_name.len())]; - match type_crate_name { - _ if type_crate_name == root_crate_name => true, - "alloc" => self.allow_alloc, - "core" => self.allow_core, - "std" => self.allow_std, - _ => self - .allowed_external_types - .iter() - .any(|glob| glob.matches(type_name)), - } - } -} - -impl Default for Config { - fn default() -> Self { - Self { - allow_alloc: default_allow_std(), - allow_core: default_allow_std(), - allow_std: default_allow_std(), - allowed_external_types: Default::default(), - } - } -} - -const fn default_allow_std() -> bool { - true -} - -struct VecWildMatchDeserializer; - -impl<'de> Visitor<'de> for VecWildMatchDeserializer { - type Value = Vec; - - fn expecting(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str("list of glob strings") - } - - fn visit_seq(self, mut seq: A) -> Result - where - A: SeqAccess<'de>, - { - let mut result = Vec::new(); - while let Some(value) = seq.next_element::<&str>()? { - result.push(WildMatch::new(value)); - } - Ok(result) - } -} - -fn deserialize_vec_wild_match<'de, D>(de: D) -> Result, D::Error> -where - D: Deserializer<'de>, -{ - de.deserialize_any(VecWildMatchDeserializer) -} - -#[cfg(test)] -mod tests { - use super::Config; - use wildmatch::WildMatch; - - #[test] - fn deserialize_config() { - let config = r#" - allow_std = false - allowed_external_types = [ - "test::*", - "another_test::something::*::something", - ] - "#; - let config: Config = toml::from_str(config).unwrap(); - assert!(config.allow_alloc); - assert!(config.allow_core); - assert!(!config.allow_std); - assert!(config.allowed_external_types[0].matches("test::something")); - assert!(!config.allowed_external_types[0].matches("other::something")); - assert!(config.allowed_external_types[1].matches("another_test::something::foo::something")); - assert!(!config.allowed_external_types[1].matches("another_test::other::foo::something")); - } - - #[test] - fn test_allows_type() { - let config = Config { - allowed_external_types: vec![WildMatch::new("one::*"), WildMatch::new("two::*")], - ..Default::default() - }; - assert!(config.allows_type("root", "alloc::System")); - assert!(config.allows_type("root", "std::vec::Vec")); - assert!(config.allows_type("root", "std::path::Path")); - - assert!(config.allows_type("root", "root::thing")); - assert!(config.allows_type("root", "one::thing")); - assert!(config.allows_type("root", "two::thing")); - assert!(!config.allows_type("root", "three::thing")); - } -} diff --git a/tools/cargo-check-external-types/src/error.rs b/tools/cargo-check-external-types/src/error.rs deleted file mode 100644 index fed669eb36e..00000000000 --- a/tools/cargo-check-external-types/src/error.rs +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -use anyhow::{Context, Result}; -use owo_colors::{OwoColorize, Stream}; -use pest::Position; -use rustdoc_types::Span; -use std::cmp::Ordering; -use std::collections::HashMap; -use std::fmt; -use std::path::{Path, PathBuf}; - -/// Where the error occurred relative to the [`Path`](crate::path::Path). -/// -/// For example, if the path is a path to a function, then this could point to something -/// specific about that function, such as a specific function argument that is in error. -/// -/// There is overlap in this enum with [`ComponentType`](crate::path::ComponentType) since -/// some paths are specific enough to locate the external type. -#[derive(Clone, Debug, Eq, PartialEq)] -pub enum ErrorLocation { - AssocType, - ArgumentNamed(String), - ClosureInput, - ClosureOutput, - ConstGeneric, - Constant, - EnumTupleEntry, - GenericArg, - GenericDefaultBinding, - ImplementedTrait, - QualifiedSelfType, - QualifiedSelfTypeAsTrait, - ReExport, - ReturnValue, - Static, - StructField, - TraitBound, - TypeDef, - WhereBound, -} - -impl fmt::Display for ErrorLocation { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let s = match self { - Self::AssocType => "associated type", - Self::ArgumentNamed(name) => return write!(f, "argument named `{}` of", name), - Self::ClosureInput => "closure input of", - Self::ClosureOutput => "closure output of", - Self::ConstGeneric => "const generic of", - Self::Constant => "constant", - Self::EnumTupleEntry => "enum tuple entry of", - Self::GenericArg => "generic arg of", - Self::GenericDefaultBinding => "generic default binding of", - Self::ImplementedTrait => "implemented trait of", - Self::QualifiedSelfType => "qualified self type", - Self::QualifiedSelfTypeAsTrait => "qualified type `as` trait", - Self::ReExport => "re-export named", - Self::ReturnValue => "return value of", - Self::Static => "static value", - Self::StructField => "struct field of", - Self::TraitBound => "trait bound of", - Self::TypeDef => "typedef type of", - Self::WhereBound => "where bound of", - }; - write!(f, "{}", s) - } -} - -/// Error type for validation errors that get displayed to the user on the CLI. -#[derive(Debug)] -pub enum ValidationError { - UnapprovedExternalTypeRef { - type_name: String, - what: ErrorLocation, - in_what_type: String, - location: Option, - sort_key: String, - }, -} - -impl ValidationError { - pub fn unapproved_external_type_ref( - type_name: impl Into, - what: &ErrorLocation, - in_what_type: impl Into, - location: Option<&Span>, - ) -> Self { - let type_name = type_name.into(); - let in_what_type = in_what_type.into(); - let sort_key = format!( - "{}:{}:{}:{}", - location_sort_key(location), - type_name, - what, - in_what_type - ); - Self::UnapprovedExternalTypeRef { - type_name, - what: what.clone(), - in_what_type, - location: location.cloned(), - sort_key, - } - } - - pub fn type_name(&self) -> &str { - match self { - Self::UnapprovedExternalTypeRef { type_name, .. } => type_name, - } - } - - pub fn location(&self) -> Option<&Span> { - match self { - Self::UnapprovedExternalTypeRef { location, .. } => location.as_ref(), - } - } - - fn sort_key(&self) -> &str { - match self { - Self::UnapprovedExternalTypeRef { sort_key, .. } => sort_key.as_ref(), - } - } - - pub fn fmt_headline(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - Self::UnapprovedExternalTypeRef { type_name, .. } => { - let inner = format!( - "Unapproved external type `{}` referenced in public API", - type_name - ); - write!( - f, - "{} {}", - "error:" - .if_supports_color(Stream::Stdout, |text| text.red()) - .if_supports_color(Stream::Stdout, |text| text.bold()), - inner.if_supports_color(Stream::Stdout, |text| text.bold()) - ) - } - } - } - - pub fn subtext(&self) -> String { - match self { - Self::UnapprovedExternalTypeRef { - what, in_what_type, .. - } => format!("in {} `{}`", what, in_what_type), - } - } -} - -fn location_sort_key(location: Option<&Span>) -> String { - if let Some(location) = location { - format!( - "{}:{:07}:{:07}", - location.filename.to_string_lossy(), - location.begin.0, - location.begin.1 - ) - } else { - "none".into() - } -} - -impl Ord for ValidationError { - fn cmp(&self, other: &Self) -> Ordering { - self.partial_cmp(other).unwrap() - } -} - -impl PartialOrd for ValidationError { - fn partial_cmp(&self, other: &Self) -> Option { - self.sort_key().partial_cmp(other.sort_key()) - } -} - -impl Eq for ValidationError {} - -impl PartialEq for ValidationError { - fn eq(&self, other: &Self) -> bool { - self.sort_key() == other.sort_key() - } -} - -impl fmt::Display for ValidationError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - self.fmt_headline(f) - } -} - -/// Pretty printer for error context. -/// -/// This makes validation errors look similar to the compiler errors from rustc. -pub struct ErrorPrinter { - workspace_root: PathBuf, - file_cache: HashMap, -} - -impl ErrorPrinter { - pub fn new(workspace_root: impl Into) -> Self { - Self { - workspace_root: workspace_root.into(), - file_cache: HashMap::new(), - } - } - - fn get_file_contents(&mut self, path: &Path) -> Result<&str> { - if !self.file_cache.contains_key(path) { - let full_file_name = self.workspace_root.join(path).canonicalize()?; - let contents = std::fs::read_to_string(&full_file_name) - .context("failed to load source file for error context") - .context(full_file_name.to_string_lossy().to_string())?; - self.file_cache.insert(path.to_path_buf(), contents); - } - Ok(self.file_cache.get(path).unwrap()) - } - - pub fn pretty_print_error_context(&mut self, location: &Span, subtext: String) { - match self.get_file_contents(&location.filename) { - Ok(file_contents) => { - let begin = Self::position_from_line_col(file_contents, location.begin); - let end = Self::position_from_line_col(file_contents, location.end); - - // HACK: Using Pest to do the pretty error context formatting for lack of - // knowledge of a smaller library tailored to this use-case - let variant = pest::error::ErrorVariant::<()>::CustomError { message: subtext }; - let err_context = match (begin, end) { - (Some(b), Some(e)) => { - Some(pest::error::Error::new_from_span(variant, b.span(&e))) - } - (Some(b), None) => Some(pest::error::Error::new_from_pos(variant, b)), - _ => None, - }; - if let Some(err_context) = err_context { - println!( - "{}\n", - err_context.with_path(&location.filename.to_string_lossy()) - ); - } - } - Err(err) => { - println!("error: {subtext}"); - println!( - " --> {}:{}:{}", - location.filename.to_string_lossy(), - location.begin.0, - location.begin.1 + 1 - ); - println!(" | Failed to load {:?}", location.filename); - println!(" | relative to {:?}", self.workspace_root); - println!(" | to provide error message context."); - println!(" | Cause: {err:?}"); - } - } - } - - fn position_from_line_col(contents: &str, (line, col): (usize, usize)) -> Option { - let (mut cl, mut cc) = (1, 1); - let content_bytes = contents.as_bytes(); - for (index, &byte) in content_bytes.iter().enumerate() { - if cl == line && cc == col { - return Position::new(contents, index); - } - - cc += 1; - if byte == b'\n' { - cl += 1; - cc = 0; - } - } - None - } -} diff --git a/tools/cargo-check-external-types/src/lib.rs b/tools/cargo-check-external-types/src/lib.rs deleted file mode 100644 index 88b90ef35b7..00000000000 --- a/tools/cargo-check-external-types/src/lib.rs +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -pub mod cargo; -pub mod config; -pub mod error; -pub mod path; -pub mod visitor; - -/// A macro for attaching info to error messages pointing to the line of code responsible for the error. -/// [Thanks to dtolnay for this macro](https://github.com/dtolnay/anyhow/issues/22#issuecomment-542309452) -#[macro_export] -macro_rules! here { - () => { - concat!("error at ", file!(), ":", line!(), ":", column!()) - }; - ($message:tt) => { - concat!($message, " (", here!(), ")") - }; -} diff --git a/tools/cargo-check-external-types/src/main.rs b/tools/cargo-check-external-types/src/main.rs deleted file mode 100644 index acb59961d04..00000000000 --- a/tools/cargo-check-external-types/src/main.rs +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -use anyhow::{anyhow, bail}; -use anyhow::{Context, Result}; -use cargo_check_external_types::cargo::CargoRustDocJson; -use cargo_check_external_types::error::ErrorPrinter; -use cargo_check_external_types::here; -use cargo_check_external_types::visitor::Visitor; -use cargo_metadata::{CargoOpt, Metadata}; -use clap::Parser; -use owo_colors::{OwoColorize, Stream}; -use std::borrow::Cow; -use std::fmt; -use std::fs; -use std::path::PathBuf; -use std::process; -use std::str::FromStr; -use tracing_subscriber::prelude::*; -use tracing_subscriber::EnvFilter; - -#[derive(Debug)] -enum OutputFormat { - Errors, - MarkdownTable, -} - -impl fmt::Display for OutputFormat { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - f.write_str(match self { - Self::Errors => "errors", - Self::MarkdownTable => "markdown-table", - }) - } -} - -impl FromStr for OutputFormat { - type Err = anyhow::Error; - - fn from_str(s: &str) -> Result { - match s { - "errors" => Ok(OutputFormat::Errors), - "markdown-table" => Ok(OutputFormat::MarkdownTable), - _ => Err(anyhow!( - "invalid output format: {}. Expected `errors` or `markdown-table`.", - s - )), - } - } -} - -#[derive(clap::Args, Debug)] -struct CheckExternalTypesArgs { - /// Enables all crate features - #[clap(long)] - all_features: bool, - /// Disables default features - #[clap(long)] - no_default_features: bool, - /// Comma delimited list of features to enable in the crate - #[clap(long, use_value_delimiter = true)] - features: Option>, - /// Path to the Cargo manifest - manifest_path: Option, - - /// Path to config toml to read - #[clap(long)] - config: Option, - /// Enable verbose output for debugging - #[clap(short, long)] - verbose: bool, - /// Format to output results in - #[clap(long, default_value_t = OutputFormat::Errors)] - output_format: OutputFormat, -} - -#[derive(Parser, Debug)] -#[clap(author, version, about, bin_name = "cargo")] -enum Args { - CheckExternalTypes(CheckExternalTypesArgs), -} - -enum Error { - ValidationErrors, - Failure(anyhow::Error), -} - -impl From for Error { - fn from(err: anyhow::Error) -> Self { - Error::Failure(err) - } -} - -fn main() { - process::exit(match run_main() { - Ok(_) => 0, - Err(Error::ValidationErrors) => 1, - Err(Error::Failure(err)) => { - println!("{:#}", dbg!(err)); - 2 - } - }) -} - -fn run_main() -> Result<(), Error> { - let Args::CheckExternalTypes(args) = Args::parse(); - if args.verbose { - let filter_layer = EnvFilter::try_from_default_env() - .or_else(|_| EnvFilter::try_new("debug")) - .unwrap(); - let fmt_layer = tracing_subscriber::fmt::layer() - .without_time() - .with_ansi(true) - .with_level(true) - .with_target(false) - .pretty(); - tracing_subscriber::registry() - .with(filter_layer) - .with(fmt_layer) - .init(); - } - - let config = if let Some(config_path) = &args.config { - let contents = fs::read_to_string(config_path).context("failed to read config file")?; - toml::from_str(&contents).context("failed to parse config file")? - } else { - Default::default() - }; - - let mut cargo_metadata_cmd = cargo_metadata::MetadataCommand::new(); - if args.all_features { - cargo_metadata_cmd.features(CargoOpt::AllFeatures); - } - if args.no_default_features { - cargo_metadata_cmd.features(CargoOpt::NoDefaultFeatures); - } - if let Some(features) = args.features { - cargo_metadata_cmd.features(CargoOpt::SomeFeatures(features)); - } - let crate_path = if let Some(manifest_path) = args.manifest_path { - cargo_metadata_cmd.manifest_path(&manifest_path); - manifest_path - .canonicalize() - .context(here!())? - .parent() - .expect("parent path") - .to_path_buf() - } else { - std::env::current_dir() - .context(here!())? - .canonicalize() - .context(here!())? - }; - let cargo_metadata = cargo_metadata_cmd.exec().context(here!())?; - let cargo_features = resolve_features(&cargo_metadata)?; - - eprintln!("Running rustdoc to produce json doc output..."); - let package = CargoRustDocJson::new( - &*cargo_metadata - .root_package() - .as_ref() - .map(|package| Cow::Borrowed(package.name.as_str())) - .unwrap_or_else(|| crate_path.file_name().expect("file name").to_string_lossy()), - &crate_path, - &cargo_metadata.target_directory, - cargo_features, - ) - .run() - .context(here!())?; - - eprintln!("Examining all public types..."); - let errors = Visitor::new(config, package)?.visit_all()?; - match args.output_format { - OutputFormat::Errors => { - let mut error_printer = ErrorPrinter::new(&cargo_metadata.workspace_root); - for error in &errors { - println!("{}", error); - if let Some(location) = error.location() { - error_printer.pretty_print_error_context(location, error.subtext()) - } - } - if !errors.is_empty() { - println!( - "{} {} emitted", - errors.len(), - "errors".if_supports_color(Stream::Stdout, |text| text.red()) - ); - return Err(Error::ValidationErrors); - } - } - OutputFormat::MarkdownTable => { - println!("| Crate | Type | Used In |"); - println!("| --- | --- | --- |"); - let mut rows = Vec::new(); - for error in &errors { - let type_name = error.type_name(); - let crate_name = &type_name[0..type_name.find("::").unwrap_or(type_name.len())]; - let location = error.location().unwrap(); - rows.push(format!( - "| {} | {} | {}:{}:{} |", - crate_name, - type_name, - location.filename.to_string_lossy(), - location.begin.0, - location.begin.1 - )); - } - rows.sort(); - rows.into_iter().for_each(|row| println!("{}", row)); - } - } - - Ok(()) -} - -fn resolve_features(metadata: &Metadata) -> Result> { - let root_package = metadata - .root_package() - .ok_or_else(|| anyhow!("No root package found"))?; - if let Some(resolve) = &metadata.resolve { - let root_node = resolve - .nodes - .iter() - .find(|&n| n.id == root_package.id) - .ok_or_else(|| anyhow!("Failed to find node for root package"))?; - Ok(root_node.features.clone()) - } else { - bail!("Cargo metadata didn't have resolved nodes"); - } -} diff --git a/tools/cargo-check-external-types/src/path.rs b/tools/cargo-check-external-types/src/path.rs deleted file mode 100644 index 29123e63c67..00000000000 --- a/tools/cargo-check-external-types/src/path.rs +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -use rustdoc_types::{Item, Span}; -use std::fmt; - -/// Component type for components in a [`Path`]. -#[derive(Copy, Clone, Debug)] -pub enum ComponentType { - AssocConst, - AssocType, - Constant, - Crate, - Enum, - EnumVariant, - Function, - Method, - Module, - ReExport, - Static, - Struct, - StructField, - Trait, - TypeDef, - Union, -} - -/// Represents one component in a [`Path`]. -#[derive(Clone, Debug)] -struct Component { - typ: ComponentType, - name: String, - span: Option, -} - -impl Component { - fn new(typ: ComponentType, name: String, span: Option) -> Self { - Self { typ, name, span } - } -} - -/// Represents the full path to an item being visited by [`Visitor`](crate::visitor::Visitor). -/// -/// This is equivalent to the type path of that item, which has to be re-assembled since -/// it is lost in the flat structure of the Rustdoc JSON output. -#[derive(Clone, Debug)] -pub struct Path { - stack: Vec, -} - -impl Path { - pub fn new(crate_name: &str) -> Self { - Self { - stack: vec![Component::new( - ComponentType::Crate, - crate_name.into(), - None, - )], - } - } - - pub fn push(&mut self, typ: ComponentType, item: &Item) { - self.push_raw(typ, item.name.as_ref().expect("name"), item.span.as_ref()); - } - - pub fn push_raw(&mut self, typ: ComponentType, name: &str, span: Option<&Span>) { - self.stack - .push(Component::new(typ, name.into(), span.cloned())); - } - - /// Returns the span (file + beginning and end positions) of the last [`Component`] in the stack. - pub fn last_span(&self) -> Option<&Span> { - self.stack.last().and_then(|c| c.span.as_ref()) - } - - /// Returns the [`ComponentType`] of the last [`Component`] in the path. - pub fn last_typ(&self) -> Option { - self.stack.last().map(|c| c.typ) - } -} - -impl fmt::Display for Path { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - let names: Vec<&str> = self - .stack - .iter() - .map(|component| component.name.as_str()) - .collect(); - write!(f, "{}", names.join("::")) - } -} diff --git a/tools/cargo-check-external-types/src/visitor.rs b/tools/cargo-check-external-types/src/visitor.rs deleted file mode 100644 index d33bead4c0a..00000000000 --- a/tools/cargo-check-external-types/src/visitor.rs +++ /dev/null @@ -1,579 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -use crate::config::Config; -use crate::error::{ErrorLocation, ValidationError}; -use crate::here; -use crate::path::{ComponentType, Path}; -use anyhow::{anyhow, Context, Result}; -use rustdoc_types::{ - Crate, FnDecl, GenericArgs, GenericBound, GenericParamDef, GenericParamDefKind, Generics, Id, - Item, ItemEnum, ItemSummary, Struct, Term, Trait, Type, Union, Variant, Visibility, - WherePredicate, -}; -use std::cell::RefCell; -use std::collections::{BTreeSet, HashMap}; -use tracing::debug; -use tracing_attributes::instrument; - -macro_rules! unstable_rust_feature { - ($name:expr, $documentation_uri:expr) => { - panic!( - "unstable Rust feature '{}' (see {}) is not supported by cargo-check-external-types", - $name, $documentation_uri - ) - }; -} - -#[derive(Copy, Clone, Debug, Eq, PartialEq)] -enum VisibilityCheck { - /// Check to make sure the item is public before visiting it - Default, - /// Assume the item is public and examine it. - /// This is useful for visiting private items that are publically re-exported - AssumePublic, -} - -/// Visits all items in the Rustdoc JSON output to discover external types in public APIs -/// and track them as validation errors if the [`Config`] doesn't allow them. -pub struct Visitor { - config: Config, - root_crate_id: u32, - root_crate_name: String, - index: HashMap, - paths: HashMap, - errors: RefCell>, -} - -impl Visitor { - pub fn new(config: Config, package: Crate) -> Result { - Ok(Visitor { - config, - root_crate_id: Self::root_crate_id(&package)?, - root_crate_name: Self::root_crate_name(&package)?, - index: package.index, - paths: package.paths, - errors: RefCell::new(BTreeSet::new()), - }) - } - - /// This is the entry point for visiting the entire Rustdoc JSON tree, starting - /// from the root module (the only module where `is_crate` is true). - pub fn visit_all(self) -> Result> { - let root_path = Path::new(&self.root_crate_name); - let root_module = self - .index - .values() - .filter_map(|item| { - if let ItemEnum::Module(module) = &item.inner { - Some(module) - } else { - None - } - }) - .find(|module| module.is_crate) - .ok_or_else(|| anyhow!("failed to find crate root module"))?; - - for id in &root_module.items { - let item = self.item(id).context(here!())?; - self.visit_item(&root_path, item, VisibilityCheck::Default)?; - } - Ok(self.errors.take()) - } - - /// Returns true if the given item is public. In some cases, this must be determined - /// by examining the surrounding context. For example, enum variants are public if the - /// enum is public, even if their visibility is set to `Visibility::Default`. - fn is_public(path: &Path, item: &Item) -> bool { - match item.visibility { - Visibility::Public => true, - Visibility::Default => match &item.inner { - // Enum variants are public if the enum is public - ItemEnum::Variant(_) => matches!(path.last_typ(), Some(ComponentType::Enum)), - // Struct fields inside of enum variants are public if the enum is public - ItemEnum::StructField(_) => { - matches!(path.last_typ(), Some(ComponentType::EnumVariant)) - } - // Trait items are public if the trait is public - _ => matches!(path.last_typ(), Some(ComponentType::Trait)), - }, - _ => false, - } - } - - #[instrument(level = "debug", skip(self, path, item), fields(path = %path, name = ?item.name, id = %item.id.0))] - fn visit_item( - &self, - path: &Path, - item: &Item, - visibility_check: VisibilityCheck, - ) -> Result<()> { - if visibility_check == VisibilityCheck::Default && !Self::is_public(path, item) { - return Ok(()); - } - - let mut path = path.clone(); - match &item.inner { - ItemEnum::AssocConst { type_, .. } => { - path.push(ComponentType::AssocConst, item); - self.visit_type(&path, &ErrorLocation::StructField, type_) - .context(here!())?; - } - ItemEnum::AssocType { - bounds, - default, - generics, - } => { - path.push(ComponentType::AssocType, item); - if let Some(typ) = default { - self.visit_type(&path, &ErrorLocation::AssocType, typ).context(here!())?; - } - self.visit_generic_bounds(&path, bounds).context(here!())?; - self.visit_generics(&path, generics).context(here!())?; - } - ItemEnum::Constant(constant) => { - path.push(ComponentType::Constant, item); - self.visit_type(&path, &ErrorLocation::Constant, &constant.type_).context(here!())?; - } - ItemEnum::Enum(enm) => { - path.push(ComponentType::Enum, item); - self.visit_generics(&path, &enm.generics).context(here!())?; - for id in &enm.impls { - self.visit_impl(&path, self.item(id).context(here!())?)?; - } - for id in &enm.variants { - self.visit_item(&path, self.item(id).context(here!())?, VisibilityCheck::Default).context(here!())?; - } - } - ItemEnum::ForeignType => unstable_rust_feature!( - "extern_types", - "https://doc.rust-lang.org/beta/unstable-book/language-features/extern-types.html" - ), - ItemEnum::Function(function) => { - path.push(ComponentType::Function, item); - self.visit_fn_decl(&path, &function.decl).context(here!())?; - self.visit_generics(&path, &function.generics).context(here!())?; - } - ItemEnum::Import(import) => { - if let Some(target_id) = &import.id { - if self.in_root_crate(target_id) { - // Override the visibility check for re-exported items - self.visit_item( - &path, - self.item(target_id).context(here!())?, - VisibilityCheck::AssumePublic - ).context(here!())?; - } - path.push_raw(ComponentType::ReExport, &import.name, item.span.as_ref()); - self.check_external(&path, &ErrorLocation::ReExport, target_id) - .context(here!())?; - } - } - ItemEnum::Method(method) => { - path.push(ComponentType::Method, item); - self.visit_fn_decl(&path, &method.decl).context(here!())?; - self.visit_generics(&path, &method.generics).context(here!())?; - } - ItemEnum::Module(module) => { - if !module.is_crate { - path.push(ComponentType::Module, item); - } - for id in &module.items { - let module_item = self.item(id).context(here!())?; - // Re-exports show up twice in the doc json: once as an `ItemEnum::Import`, - // and once as the type as if it were originating from the root crate (but - // with a different crate ID). We only want to examine the `ItemEnum::Import` - // for re-exports since it includes the correct span where the re-export occurs, - // and we don't want to examine the innards of the re-export. - if module_item.crate_id == self.root_crate_id { - self.visit_item(&path, module_item, VisibilityCheck::Default).context(here!())?; - } - } - } - ItemEnum::OpaqueTy(_) => unstable_rust_feature!("type_alias_impl_trait", "https://doc.rust-lang.org/beta/unstable-book/language-features/type-alias-impl-trait.html"), - ItemEnum::Static(sttc) => { - path.push(ComponentType::Static, item); - self.visit_type(&path, &ErrorLocation::Static, &sttc.type_).context(here!())?; - } - ItemEnum::Struct(strct) => { - path.push(ComponentType::Struct, item); - self.visit_struct(&path, strct).context(here!())?; - } - ItemEnum::StructField(typ) => { - path.push(ComponentType::StructField, item); - self.visit_type(&path, &ErrorLocation::StructField, typ) - .context(here!())?; - } - ItemEnum::Trait(trt) => { - path.push(ComponentType::Trait, item); - self.visit_trait(&path, trt).context(here!())?; - } - ItemEnum::Typedef(typedef) => { - path.push(ComponentType::TypeDef, item); - self.visit_type(&path, &ErrorLocation::TypeDef, &typedef.type_) - .context(here!())?; - self.visit_generics(&path, &typedef.generics).context(here!())?; - } - ItemEnum::TraitAlias(_) => unstable_rust_feature!( - "trait_alias", - "https://doc.rust-lang.org/beta/unstable-book/language-features/trait-alias.html" - ), - ItemEnum::Union(unn) => { - path.push(ComponentType::Union, item); - self.visit_union(&path, unn).context(here!())?; - } - ItemEnum::Variant(variant) => { - path.push(ComponentType::EnumVariant, item); - self.visit_variant(&path, variant).context(here!())?; - } - ItemEnum::ExternCrate { .. } - | ItemEnum::Impl(_) - | ItemEnum::Macro(_) - | ItemEnum::PrimitiveType(_) - | ItemEnum::ProcMacro(_) => {} - } - Ok(()) - } - - #[instrument(level = "debug", skip(self, path, strct), fields(path = %path))] - fn visit_struct(&self, path: &Path, strct: &Struct) -> Result<()> { - self.visit_generics(path, &strct.generics)?; - for id in &strct.fields { - let field = self.item(id).context(here!())?; - self.visit_item(path, field, VisibilityCheck::Default)?; - } - for id in &strct.impls { - self.visit_impl(path, self.item(id).context(here!())?)?; - } - Ok(()) - } - - #[instrument(level = "debug", skip(self, path, unn), fields(path = %path))] - fn visit_union(&self, path: &Path, unn: &Union) -> Result<()> { - self.visit_generics(path, &unn.generics)?; - for id in &unn.fields { - let field = self.item(id).context(here!())?; - self.visit_item(path, field, VisibilityCheck::Default)?; - } - for id in &unn.impls { - self.visit_impl(path, self.item(id).context(here!())?)?; - } - Ok(()) - } - - #[instrument(level = "debug", skip(self, path, trt), fields(path = %path))] - fn visit_trait(&self, path: &Path, trt: &Trait) -> Result<()> { - self.visit_generics(path, &trt.generics)?; - self.visit_generic_bounds(path, &trt.bounds)?; - for id in &trt.items { - let item = self.item(id).context(here!())?; - self.visit_item(path, item, VisibilityCheck::Default)?; - } - Ok(()) - } - - #[instrument(level = "debug", skip(self, path, item), fields(path = %path, id = %item.id.0))] - fn visit_impl(&self, path: &Path, item: &Item) -> Result<()> { - if let ItemEnum::Impl(imp) = &item.inner { - // Ignore blanket implementations - if imp.blanket_impl.is_some() { - return Ok(()); - } - self.visit_generics(path, &imp.generics)?; - for id in &imp.items { - self.visit_item( - path, - self.item(id).context(here!())?, - VisibilityCheck::Default, - )?; - } - if let Some(trait_) = &imp.trait_ { - self.visit_type(path, &ErrorLocation::ImplementedTrait, trait_) - .context(here!())?; - } - } else { - unreachable!("should be passed an Impl item"); - } - Ok(()) - } - - #[instrument(level = "debug", skip(self, path, decl), fields(path = %path))] - fn visit_fn_decl(&self, path: &Path, decl: &FnDecl) -> Result<()> { - for (index, (name, typ)) in decl.inputs.iter().enumerate() { - if index == 0 && name == "self" { - continue; - } - self.visit_type(path, &ErrorLocation::ArgumentNamed(name.into()), typ) - .context(here!())?; - } - if let Some(output) = &decl.output { - self.visit_type(path, &ErrorLocation::ReturnValue, output) - .context(here!())?; - } - Ok(()) - } - - #[instrument(level = "debug", skip(self, path, typ), fields(path = %path))] - fn visit_type(&self, path: &Path, what: &ErrorLocation, typ: &Type) -> Result<()> { - match typ { - Type::ResolvedPath { - id, - args, - param_names, - .. - } => { - self.check_external(path, what, id).context(here!())?; - if let Some(args) = args { - self.visit_generic_args(path, args)?; - } - self.visit_generic_bounds(path, param_names)?; - } - Type::Generic(_) => {} - Type::Primitive(_) => {} - Type::FunctionPointer(fp) => { - self.visit_fn_decl(path, &fp.decl)?; - self.visit_generic_param_defs(path, &fp.generic_params)?; - } - Type::Tuple(types) => { - for typ in types { - self.visit_type(path, &ErrorLocation::EnumTupleEntry, typ)?; - } - } - Type::Slice(typ) => self.visit_type(path, what, typ).context(here!())?, - Type::Array { type_, .. } => self.visit_type(path, what, type_).context(here!())?, - Type::ImplTrait(impl_trait) => { - for bound in impl_trait { - match bound { - GenericBound::TraitBound { - trait_, - generic_params, - .. - } => { - self.visit_type(path, what, trait_)?; - self.visit_generic_param_defs(path, generic_params)?; - } - GenericBound::Outlives(_) => {} - } - } - } - Type::Infer => { - unimplemented!( - "visit_type for Type::Infer: not sure what Rust code triggers this. \ - If you encounter this, please report it with a link to the code it happens with." - ) - } - Type::RawPointer { type_, .. } => { - self.visit_type(path, what, type_).context(here!())? - } - Type::BorrowedRef { type_, .. } => { - self.visit_type(path, what, type_).context(here!())? - } - Type::QualifiedPath { - self_type, trait_, .. - } => { - self.visit_type(path, &ErrorLocation::QualifiedSelfType, self_type)?; - self.visit_type(path, &ErrorLocation::QualifiedSelfTypeAsTrait, trait_)?; - } - } - Ok(()) - } - - #[instrument(level = "debug", skip(self, path, args), fields(path = %path))] - fn visit_generic_args(&self, path: &Path, args: &GenericArgs) -> Result<()> { - match args { - GenericArgs::AngleBracketed { args, bindings } => { - for arg in args { - match arg { - rustdoc_types::GenericArg::Type(typ) => { - self.visit_type(path, &ErrorLocation::GenericArg, typ)? - } - rustdoc_types::GenericArg::Lifetime(_) - | rustdoc_types::GenericArg::Const(_) - | rustdoc_types::GenericArg::Infer => {} - } - } - for binding in bindings { - match &binding.binding { - rustdoc_types::TypeBindingKind::Equality(term) => { - if let Term::Type(typ) = term { - self.visit_type(path, &ErrorLocation::GenericDefaultBinding, typ) - .context(here!())?; - } - } - rustdoc_types::TypeBindingKind::Constraint(bounds) => { - self.visit_generic_bounds(path, bounds)?; - } - } - } - } - GenericArgs::Parenthesized { inputs, output } => { - for input in inputs { - self.visit_type(path, &ErrorLocation::ClosureInput, input) - .context(here!())?; - } - if let Some(output) = output { - self.visit_type(path, &ErrorLocation::ClosureOutput, output) - .context(here!())?; - } - } - } - Ok(()) - } - - #[instrument(level = "debug", skip(self, path, bounds), fields(path = %path))] - fn visit_generic_bounds(&self, path: &Path, bounds: &[GenericBound]) -> Result<()> { - for bound in bounds { - if let GenericBound::TraitBound { - trait_, - generic_params, - .. - } = bound - { - self.visit_type(path, &ErrorLocation::TraitBound, trait_) - .context(here!())?; - self.visit_generic_param_defs(path, generic_params)?; - } - } - Ok(()) - } - - #[instrument(level = "debug", skip(self, path, params), fields(path = %path))] - fn visit_generic_param_defs(&self, path: &Path, params: &[GenericParamDef]) -> Result<()> { - for param in params { - match ¶m.kind { - GenericParamDefKind::Type { - bounds, - default, - synthetic: _, - } => { - self.visit_generic_bounds(path, bounds)?; - if let Some(typ) = default { - self.visit_type(path, &ErrorLocation::GenericDefaultBinding, typ) - .context(here!())?; - } - } - GenericParamDefKind::Const { type_, .. } => { - self.visit_type(path, &ErrorLocation::ConstGeneric, type_) - .context(here!())?; - } - _ => {} - } - } - Ok(()) - } - - #[instrument(level = "debug", skip(self, path, generics), fields(path = %path))] - fn visit_generics(&self, path: &Path, generics: &Generics) -> Result<()> { - self.visit_generic_param_defs(path, &generics.params)?; - for where_pred in &generics.where_predicates { - match where_pred { - WherePredicate::BoundPredicate { - type_, - bounds, - generic_params, - } => { - self.visit_type(path, &ErrorLocation::WhereBound, type_) - .context(here!())?; - self.visit_generic_bounds(path, bounds)?; - self.visit_generic_param_defs(path, generic_params)?; - } - WherePredicate::RegionPredicate { bounds, .. } => { - self.visit_generic_bounds(path, bounds)?; - } - WherePredicate::EqPredicate { lhs, .. } => { - self.visit_type(path, &ErrorLocation::WhereBound, lhs) - .context(here!())?; - } - } - } - Ok(()) - } - - #[instrument(level = "debug", skip(self, path, variant), fields(path = %path))] - fn visit_variant(&self, path: &Path, variant: &Variant) -> Result<()> { - match variant { - Variant::Plain => {} - Variant::Tuple(types) => { - for typ in types { - self.visit_type(path, &ErrorLocation::EnumTupleEntry, typ)?; - } - } - Variant::Struct(ids) => { - for id in ids { - self.visit_item( - path, - self.item(id).context(here!())?, - VisibilityCheck::Default, - )?; - } - } - } - Ok(()) - } - - fn check_external(&self, path: &Path, what: &ErrorLocation, id: &Id) -> Result<()> { - if let Ok(type_name) = self.type_name(id) { - if !self.config.allows_type(&self.root_crate_name, &type_name) { - self.add_error(ValidationError::unapproved_external_type_ref( - self.type_name(id)?, - what, - path.to_string(), - path.last_span(), - )); - } - } - // Crates like `pin_project` do some shenanigans to create and reference types that don't end up - // in the doc index, but that should only happen within the root crate. - else if !id.0.starts_with(&format!("{}:", self.root_crate_id)) { - unreachable!("A type is referencing another type that is not in the index, and that type is from another crate."); - } - Ok(()) - } - - fn add_error(&self, error: ValidationError) { - debug!("detected error {:?}", error); - self.errors.borrow_mut().insert(error); - } - - fn item(&self, id: &Id) -> Result<&Item> { - self.index - .get(id) - .ok_or_else(|| anyhow!("Failed to find item in index for ID {:?}", id)) - .context(here!()) - } - - fn item_summary(&self, id: &Id) -> Option<&ItemSummary> { - self.paths.get(id) - } - - fn type_name(&self, id: &Id) -> Result { - Ok(self.item_summary(id).context(here!())?.path.join("::")) - } - - fn root_crate_id(package: &Crate) -> Result { - Ok(Self::root(package)?.crate_id) - } - - /// Returns true if the given `id` belongs to the root crate - fn in_root_crate(&self, id: &Id) -> bool { - id.0.starts_with(&format!("{}:", self.root_crate_id)) - } - - fn root_crate_name(package: &Crate) -> Result { - Ok(Self::root(package)? - .name - .as_ref() - .expect("root should always have a name") - .clone()) - } - - fn root(package: &Crate) -> Result<&Item> { - package - .index - .get(&package.root) - .ok_or_else(|| anyhow!("root not found in index")) - .context(here!()) - } -} diff --git a/tools/cargo-check-external-types/test-workspace/.gitignore b/tools/cargo-check-external-types/test-workspace/.gitignore deleted file mode 100644 index 03314f77b5a..00000000000 --- a/tools/cargo-check-external-types/test-workspace/.gitignore +++ /dev/null @@ -1 +0,0 @@ -Cargo.lock diff --git a/tools/cargo-check-external-types/test-workspace/Cargo.toml b/tools/cargo-check-external-types/test-workspace/Cargo.toml deleted file mode 100644 index 9f50884ad59..00000000000 --- a/tools/cargo-check-external-types/test-workspace/Cargo.toml +++ /dev/null @@ -1,2 +0,0 @@ -[workspace] -members = ["external-lib", "test-crate", "test-reexports-crate"] diff --git a/tools/cargo-check-external-types/test-workspace/external-lib/Cargo.toml b/tools/cargo-check-external-types/test-workspace/external-lib/Cargo.toml deleted file mode 100644 index 6f16ff93203..00000000000 --- a/tools/cargo-check-external-types/test-workspace/external-lib/Cargo.toml +++ /dev/null @@ -1,7 +0,0 @@ -[package] -name = "external-lib" -version = "0.1.0" -edition = "2021" -publish = false - -[dependencies] diff --git a/tools/cargo-check-external-types/test-workspace/external-lib/src/lib.rs b/tools/cargo-check-external-types/test-workspace/external-lib/src/lib.rs deleted file mode 100644 index d35c9c1cfcd..00000000000 --- a/tools/cargo-check-external-types/test-workspace/external-lib/src/lib.rs +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -//! This crate exports a bunch of types for testing cargo-check-external-types against `test-crate` - -pub struct SomeStruct; -pub struct SomeOtherStruct; - -pub trait SimpleTrait { - fn something(&self) -> u32; -} - -impl SimpleTrait for () { - fn something(&self) -> u32 { - 0 - } -} - -pub trait SimpleGenericTrait { - fn something(&self, thing: T) -> u32; -} - -pub trait AssociatedGenericTrait { - type Input; - type Output; - type Error; - - fn something(&self, input: Self::Input) -> Self::Output; - - fn something_result(&self, input: Self::Input) -> Result; -} - -pub struct SimpleNewType(pub u32); - -#[repr(C)] -#[derive(Copy, Clone)] -pub struct ReprCType { - i: i32, - f: f32, -} diff --git a/tools/cargo-check-external-types/test-workspace/test-crate/Cargo.toml b/tools/cargo-check-external-types/test-workspace/test-crate/Cargo.toml deleted file mode 100644 index f80e0628608..00000000000 --- a/tools/cargo-check-external-types/test-workspace/test-crate/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "test-crate" -version = "0.1.0" -edition = "2021" -publish = false - -[dependencies] -external-lib = { path = "../external-lib" } diff --git a/tools/cargo-check-external-types/test-workspace/test-crate/src/lib.rs b/tools/cargo-check-external-types/test-workspace/test-crate/src/lib.rs deleted file mode 100644 index 3b643d226fb..00000000000 --- a/tools/cargo-check-external-types/test-workspace/test-crate/src/lib.rs +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -#![feature(generic_associated_types)] -#![allow(dead_code)] - -//! This crate is used to test the cargo-check-external-types by exercising the all possible -//! exposure of external types in a public API. - -pub mod test_union; - -use external_lib::{ - AssociatedGenericTrait, - SimpleNewType, - SimpleTrait, - SomeOtherStruct, - SomeStruct, - // Remove this comment if more lines are needed for imports in the future to preserve line numbers - // Remove this comment if more lines are needed for imports in the future to preserve line numbers - // Remove this comment if more lines are needed for imports in the future to preserve line numbers - // Remove this comment if more lines are needed for imports in the future to preserve line numbers - // Remove this comment if more lines are needed for imports in the future to preserve line numbers - // Remove this comment if more lines are needed for imports in the future to preserve line numbers - // Remove this comment if more lines are needed for imports in the future to preserve line numbers - // Remove this comment if more lines are needed for imports in the future to preserve line numbers -}; - -pub struct LocalStruct; - -pub fn fn_with_local_struct(_local: LocalStruct) -> LocalStruct { - unimplemented!() -} - -fn not_pub_external_in_fn_input(_one: &SomeStruct, _two: impl SimpleTrait) {} - -pub fn external_in_fn_input(_one: &SomeStruct, _two: impl SimpleTrait) {} - -fn not_pub_external_in_fn_output() -> SomeStruct { - unimplemented!() -} -pub fn external_in_fn_output() -> SomeStruct { - unimplemented!() -} - -pub fn external_opaque_type_in_output() -> impl SimpleTrait { - unimplemented!() -} - -fn not_pub_external_in_fn_output_generic() -> Option { - unimplemented!() -} -pub fn external_in_fn_output_generic() -> Option { - unimplemented!() -} - -// Try to trick cargo-check-external-types here by putting something in a private module and re-exporting it -mod private_module { - use external_lib::SomeStruct; - - pub fn something(_one: &SomeStruct) {} -} -pub use private_module::something; - -pub struct StructWithExternalFields { - pub field: SomeStruct, - pub optional_field: Option, -} - -impl StructWithExternalFields { - pub fn new(_field: impl Into, _optional_field: Option) -> Self { - unimplemented!() - } -} - -pub trait TraitReferencingExternals { - fn something(&self, a: SomeStruct) -> LocalStruct; - fn optional_something(&self, a: Option) -> LocalStruct; - fn otherthing(&self) -> SomeStruct; - fn optional_otherthing(&self) -> Option; -} - -pub enum EnumWithExternals { - NormalTuple(LocalStruct), - NormalStruct { - v: LocalStruct, - }, - TupleEnum(SomeStruct, Box), - StructEnum { - some_struct: SomeStruct, - simple_trait: Box, - }, - GenericTupleEnum(T), - GenericStructEnum { - t: T, - }, -} - -impl EnumWithExternals { - pub fn thing(_t: LocalStruct) -> Self { - unimplemented!() - } - pub fn another_thing(_s: S) -> Self { - unimplemented!() - } -} - -pub static SOME_STRUCT: SomeStruct = SomeStruct; -pub const SOME_CONST: SomeStruct = SomeStruct; - -pub mod some_pub_mod { - use external_lib::SomeStruct; - - pub static OPTIONAL_STRUCT: Option = None; - pub const OPTIONAL_CONST: Option = None; -} - -pub type NotExternalReferencing = u32; -pub type ExternalReferencingTypedef = SomeStruct; -pub type OptionalExternalReferencingTypedef = Option; -pub type DynExternalReferencingTypedef = Box; -pub type ExternalReferencingRawPtr = *const SomeStruct; - -pub fn fn_with_external_trait_bounds(_thing: T) -where - I: Into, - O: Into, - E: std::error::Error, - T: AssociatedGenericTrait, -{ -} - -pub trait SomeTraitWithExternalDefaultTypes { - type Thing: SimpleTrait; - type OtherThing: AssociatedGenericTrait< - Input = SomeStruct, - Output = u32, - Error = SomeOtherStruct, - >; - - fn something(&self, input: Self::Thing) -> Self::OtherThing; -} - -pub trait SomeTraitWithGenericAssociatedType { - type MyGAT - where - T: SimpleTrait; - - fn some_fn(&self, thing: Self::MyGAT); -} - -pub struct AssocConstStruct; - -impl AssocConstStruct { - pub const SOME_CONST: u32 = 5; - - pub const OTHER_CONST: SimpleNewType = SimpleNewType(5); -} diff --git a/tools/cargo-check-external-types/test-workspace/test-crate/src/test_union.rs b/tools/cargo-check-external-types/test-workspace/test-crate/src/test_union.rs deleted file mode 100644 index 9b311ed87cb..00000000000 --- a/tools/cargo-check-external-types/test-workspace/test-crate/src/test_union.rs +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -use external_lib::{ReprCType, SimpleTrait}; - -#[repr(C)] -pub union SimpleUnion { - pub repr_c: ReprCType, - pub something_else: u64, -} - -impl SimpleUnion { - pub fn repr_c(&self) -> &ReprCType { - &self.repr_c - } -} - -#[repr(C)] -pub union GenericUnion { - pub repr_c: T, - pub something_else: u64, -} diff --git a/tools/cargo-check-external-types/test-workspace/test-reexports-crate/Cargo.toml b/tools/cargo-check-external-types/test-workspace/test-reexports-crate/Cargo.toml deleted file mode 100644 index 8790abe4ff1..00000000000 --- a/tools/cargo-check-external-types/test-workspace/test-reexports-crate/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "test-reexports-crate" -version = "0.1.0" -edition = "2021" -publish = false - -[dependencies] -external-lib = { path = "../external-lib" } diff --git a/tools/cargo-check-external-types/test-workspace/test-reexports-crate/src/lib.rs b/tools/cargo-check-external-types/test-workspace/test-reexports-crate/src/lib.rs deleted file mode 100644 index 0b98a088490..00000000000 --- a/tools/cargo-check-external-types/test-workspace/test-reexports-crate/src/lib.rs +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -pub use external_lib::AssociatedGenericTrait; -pub use external_lib::ReprCType; -pub use external_lib::SimpleTrait; - -pub mod Something { - pub use external_lib::SimpleGenericTrait; - pub use external_lib::SimpleNewType; -} - -pub use external_lib::SomeOtherStruct; -pub use external_lib::SomeStruct; diff --git a/tools/cargo-check-external-types/tests/allow-some-types-expected-output.txt b/tools/cargo-check-external-types/tests/allow-some-types-expected-output.txt deleted file mode 100644 index f954bcf2e16..00000000000 --- a/tools/cargo-check-external-types/tests/allow-some-types-expected-output.txt +++ /dev/null @@ -1,39 +0,0 @@ -error: Unapproved external type `external_lib::AssociatedGenericTrait` referenced in public API - --> test-crate/src/lib.rs:125:1 - | -125 | pub fn fn_with_external_trait_bounds(_thing: T) - | ... -132 | }␊ - | ^ - | - = in trait bound of `test_crate::fn_with_external_trait_bounds` - -error: Unapproved external type `external_lib::AssociatedGenericTrait` referenced in public API - --> test-crate/src/lib.rs:136:5 - | -136 | type OtherThing: AssociatedGenericTrait< - | ... -140 | >;␊ - | ^^ - | - = in trait bound of `test_crate::SomeTraitWithExternalDefaultTypes::OtherThing` - -error: Unapproved external type `external_lib::ReprCType` referenced in public API - --> test-crate/src/test_union.rs:10:5 - | -10 | pub repr_c: ReprCType, - | ^-------------------^ - | - = in struct field of `test_crate::test_union::SimpleUnion::repr_c` - -error: Unapproved external type `external_lib::ReprCType` referenced in public API - --> test-crate/src/test_union.rs:15:5 - | -15 | pub fn repr_c(&self) -> &ReprCType { - | ... -17 | }␊ - | ^ - | - = in return value of `test_crate::test_union::SimpleUnion::repr_c` - -4 errors emitted diff --git a/tools/cargo-check-external-types/tests/allow-some-types.toml b/tools/cargo-check-external-types/tests/allow-some-types.toml deleted file mode 100644 index a43571daaa5..00000000000 --- a/tools/cargo-check-external-types/tests/allow-some-types.toml +++ /dev/null @@ -1,6 +0,0 @@ -# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -# SPDX-License-Identifier: Apache-2.0 - -allowed_external_types = [ - "external_lib::S*", -] diff --git a/tools/cargo-check-external-types/tests/default-config-expected-output.txt b/tools/cargo-check-external-types/tests/default-config-expected-output.txt deleted file mode 100644 index 5854df7a590..00000000000 --- a/tools/cargo-check-external-types/tests/default-config-expected-output.txt +++ /dev/null @@ -1,369 +0,0 @@ -error: Unapproved external type `external_lib::SimpleTrait` referenced in public API - --> test-crate/src/lib.rs:38:1 - | -38 | pub fn external_in_fn_input(_one: &SomeStruct, _two: impl SimpleTrait) {} - | ^-----------------------------------------------------------------------^ - | - = in argument named `_two` of `test_crate::external_in_fn_input` - -error: Unapproved external type `external_lib::SimpleTrait` referenced in public API - --> test-crate/src/lib.rs:38:1 - | -38 | pub fn external_in_fn_input(_one: &SomeStruct, _two: impl SimpleTrait) {} - | ^-----------------------------------------------------------------------^ - | - = in trait bound of `test_crate::external_in_fn_input` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:38:1 - | -38 | pub fn external_in_fn_input(_one: &SomeStruct, _two: impl SimpleTrait) {} - | ^-----------------------------------------------------------------------^ - | - = in argument named `_one` of `test_crate::external_in_fn_input` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:43:1 - | -43 | pub fn external_in_fn_output() -> SomeStruct { - | ... -45 | }␊ - | ^ - | - = in return value of `test_crate::external_in_fn_output` - -error: Unapproved external type `external_lib::SimpleTrait` referenced in public API - --> test-crate/src/lib.rs:47:1 - | -47 | pub fn external_opaque_type_in_output() -> impl SimpleTrait { - | ... -49 | }␊ - | ^ - | - = in return value of `test_crate::external_opaque_type_in_output` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:54:1 - | -54 | pub fn external_in_fn_output_generic() -> Option { - | ... -56 | }␊ - | ^ - | - = in generic arg of `test_crate::external_in_fn_output_generic` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:62:5 - | -62 | pub fn something(_one: &SomeStruct) {} - | ^------------------------------------^ - | - = in argument named `_one` of `test_crate::something` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:67:5 - | -67 | pub field: SomeStruct, - | ^-------------------^ - | - = in struct field of `test_crate::StructWithExternalFields::field` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:68:5 - | -68 | pub optional_field: Option, - | ^------------------------------------^ - | - = in generic arg of `test_crate::StructWithExternalFields::optional_field` - -error: Unapproved external type `external_lib::SomeOtherStruct` referenced in public API - --> test-crate/src/lib.rs:72:5 - | -72 | pub fn new(_field: impl Into, _optional_field: Option) -> Self { - | ... -74 | }␊ - | ^ - | - = in generic arg of `test_crate::StructWithExternalFields::new` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:72:5 - | -72 | pub fn new(_field: impl Into, _optional_field: Option) -> Self { - | ... -74 | }␊ - | ^ - | - = in generic arg of `test_crate::StructWithExternalFields::new` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:78:5 - | -78 | fn something(&self, a: SomeStruct) -> LocalStruct; - | ^------------------------------------------------^ - | - = in argument named `a` of `test_crate::TraitReferencingExternals::something` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:79:5 - | -79 | fn optional_something(&self, a: Option) -> LocalStruct; - | ^-----------------------------------------------------------------^ - | - = in generic arg of `test_crate::TraitReferencingExternals::optional_something` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:80:5 - | -80 | fn otherthing(&self) -> SomeStruct; - | ^---------------------------------^ - | - = in return value of `test_crate::TraitReferencingExternals::otherthing` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:81:5 - | -81 | fn optional_otherthing(&self) -> Option; - | ^--------------------------------------------------^ - | - = in generic arg of `test_crate::TraitReferencingExternals::optional_otherthing` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:84:1 - | -84 | pub enum EnumWithExternals { - | ... -98 | }␊ - | ^ - | - = in generic default binding of `test_crate::EnumWithExternals` - -error: Unapproved external type `external_lib::SimpleTrait` referenced in public API - --> test-crate/src/lib.rs:89:5 - | -89 | TupleEnum(SomeStruct, Box), - | ^-----------------------------------------^ - | - = in generic arg of `test_crate::EnumWithExternals::TupleEnum` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:89:5 - | -89 | TupleEnum(SomeStruct, Box), - | ^-----------------------------------------^ - | - = in enum tuple entry of `test_crate::EnumWithExternals::TupleEnum` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:91:9 - | -91 | some_struct: SomeStruct, - | ^---------------------^ - | - = in struct field of `test_crate::EnumWithExternals::StructEnum::some_struct` - -error: Unapproved external type `external_lib::SimpleTrait` referenced in public API - --> test-crate/src/lib.rs:92:9 - | -92 | simple_trait: Box, - | ^--------------------------------^ - | - = in generic arg of `test_crate::EnumWithExternals::StructEnum::simple_trait` - -error: Unapproved external type `external_lib::SimpleTrait` referenced in public API - --> test-crate/src/lib.rs:104:5 - | -104 | pub fn another_thing(_s: S) -> Self { - | ... -106 | }␊ - | ^ - | - = in trait bound of `test_crate::EnumWithExternals::another_thing` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:109:1 - | -109 | pub static SOME_STRUCT: SomeStruct = SomeStruct; - | ^----------------------------------------------^ - | - = in static value `test_crate::SOME_STRUCT` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:110:1 - | -110 | pub const SOME_CONST: SomeStruct = SomeStruct; - | ^--------------------------------------------^ - | - = in constant `test_crate::SOME_CONST` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:115:5 - | -115 | pub static OPTIONAL_STRUCT: Option = None; - | ^----------------------------------------------------^ - | - = in generic arg of `test_crate::some_pub_mod::OPTIONAL_STRUCT` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:116:5 - | -116 | pub const OPTIONAL_CONST: Option = None; - | ^--------------------------------------------------^ - | - = in generic arg of `test_crate::some_pub_mod::OPTIONAL_CONST` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:120:1 - | -120 | pub type ExternalReferencingTypedef = SomeStruct; - | ^-----------------------------------------------^ - | - = in typedef type of `test_crate::ExternalReferencingTypedef` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:121:1 - | -121 | pub type OptionalExternalReferencingTypedef = Option; - | ^---------------------------------------------------------------^ - | - = in generic arg of `test_crate::OptionalExternalReferencingTypedef` - -error: Unapproved external type `external_lib::SimpleTrait` referenced in public API - --> test-crate/src/lib.rs:122:1 - | -122 | pub type DynExternalReferencingTypedef = Box; - | ^------------------------------------------------------------^ - | - = in generic arg of `test_crate::DynExternalReferencingTypedef` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:123:1 - | -123 | pub type ExternalReferencingRawPtr = *const SomeStruct; - | ^-----------------------------------------------------^ - | - = in typedef type of `test_crate::ExternalReferencingRawPtr` - -error: Unapproved external type `external_lib::AssociatedGenericTrait` referenced in public API - --> test-crate/src/lib.rs:125:1 - | -125 | pub fn fn_with_external_trait_bounds(_thing: T) - | ... -132 | }␊ - | ^ - | - = in trait bound of `test_crate::fn_with_external_trait_bounds` - -error: Unapproved external type `external_lib::SomeOtherStruct` referenced in public API - --> test-crate/src/lib.rs:125:1 - | -125 | pub fn fn_with_external_trait_bounds(_thing: T) - | ... -132 | }␊ - | ^ - | - = in generic arg of `test_crate::fn_with_external_trait_bounds` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:125:1 - | -125 | pub fn fn_with_external_trait_bounds(_thing: T) - | ... -132 | }␊ - | ^ - | - = in generic arg of `test_crate::fn_with_external_trait_bounds` - -error: Unapproved external type `external_lib::SimpleTrait` referenced in public API - --> test-crate/src/lib.rs:135:5 - | -135 | type Thing: SimpleTrait; - | ^----------------------^ - | - = in trait bound of `test_crate::SomeTraitWithExternalDefaultTypes::Thing` - -error: Unapproved external type `external_lib::AssociatedGenericTrait` referenced in public API - --> test-crate/src/lib.rs:136:5 - | -136 | type OtherThing: AssociatedGenericTrait< - | ... -140 | >;␊ - | ^^ - | - = in trait bound of `test_crate::SomeTraitWithExternalDefaultTypes::OtherThing` - -error: Unapproved external type `external_lib::SomeOtherStruct` referenced in public API - --> test-crate/src/lib.rs:136:5 - | -136 | type OtherThing: AssociatedGenericTrait< - | ... -140 | >;␊ - | ^^ - | - = in generic default binding of `test_crate::SomeTraitWithExternalDefaultTypes::OtherThing` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-crate/src/lib.rs:136:5 - | -136 | type OtherThing: AssociatedGenericTrait< - | ... -140 | >;␊ - | ^^ - | - = in generic default binding of `test_crate::SomeTraitWithExternalDefaultTypes::OtherThing` - -error: Unapproved external type `external_lib::SimpleTrait` referenced in public API - --> test-crate/src/lib.rs:146:5 - | -146 | type MyGAT - | ... -148 | T: SimpleTrait;␊ - | ^-----------------^ - | - = in trait bound of `test_crate::SomeTraitWithGenericAssociatedType::MyGAT` - -error: Unapproved external type `external_lib::SimpleTrait` referenced in public API - --> test-crate/src/lib.rs:150:5 - | -150 | fn some_fn(&self, thing: Self::MyGAT); - | ^-------------------------------------------------------^ - | - = in trait bound of `test_crate::SomeTraitWithGenericAssociatedType::some_fn` - -error: Unapproved external type `external_lib::SimpleNewType` referenced in public API - --> test-crate/src/lib.rs:158:5 - | -158 | pub const OTHER_CONST: SimpleNewType = SimpleNewType(5); - | ^------------------------------------------------------^ - | - = in struct field of `test_crate::AssocConstStruct::OTHER_CONST` - -error: Unapproved external type `external_lib::ReprCType` referenced in public API - --> test-crate/src/test_union.rs:10:5 - | -10 | pub repr_c: ReprCType, - | ^-------------------^ - | - = in struct field of `test_crate::test_union::SimpleUnion::repr_c` - -error: Unapproved external type `external_lib::ReprCType` referenced in public API - --> test-crate/src/test_union.rs:15:5 - | -15 | pub fn repr_c(&self) -> &ReprCType { - | ... -17 | }␊ - | ^ - | - = in return value of `test_crate::test_union::SimpleUnion::repr_c` - -error: Unapproved external type `external_lib::SimpleTrait` referenced in public API - --> test-crate/src/test_union.rs:21:1 - | -21 | pub union GenericUnion { - | ... -24 | }␊ - | ^ - | - = in trait bound of `test_crate::test_union::GenericUnion` - -42 errors emitted diff --git a/tools/cargo-check-external-types/tests/integration_test.rs b/tools/cargo-check-external-types/tests/integration_test.rs deleted file mode 100644 index 84686dfa5cc..00000000000 --- a/tools/cargo-check-external-types/tests/integration_test.rs +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -use cargo_check_external_types::cargo::handle_failure; -use pretty_assertions::assert_str_eq; -use std::fs; -use std::path::Path; -use std::process::Output; -use test_bin::get_test_bin; - -/// Returns (stdout, stderr) -pub fn output_text(output: &Output) -> (String, String) { - ( - String::from_utf8_lossy(&output.stdout).to_string(), - String::from_utf8_lossy(&output.stderr).to_string(), - ) -} - -fn run_with_args(in_path: impl AsRef, args: &[&str]) -> String { - let mut cmd = get_test_bin("cargo-check-external-types"); - cmd.current_dir(in_path.as_ref()); - cmd.arg("check-external-types"); - for &arg in args { - cmd.arg(arg); - } - let output = cmd - .output() - .expect("failed to start cargo-check-external-types"); - match output.status.code() { - Some(1) => { /* expected */ } - _ => handle_failure("cargo-check-external-types", &output).unwrap(), - } - let (stdout, _) = output_text(&output); - stdout -} - -#[test] -fn with_default_config() { - let expected_output = fs::read_to_string("tests/default-config-expected-output.txt").unwrap(); - let actual_output = run_with_args("test-workspace/test-crate", &[]); - assert_str_eq!(expected_output, actual_output); -} - -#[test] -fn with_some_allowed_types() { - let expected_output = fs::read_to_string("tests/allow-some-types-expected-output.txt").unwrap(); - let actual_output = run_with_args( - "test-workspace/test-crate", - &["--config", "../../tests/allow-some-types.toml"], - ); - assert_str_eq!(expected_output, actual_output); -} - -#[test] -fn with_output_format_markdown_table() { - let expected_output = - fs::read_to_string("tests/output-format-markdown-table-expected-output.md").unwrap(); - let actual_output = run_with_args( - "test-workspace/test-crate", - &["--output-format", "markdown-table"], - ); - assert_str_eq!(expected_output, actual_output); -} - -// Make sure that the visitor doesn't attempt to visit the inner items of re-exported external types. -// Rustdoc doesn't include these inner items in its JSON output, which leads to obtuse crashes if they're -// referenced. It's also just the wrong behavior to look into the type being re-exported, since if it's -// approved, then it doesn't matter what it referenced. If it's not approved, then the re-export itself -// is the violation. -#[test] -fn test_reexports() { - let expected_output = fs::read_to_string("tests/test-reexports-expected-output.md").unwrap(); - let actual_output = run_with_args("test-workspace/test-reexports-crate", &[]); - assert_str_eq!(expected_output, actual_output); -} diff --git a/tools/cargo-check-external-types/tests/output-format-markdown-table-expected-output.md b/tools/cargo-check-external-types/tests/output-format-markdown-table-expected-output.md deleted file mode 100644 index 12f1a19ccfa..00000000000 --- a/tools/cargo-check-external-types/tests/output-format-markdown-table-expected-output.md +++ /dev/null @@ -1,44 +0,0 @@ -| Crate | Type | Used In | -| --- | --- | --- | -| external_lib | external_lib::AssociatedGenericTrait | test-crate/src/lib.rs:125:0 | -| external_lib | external_lib::AssociatedGenericTrait | test-crate/src/lib.rs:136:4 | -| external_lib | external_lib::ReprCType | test-crate/src/test_union.rs:10:4 | -| external_lib | external_lib::ReprCType | test-crate/src/test_union.rs:15:4 | -| external_lib | external_lib::SimpleNewType | test-crate/src/lib.rs:158:4 | -| external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:104:4 | -| external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:122:0 | -| external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:135:4 | -| external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:146:4 | -| external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:150:4 | -| external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:38:0 | -| external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:38:0 | -| external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:47:0 | -| external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:89:4 | -| external_lib | external_lib::SimpleTrait | test-crate/src/lib.rs:92:8 | -| external_lib | external_lib::SimpleTrait | test-crate/src/test_union.rs:21:0 | -| external_lib | external_lib::SomeOtherStruct | test-crate/src/lib.rs:125:0 | -| external_lib | external_lib::SomeOtherStruct | test-crate/src/lib.rs:136:4 | -| external_lib | external_lib::SomeOtherStruct | test-crate/src/lib.rs:72:4 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:109:0 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:110:0 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:115:4 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:116:4 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:120:0 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:121:0 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:123:0 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:125:0 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:136:4 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:38:0 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:43:0 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:54:0 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:62:4 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:67:4 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:68:4 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:72:4 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:78:4 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:79:4 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:80:4 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:81:4 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:84:0 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:89:4 | -| external_lib | external_lib::SomeStruct | test-crate/src/lib.rs:91:8 | diff --git a/tools/cargo-check-external-types/tests/test-reexports-expected-output.md b/tools/cargo-check-external-types/tests/test-reexports-expected-output.md deleted file mode 100644 index bfd40d1d02c..00000000000 --- a/tools/cargo-check-external-types/tests/test-reexports-expected-output.md +++ /dev/null @@ -1,57 +0,0 @@ -error: Unapproved external type `external_lib::AssociatedGenericTrait` referenced in public API - --> test-reexports-crate/src/lib.rs:6:1 - | -6 | pub use external_lib::AssociatedGenericTrait; - | ^-------------------------------------------^ - | - = in re-export named `test_reexports_crate::AssociatedGenericTrait` - -error: Unapproved external type `external_lib::ReprCType` referenced in public API - --> test-reexports-crate/src/lib.rs:7:1 - | -7 | pub use external_lib::ReprCType; - | ^------------------------------^ - | - = in re-export named `test_reexports_crate::ReprCType` - -error: Unapproved external type `external_lib::SimpleTrait` referenced in public API - --> test-reexports-crate/src/lib.rs:8:1 - | -8 | pub use external_lib::SimpleTrait; - | ^--------------------------------^ - | - = in re-export named `test_reexports_crate::SimpleTrait` - -error: Unapproved external type `external_lib::SimpleGenericTrait` referenced in public API - --> test-reexports-crate/src/lib.rs:11:5 - | -11 | pub use external_lib::SimpleGenericTrait; - | ^---------------------------------------^ - | - = in re-export named `test_reexports_crate::Something::SimpleGenericTrait` - -error: Unapproved external type `external_lib::SimpleNewType` referenced in public API - --> test-reexports-crate/src/lib.rs:12:5 - | -12 | pub use external_lib::SimpleNewType; - | ^----------------------------------^ - | - = in re-export named `test_reexports_crate::Something::SimpleNewType` - -error: Unapproved external type `external_lib::SomeOtherStruct` referenced in public API - --> test-reexports-crate/src/lib.rs:15:1 - | -15 | pub use external_lib::SomeOtherStruct; - | ^------------------------------------^ - | - = in re-export named `test_reexports_crate::SomeOtherStruct` - -error: Unapproved external type `external_lib::SomeStruct` referenced in public API - --> test-reexports-crate/src/lib.rs:16:1 - | -16 | pub use external_lib::SomeStruct; - | ^-------------------------------^ - | - = in re-export named `test_reexports_crate::SomeStruct` - -7 errors emitted diff --git a/tools/ci-build/scripts/check-tools b/tools/ci-build/scripts/check-tools index 1dedf36b939..06aec615169 100755 --- a/tools/ci-build/scripts/check-tools +++ b/tools/ci-build/scripts/check-tools @@ -22,7 +22,6 @@ function test_tool { popd &>/dev/null } -test_tool "tools/cargo-check-external-types" "${RUST_NIGHTLY_VERSION}" test_tool "tools/changelogger" "${RUST_STABLE_VERSION}" test_tool "tools/ci-cdk/canary-runner" "${RUST_STABLE_VERSION}" test_tool "tools/crate-hasher" "${RUST_STABLE_VERSION}" From d879da1f14f5d69e8ab4cf62d1935d65bf1e80b5 Mon Sep 17 00:00:00 2001 From: Harry Barber <106155934+hlbarber@users.noreply.github.com> Date: Tue, 11 Oct 2022 23:54:24 +0100 Subject: [PATCH 32/57] Add PluginExt extension trait and FilterByOperationName plugin (#1837) * Make Operation fields public * Split into modules and add FilterByOperationName --- .../src/operation/mod.rs | 7 +- .../aws-smithy-http-server/src/plugin.rs | 86 ----------------- .../src/plugin/filter.rs | 50 ++++++++++ .../src/plugin/identity.rs | 20 ++++ .../aws-smithy-http-server/src/plugin/mod.rs | 93 +++++++++++++++++++ .../src/plugin/stack.rs | 37 ++++++++ 6 files changed, 205 insertions(+), 88 deletions(-) delete mode 100644 rust-runtime/aws-smithy-http-server/src/plugin.rs create mode 100644 rust-runtime/aws-smithy-http-server/src/plugin/filter.rs create mode 100644 rust-runtime/aws-smithy-http-server/src/plugin/identity.rs create mode 100644 rust-runtime/aws-smithy-http-server/src/plugin/mod.rs create mode 100644 rust-runtime/aws-smithy-http-server/src/plugin/stack.rs diff --git a/rust-runtime/aws-smithy-http-server/src/operation/mod.rs b/rust-runtime/aws-smithy-http-server/src/operation/mod.rs index ddfab157d69..9bcfa146511 100644 --- a/rust-runtime/aws-smithy-http-server/src/operation/mod.rs +++ b/rust-runtime/aws-smithy-http-server/src/operation/mod.rs @@ -193,8 +193,11 @@ pub use upgrade::*; /// /// The `L` is held and applied lazily during [`Upgradable::upgrade`]. pub struct Operation { - inner: S, - layer: L, + /// The inner [`Service`](tower::Service) representing the logic of the operation. + pub inner: S, + /// The [`Layer`](tower::Layer) applied to the HTTP [`Service`](tower::Service) after `S` has been wrapped in + /// [`Upgrade`]. + pub layer: L, } impl Operation { diff --git a/rust-runtime/aws-smithy-http-server/src/plugin.rs b/rust-runtime/aws-smithy-http-server/src/plugin.rs deleted file mode 100644 index 206a0d7fea7..00000000000 --- a/rust-runtime/aws-smithy-http-server/src/plugin.rs +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -use crate::operation::Operation; - -/// Provides a standard interface for applying [`Plugin`]s to a service builder. This is implemented automatically for -/// all builders. -/// -/// As [`Plugin`]s modify the way in which [`Operation`]s are [`upgraded`](crate::operation::Upgradable) we can use -/// [`Pluggable`] as a foundation to write extension traits which are implemented for all service builders. -/// -/// # Example -/// -/// ``` -/// # struct PrintPlugin; -/// # use aws_smithy_http_server::plugin::Pluggable; -/// trait PrintExt: Pluggable { -/// fn print(self) -> Self::Output where Self: Sized { -/// self.apply(PrintPlugin) -/// } -/// } -/// -/// impl PrintExt for Builder where Builder: Pluggable {} -/// ``` -pub trait Pluggable { - type Output; - - /// Applies a [`Plugin`] to the service builder. - fn apply(self, plugin: NewPlugin) -> Self::Output; -} - -/// A mapping from one [`Operation`] to another. Used to modify the behavior of -/// [`Upgradable`](crate::operation::Upgradable) and therefore the resulting service builder, -/// -/// The generics `Protocol` and `Op` allow the behavior to be parameterized. -/// -/// Every service builder enjoys [`Pluggable`] and therefore can be provided with a [`Plugin`] using -/// [`Pluggable::apply`]. -pub trait Plugin { - type Service; - type Layer; - - /// Maps an [`Operation`] to another. - fn map(&self, input: Operation) -> Operation; -} - -/// An [`Plugin`] that maps an `input` [`Operation`] to itself. -pub struct IdentityPlugin; - -impl Plugin for IdentityPlugin { - type Service = S; - type Layer = L; - - fn map(&self, input: Operation) -> Operation { - input - } -} - -/// A wrapper struct which composes an `Inner` and an `Outer` [`Plugin`]. -pub struct PluginStack { - inner: Inner, - outer: Outer, -} - -impl PluginStack { - /// Creates a new [`PluginStack`]. - pub fn new(inner: Inner, outer: Outer) -> Self { - PluginStack { inner, outer } - } -} - -impl Plugin for PluginStack -where - Inner: Plugin, - Outer: Plugin, -{ - type Service = Outer::Service; - type Layer = Outer::Layer; - - fn map(&self, input: Operation) -> Operation { - let inner = self.inner.map(input); - self.outer.map(inner) - } -} diff --git a/rust-runtime/aws-smithy-http-server/src/plugin/filter.rs b/rust-runtime/aws-smithy-http-server/src/plugin/filter.rs new file mode 100644 index 00000000000..5a00b0d285b --- /dev/null +++ b/rust-runtime/aws-smithy-http-server/src/plugin/filter.rs @@ -0,0 +1,50 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +use tower::util::Either; + +use crate::operation::{Operation, OperationShape}; + +use super::Plugin; + +/// A [`Plugin`] used to filter [`Plugin::map`] application using a predicate over the [`OperationShape::NAME`]. +/// +/// See [`PluginExt::filter_by_operation_name`](super::PluginExt::filter_by_operation_name) for more information. +pub struct FilterByOperationName { + inner: Inner, + predicate: F, +} + +impl FilterByOperationName { + /// Creates a new [`FilterByOperationName`]. + pub(crate) fn new(inner: Inner, predicate: F) -> Self { + Self { inner, predicate } + } +} + +impl Plugin for FilterByOperationName +where + F: Fn(&str) -> bool, + Inner: Plugin, + Op: OperationShape, +{ + type Service = Either; + type Layer = Either; + + fn map(&self, input: Operation) -> Operation { + if (self.predicate)(Op::NAME) { + let Operation { inner, layer } = self.inner.map(input); + Operation { + inner: Either::A(inner), + layer: Either::A(layer), + } + } else { + Operation { + inner: Either::B(input.inner), + layer: Either::B(input.layer), + } + } + } +} diff --git a/rust-runtime/aws-smithy-http-server/src/plugin/identity.rs b/rust-runtime/aws-smithy-http-server/src/plugin/identity.rs new file mode 100644 index 00000000000..d0a6d1390be --- /dev/null +++ b/rust-runtime/aws-smithy-http-server/src/plugin/identity.rs @@ -0,0 +1,20 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +use crate::operation::Operation; + +use super::Plugin; + +/// A [`Plugin`] that maps an `input` [`Operation`] to itself. +pub struct IdentityPlugin; + +impl Plugin for IdentityPlugin { + type Service = S; + type Layer = L; + + fn map(&self, input: Operation) -> Operation { + input + } +} diff --git a/rust-runtime/aws-smithy-http-server/src/plugin/mod.rs b/rust-runtime/aws-smithy-http-server/src/plugin/mod.rs new file mode 100644 index 00000000000..3317337bd71 --- /dev/null +++ b/rust-runtime/aws-smithy-http-server/src/plugin/mod.rs @@ -0,0 +1,93 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +mod filter; +mod identity; +mod stack; + +use crate::operation::Operation; + +pub use filter::*; +pub use identity::*; +pub use stack::*; + +/// Provides a standard interface for applying [`Plugin`]s to a service builder. This is implemented automatically for +/// all builders. +/// +/// As [`Plugin`]s modify the way in which [`Operation`]s are [`upgraded`](crate::operation::Upgradable) we can use +/// [`Pluggable`] as a foundation to write extension traits which are implemented for all service builders. +/// +/// # Example +/// +/// ``` +/// # struct PrintPlugin; +/// # use aws_smithy_http_server::plugin::Pluggable; +/// trait PrintExt: Pluggable { +/// fn print(self) -> Self::Output where Self: Sized { +/// self.apply(PrintPlugin) +/// } +/// } +/// +/// impl PrintExt for Builder where Builder: Pluggable {} +/// ``` +pub trait Pluggable { + type Output; + + /// Applies a [`Plugin`] to the service builder. + fn apply(self, plugin: NewPlugin) -> Self::Output; +} + +/// A mapping from one [`Operation`] to another. Used to modify the behavior of +/// [`Upgradable`](crate::operation::Upgradable) and therefore the resulting service builder, +/// +/// The generics `Protocol` and `Op` allow the behavior to be parameterized. +/// +/// Every service builder enjoys [`Pluggable`] and therefore can be provided with a [`Plugin`] using +/// [`Pluggable::apply`]. +pub trait Plugin { + type Service; + type Layer; + + /// Maps an [`Operation`] to another. + fn map(&self, input: Operation) -> Operation; +} + +/// An extension trait for [`Plugin`]. +pub trait PluginExt: Plugin { + /// Stacks another [`Plugin`], running them sequentially. + fn stack(self, other: Other) -> PluginStack + where + Self: Sized, + { + PluginStack::new(self, other) + } + + /// Filters the application of the [`Plugin`] using a predicate over the + /// [`OperationShape::NAME`](crate::operation::OperationShape). + /// + /// # Example + /// + /// ```rust + /// # use aws_smithy_http_server::{plugin::{Plugin, PluginExt}, operation::{Operation, OperationShape}}; + /// # struct Pl; + /// # struct CheckHealth; + /// # impl OperationShape for CheckHealth { const NAME: &'static str = ""; type Input = (); type Output = (); type Error = (); } + /// # impl Plugin<(), CheckHealth, (), ()> for Pl { type Service = (); type Layer = (); fn map(&self, input: Operation<(), ()>) -> Operation<(), ()> { input }} + /// # let plugin = Pl; + /// # let operation = Operation { inner: (), layer: () }; + /// // Prevents `plugin` from being applied to the `CheckHealth` operation. + /// let filtered_plugin = plugin.filter_by_operation_name(|name| name != CheckHealth::NAME); + /// let new_operation = filtered_plugin.map(operation); + /// ``` + fn filter_by_operation_name(self, predicate: F) -> FilterByOperationName + where + Self: Sized, + F: Fn(&str) -> bool, + { + FilterByOperationName::new(self, predicate) + } +} + +impl PluginExt for Pl where Pl: Plugin {} diff --git a/rust-runtime/aws-smithy-http-server/src/plugin/stack.rs b/rust-runtime/aws-smithy-http-server/src/plugin/stack.rs new file mode 100644 index 00000000000..424a9903711 --- /dev/null +++ b/rust-runtime/aws-smithy-http-server/src/plugin/stack.rs @@ -0,0 +1,37 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +use crate::operation::Operation; + +use super::Plugin; + +/// A wrapper struct which composes an `Inner` and an `Outer` [`Plugin`]. +/// +/// The `Inner::map` is run _then_ the `Outer::map`. +pub struct PluginStack { + inner: Inner, + outer: Outer, +} + +impl PluginStack { + /// Creates a new [`PluginStack`]. + pub fn new(inner: Inner, outer: Outer) -> Self { + PluginStack { inner, outer } + } +} + +impl Plugin for PluginStack +where + Inner: Plugin, + Outer: Plugin, +{ + type Service = Outer::Service; + type Layer = Outer::Layer; + + fn map(&self, input: Operation) -> Operation { + let inner = self.inner.map(input); + self.outer.map(inner) + } +} From 03ad6e7e52923071de77f647b69931969ea978ef Mon Sep 17 00:00:00 2001 From: Harry Barber <106155934+hlbarber@users.noreply.github.com> Date: Wed, 12 Oct 2022 12:16:13 +0100 Subject: [PATCH 33/57] Fix broken module path in instrumentation documentation (#1843) --- design/src/server/instrumentation.md | 14 +++++++------- design/src/server/pokemon_service.md | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/design/src/server/instrumentation.md b/design/src/server/instrumentation.md index b4647831f53..ff6e691389e 100644 --- a/design/src/server/instrumentation.md +++ b/design/src/server/instrumentation.md @@ -53,7 +53,7 @@ Smithy provides an out-the-box middleware which: - Opens a DEBUG level span, prior to request handling, including the operation name and request URI and headers. - Emits a DEBUG level event, after to request handling, including the response headers and status code. -This is applied by default and can be enabled and disabled by filtering on `aws_smithy_http_server::logging`. +This is applied by default and can be enabled and disabled by filtering on `aws_smithy_http_server::instrumentation`. @@ -83,21 +83,21 @@ RUST_LOG=aws_smithy_http_server=debug,pokemon_service=debug cargo r and then using `cargo t` to run integration tests against the server, yields the following logs: ```text - 2022-09-27T09:13:35.372517Z DEBUG aws_smithy_http_server::logging::service: response, headers: {"content-type": "application/json", "content-length": "17"}, status_code: 200 OK + 2022-09-27T09:13:35.372517Z DEBUG aws_smithy_http_server::instrumentation::service: response, headers: {"content-type": "application/json", "content-length": "17"}, status_code: 200 OK at /smithy-rs/rust-runtime/aws-smithy-http-server/src/logging/service.rs:47 - in aws_smithy_http_server::logging::service::request with operation: get_server_statistics, method: GET, uri: /stats, headers: {"host": "localhost:13734"} + in aws_smithy_http_server::instrumentation::service::request with operation: get_server_statistics, method: GET, uri: /stats, headers: {"host": "localhost:13734"} 2022-09-27T09:13:35.374104Z DEBUG pokemon_service: attempting to authenticate storage user at pokemon-service/src/lib.rs:184 - in aws_smithy_http_server::logging::service::request with operation: get_storage, method: GET, uri: /pokedex/{redacted}, headers: {"passcode": "{redacted}", "host": "localhost:13734"} + in aws_smithy_http_server::instrumentation::service::request with operation: get_storage, method: GET, uri: /pokedex/{redacted}, headers: {"passcode": "{redacted}", "host": "localhost:13734"} 2022-09-27T09:13:35.374152Z DEBUG pokemon_service: authentication failed at pokemon-service/src/lib.rs:188 - in aws_smithy_http_server::logging::service::request with operation: get_storage, method: GET, uri: /pokedex/{redacted}, headers: {"passcode": "{redacted}", "host": "localhost:13734"} + in aws_smithy_http_server::instrumentation::service::request with operation: get_storage, method: GET, uri: /pokedex/{redacted}, headers: {"passcode": "{redacted}", "host": "localhost:13734"} - 2022-09-27T09:13:35.374230Z DEBUG aws_smithy_http_server::logging::service: response, headers: {"content-type": "application/json", "x-amzn-errortype": "NotAuthorized", "content-length": "2"}, status_code: 401 Unauthorized + 2022-09-27T09:13:35.374230Z DEBUG aws_smithy_http_server::instrumentation::service: response, headers: {"content-type": "application/json", "x-amzn-errortype": "NotAuthorized", "content-length": "2"}, status_code: 401 Unauthorized at /smithy-rs/rust-runtime/aws-smithy-http-server/src/logging/service.rs:47 - in aws_smithy_http_server::logging::service::request with operation: get_storage, method: GET, uri: /pokedex/{redacted}, headers: {"passcode": "{redacted}", "host": "localhost:13734"} + in aws_smithy_http_server::instrumentation::service::request with operation: get_storage, method: GET, uri: /pokedex/{redacted}, headers: {"passcode": "{redacted}", "host": "localhost:13734"} ``` ## Interactions with Sensitivity diff --git a/design/src/server/pokemon_service.md b/design/src/server/pokemon_service.md index 6842bcf5c4c..cb90f48dd04 100644 --- a/design/src/server/pokemon_service.md +++ b/design/src/server/pokemon_service.md @@ -150,9 +150,9 @@ aws_smithy_http_server::routing::Router::new_rest_json_router(vec![ At this level, logging might be prohibited by the [`@sensitive`][10] trait. If there are no `@sensitive` shapes, the generated code looks like: ```rust -let request_fmt = aws_smithy_http_server::logging::sensitivity::RequestFmt::new(); -let response_fmt = aws_smithy_http_server::logging::sensitivity::ResponseFmt::new(); -let svc = aws_smithy_http_server::logging::InstrumentOperation::new( +let request_fmt = aws_smithy_http_server::instrumentation::sensitivity::RequestFmt::new(); +let response_fmt = aws_smithy_http_server::instrumentation::sensitivity::ResponseFmt::new(); +let svc = aws_smithy_http_server::instrumentation::InstrumentOperation::new( svc, "capture_pokemon_operation", ) @@ -164,20 +164,20 @@ Accessing the Pokédex is modeled as a restricted operation: a passcode is neede To not log the passcode, the code will be generated [here][11] as: ```rust -let request_fmt = aws_smithy_http_server::logging::sensitivity::RequestFmt::new() +let request_fmt = aws_smithy_http_server::instrumentation::sensitivity::RequestFmt::new() .header(|name: &http::header::HeaderName| { #[allow(unused_variables)] let name = name.as_str(); let name_match = matches!(name, "passcode"); let key_suffix = None; let value = name_match; - aws_smithy_http_server::logging::sensitivity::headers::HeaderMarker { + aws_smithy_http_server::instrumentation::sensitivity::headers::HeaderMarker { value, key_suffix, } }) .label(|index: usize| matches!(index, 1)); -let response_fmt = aws_smithy_http_server::logging::sensitivity::ResponseFmt::new(); +let response_fmt = aws_smithy_http_server::instrumentation::sensitivity::ResponseFmt::new(); ``` Each route is a pair, [`BoxCloneService`][12] wrapping the service operation (the implementation) and From 7866477fd4798306611b948d602f882d392da71e Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Wed, 12 Oct 2022 10:53:28 -0700 Subject: [PATCH 34/57] Add RFC for Error Context and Compatibility (#1819) Co-authored-by: Zelda Hessler --- design/src/SUMMARY.md | 1 + design/src/rfcs/overview.md | 1 + ...rfc0022_error_context_and_compatibility.md | 405 ++++++++++++++++++ 3 files changed, 407 insertions(+) create mode 100644 design/src/rfcs/rfc0022_error_context_and_compatibility.md diff --git a/design/src/SUMMARY.md b/design/src/SUMMARY.md index 5a25cb39da8..8067cc5a9cc 100644 --- a/design/src/SUMMARY.md +++ b/design/src/SUMMARY.md @@ -42,6 +42,7 @@ - [RFC-0019: Event Streams Errors](./rfcs/rfc0019_event_streams_errors.md) - [RFC-0020: Service Builder Improvements](./rfcs/rfc0020_service_builder.md) - [RFC-0021: Dependency Versions](./rfcs/rfc0021_dependency_versions.md) + - [RFC-0022: Error Context and Compatibility](./rfcs/rfc0022_error_context_and_compatibility.md) - [Contributing](./contributing/overview.md) - [Writing and debugging a low-level feature that relies on HTTP](./contributing/writing_and_debugging_a_low-level_feature_that_relies_on_HTTP.md) diff --git a/design/src/rfcs/overview.md b/design/src/rfcs/overview.md index b5878b801be..1bbdd70bd0d 100644 --- a/design/src/rfcs/overview.md +++ b/design/src/rfcs/overview.md @@ -31,3 +31,4 @@ - [RFC-0019: Event Streams Errors](./rfc0019_event_streams_errors.md) - [RFC-0020: Service Builder Improvements](./rfc0020_service_builder.md) - [RFC-0021: Dependency Versions](./rfc0021_dependency_versions.md) +- [RFC-0022: Error Context and Compatibility](./rfc0022_error_context_and_compatibility.md) diff --git a/design/src/rfcs/rfc0022_error_context_and_compatibility.md b/design/src/rfcs/rfc0022_error_context_and_compatibility.md new file mode 100644 index 00000000000..c3957a21c2f --- /dev/null +++ b/design/src/rfcs/rfc0022_error_context_and_compatibility.md @@ -0,0 +1,405 @@ +RFC: Error Context and Compatibility +==================================== + +> Status: Accepted +> +> Applies to: Generated clients and shared rust-runtime crates + +This RFC proposes a pattern for writing Rust errors to provide consistent +error context AND forwards/backwards compatibility. The goal is to strike +a balance between these four goals: + +1. Errors are forwards compatible, and changes to errors are backwards compatible +2. Errors are idiomatic and ergonomic. It is easy to match on them and extract additional + information for cases where that's useful. The type system prevents errors from being used + incorrectly (for example, incorrectly retrieving context for a different error variant) +3. Error messages are easy to debug +4. Errors implement best practices with Rust's `Error` trait (for example, implementing the optional `source()` function where possible) + +_Note:_ This RFC is _not_ about error backwards compatibility when it comes to error serialization/deserialization +for transfer over the wire. The Smithy protocols cover that aspect. + +Past approaches in smithy-rs +---------------------------- + +This section examines some examples found in `aws-config` that illustrate different problems +that this RFC will attempt to solve, and calls out what was done well, and what could be improved upon. + +### Case study: `InvalidFullUriError` + +To start, let's examine `InvalidFullUriError` (doc comments omitted): +```rust +#[derive(Debug)] +#[non_exhaustive] +pub enum InvalidFullUriError { + #[non_exhaustive] InvalidUri(InvalidUri), + #[non_exhaustive] NoDnsService, + #[non_exhaustive] MissingHost, + #[non_exhaustive] NotLoopback, + DnsLookupFailed(io::Error), +} + +impl Display for InvalidFullUriError { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + match self { + InvalidFullUriError::InvalidUri(err) => write!(f, "URI was invalid: {}", err), + InvalidFullUriError::MissingHost => write!(f, "URI did not specify a host"), + // ... omitted ... + } + } +} + +impl Error for InvalidFullUriError { + fn source(&self) -> Option<&(dyn Error + 'static)> { + match self { + InvalidFullUriError::InvalidUri(err) => Some(err), + InvalidFullUriError::DnsLookupFailed(err) => Some(err), + _ => None, + } + } +} +``` + +This error does a few things well: +1. Using `#[non_exhaustive]` on the enum allows new errors to be added in the future. +2. Breaking out different error types allows for more useful error messages, potentially with error-specific context. + Customers can match on these different error variants to change their program flow, although it's not immediately + obvious if such use cases exist for this error. +4. The error cause is available through the `Error::source()` impl for variants that have a cause. + +However, there are also a number of things that could be improved: +1. All tuple/struct enum members are public, and `InvalidUri` is an error from the `http` crate. + Exposing a type from another crate can potentially lock the GA SDK into a specific crate version + if breaking changes are ever made to the exposed types. In this specific case, it prevents + using alternate HTTP implementations that don't use the `http` crate. +2. `DnsLookupFailed` is missing `#[non_exhaustive]`, so new members can never be added to it. +3. Use of enum tuples, even with `#[non_exhaustive]`, adds friction to evolving the API since the + tuple members cannot be named. +4. Printing the source error in the `Display` impl leads to error repetition by reporters + that examine the full source chain. +5. The `source()` impl has a `_` match arm, which means future implementers could forget to propagate + a source when adding new error variants. +6. The error source can be downcasted to `InvalidUri` type from `http` in customer code. This is + a leaky abstraction where customers can start to rely on the underlying library the SDK uses + in its implementation, and if that library is replaced/changed, it can silently break the + customer's application. _Note:_ later in the RFC, I'll demonstrate why fixing this issue is not practical. + +### Case study: `ProfileParseError` + +Next, let's look at a much simpler error. The `ProfileParseError` is focused purely on the parsing +logic for the SDK config file: + +```rust +#[derive(Debug, Clone)] +pub struct ProfileParseError { + location: Location, + message: String, +} + +impl Display for ProfileParseError { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + write!( + f, + "error parsing {} on line {}:\n {}", + self.location.path, self.location.line_number, self.message + ) + } +} + +impl Error for ProfileParseError {} +``` + +What this error does well: +- The members are private, so `#[non_exhaustive]` isn't even necessary +- The error is completely opaque (maximizing compatibility) while still being + debuggable thanks to the flexible messaging + +What could be improved: +- It needlessly implements `Clone`, which may prevent it from holding + an error source in the future since errors are often not `Clone`. +- In the future, if more error variants are needed, a private inner error + kind enum could be added to change messaging, but there's not a _nice_ way to + expose new variant-specific information to the customer. +- Programmatic access to the error `Location` may be desired, but + this can be trivially added in the future without a breaking change by + adding an accessor method. + +### Case study: code generated client errors + +The SDK currently generates errors such as the following (from S3): + +```rust +#[non_exhaustive] +pub enum Error { + BucketAlreadyExists(BucketAlreadyExists), + BucketAlreadyOwnedByYou(BucketAlreadyOwnedByYou), + InvalidObjectState(InvalidObjectState), + NoSuchBucket(NoSuchBucket), + NoSuchKey(NoSuchKey), + NoSuchUpload(NoSuchUpload), + NotFound(NotFound), + ObjectAlreadyInActiveTierError(ObjectAlreadyInActiveTierError), + ObjectNotInActiveTierError(ObjectNotInActiveTierError), + Unhandled(Box), +} +``` + +Each error variant gets its own struct, which can hold error-specific contextual information. +Except for the `Unhandled` variant, both the error enum and the details on each variant are extensible. +The `Unhandled` variant should move the error source into a struct so that its type can be hidden. +Otherwise, the code generated errors are already aligned with the goals of this RFC. + +Approaches from other projects +------------------------------ + +### `std::io::Error` + +The standard library uses an `Error` struct with an accompanying `ErrorKind` enum +for its IO error. Roughly: + +```rust +#[derive(Debug)] +#[non_exhaustive] +pub enum ErrorKind { + NotFound, + // ... omitted ... + Other, +} + +#[derive(Debug)] +pub struct Error { + kind: ErrorKind, + source: Box, +} +``` + +What this error does well: +- It is extensible since the `ErrorKind` is non-exhaustive +- It has an `Other` error type that can be instantiated by users in unit tests, + making it easier to unit test error handling + +What could be improved: +- There isn't an ergonomic way to add programmatically accessible error-specific context + to this error in the future +- The source error can be downcasted, which could be a trap for backwards compatibility. + +### Hyper 1.0 + +Hyper is has outlined [some problems they want to address with errors](https://github.com/hyperium/hyper/blob/bd7928f3dd6a8461f0f0fdf7ee0fd95c2f156f88/docs/ROADMAP.md#errors) +for the coming 1.0 release. To summarize: + +- It's difficult to match on specific errors (Hyper 0.x's `Error` relies + on `is_x` methods for error matching rather than enum matching). +- Error reporters duplicate information since the hyper 0.x errors include the display of their error sources +- `Error::source()` can leak internal dependencies + +Opaque Error Sources +-------------------- + +There is [discussion in the errors working group](https://github.com/rust-lang/project-error-handling/issues/53) +about how to avoid leaking internal dependency error types through error source downcasting. One option is to +create an opaque error wrapping new-type that removes the ability to downcast to the other library's error. +This, however, can be circumvented via unsafe code, and also breaks the ability for error reporters to +properly display the error (for example, if the error has backtrace information, that would be +inaccessible to the reporter). + +This situation might improve if the nightly `request_value`/`request_ref`/`provide` functions on +`std::error::Error` are stabilized, since then contextual information needed for including things +such as a backtrace could still be retrieved through the opaque error new-type. + +This RFC proposes that error types from other libraries not be directly exposed in the API, but rather, +be exposed indirectly through `Error::source` as `&dyn Error + 'static`. + +Errors should not require downcasting to be useful. Downcasting the error's source should be +a last resort, and with the understanding that the type could change at a later date with no +compile-time guarantees. + +Error Proposal +-------------- + +Taking a customer's perspective, there are two broad categories of errors: + +1. **Actionable:** Errors that can/should influence program flow; where it's useful to + do different work based on additional error context or error variant information +2. **Informative:** Errors that inform that something went wrong, but where + it's not useful to match on the error to change program flow + +This RFC proposes that a consistent pattern be introduced to cover these two use cases for +all errors in the public API for the Rust runtime crates and generated client crates. + +### Actionable error pattern + +Actionable errors are represented as enums. If an error variant has an error source or additional contextual +information, it must use a separate context struct that is referenced via tuple in the enum. For example: + +```rust +pub enum Error { + // Good: This is exhaustive and uses a tuple, but its sole member is an extensible struct with private fields + VariantA(VariantA), + + // Bad: The fields are directly exposed and can't have accessor methods. The error + // source type also can't be changed at a later date since. + #[non_exhaustive] + VariantB { + some_additional_info: u32, + source: AnotherError // AnotherError is from this crate + }, + + // Bad: There's no way to add additional contextual information to this error in the future, even + // though it is non-exhaustive. Changing it to a tuple or struct later leads to compile errors in existing + // match statements. + #[non_exhaustive] + VariantC, + + // Bad: Not extensible if additional context is added later (unless that context can be added to `AnotherError`) + #[non_exhaustive] + VariantD(AnotherError), + + // Bad: Not extensible. If new context is added later (for example, a second endpoint), there's no way to name it. + #[non_exhaustive] + VariantE(Endpoint, AnotherError), + + // Bad: Exposes another library's error type in the public API, + // which makes upgrading or replacing that library a breaking change + #[non_exhaustive] + VariantF { + source: http::uri::InvalidUri + }, + + // Bad: The error source type is public, and even though its a boxed error, it won't + // be possible to change it to an opaque error type later (for example, if/when + // opaque errors become practical due to standard library stabilizations). + #[non_exhaustive] + VariantG { + source: Box, + } +} + +pub struct VariantA { + some_field: u32, + // This is private, so it's fine to reference the external library's error type + source: http::uri::InvalidUri +} + +impl VariantA { + fn some_field(&self) -> u32 { + self.some_field + } +} +``` + +Error variants that contain a source must return it from the `Error::source` method. +The `source` implementation _should not_ use the catch all (`_`) match arm, as this makes it easy to miss +adding a new error variant's source at a later date. + +The error `Display` implementation _must not_ include the source in its output: + +```rust +// Good +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::VariantA => write!(f, "variant a"), + Self::VariantB { some_additional_info, .. } => write!(f, "variant b ({some_additional_info})"), + // ... and so on + } + } +} + +// Bad +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + Self::VariantA => write!(f, "variant a"), + // Bad: includes the source in the `Display` output, which leads to duplicate error information + Self::VariantB { some_additional_info, source } => write!(f, "variant b ({some_additional_info}): {source}"), + // ... and so on + } + } +} +``` + +### Informative error pattern + +Informative errors must be represented as structs. If error messaging changes based on an underlying cause, then a +private error kind enum can be used internally for this purpose. For example: + +```rust +#[derive(Debug)] +pub struct InformativeError { + some_additional_info: u32, + source: AnotherError, +} + +impl fmt::Display for InformativeError { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "some informative message with {}", self.some_additional_info) + } +} + +impl Error for InformativeError { + fn source(&self) -> Option<&(dyn Error + 'static)> { + Some(&self.source) + } +} +``` + +In general, informative errors should be referenced by variants in actionable errors since they cannot be converted +to actionable errors at a later date without a breaking change. This is not a hard rule, however. Use your best judgement +for the situation. + +### Displaying full error context + +In code where errors are logged rather than returned to the customer, the full error source chain +must be displayed. This will be made easy by placing a `DisplayErrorContext` struct in `aws-smithy-types` that +is used as a wrapper to get the better error formatting: + +```rust +tracing::warn!(err = %DisplayErrorContext(err), "some message"); +``` + +This might be implemented as follows: + +```rust +#[derive(Debug)] +pub struct DisplayErrorContext(pub E); + +impl fmt::Display for DisplayErrorContext { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write_err(f, &self.0)?; + // Also add a debug version of the error at the end + write!(f, " ({:?})", self) + } +} + +fn write_err(f: &mut fmt::Formatter<'_>, err: &dyn Error) -> fmt::Result { + write!(f, "{}", err)?; + if let Some(source) = err.source() { + write!(f, ": ")?; + write_err(f, source)?; + } + Ok(()) +} +``` + +Changes Checklist +----------------- + +- [ ] Update every struct/enum that implements `Error` in all the non-server Rust runtime crates +- [ ] Hide error source type in `Unhandled` variant in code generated errors +- [ ] Remove `Clone` from `ProfileParseError` and any others that have it + +Error Code Review Checklist +--------------------------- + +This is a checklist meant to aid code review of new errors: + +- [ ] The error fits either the actionable or informative pattern +- [ ] If the error is informative, it's clear that it will never be expanded with additional variants in the future +- [ ] The `Display` impl does not write the error source to the formatter +- [ ] The catch all `_` match arm is not used in the `Display` or `Error::source` implementations +- [ ] Error types from external libraries are not exposed in the public API +- [ ] Error enums are `#[non_exhaustive]` +- [ ] Error enum variants that don't have a separate error context struct are `#[non_exhaustive]` +- [ ] Error context is exposed via accessors rather than by public fields +- [ ] Errors and their context structs are in an `error` submodule for any given module. They are not mixed with other non-error code From aa60badfe88923d8986a76d26950d5c6d373f778 Mon Sep 17 00:00:00 2001 From: david-perez Date: Thu, 13 Oct 2022 13:51:10 +0200 Subject: [PATCH 35/57] Correctly serialize `String`s in XML (#1832) The logic that keeps track of whether we're working with a borrowed or an owned value is flawed. It just so happened to work when requesting owned values from borrowed values because we called `autoDeref` before creating the value expression. That logic should instead be used _within_ `ValueExpression` to appease Clippy there too. Fixes #1831. --- codegen-client-test/model/rest-xml-extras.smithy | 15 ++++++++++++++- .../protocols/serialize/ValueExpression.kt | 4 +++- .../XmlBindingTraitSerializerGenerator.kt | 16 +++++++++------- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/codegen-client-test/model/rest-xml-extras.smithy b/codegen-client-test/model/rest-xml-extras.smithy index 9c520676edd..76a6bbd9fa8 100644 --- a/codegen-client-test/model/rest-xml-extras.smithy +++ b/codegen-client-test/model/rest-xml-extras.smithy @@ -20,6 +20,7 @@ service RestXmlExtras { ChecksumRequired, StringHeader, CreateFoo, + RequiredMember, ] } @@ -242,5 +243,17 @@ structure StringHeaderOutput { field: String, @httpHeader("x-enum") - enumHeader: StringEnum + enumHeader: StringEnum, +} + +/// This operation tests that we can serialize `required` members. +@http(uri: "/required-member", method: "GET") +operation RequiredMember { + input: RequiredMemberInputOutput + output: RequiredMemberInputOutput +} + +structure RequiredMemberInputOutput { + @required + requiredString: String } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/ValueExpression.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/ValueExpression.kt index 4d7a2ce3e5b..6ab3aea1e34 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/ValueExpression.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/ValueExpression.kt @@ -5,6 +5,8 @@ package software.amazon.smithy.rust.codegen.core.smithy.protocols.serialize +import software.amazon.smithy.rust.codegen.core.rustlang.autoDeref + sealed class ValueExpression { abstract val name: String @@ -12,7 +14,7 @@ sealed class ValueExpression { data class Value(override val name: String) : ValueExpression() fun asValue(): String = when (this) { - is Reference -> "*$name" + is Reference -> autoDeref(name) is Value -> name } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt index 8f83d8fe6af..285f362f363 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt @@ -19,7 +19,6 @@ import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.TimestampShape import software.amazon.smithy.model.shapes.UnionShape -import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.model.traits.XmlFlattenedTrait import software.amazon.smithy.model.traits.XmlNamespaceTrait @@ -285,11 +284,9 @@ class XmlBindingTraitSerializerGenerator( } private fun RustWriter.serializeRawMember(member: MemberShape, input: String) { - when (val shape = model.expectShape(member.target)) { - is StringShape -> if (shape.hasTrait()) { + when (model.expectShape(member.target)) { + is StringShape -> { rust("$input.as_str()") - } else { - rust("$input.as_ref()") } is BooleanShape, is NumberShape -> { rust( @@ -444,7 +441,7 @@ class XmlBindingTraitSerializerGenerator( * ``` * * If [member] is not an optional shape, generate code like: - * `{ .. Block }` + * `{ .. BLOCK }` * * [inner] is passed a new `ctx` object to use for code generation which handles the * potentially new name of the input. @@ -462,7 +459,12 @@ class XmlBindingTraitSerializerGenerator( } } else { with(util) { - ignoreZeroValues(member, ValueExpression.Value(autoDeref(ctx.input))) { + val valueExpression = if (ctx.input.startsWith("&")) { + ValueExpression.Reference(ctx.input) + } else { + ValueExpression.Value(ctx.input) + } + ignoreZeroValues(member, valueExpression) { inner(ctx) } } From c7ddb164b28b920313432789cfe05d8112a035cc Mon Sep 17 00:00:00 2001 From: Julian Antonielli Date: Fri, 14 Oct 2022 15:31:42 +0100 Subject: [PATCH 36/57] Check that release workflow is run on main (#1856) * Announce whether the release script is running in dry_run mode or not * Check that release is running in main branch * Fix `run_name` -> `run-name` * Import actions/github-script@v6 in main-branch-check * Add missing `steps` attribute in main-branch-check * Use `with` attribute with actions/github-script@v6 * Use single quotes instead of double quotes * Use single quotes: "main" -> 'main' * Add runs-on attribute --- .github/workflows/release.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d13df296edc..e25b5510594 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,6 +13,7 @@ env: rust_version: 1.61.0 name: Release smithy-rs +run-name: ${{ github.workflow }} - ${{ inputs.dry_run && 'Dry run' || 'Production run' }} on: workflow_dispatch: inputs: @@ -23,12 +24,25 @@ on: default: true jobs: + main-branch-check: + name: Check that workflow is running in main + runs-on: ubuntu-latest + steps: + - name: Main branch check + if: ${{ github.ref_name != 'main' }} + uses: actions/github-script@v6 + with: + script: | + core.setFailed("The release workflow can only be ran on main (current branch: ${{ github.ref_name }})") + # If a release is kicked off before an image is built after push to main, # or if a dry-run release is kicked off against a non-main branch to test # automation changes, we'll need to build a base image to work against. # This job will be a no-op if an image was already built on main. acquire-base-image: name: Acquire Base Image + needs: + - main-branch-check runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 From 18d969e16000a4fa1283e0532f3cd71748ea67d7 Mon Sep 17 00:00:00 2001 From: Luca Palmieri <20745048+LukeMathWalker@users.noreply.github.com> Date: Mon, 17 Oct 2022 09:32:12 +0100 Subject: [PATCH 37/57] Upgrade to Rust 1.62.0 (#1825) * Run clippy --fix for Rust 1.62.0 and format the resulting code * Run clippy --fix on all targets * Run clippy --fix with all features enabled * Avoid extra allocation * Use more idiomatic assert * Ignore noisy lint * Update pyo3 and pyo3-asyncio to 0.17.0 * Implement Eq on aws-smithy-checksums::Error * Implement Eq on Protocol * Replace conditionals with range-containment * Implement Eq on types in aws-smithy-types * Implement Eq on types in aws-smithy-http-server-python * Implement Eq on types in aws-smithy-eventstream * Implement Eq on types in aws-smithy-xml * Implement Eq on aws-sigv4 * Update CI to use Rust 1.62.0 * Add Eq for generated types that implement PartialEq * Allow clippy::needless_return in generated code * Remove unnecessary reborrow in http_serde * Remove unnecessary borrow in operation_deser * Add CHANGELOG entries * Revert "Add Eq for generated types that implement PartialEq" This reverts commit 5169bd95aa4dbbfc77c23bf7415e98ebc6361733. * Update pyo3 and pyo3-asyncio in generated code for python server * Allow clippy::derive_partial_eq_without_eq on structs and builders * Run clippy on tools * Fix accidental move in generated code * Revert "Allow clippy::derive_partial_eq_without_eq on structs and builders" This reverts commit 068c63ca2030879584e7b602bd0648abab19cabe. * Fix another accidental move in generated code * Undo unwanted change to model * Re-add reborrow in HttpBindingGenerator * Fix clippy::format-push-string in changelogger * Fix more uses of str.push_str(&format!(...)) * Remove unnecessary parenthesis * Run ktlint * Update aws/rust-runtime/aws-http/src/content_encoding.rs Co-authored-by: John DiSanti * Update aws/rust-runtime/aws-http/src/content_encoding.rs Co-authored-by: John DiSanti * Ignore doctest for non-exported macro Rust 1.62 introduced a breaking change where doctests for non-exported macros are now run by default. These don't compile because the macro can't be imported in it. See https://github.com/rust-lang/rust/issues/97030 for more info. * Run cargo fmt * Use $crate instead of crate in macro * Revert "Implement Eq on types in aws-smithy-types" This reverts commit c45a6b5a56d391923efce3c884291c330218982d. * Revert "Implement Eq on types in aws-smithy-eventstream" This reverts commit 78f4b07344d2cbb9d06b30ffd9bad16031fdd83b. * Revert "Implement Eq on types in aws-smithy-xml" This reverts commit 590f01af7326bde7de97cae97feeedf593b9239b. * Revert "Implement Eq on aws-sigv4" This reverts commit d78bb62124c4b3a24a35bdd655995de11252d17f. * Revert "Implement Eq on types in aws-smithy-http-server-python" This reverts commit f2cd9018844130d441820742dc1cf1c7abeaa38b. * Revert "Implement Eq on aws-smithy-checksums::Error" This reverts commit 5da170405e12d5077f67b8f8e41c2319138244d4. Co-authored-by: Julian Antonielli Co-authored-by: John DiSanti --- .github/workflows/ci.yml | 2 +- .github/workflows/pull-request-bot.yml | 2 +- .github/workflows/release.yml | 2 +- CHANGELOG.next.toml | 19 +++++++++++++++++++ aws/rust-runtime/aws-endpoint/src/lib.rs | 6 ++---- .../aws-http/src/content_encoding.rs | 12 +++++++++--- .../aws-http/src/recursion_detection.rs | 2 +- aws/rust-runtime/aws-http/src/retry.rs | 6 ++---- .../aws-inlineable/src/http_body_checksum.rs | 2 +- .../tests/middleware_e2e_test.rs | 4 ++-- .../aws-sigv4/src/event_stream.rs | 4 ++-- .../src/http_request/canonical_request.rs | 2 +- .../aws-types/src/build_metadata.rs | 2 +- .../customizations/AllowLintsGenerator.kt | 3 +++ .../protocols/HttpBoundProtocolGenerator.kt | 2 +- .../smithy/PythonServerCargoDependency.kt | 4 ++-- gradle.properties | 2 +- .../aws-smithy-async/src/future/fn_stream.rs | 2 +- .../aws-smithy-eventstream/src/frame.rs | 4 ++-- .../aws-smithy-eventstream/src/str_bytes.rs | 2 +- .../aws-smithy-http-server-python/Cargo.toml | 4 ++-- .../instrumentation/sensitivity/sensitive.rs | 4 ++-- .../instrumentation/sensitivity/uri/label.rs | 10 +++++----- .../instrumentation/sensitivity/uri/query.rs | 10 +++++----- .../aws-smithy-http-server/src/protocols.rs | 2 +- .../aws-smithy-http-server/src/routing/mod.rs | 2 +- .../src/routing/tiny_map.rs | 6 +++--- rust-runtime/aws-smithy-http/src/header.rs | 18 ++++++------------ rust-runtime/aws-smithy-http/src/retry.rs | 6 ++---- .../aws-smithy-json/src/deserialize/token.rs | 2 +- .../aws-smithy-protocol-test/src/lib.rs | 4 +--- rust-runtime/aws-smithy-query/src/lib.rs | 9 +++++++-- .../aws-smithy-types/src/date_time/format.rs | 2 +- rust-runtime/aws-smithy-types/src/lib.rs | 4 ++-- rust-runtime/aws-smithy-xml/src/decode.rs | 6 +++--- rust-runtime/aws-smithy-xml/src/unescape.rs | 2 +- .../tests/handwritten_parsers.rs | 1 + tools/Dockerfile | 4 ++-- tools/changelogger/src/render.rs | 5 ++++- tools/ci-cdk/canary-lambda/src/canary.rs | 2 +- tools/crate-hasher/src/file_list.rs | 3 ++- tools/publisher/src/cargo/publish.rs | 6 +++--- tools/publisher/src/package.rs | 5 ++--- tools/publisher/src/sort.rs | 2 +- tools/publisher/src/subcommand/publish.rs | 6 +++--- .../src/subcommand/tag_versions_manifest.rs | 2 +- tools/sdk-lints/src/copyright.rs | 2 +- tools/sdk-sync/src/sync.rs | 3 ++- tools/smithy-rs-tool-common/src/git.rs | 4 ++-- 49 files changed, 122 insertions(+), 98 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 92f145542f2..d84e48b715b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ on: workflow_call: env: - rust_version: 1.61.0 + rust_version: 1.62.0 rust_toolchain_components: clippy,rustfmt jobs: diff --git a/.github/workflows/pull-request-bot.yml b/.github/workflows/pull-request-bot.yml index 2e9125340b7..75f294e91ca 100644 --- a/.github/workflows/pull-request-bot.yml +++ b/.github/workflows/pull-request-bot.yml @@ -28,7 +28,7 @@ concurrency: env: java_version: 11 - rust_version: 1.61.0 + rust_version: 1.62.0 rust_toolchain_components: clippy,rustfmt apt_dependencies: libssl-dev gnuplot jq diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e25b5510594..fc5f8590a8a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -10,7 +10,7 @@ concurrency: cancel-in-progress: true env: - rust_version: 1.61.0 + rust_version: 1.62.0 name: Release smithy-rs run-name: ${{ github.workflow }} - ${{ inputs.dry_run && 'Dry run' || 'Production run' }} diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 781d528fc41..c3272671a74 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -11,6 +11,25 @@ # meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"} # author = "rcoh" + +[[smithy-rs]] +message = "Bump MSRV to be 1.62.0." +references = ["smithy-rs#1825"] +meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all" } +author = "LukeMathWalker" + +[[smithy-rs]] +message = "Bump pyo3 and pyo3-asyncio from 0.16.x to 0.17.0 for aws-smithy-http-server-python." +references = ["smithy-rs#1825"] +meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" } +author = "LukeMathWalker" + +[[aws-sdk-rust]] +message = "Bump MSRV to be 1.62.0." +references = ["smithy-rs#1825"] +meta = { "breaking" = true, "tada" = false, "bug" = false } +author = "LukeMathWalker" + [[smithy-rs]] message = """ Replace all usages of `AtomicU64` with `AtomicUsize` to support 32bit targets. diff --git a/aws/rust-runtime/aws-endpoint/src/lib.rs b/aws/rust-runtime/aws-endpoint/src/lib.rs index ab3e9549112..fbf81a7feaf 100644 --- a/aws/rust-runtime/aws-endpoint/src/lib.rs +++ b/aws/rust-runtime/aws-endpoint/src/lib.rs @@ -283,8 +283,7 @@ mod test { props.insert(region.clone()); props.insert(SigningService::from_static("qldb")); props.insert( - EndpointShim::from_arc(provider) - .resolve_endpoint(&Params::new(Some(region.clone()))), + EndpointShim::from_arc(provider).resolve_endpoint(&Params::new(Some(region))), ); }; let req = AwsEndpointStage.apply(req).expect("should succeed"); @@ -314,8 +313,7 @@ mod test { props.insert(region.clone()); props.insert(SigningService::from_static("qldb")); props.insert( - EndpointShim::from_arc(provider) - .resolve_endpoint(&Params::new(Some(region.clone()))), + EndpointShim::from_arc(provider).resolve_endpoint(&Params::new(Some(region))), ); }; let req = AwsEndpointStage.apply(req).expect("should succeed"); diff --git a/aws/rust-runtime/aws-http/src/content_encoding.rs b/aws/rust-runtime/aws-http/src/content_encoding.rs index e25b2c8b5c3..6b900ab7506 100644 --- a/aws/rust-runtime/aws-http/src/content_encoding.rs +++ b/aws/rust-runtime/aws-http/src/content_encoding.rs @@ -376,7 +376,7 @@ mod tests { impl SputteringBody { fn len(&self) -> usize { - self.parts.iter().flat_map(|b| b).map(|b| b.len()).sum() + self.parts.iter().flatten().map(|b| b.len()).sum() } } @@ -462,7 +462,10 @@ mod tests { }; let timeout_duration = Duration::from_secs(3); - if let Err(_) = tokio::time::timeout(timeout_duration, test_fut).await { + if tokio::time::timeout(timeout_duration, test_fut) + .await + .is_err() + { panic!("test_aws_chunked_encoding timed out after {timeout_duration:?}"); } } @@ -513,7 +516,10 @@ mod tests { }; let timeout_duration = Duration::from_secs(3); - if let Err(_) = tokio::time::timeout(timeout_duration, test_fut).await { + if tokio::time::timeout(timeout_duration, test_fut) + .await + .is_err() + { panic!( "test_aws_chunked_encoding_sputtering_body timed out after {timeout_duration:?}" ); diff --git a/aws/rust-runtime/aws-http/src/recursion_detection.rs b/aws/rust-runtime/aws-http/src/recursion_detection.rs index 37805a534e1..5e849598b4f 100644 --- a/aws/rust-runtime/aws-http/src/recursion_detection.rs +++ b/aws/rust-runtime/aws-http/src/recursion_detection.rs @@ -160,7 +160,7 @@ mod test { ) } assert_ok(validate_headers( - &augmented_req.http().headers(), + augmented_req.http().headers(), test_case.request_headers_after(), )) } diff --git a/aws/rust-runtime/aws-http/src/retry.rs b/aws/rust-runtime/aws-http/src/retry.rs index 4ee9a3c792a..0ce9d368f83 100644 --- a/aws/rust-runtime/aws-http/src/retry.rs +++ b/aws/rust-runtime/aws-http/src/retry.rs @@ -143,7 +143,7 @@ mod test { ) -> Result, SdkError> { Err(SdkError::ServiceError { err, - raw: operation::Response::new(raw.map(|b| SdkBody::from(b))), + raw: operation::Response::new(raw.map(SdkBody::from)), }) } @@ -265,9 +265,7 @@ mod test { policy.classify_retry( Result::, SdkError>::Err(SdkError::ResponseError { err: Box::new(UnmodeledError), - raw: operation::Response::new( - http::Response::new("OK").map(|b| SdkBody::from(b)) - ), + raw: operation::Response::new(http::Response::new("OK").map(SdkBody::from)), }) .as_ref() ), diff --git a/aws/rust-runtime/aws-inlineable/src/http_body_checksum.rs b/aws/rust-runtime/aws-inlineable/src/http_body_checksum.rs index 4848f5c89ac..24679851fbf 100644 --- a/aws/rust-runtime/aws-inlineable/src/http_body_checksum.rs +++ b/aws/rust-runtime/aws-inlineable/src/http_body_checksum.rs @@ -265,7 +265,7 @@ mod tests { for i in 0..10000 { let line = format!("This is a large file created for testing purposes {}", i); file.as_file_mut().write(line.as_bytes()).unwrap(); - crc32c_checksum.update(&line.as_bytes()); + crc32c_checksum.update(line.as_bytes()); } let body = ByteStream::read_from() diff --git a/aws/rust-runtime/aws-inlineable/tests/middleware_e2e_test.rs b/aws/rust-runtime/aws-inlineable/tests/middleware_e2e_test.rs index e52667290b4..90fdc32373b 100644 --- a/aws/rust-runtime/aws-inlineable/tests/middleware_e2e_test.rs +++ b/aws/rust-runtime/aws-inlineable/tests/middleware_e2e_test.rs @@ -82,7 +82,7 @@ fn test_operation() -> Operation Operation().ok()); } - _ => panic!("Unexpected `MissingContentTypeReason`: {}", e.to_string()), + _ => panic!("Unexpected `MissingContentTypeReason`: {}", e), }, } } diff --git a/rust-runtime/aws-smithy-http-server/src/routing/mod.rs b/rust-runtime/aws-smithy-http-server/src/routing/mod.rs index e72f04f30d0..ec6b4394a6e 100644 --- a/rust-runtime/aws-smithy-http-server/src/routing/mod.rs +++ b/rust-runtime/aws-smithy-http-server/src/routing/mod.rs @@ -323,7 +323,7 @@ mod rest_tests { #[inline] fn call(&mut self, req: Request) -> Self::Future { - let body = boxed(Body::from(format!("{} :: {}", self.0, req.uri().to_string()))); + let body = boxed(Body::from(format!("{} :: {}", self.0, req.uri()))); let fut = async { Ok(Response::builder().status(&http::StatusCode::OK).body(body).unwrap()) }; Box::pin(fut) } diff --git a/rust-runtime/aws-smithy-http-server/src/routing/tiny_map.rs b/rust-runtime/aws-smithy-http-server/src/routing/tiny_map.rs index 625bd2d4f68..236da27797a 100644 --- a/rust-runtime/aws-smithy-http-server/src/routing/tiny_map.rs +++ b/rust-runtime/aws-smithy-http-server/src/routing/tiny_map.rs @@ -122,9 +122,9 @@ mod tests { const CUTOFF: usize = 5; - const SMALL_VALUES: [(&'static str, usize); 3] = [("a", 0), ("b", 1), ("c", 2)]; - const MEDIUM_VALUES: [(&'static str, usize); 5] = [("a", 0), ("b", 1), ("c", 2), ("d", 3), ("e", 4)]; - const LARGE_VALUES: [(&'static str, usize); 10] = [ + const SMALL_VALUES: [(&str, usize); 3] = [("a", 0), ("b", 1), ("c", 2)]; + const MEDIUM_VALUES: [(&str, usize); 5] = [("a", 0), ("b", 1), ("c", 2), ("d", 3), ("e", 4)]; + const LARGE_VALUES: [(&str, usize); 10] = [ ("a", 0), ("b", 1), ("c", 2), diff --git a/rust-runtime/aws-smithy-http/src/header.rs b/rust-runtime/aws-smithy-http/src/header.rs index 965bcdd8e0d..69ef14ea479 100644 --- a/rust-runtime/aws-smithy-http/src/header.rs +++ b/rust-runtime/aws-smithy-http/src/header.rs @@ -604,10 +604,8 @@ mod test { let merged_header_map = append_merge_header_maps(left_hand_side_headers, right_hand_side_headers); - let actual_merged_values: Vec<_> = merged_header_map - .get_all(header_name.clone()) - .into_iter() - .collect(); + let actual_merged_values: Vec<_> = + merged_header_map.get_all(header_name).into_iter().collect(); let expected_merged_values = vec![left_header_value, right_header_value]; @@ -630,10 +628,8 @@ mod test { let merged_header_map = append_merge_header_maps(left_hand_side_headers, right_hand_side_headers); - let actual_merged_values: Vec<_> = merged_header_map - .get_all(header_name.clone()) - .into_iter() - .collect(); + let actual_merged_values: Vec<_> = + merged_header_map.get_all(header_name).into_iter().collect(); let expected_merged_values = vec![left_header_value_1, left_header_value_2, right_header_value]; @@ -655,10 +651,8 @@ mod test { let merged_header_map = append_merge_header_maps(left_hand_side_headers, right_hand_side_headers); - let actual_merged_values: Vec<_> = merged_header_map - .get_all(header_name.clone()) - .into_iter() - .collect(); + let actual_merged_values: Vec<_> = + merged_header_map.get_all(header_name).into_iter().collect(); let expected_merged_values = vec![right_header_value_1, right_header_value_2]; diff --git a/rust-runtime/aws-smithy-http/src/retry.rs b/rust-runtime/aws-smithy-http/src/retry.rs index b562b66290b..48e86894cba 100644 --- a/rust-runtime/aws-smithy-http/src/retry.rs +++ b/rust-runtime/aws-smithy-http/src/retry.rs @@ -124,7 +124,7 @@ mod test { ) -> Result, SdkError> { Err(SdkError::ServiceError { err, - raw: operation::Response::new(raw.map(|b| SdkBody::from(b))), + raw: operation::Response::new(raw.map(SdkBody::from)), }) } @@ -194,9 +194,7 @@ mod test { policy.classify_retry( Result::, SdkError>::Err(SdkError::ResponseError { err: Box::new(UnmodeledError), - raw: operation::Response::new( - http::Response::new("OK").map(|b| SdkBody::from(b)) - ), + raw: operation::Response::new(http::Response::new("OK").map(SdkBody::from)), }) .as_ref() ), diff --git a/rust-runtime/aws-smithy-json/src/deserialize/token.rs b/rust-runtime/aws-smithy-json/src/deserialize/token.rs index 6525651828e..3bead63fadf 100644 --- a/rust-runtime/aws-smithy-json/src/deserialize/token.rs +++ b/rust-runtime/aws-smithy-json/src/deserialize/token.rs @@ -600,7 +600,7 @@ pub mod test { Err(Error::new( ErrorReason::Custom(Cow::Owned(format!( "{} is not a valid epoch", - invalid.replace("-", "") + invalid.replace('-', "") ))), None, )), diff --git a/rust-runtime/aws-smithy-protocol-test/src/lib.rs b/rust-runtime/aws-smithy-protocol-test/src/lib.rs index 1825867efd0..651459e00ec 100644 --- a/rust-runtime/aws-smithy-protocol-test/src/lib.rs +++ b/rust-runtime/aws-smithy-protocol-test/src/lib.rs @@ -386,9 +386,7 @@ mod tests { fn test_validate_empty_query_string() { let request = Request::builder().uri("/foo").body(()).unwrap(); validate_query_string(&request, &[]).expect("no required params should pass"); - validate_query_string(&request, &["a"]) - .err() - .expect("no params provided"); + validate_query_string(&request, &["a"]).expect_err("no params provided"); } #[test] diff --git a/rust-runtime/aws-smithy-query/src/lib.rs b/rust-runtime/aws-smithy-query/src/lib.rs index f8065be16ed..67c0d2ee1d1 100644 --- a/rust-runtime/aws-smithy-query/src/lib.rs +++ b/rust-runtime/aws-smithy-query/src/lib.rs @@ -9,6 +9,7 @@ use aws_smithy_types::date_time::{DateTimeFormatError, Format}; use aws_smithy_types::primitive::Encoder; use aws_smithy_types::{DateTime, Number}; use std::borrow::Cow; +use std::fmt::Write; use urlencoding::encode; pub struct QueryWriter<'a> { @@ -62,14 +63,18 @@ impl<'a> QueryMapWriter<'a> { pub fn entry(&mut self, key: &str) -> QueryValueWriter { let entry = if self.flatten { "" } else { ".entry" }; - self.output.push_str(&format!( + write!( + &mut self.output, "&{}{}.{}.{}={}", self.prefix, entry, self.next_index, self.key_name, encode(key) - )); + ) + // The `Write` implementation for `String` is infallible, + // see https://doc.rust-lang.org/src/alloc/string.rs.html#2815 + .unwrap(); let value_name = format!( "{}{}.{}.{}", self.prefix, entry, self.next_index, self.value_name diff --git a/rust-runtime/aws-smithy-types/src/date_time/format.rs b/rust-runtime/aws-smithy-types/src/date_time/format.rs index dd5d72d1b37..560a16409eb 100644 --- a/rust-runtime/aws-smithy-types/src/date_time/format.rs +++ b/rust-runtime/aws-smithy-types/src/date_time/format.rs @@ -532,7 +532,7 @@ mod tests { .smithy_format_value .as_ref() .expect("parse test cases should always have a formatted value"); - let actual = parse(&to_parse); + let actual = parse(to_parse); assert!( actual.is_ok(), diff --git a/rust-runtime/aws-smithy-types/src/lib.rs b/rust-runtime/aws-smithy-types/src/lib.rs index 3e7b599e15b..6a18c187a0a 100644 --- a/rust-runtime/aws-smithy-types/src/lib.rs +++ b/rust-runtime/aws-smithy-types/src/lib.rs @@ -291,7 +291,7 @@ impl TryFrom for f64 { } } Number::NegInt(v) => { - if -(1 << 53) <= v && v <= (1 << 53) { + if (-(1 << 53)..=(1 << 53)).contains(&v) { Ok(v as Self) } else { Err(Self::Error::I64ToFloatLossyConversion(v)) @@ -316,7 +316,7 @@ impl TryFrom for f32 { } } Number::NegInt(v) => { - if -(1 << 24) <= v && v <= (1 << 24) { + if (-(1 << 24)..=(1 << 24)).contains(&v) { Ok(v as Self) } else { Err(Self::Error::I64ToFloatLossyConversion(v)) diff --git a/rust-runtime/aws-smithy-xml/src/decode.rs b/rust-runtime/aws-smithy-xml/src/decode.rs index cd0c6ba635d..936d4c3d32e 100644 --- a/rust-runtime/aws-smithy-xml/src/decode.rs +++ b/rust-runtime/aws-smithy-xml/src/decode.rs @@ -463,7 +463,7 @@ mod test { let xml = r#""#; let mut doc = Document::new(xml); let mut scoped = doc.root_element().expect("valid doc"); - assert_eq!(scoped.start_el.closed, true); + assert!(scoped.start_el.closed); assert!(scoped.next_tag().is_none()) } @@ -531,8 +531,8 @@ mod test { root.start_el().attributes, vec![Attr { name: Name { - prefix: "xsi".into(), - local: "type".into() + prefix: "xsi", + local: "type" }, value: "CanonicalUser".into() }] diff --git a/rust-runtime/aws-smithy-xml/src/unescape.rs b/rust-runtime/aws-smithy-xml/src/unescape.rs index 170530596d8..3f779ebc0c3 100644 --- a/rust-runtime/aws-smithy-xml/src/unescape.rs +++ b/rust-runtime/aws-smithy-xml/src/unescape.rs @@ -150,7 +150,7 @@ mod test { fn no_panics(s: String) { let unescaped = unescape(&s); // if the string needed to be escaped, we - if s.contains("&") { + if s.contains('&') { assert!( matches!(unescaped, Ok(Cow::Owned(_)) | Err(_)) ); diff --git a/rust-runtime/aws-smithy-xml/tests/handwritten_parsers.rs b/rust-runtime/aws-smithy-xml/tests/handwritten_parsers.rs index d8bedd9870b..a58f0b3241a 100644 --- a/rust-runtime/aws-smithy-xml/tests/handwritten_parsers.rs +++ b/rust-runtime/aws-smithy-xml/tests/handwritten_parsers.rs @@ -44,6 +44,7 @@ fn deserialize_xml_attribute(inp: &str) -> Result { let mut doc = Document::new(inp); let mut root = doc.root_element()?; #[allow(unused_assignments)] + #[allow(clippy::blacklisted_name)] let mut foo: Option = None; let mut bar: Option = None; foo = root.start_el().attr("foo").map(|attr| attr.to_string()); diff --git a/tools/Dockerfile b/tools/Dockerfile index 9d8c0b963b7..b2f11d4d90d 100644 --- a/tools/Dockerfile +++ b/tools/Dockerfile @@ -45,7 +45,7 @@ RUN set -eux; \ # Rust & Tools Installation Stage # FROM bare_base_image AS install_rust -ARG rust_stable_version=1.61.0 +ARG rust_stable_version=1.62.0 ARG rust_nightly_version=nightly-2022-07-25 ARG cargo_deny_version=0.12.2 ARG cargo_udeps_version=0.1.29 @@ -117,7 +117,7 @@ RUN set -eux; \ # Final image # FROM bare_base_image AS final_image -ARG rust_stable_version=1.61.0 +ARG rust_stable_version=1.62.0 ARG rust_nightly_version=nightly-2022-07-25 RUN set -eux; \ yum -y updateinfo; \ diff --git a/tools/changelogger/src/render.rs b/tools/changelogger/src/render.rs index 0a61b3609c6..9bb8e765a4d 100644 --- a/tools/changelogger/src/render.rs +++ b/tools/changelogger/src/render.rs @@ -377,7 +377,10 @@ fn render(entries: &[ChangelogEntry], release_header: &str) -> (String, String) out.push_str("- @"); out.push_str(&contributor_handle); if !contribution_references.is_empty() { - out.push_str(&format!(" ({})", contribution_references)); + write!(&mut out, " ({})", contribution_references) + // The `Write` implementation for `String` is infallible, + // see https://doc.rust-lang.org/src/alloc/string.rs.html#2815 + .unwrap() } out.push('\n'); } diff --git a/tools/ci-cdk/canary-lambda/src/canary.rs b/tools/ci-cdk/canary-lambda/src/canary.rs index 242c9f0c076..d46345a32d9 100644 --- a/tools/ci-cdk/canary-lambda/src/canary.rs +++ b/tools/ci-cdk/canary-lambda/src/canary.rs @@ -20,7 +20,7 @@ macro_rules! mk_canary { pub(crate) fn mk_canary( clients: &Clients, env: &CanaryEnv, - ) -> Option<(&'static str, crate::canary::CanaryFuture)> { + ) -> Option<(&'static str, $crate::canary::CanaryFuture)> { Some(($name, Box::pin($run_canary(clients, env)))) } }; diff --git a/tools/crate-hasher/src/file_list.rs b/tools/crate-hasher/src/file_list.rs index a7b10f39eb0..03f6090cb69 100644 --- a/tools/crate-hasher/src/file_list.rs +++ b/tools/crate-hasher/src/file_list.rs @@ -5,6 +5,7 @@ use anyhow::{Context, Result}; use std::collections::BTreeSet; +use std::fmt::Write; use std::fs::Metadata; use std::path::Path; @@ -84,7 +85,7 @@ impl FileMetadata { /// Returns a string to hash for this file fn hash_entry(&self) -> String { let mut entry = String::with_capacity(7 + self.path.len() + 1 + self.sha256.len() + 1); - entry.push_str(&format!("{:06o} ", self.mode)); + write!(&mut entry, "{:06o} ", self.mode).unwrap(); entry.push_str(&self.path); entry.push(' '); entry.push_str(&self.sha256); diff --git a/tools/publisher/src/cargo/publish.rs b/tools/publisher/src/cargo/publish.rs index a8a08a6cdc7..71e79e3814e 100644 --- a/tools/publisher/src/cargo/publish.rs +++ b/tools/publisher/src/cargo/publish.rs @@ -71,7 +71,7 @@ mod tests { "aws-sdk-dynamodb", Version::parse("0.0.22-alpha").unwrap(), ), - package_path: env::current_dir().unwrap().into(), + package_path: env::current_dir().unwrap(), } .spawn() .await @@ -86,7 +86,7 @@ mod tests { "something", Version::parse("0.0.22-alpha").unwrap(), ), - package_path: env::current_dir().unwrap().into(), + package_path: env::current_dir().unwrap(), } .spawn() .await; @@ -108,7 +108,7 @@ mod tests { "aws-sdk-dynamodb", Version::parse("0.0.22-alpha").unwrap(), ), - package_path: env::current_dir().unwrap().into(), + package_path: env::current_dir().unwrap(), } .spawn() .await diff --git a/tools/publisher/src/package.rs b/tools/publisher/src/package.rs index 4777e0a8a3b..2cc13df3ad8 100644 --- a/tools/publisher/src/package.rs +++ b/tools/publisher/src/package.rs @@ -386,7 +386,7 @@ mod tests { let error = format!( "{}", - read_package(&path, manifest).err().expect("should fail") + read_package(&path, manifest).expect_err("should fail") ); assert!( error.contains("Invalid crate version"), @@ -517,8 +517,7 @@ mod tests { &[("C", "1.2.0"), ("D", "1.3.0"), ("F", "1.4.0")], ), ]) - .err() - .expect("fail"); + .expect_err("fail"); assert_eq!( "crate A has multiple versions: 1.1.0 and 1.0.0", format!("{}", error) diff --git a/tools/publisher/src/sort.rs b/tools/publisher/src/sort.rs index cff1d21ad5b..a6da808a4e4 100644 --- a/tools/publisher/src/sort.rs +++ b/tools/publisher/src/sort.rs @@ -120,7 +120,7 @@ mod tests { package("C", &["B"]), ]; - let error = dependency_order(packages).err().expect("cycle"); + let error = dependency_order(packages).expect_err("cycle"); assert_eq!("dependency cycle detected", format!("{}", error)); } diff --git a/tools/publisher/src/subcommand/publish.rs b/tools/publisher/src/subcommand/publish.rs index a2fdc171fb8..58cc9ea8333 100644 --- a/tools/publisher/src/subcommand/publish.rs +++ b/tools/publisher/src/subcommand/publish.rs @@ -126,7 +126,7 @@ async fn is_published(handle: &PackageHandle) -> Result { 3, Duration::from_secs(5), || async { - let expected_version = (&handle.version).to_string(); + let expected_version = handle.version.to_string(); let crate_info = match CRATES_IO_CLIENT.get_crate(&handle.name).await { Ok(info) => info, Err(Error::NotFound(_)) => return Ok(false), @@ -260,9 +260,9 @@ mod test { #[tokio::test] async fn crate_published_works() { let handle = PackageHandle::new("aws-smithy-http", "0.27.0-alpha.1".parse().unwrap()); - assert_eq!(is_published(&handle).await.expect("failed"), true); + assert!(is_published(&handle).await.expect("failed")); // we will never publish this version let handle = PackageHandle::new("aws-smithy-http", "0.21.0-alpha.1".parse().unwrap()); - assert_eq!(is_published(&handle).await.expect("failed"), false); + assert!(!is_published(&handle).await.expect("failed")); } } diff --git a/tools/publisher/src/subcommand/tag_versions_manifest.rs b/tools/publisher/src/subcommand/tag_versions_manifest.rs index dfc52c7f57f..ebd05d99109 100644 --- a/tools/publisher/src/subcommand/tag_versions_manifest.rs +++ b/tools/publisher/src/subcommand/tag_versions_manifest.rs @@ -86,7 +86,7 @@ mod tests { .unwrap(); let expected = { - let mut expected = original.clone(); + let mut expected = original; expected.release.as_mut().unwrap().tag = Some("some-release-tag".to_string()); expected }; diff --git a/tools/sdk-lints/src/copyright.rs b/tools/sdk-lints/src/copyright.rs index 04b61a59ce4..5645fb6590b 100644 --- a/tools/sdk-lints/src/copyright.rs +++ b/tools/sdk-lints/src/copyright.rs @@ -55,7 +55,7 @@ fn check_copyright_header(path: impl AsRef) -> Vec { path.as_ref().display() ))]; } - return vec![]; + vec![] } fn needs_copyright_header(path: &Path) -> bool { diff --git a/tools/sdk-sync/src/sync.rs b/tools/sdk-sync/src/sync.rs index aa2fd6fc65f..1512bd0909a 100644 --- a/tools/sdk-sync/src/sync.rs +++ b/tools/sdk-sync/src/sync.rs @@ -10,6 +10,7 @@ use anyhow::{bail, Context, Result}; use smithy_rs_tool_common::git::{Commit, CommitHash, Git, GitCLI}; use smithy_rs_tool_common::macros::here; use std::collections::BTreeSet; +use std::fmt::Write; use std::path::{Path, PathBuf}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::mpsc::{Sender, TryRecvError}; @@ -405,7 +406,7 @@ impl Sync { .map(|c| format!("{} <{}>", c.author_name, c.author_email)) .collect(); for author in authors { - commit_message.push_str(&format!("Co-authored-by: {}\n", author)); + writeln!(&mut commit_message, "Co-authored-by: {}", author).unwrap(); } commit_message } diff --git a/tools/smithy-rs-tool-common/src/git.rs b/tools/smithy-rs-tool-common/src/git.rs index b22543f0ab5..b1b34aa263b 100644 --- a/tools/smithy-rs-tool-common/src/git.rs +++ b/tools/smithy-rs-tool-common/src/git.rs @@ -7,7 +7,7 @@ use crate::shell::{handle_failure, output_text}; use anyhow::{bail, Context, Result}; use std::borrow::Cow; use std::ffi::OsStr; -use std::fmt; +use std::fmt::{self, Write}; use std::path::{Path, PathBuf}; use std::process::Command; use tracing::debug; @@ -415,7 +415,7 @@ fn split_file_names(value: &str) -> Vec { fn log_command(command: Command) -> Command { let mut message = String::new(); if let Some(cwd) = command.get_current_dir() { - message.push_str(&format!("[in {:?}]: ", cwd)); + write!(&mut message, "[in {:?}]: ", cwd).unwrap(); } message.push_str(command.get_program().to_str().expect("valid str")); for arg in command.get_args() { From 55d16b1131ca8eea2e0855aaa9a5a9764e17c5da Mon Sep 17 00:00:00 2001 From: Harry Barber <106155934+hlbarber@users.noreply.github.com> Date: Mon, 17 Oct 2022 15:00:43 +0100 Subject: [PATCH 38/57] Make protocol ZSTs match shape ID names (#1858) --- .../generators/protocol/ServerProtocol.kt | 8 ++--- design/src/rfcs/rfc0020_service_builder.md | 6 ++-- design/src/server/anatomy.md | 20 +++++------ .../src/error.rs | 11 +++--- .../src/middleware/handler.rs | 10 +++--- .../src/middleware/layer.rs | 6 ++-- .../src/proto/aws_json_10/mod.rs | 2 +- .../src/proto/aws_json_10/router.rs | 4 +-- .../src/proto/aws_json_11/mod.rs | 2 +- .../src/proto/aws_json_11/router.rs | 4 +-- .../src/proto/rest_json_1/mod.rs | 2 +- .../src/proto/rest_json_1/router.rs | 4 +-- .../src/proto/rest_xml/mod.rs | 2 +- .../src/proto/rest_xml/router.rs | 6 ++-- .../aws-smithy-http-server/src/routing/mod.rs | 36 +++++++++---------- .../src/runtime_error.rs | 32 ++++++++--------- 16 files changed, 77 insertions(+), 78 deletions(-) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt index 651a47ac93c..73f3fd1dacb 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocol.kt @@ -99,10 +99,10 @@ class ServerAwsJsonProtocol( override fun markerStruct(): RuntimeType { return when (version) { is AwsJsonVersion.Json10 -> { - ServerRuntimeType.Protocol("AwsJson10", "aws_json_10", runtimeConfig) + ServerRuntimeType.Protocol("AwsJson1_0", "aws_json_10", runtimeConfig) } is AwsJsonVersion.Json11 -> { - ServerRuntimeType.Protocol("AwsJson11", "aws_json_11", runtimeConfig) + ServerRuntimeType.Protocol("AwsJson1_1", "aws_json_11", runtimeConfig) } } } @@ -211,7 +211,7 @@ class ServerRestJsonProtocol( fun fromCoreProtocol(restJson: RestJson): ServerRestJsonProtocol = ServerRestJsonProtocol(restJson.codegenContext) } - override fun markerStruct() = ServerRuntimeType.Protocol("AwsRestJson1", "rest_json_1", runtimeConfig) + override fun markerStruct() = ServerRuntimeType.Protocol("RestJson1", "rest_json_1", runtimeConfig) override fun routerType() = restRouterType(runtimeConfig) @@ -240,7 +240,7 @@ class ServerRestXmlProtocol( } } - override fun markerStruct() = ServerRuntimeType.Protocol("AwsRestXml", "rest_xml", runtimeConfig) + override fun markerStruct() = ServerRuntimeType.Protocol("RestXml", "rest_xml", runtimeConfig) override fun routerType() = restRouterType(runtimeConfig) diff --git a/design/src/rfcs/rfc0020_service_builder.md b/design/src/rfcs/rfc0020_service_builder.md index 05b6e43bc6f..a0fad97e305 100644 --- a/design/src/rfcs/rfc0020_service_builder.md +++ b/design/src/rfcs/rfc0020_service_builder.md @@ -231,7 +231,7 @@ pub struct Route { enum Routes { RestXml(Vec<(Route, RequestSpec)>), RestJson1(Vec<(Route, RequestSpec)>), - AwsJson10(TinyMap), + AwsJson1_0(TinyMap), AwsJson11(TinyMap), } @@ -729,8 +729,8 @@ Currently there is a single `Router` structure, described in [Router](#router), enum Routes { RestXml(/* Container */), RestJson1(/* Container */), - AwsJson10(/* Container */), - AwsJson11(/* Container */), + AwsJson1_0(/* Container */), + AwsJson1_1(/* Container */), } ``` diff --git a/design/src/server/anatomy.md b/design/src/server/anatomy.md index 7c14ecd15e6..4c856a1fdc3 100644 --- a/design/src/server/anatomy.md +++ b/design/src/server/anatomy.md @@ -241,16 +241,16 @@ Note that both traits are parameterized by `Protocol`. These [protocols](https:/ ```rust /// [AWS REST JSON 1.0 Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-restjson1-protocol.html). -pub struct AwsRestJson1; +pub struct RestJson1; /// [AWS REST XML Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-restxml-protocol.html). -pub struct AwsRestXml; +pub struct RestXml; /// [AWS JSON 1.0 Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-json-1_0-protocol.html). -pub struct AwsJson10; +pub struct AwsJson1_0; /// [AWS JSON 1.1 Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-json-1_1-protocol.html). -pub struct AwsJson11; +pub struct AwsJson1_1; ``` ## Upgrading a Model Service @@ -526,15 +526,15 @@ To finalize the build and construct the complete service, `PokemonService`, each /// Constructs a [`PokemonService`] from the arguments provided to the builder. pub fn build(self) -> PokemonService where - Op1: Upgradable, + Op1: Upgradable, Op1::Service: tower::Service, - Op2: Upgradable, + Op2: Upgradable, Op2::Service: tower::Service, /* ... */ - Op6: Upgradable, + Op6: Upgradable, Op6::Service: tower::Service, ``` @@ -599,10 +599,10 @@ The build method then proceeds as follows: /// Constructs a [`PokemonService`] from the arguments provided to the builder. pub fn build(self) -> PokemonService where - Op1: Upgradable, + Op1: Upgradable, Op1::Service: tower::Service, - Op2: Upgradable, + Op2: Upgradable, Op2::Service: tower::Service, /* ... */ @@ -630,7 +630,7 @@ where /// The Pokémon Service allows you to retrieve information about Pokémon species. #[derive(Clone)] pub struct PokemonService { - router: RoutingService, AwsRestJson1>, + router: RoutingService, RestJson1>, } ``` diff --git a/rust-runtime/aws-smithy-http-server-python/src/error.rs b/rust-runtime/aws-smithy-http-server-python/src/error.rs index a6396fa969d..b2cf345bcd4 100644 --- a/rust-runtime/aws-smithy-http-server-python/src/error.rs +++ b/rust-runtime/aws-smithy-http-server-python/src/error.rs @@ -8,8 +8,7 @@ use aws_smithy_http_server::{ body::{to_boxed, BoxBody}, proto::{ - aws_json_10::AwsJson10, aws_json_11::AwsJson11, rest_json_1::AwsRestJson1, - rest_xml::AwsRestXml, + aws_json_10::AwsJson1_0, aws_json_11::AwsJson1_1, rest_json_1::RestJson1, rest_xml::RestXml, }, response::IntoResponse, }; @@ -68,7 +67,7 @@ impl From for PyMiddlewareException { } } -impl IntoResponse for PyMiddlewareException { +impl IntoResponse for PyMiddlewareException { fn into_response(self) -> http::Response { http::Response::builder() .status(self.status_code) @@ -79,7 +78,7 @@ impl IntoResponse for PyMiddlewareException { } } -impl IntoResponse for PyMiddlewareException { +impl IntoResponse for PyMiddlewareException { fn into_response(self) -> http::Response { http::Response::builder() .status(self.status_code) @@ -89,7 +88,7 @@ impl IntoResponse for PyMiddlewareException { } } -impl IntoResponse for PyMiddlewareException { +impl IntoResponse for PyMiddlewareException { fn into_response(self) -> http::Response { http::Response::builder() .status(self.status_code) @@ -100,7 +99,7 @@ impl IntoResponse for PyMiddlewareException { } } -impl IntoResponse for PyMiddlewareException { +impl IntoResponse for PyMiddlewareException { fn into_response(self) -> http::Response { http::Response::builder() .status(self.status_code) diff --git a/rust-runtime/aws-smithy-http-server-python/src/middleware/handler.rs b/rust-runtime/aws-smithy-http-server-python/src/middleware/handler.rs index 20a4104925e..68fdc12accd 100644 --- a/rust-runtime/aws-smithy-http-server-python/src/middleware/handler.rs +++ b/rust-runtime/aws-smithy-http-server-python/src/middleware/handler.rs @@ -170,7 +170,7 @@ impl PyMiddlewares { #[cfg(test)] mod tests { - use aws_smithy_http_server::proto::rest_json_1::AwsRestJson1; + use aws_smithy_http_server::proto::rest_json_1::RestJson1; use http::HeaderValue; use hyper::body::to_bytes; use pretty_assertions::assert_eq; @@ -180,7 +180,7 @@ mod tests { #[tokio::test] async fn request_middleware_chain_keeps_headers_changes() -> PyResult<()> { let locals = crate::tests::initialize(); - let mut middlewares = PyMiddlewares::new::(vec![]); + let mut middlewares = PyMiddlewares::new::(vec![]); Python::with_gil(|py| { let middleware = PyModule::new(py, "middleware").unwrap(); @@ -230,7 +230,7 @@ def second_middleware(request: Request): #[tokio::test] async fn request_middleware_return_response() -> PyResult<()> { let locals = crate::tests::initialize(); - let mut middlewares = PyMiddlewares::new::(vec![]); + let mut middlewares = PyMiddlewares::new::(vec![]); Python::with_gil(|py| { let middleware = PyModule::new(py, "middleware").unwrap(); @@ -265,7 +265,7 @@ def middleware(request: Request): #[tokio::test] async fn request_middleware_raise_middleware_exception() -> PyResult<()> { let locals = crate::tests::initialize(); - let mut middlewares = PyMiddlewares::new::(vec![]); + let mut middlewares = PyMiddlewares::new::(vec![]); Python::with_gil(|py| { let middleware = PyModule::new(py, "middleware").unwrap(); @@ -304,7 +304,7 @@ def middleware(request: Request): #[tokio::test] async fn request_middleware_raise_python_exception() -> PyResult<()> { let locals = crate::tests::initialize(); - let mut middlewares = PyMiddlewares::new::(vec![]); + let mut middlewares = PyMiddlewares::new::(vec![]); Python::with_gil(|py| { let middleware = PyModule::from_code( diff --git a/rust-runtime/aws-smithy-http-server-python/src/middleware/layer.rs b/rust-runtime/aws-smithy-http-server-python/src/middleware/layer.rs index 6c1cb6bce01..04e62fd7329 100644 --- a/rust-runtime/aws-smithy-http-server-python/src/middleware/layer.rs +++ b/rust-runtime/aws-smithy-http-server-python/src/middleware/layer.rs @@ -160,7 +160,7 @@ mod tests { use super::*; use aws_smithy_http_server::body::to_boxed; - use aws_smithy_http_server::proto::rest_json_1::AwsRestJson1; + use aws_smithy_http_server::proto::rest_json_1::RestJson1; use pyo3::prelude::*; use tower::{Service, ServiceBuilder, ServiceExt}; @@ -174,7 +174,7 @@ mod tests { #[tokio::test] async fn request_middlewares_are_chained_inside_layer() -> PyResult<()> { let locals = crate::tests::initialize(); - let mut middlewares = PyMiddlewares::new::(vec![]); + let mut middlewares = PyMiddlewares::new::(vec![]); Python::with_gil(|py| { let middleware = PyModule::new(py, "middleware").unwrap(); @@ -211,7 +211,7 @@ def second_middleware(request: Request): })?; let mut service = ServiceBuilder::new() - .layer(PyMiddlewareLayer::::new(middlewares, locals)) + .layer(PyMiddlewareLayer::::new(middlewares, locals)) .service_fn(echo); let request = Request::get("/").body(Body::empty()).unwrap(); diff --git a/rust-runtime/aws-smithy-http-server/src/proto/aws_json_10/mod.rs b/rust-runtime/aws-smithy-http-server/src/proto/aws_json_10/mod.rs index 183aaf81194..43cb03409e9 100644 --- a/rust-runtime/aws-smithy-http-server/src/proto/aws_json_10/mod.rs +++ b/rust-runtime/aws-smithy-http-server/src/proto/aws_json_10/mod.rs @@ -6,4 +6,4 @@ pub mod router; /// [AWS JSON 1.0 Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-json-1_0-protocol.html). -pub struct AwsJson10; +pub struct AwsJson1_0; diff --git a/rust-runtime/aws-smithy-http-server/src/proto/aws_json_10/router.rs b/rust-runtime/aws-smithy-http-server/src/proto/aws_json_10/router.rs index e6805dc769c..5c582f569cf 100644 --- a/rust-runtime/aws-smithy-http-server/src/proto/aws_json_10/router.rs +++ b/rust-runtime/aws-smithy-http-server/src/proto/aws_json_10/router.rs @@ -9,11 +9,11 @@ use crate::proto::aws_json::router::Error; use crate::response::IntoResponse; use crate::routers::{method_disallowed, UNKNOWN_OPERATION_EXCEPTION}; -use super::AwsJson10; +use super::AwsJson1_0; pub use crate::proto::aws_json::router::*; -impl IntoResponse for Error { +impl IntoResponse for Error { fn into_response(self) -> http::Response { match self { Error::MethodNotAllowed => method_disallowed(), diff --git a/rust-runtime/aws-smithy-http-server/src/proto/aws_json_11/mod.rs b/rust-runtime/aws-smithy-http-server/src/proto/aws_json_11/mod.rs index 3bc1f75c61c..2e1a0acce58 100644 --- a/rust-runtime/aws-smithy-http-server/src/proto/aws_json_11/mod.rs +++ b/rust-runtime/aws-smithy-http-server/src/proto/aws_json_11/mod.rs @@ -6,4 +6,4 @@ pub mod router; /// [AWS JSON 1.1 Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-json-1_1-protocol.html). -pub struct AwsJson11; +pub struct AwsJson1_1; diff --git a/rust-runtime/aws-smithy-http-server/src/proto/aws_json_11/router.rs b/rust-runtime/aws-smithy-http-server/src/proto/aws_json_11/router.rs index dcd1cace6a4..8d0f8c0a06d 100644 --- a/rust-runtime/aws-smithy-http-server/src/proto/aws_json_11/router.rs +++ b/rust-runtime/aws-smithy-http-server/src/proto/aws_json_11/router.rs @@ -9,11 +9,11 @@ use crate::proto::aws_json::router::Error; use crate::response::IntoResponse; use crate::routers::{method_disallowed, UNKNOWN_OPERATION_EXCEPTION}; -use super::AwsJson11; +use super::AwsJson1_1; pub use crate::proto::aws_json::router::*; -impl IntoResponse for Error { +impl IntoResponse for Error { fn into_response(self) -> http::Response { match self { Error::MethodNotAllowed => method_disallowed(), diff --git a/rust-runtime/aws-smithy-http-server/src/proto/rest_json_1/mod.rs b/rust-runtime/aws-smithy-http-server/src/proto/rest_json_1/mod.rs index f0bd51ec3f6..db7c64a84b3 100644 --- a/rust-runtime/aws-smithy-http-server/src/proto/rest_json_1/mod.rs +++ b/rust-runtime/aws-smithy-http-server/src/proto/rest_json_1/mod.rs @@ -6,4 +6,4 @@ pub mod router; /// [AWS REST JSON 1.0 Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-restjson1-protocol.html). -pub struct AwsRestJson1; +pub struct RestJson1; diff --git a/rust-runtime/aws-smithy-http-server/src/proto/rest_json_1/router.rs b/rust-runtime/aws-smithy-http-server/src/proto/rest_json_1/router.rs index 8f37efbfe58..c737b665c49 100644 --- a/rust-runtime/aws-smithy-http-server/src/proto/rest_json_1/router.rs +++ b/rust-runtime/aws-smithy-http-server/src/proto/rest_json_1/router.rs @@ -9,11 +9,11 @@ use crate::proto::rest::router::Error; use crate::response::IntoResponse; use crate::routers::{method_disallowed, UNKNOWN_OPERATION_EXCEPTION}; -use super::AwsRestJson1; +use super::RestJson1; pub use crate::proto::rest::router::*; -impl IntoResponse for Error { +impl IntoResponse for Error { fn into_response(self) -> http::Response { match self { Error::NotFound => http::Response::builder() diff --git a/rust-runtime/aws-smithy-http-server/src/proto/rest_xml/mod.rs b/rust-runtime/aws-smithy-http-server/src/proto/rest_xml/mod.rs index 42eadb468f6..ba6ed3d0192 100644 --- a/rust-runtime/aws-smithy-http-server/src/proto/rest_xml/mod.rs +++ b/rust-runtime/aws-smithy-http-server/src/proto/rest_xml/mod.rs @@ -6,4 +6,4 @@ pub mod router; /// [AWS REST XML Protocol](https://awslabs.github.io/smithy/2.0/aws/protocols/aws-restxml-protocol.html). -pub struct AwsRestXml; +pub struct RestXml; diff --git a/rust-runtime/aws-smithy-http-server/src/proto/rest_xml/router.rs b/rust-runtime/aws-smithy-http-server/src/proto/rest_xml/router.rs index 6ef812a25ef..1b1b21742fc 100644 --- a/rust-runtime/aws-smithy-http-server/src/proto/rest_xml/router.rs +++ b/rust-runtime/aws-smithy-http-server/src/proto/rest_xml/router.rs @@ -11,12 +11,12 @@ use crate::response::IntoResponse; use crate::routers::method_disallowed; use crate::routers::UNKNOWN_OPERATION_EXCEPTION; -use super::AwsRestXml; +use super::RestXml; pub use crate::proto::rest::router::*; /// An AWS REST routing error. -impl IntoResponse for Error { +impl IntoResponse for Error { fn into_response(self) -> http::Response { match self { Error::NotFound => http::Response::builder() @@ -26,7 +26,7 @@ impl IntoResponse for Error { UNKNOWN_OPERATION_EXCEPTION.to_string(), )) .body(empty()) - .expect("invalid HTTP response for REST JSON routing error; please file a bug report under https://github.com/awslabs/smithy-rs/issues"), + .expect("invalid HTTP response for REST XML routing error; please file a bug report under https://github.com/awslabs/smithy-rs/issues"), Error::MethodNotAllowed => method_disallowed(), } } diff --git a/rust-runtime/aws-smithy-http-server/src/routing/mod.rs b/rust-runtime/aws-smithy-http-server/src/routing/mod.rs index ec6b4394a6e..1cd3dd21e75 100644 --- a/rust-runtime/aws-smithy-http-server/src/routing/mod.rs +++ b/rust-runtime/aws-smithy-http-server/src/routing/mod.rs @@ -16,8 +16,8 @@ use self::request_spec::RequestSpec; use crate::{ body::{boxed, Body, BoxBody, HttpBody}, proto::{ - aws_json::router::AwsJsonRouter, aws_json_10::AwsJson10, aws_json_11::AwsJson11, rest::router::RestRouter, - rest_json_1::AwsRestJson1, rest_xml::AwsRestXml, + aws_json::router::AwsJsonRouter, aws_json_10::AwsJson1_0, aws_json_11::AwsJson1_1, rest::router::RestRouter, + rest_json_1::RestJson1, rest_xml::RestXml, }, }; use crate::{error::BoxError, routers::RoutingService}; @@ -75,10 +75,10 @@ pub struct Router { /// directly found in the `X-Amz-Target` HTTP header. #[derive(Debug)] enum Routes { - RestXml(RoutingService>, AwsRestXml>), - RestJson1(RoutingService>, AwsRestJson1>), - AwsJson10(RoutingService>, AwsJson10>), - AwsJson11(RoutingService>, AwsJson11>), + RestXml(RoutingService>, RestXml>), + RestJson1(RoutingService>, RestJson1>), + AwsJson1_0(RoutingService>, AwsJson1_0>), + AwsJson1_1(RoutingService>, AwsJson1_1>), } impl Clone for Router { @@ -90,11 +90,11 @@ impl Clone for Router { Routes::RestXml(routes) => Router { routes: Routes::RestXml(routes.clone()), }, - Routes::AwsJson10(routes) => Router { - routes: Routes::AwsJson10(routes.clone()), + Routes::AwsJson1_0(routes) => Router { + routes: Routes::AwsJson1_0(routes.clone()), }, - Routes::AwsJson11(routes) => Router { - routes: Routes::AwsJson11(routes.clone()), + Routes::AwsJson1_1(routes) => Router { + routes: Routes::AwsJson1_1(routes.clone()), }, } } @@ -141,11 +141,11 @@ where Routes::RestXml(routes) => Router { routes: Routes::RestXml(routes.map(|router| router.layer(layer).boxed())), }, - Routes::AwsJson10(routes) => Router { - routes: Routes::AwsJson10(routes.map(|router| router.layer(layer).boxed())), + Routes::AwsJson1_0(routes) => Router { + routes: Routes::AwsJson1_0(routes.map(|router| router.layer(layer).boxed())), }, - Routes::AwsJson11(routes) => Router { - routes: Routes::AwsJson11(routes.map(|router| router.layer(layer).boxed())), + Routes::AwsJson1_1(routes) => Router { + routes: Routes::AwsJson1_1(routes.map(|router| router.layer(layer).boxed())), }, } } @@ -219,7 +219,7 @@ where ); Self { - routes: Routes::AwsJson10(svc), + routes: Routes::AwsJson1_0(svc), } } @@ -244,7 +244,7 @@ where ); Self { - routes: Routes::AwsJson11(svc), + routes: Routes::AwsJson1_1(svc), } } } @@ -269,8 +269,8 @@ where Routes::RestJson1(routes) => routes.call(req), Routes::RestXml(routes) => routes.call(req), // AwsJson routes. - Routes::AwsJson10(routes) => routes.call(req), - Routes::AwsJson11(routes) => routes.call(req), + Routes::AwsJson1_0(routes) => routes.call(req), + Routes::AwsJson1_1(routes) => routes.call(req), }; RouterFuture::new(fut) } diff --git a/rust-runtime/aws-smithy-http-server/src/runtime_error.rs b/rust-runtime/aws-smithy-http-server/src/runtime_error.rs index e8174f0f08c..e389240f8e7 100644 --- a/rust-runtime/aws-smithy-http-server/src/runtime_error.rs +++ b/rust-runtime/aws-smithy-http-server/src/runtime_error.rs @@ -24,10 +24,10 @@ use http::StatusCode; use crate::extension::RuntimeErrorExtension; -use crate::proto::aws_json_10::AwsJson10; -use crate::proto::aws_json_11::AwsJson11; -use crate::proto::rest_json_1::AwsRestJson1; -use crate::proto::rest_xml::AwsRestXml; +use crate::proto::aws_json_10::AwsJson1_0; +use crate::proto::aws_json_11::AwsJson1_1; +use crate::proto::rest_json_1::RestJson1; +use crate::proto::rest_xml::RestXml; use crate::response::IntoResponse; #[derive(Debug)] @@ -67,31 +67,31 @@ impl RuntimeError { pub struct InternalFailureException; -impl IntoResponse for InternalFailureException { +impl IntoResponse for InternalFailureException { fn into_response(self) -> http::Response { - IntoResponse::::into_response(RuntimeError::InternalFailure(crate::Error::new(String::new()))) + IntoResponse::::into_response(RuntimeError::InternalFailure(crate::Error::new(String::new()))) } } -impl IntoResponse for InternalFailureException { +impl IntoResponse for InternalFailureException { fn into_response(self) -> http::Response { - IntoResponse::::into_response(RuntimeError::InternalFailure(crate::Error::new(String::new()))) + IntoResponse::::into_response(RuntimeError::InternalFailure(crate::Error::new(String::new()))) } } -impl IntoResponse for InternalFailureException { +impl IntoResponse for InternalFailureException { fn into_response(self) -> http::Response { - IntoResponse::::into_response(RuntimeError::InternalFailure(crate::Error::new(String::new()))) + IntoResponse::::into_response(RuntimeError::InternalFailure(crate::Error::new(String::new()))) } } -impl IntoResponse for InternalFailureException { +impl IntoResponse for InternalFailureException { fn into_response(self) -> http::Response { - IntoResponse::::into_response(RuntimeError::InternalFailure(crate::Error::new(String::new()))) + IntoResponse::::into_response(RuntimeError::InternalFailure(crate::Error::new(String::new()))) } } -impl IntoResponse for RuntimeError { +impl IntoResponse for RuntimeError { fn into_response(self) -> http::Response { http::Response::builder() .status(self.status_code()) @@ -104,7 +104,7 @@ impl IntoResponse for RuntimeError { } } -impl IntoResponse for RuntimeError { +impl IntoResponse for RuntimeError { fn into_response(self) -> http::Response { http::Response::builder() .status(self.status_code()) @@ -115,7 +115,7 @@ impl IntoResponse for RuntimeError { } } -impl IntoResponse for RuntimeError { +impl IntoResponse for RuntimeError { fn into_response(self) -> http::Response { http::Response::builder() .status(self.status_code()) @@ -127,7 +127,7 @@ impl IntoResponse for RuntimeError { } } -impl IntoResponse for RuntimeError { +impl IntoResponse for RuntimeError { fn into_response(self) -> http::Response { http::Response::builder() .status(self.status_code()) From c5dae879a54dde913cc2b6c5b0f9e57a310f07b7 Mon Sep 17 00:00:00 2001 From: Burak Date: Mon, 17 Oct 2022 15:52:37 +0100 Subject: [PATCH 39/57] Python: Migrate to new service builder (#1846) * Python: Migrate to new service builder * Fix orderings of imports --- .../generators/PythonApplicationGenerator.kt | 38 +++++++++------ .../src/server.rs | 48 ++++++++++++------- 2 files changed, 53 insertions(+), 33 deletions(-) diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt index 9fd367617a8..2dd7c76aeed 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonApplicationGenerator.kt @@ -17,9 +17,11 @@ import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.Errors import software.amazon.smithy.rust.codegen.core.smithy.Inputs import software.amazon.smithy.rust.codegen.core.smithy.Outputs +import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.inputShape import software.amazon.smithy.rust.codegen.core.util.outputShape +import software.amazon.smithy.rust.codegen.core.util.toPascalCase import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.python.smithy.PythonServerCargoDependency import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency @@ -69,6 +71,8 @@ class PythonApplicationGenerator( private val symbolProvider = codegenContext.symbolProvider private val libName = "lib${codegenContext.settings.moduleName.toSnakeCase()}" private val runtimeConfig = codegenContext.runtimeConfig + private val service = codegenContext.serviceShape + private val serviceName = service.id.name.toPascalCase() private val model = codegenContext.model private val codegenScope = arrayOf( @@ -84,6 +88,7 @@ class PythonApplicationGenerator( "hyper" to PythonServerCargoDependency.Hyper.asType(), "HashMap" to RustType.HashMap.RuntimeType, "parking_lot" to PythonServerCargoDependency.ParkingLot.asType(), + "http" to RuntimeType.http, ) fun render(writer: RustWriter) { @@ -175,14 +180,19 @@ class PythonApplicationGenerator( rustBlockTemplate( """ - // Dynamically codegenerate the routes, allowing to build the Smithy [#{SmithyServer}::routing::Router]. - fn build_router(&mut self, event_loop: &#{pyo3}::PyAny) -> #{pyo3}::PyResult<#{SmithyServer}::routing::Router> + fn build_service(&mut self, event_loop: &#{pyo3}::PyAny) -> #{pyo3}::PyResult< + #{tower}::util::BoxCloneService< + #{http}::Request<#{SmithyServer}::body::Body>, + #{http}::Response<#{SmithyServer}::body::BoxBody>, + std::convert::Infallible + > + > """, *codegenScope, ) { rustTemplate( """ - let router = crate::operation_registry::OperationRegistryBuilder::default(); + let builder = crate::service::$serviceName::builder(); """, *codegenScope, ) @@ -193,8 +203,8 @@ class PythonApplicationGenerator( """ let ${name}_locals = #{pyo3_asyncio}::TaskLocals::new(event_loop); let handler = self.handlers.get("$name").expect("Python handler for operation `$name` not found").clone(); - let router = router.$name(move |input, state| { - #{pyo3_asyncio}::tokio::scope(${name}_locals, crate::operation_handler::$name(input, state, handler)) + let builder = builder.$name(move |input, state| { + #{pyo3_asyncio}::tokio::scope(${name}_locals.clone(), crate::operation_handler::$name(input, state, handler.clone())) }); """, *codegenScope, @@ -202,16 +212,14 @@ class PythonApplicationGenerator( } rustTemplate( """ - let middleware_locals = pyo3_asyncio::TaskLocals::new(event_loop); + let middleware_locals = #{pyo3_asyncio}::TaskLocals::new(event_loop); let service = #{tower}::ServiceBuilder::new() + .boxed_clone() .layer( #{SmithyPython}::PyMiddlewareLayer::<#{Protocol}>::new(self.middlewares.clone(), middleware_locals), - ); - let router: #{SmithyServer}::routing::Router = router - .build() - .expect("Unable to build operation registry") - .into(); - Ok(router.layer(service)) + ) + .service(builder.build()); + Ok(service) """, "Protocol" to protocol.markerStruct(), *codegenScope, @@ -268,7 +276,7 @@ class PythonApplicationGenerator( use #{SmithyPython}::PyApp; self.run_lambda_handler(py) } - /// Build the router and start a single worker. + /// Build the service and start a single worker. ##[pyo3(text_signature = "(${'$'}self, socket, worker_number)")] pub fn start_worker( &mut self, @@ -278,8 +286,8 @@ class PythonApplicationGenerator( ) -> pyo3::PyResult<()> { use #{SmithyPython}::PyApp; let event_loop = self.configure_python_event_loop(py)?; - let router = self.build_and_configure_router(py, event_loop)?; - self.start_hyper_worker(py, socket, event_loop, router, worker_number) + let service = self.build_and_configure_service(py, event_loop)?; + self.start_hyper_worker(py, socket, event_loop, service, worker_number) } """, *codegenScope, diff --git a/rust-runtime/aws-smithy-http-server-python/src/server.rs b/rust-runtime/aws-smithy-http-server-python/src/server.rs index d9d68ff2c37..e2749ce51f9 100644 --- a/rust-runtime/aws-smithy-http-server-python/src/server.rs +++ b/rust-runtime/aws-smithy-http-server-python/src/server.rs @@ -4,17 +4,19 @@ */ // Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT. -use std::{collections::HashMap, ops::Deref, process, thread}; +use std::{collections::HashMap, convert::Infallible, ops::Deref, process, thread}; use aws_smithy_http_server::{ - routing::{LambdaHandler, Router}, + body::{Body, BoxBody}, + routing::{IntoMakeService, LambdaHandler}, AddExtensionLayer, }; +use http::{Request, Response}; use parking_lot::Mutex; use pyo3::{prelude::*, types::IntoPyDict}; use signal_hook::{consts::*, iterator::Signals}; use tokio::runtime; -use tower::ServiceBuilder; +use tower::{util::BoxCloneService, ServiceBuilder}; use crate::{middleware::PyMiddlewareHandler, PyMiddlewareType, PyMiddlewares, PySocket}; @@ -39,6 +41,9 @@ impl Deref for PyHandler { } } +// A `BoxCloneService` with default `Request`, `Response` and `Error`. +type Service = BoxCloneService, Response, Infallible>; + /// Trait defining a Python application. /// /// A Python application requires handling of multiple processes, signals and allows to register Python @@ -66,8 +71,8 @@ pub trait PyApp: Clone + pyo3::IntoPy { fn middlewares(&mut self) -> &mut PyMiddlewares; - /// Build the app's `Router` using given `event_loop`. - fn build_router(&mut self, event_loop: &pyo3::PyAny) -> pyo3::PyResult; + /// Build the app's `Service` using given `event_loop`. + fn build_service(&mut self, event_loop: &pyo3::PyAny) -> pyo3::PyResult; /// Handle the graceful termination of Python workers by looping through all the /// active workers and calling `terminate()` on them. If termination fails, this @@ -215,7 +220,7 @@ event_loop.add_signal_handler(signal.SIGINT, py: Python, socket: &PyCell, event_loop: &PyAny, - router: Router, + service: Service, worker_number: isize, ) -> PyResult<()> { // Clone the socket. @@ -241,7 +246,7 @@ event_loop.add_signal_handler(signal.SIGINT, .expect("Unable to convert socket2::Socket into std::net::TcpListener"), ) .expect("Unable to create hyper server from shared socket") - .serve(router.into_make_service()); + .serve(IntoMakeService::new(service)); tracing::debug!("Started hyper server from shared socket"); // Run forever-ish... @@ -363,10 +368,14 @@ event_loop.add_signal_handler(signal.SIGINT, /// `PythonApplicationGenerator.kt` generates the `start_worker` method: /// /// ```no_run + /// use std::convert::Infallible; /// use std::collections::HashMap; /// use pyo3::prelude::*; /// use aws_smithy_http_server_python::{PyApp, PyHandler, PyMiddlewares}; + /// use aws_smithy_http_server::body::{Body, BoxBody}; /// use parking_lot::Mutex; + /// use http::{Request, Response}; + /// use tower::util::BoxCloneService; /// /// #[pyclass] /// #[derive(Debug, Clone)] @@ -377,7 +386,7 @@ event_loop.add_signal_handler(signal.SIGINT, /// fn context(&self) -> &Option { todo!() } /// fn handlers(&mut self) -> &mut HashMap { todo!() } /// fn middlewares(&mut self) -> &mut PyMiddlewares { todo!() } - /// fn build_router(&mut self, event_loop: &PyAny) -> PyResult { todo!() } + /// fn build_service(&mut self, event_loop: &PyAny) -> PyResult, Response, Infallible>> { todo!() } /// } /// /// #[pymethods] @@ -390,8 +399,8 @@ event_loop.add_signal_handler(signal.SIGINT, /// worker_number: isize, /// ) -> pyo3::PyResult<()> { /// let event_loop = self.configure_python_event_loop(py)?; - /// let router = self.build_router(event_loop)?; - /// self.start_hyper_worker(py, socket, event_loop, router, worker_number) + /// let service = self.build_service(event_loop)?; + /// self.start_hyper_worker(py, socket, event_loop, service, worker_number) /// } /// } /// ``` @@ -459,13 +468,13 @@ event_loop.add_signal_handler(signal.SIGINT, /// it starts the Lambda handler on the current process. fn run_lambda_handler(&mut self, py: Python) -> PyResult<()> { let event_loop = self.configure_python_event_loop(py)?; - let app = self.build_and_configure_router(py, event_loop)?; + let service = self.build_and_configure_service(py, event_loop)?; let rt = runtime::Builder::new_multi_thread() .enable_all() .build() .expect("unable to start a new tokio runtime for this process"); rt.block_on(async move { - let handler = LambdaHandler::new(app); + let handler = LambdaHandler::new(service); let lambda = lambda_http::run(handler); tracing::debug!("starting lambda handler"); if let Err(err) = lambda.await { @@ -475,17 +484,20 @@ event_loop.add_signal_handler(signal.SIGINT, Ok(()) } - // Builds the router and adds necessary layers to it. - fn build_and_configure_router( + // Builds the `Service` and adds necessary layers to it. + fn build_and_configure_service( &mut self, py: Python, event_loop: &pyo3::PyAny, - ) -> pyo3::PyResult { - let app = self.build_router(event_loop)?; + ) -> pyo3::PyResult { + let service = self.build_service(event_loop)?; // Create the `PyState` object from the Python context object. let context = self.context().clone().unwrap_or_else(|| py.None()); tracing::debug!("add middlewares to rust python router"); - let app = app.layer(ServiceBuilder::new().layer(AddExtensionLayer::new(context))); - Ok(app) + let service = ServiceBuilder::new() + .boxed_clone() + .layer(AddExtensionLayer::new(context)) + .service(service); + Ok(service) } } From 9260781f455d4470274f7f8902ca0853a8cd1862 Mon Sep 17 00:00:00 2001 From: David Oguns <38018552+DavidOgunsAWS@users.noreply.github.com> Date: Mon, 17 Oct 2022 14:03:42 -0700 Subject: [PATCH 40/57] Add mavenLocal repo to allow for local dependency override (#1852) --- CHANGELOG.next.toml | 8 +++++++- settings.gradle.kts | 8 ++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index c3272671a74..6932247c3fc 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -173,4 +173,10 @@ author = "hlbarber" message = "Update aws-types zeroize to flexible version to prevent downstream version conflicts." references = ["smithy-rs#1817"] meta = { "breaking" = false, "tada" = false, "bug" = true } -author = "ethyi" \ No newline at end of file +author = "ethyi" + +[[smithy-rs]] +message = "Enable local maven repo dependency override." +references = ["smithy-rs#1852"] +meta = { "breaking" = false, "tada" = false, "bug" = false } +author = "ogudavid" diff --git a/settings.gradle.kts b/settings.gradle.kts index d957606194d..4b5bf3d75eb 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -17,3 +17,11 @@ include(":aws:sdk-codegen") include(":aws:sdk-adhoc-test") include(":aws:sdk") include(":aws:rust-runtime") + +buildscript { + repositories { + mavenLocal() + mavenCentral() + google() + } +} From aacaf160b47b3df1c3f5e25e4db034b35d16a696 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Tue, 18 Oct 2022 07:11:23 -0700 Subject: [PATCH 41/57] Mark `release-2022-10-13` as yanked to fix SDK canary (#1865) --- tools/ci-cdk/canary-runner/src/generate_matrix.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/ci-cdk/canary-runner/src/generate_matrix.rs b/tools/ci-cdk/canary-runner/src/generate_matrix.rs index 0b1dc589eea..85549c08732 100644 --- a/tools/ci-cdk/canary-runner/src/generate_matrix.rs +++ b/tools/ci-cdk/canary-runner/src/generate_matrix.rs @@ -16,6 +16,7 @@ const KNOWN_YANKED_RELEASE_TAGS: &[&str] = &[ // There wasn't a release on this date, so this is fine for testing "release-2022-07-04", // Add release tags here to get the canary passing after yanking a release + "release-2022-10-13", ]; #[derive(Debug, Parser, Eq, PartialEq)] From e4e7ef24504076be30366aa1da7ac56aa4b20504 Mon Sep 17 00:00:00 2001 From: ysaito1001 Date: Tue, 18 Oct 2022 11:14:01 -0500 Subject: [PATCH 42/57] Add myself to the maintainers list (#1870) Co-authored-by: Saito --- tools/changelogger/smithy-rs-maintainers.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/changelogger/smithy-rs-maintainers.txt b/tools/changelogger/smithy-rs-maintainers.txt index 2aa2e7b5a9b..6d302b31991 100644 --- a/tools/changelogger/smithy-rs-maintainers.txt +++ b/tools/changelogger/smithy-rs-maintainers.txt @@ -11,3 +11,4 @@ rcoh unexge velfi weihanglo +ysaito1001 From b092e6029a754605bb8835a4e5d6b130a02bd250 Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Tue, 18 Oct 2022 12:18:07 -0500 Subject: [PATCH 43/57] =?UTF-8?q?refactor:=20unify=20module=20writers=20(a?= =?UTF-8?q?pologies=20for=20the=20churn=20=F0=9F=98=85)=20(#1783)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: unify module writers refactor: use RustModule instead of strings for module names suppress: unchecked cast warning for Writable * remove: unnecessary writer references in EnumGenerator format: remove wildcard import add: intellij wildcard import rules to .editorconfig * respond to John's comment --- .editorconfig | 4 + .../smithy/rustsdk/AwsEndpointDecorator.kt | 2 +- .../rustsdk/AwsFluentClientDecorator.kt | 8 +- .../smithy/rustsdk/AwsReadmeDecorator.kt | 4 +- .../smithy/rustsdk/CrateLicenseDecorator.kt | 2 +- .../smithy/rustsdk/SdkConfigDecorator.kt | 2 +- .../rustsdk/customize/s3/S3Decorator.kt | 2 +- .../EndpointConfigCustomizationTest.kt | 4 +- .../rustsdk/SigV4SigningCustomizationTest.kt | 2 +- .../codegen/client/smithy/CodegenVisitor.kt | 14 +- .../ResiliencyConfigCustomization.kt | 4 +- .../EndpointTraitBindingGenerator.kt | 2 +- .../generators/NestedAccessorGenerator.kt | 4 +- .../smithy/generators/PaginatorGenerator.kt | 2 +- .../smithy/generators/ServiceGenerator.kt | 18 +- .../client/CustomizableOperationGenerator.kt | 14 +- .../client/FluentClientGenerator.kt | 10 +- .../config/ServiceConfigGenerator.kt | 8 +- .../protocol/ProtocolTestGenerator.kt | 10 +- .../protocols/HttpBoundProtocolGenerator.kt | 14 +- .../testutil/TestConfigCustomization.kt | 6 +- .../generators/EndpointTraitBindingsTest.kt | 18 +- .../config/ServiceConfigGeneratorTest.kt | 4 +- .../client/testutil/AddRustTestsDecorator.kt | 4 +- .../codegen/core/rustlang/CargoDependency.kt | 6 +- .../rust/codegen/core/rustlang/RustModule.kt | 2 +- .../rust/codegen/core/rustlang/RustType.kt | 12 +- .../rust/codegen/core/rustlang/RustWriter.kt | 18 +- .../rust/codegen/core/rustlang/Writable.kt | 9 +- .../codegen/core/smithy/CodegenDelegator.kt | 17 +- .../rust/codegen/core/smithy/RuntimeType.kt | 3 +- .../smithy/generators/BuilderGenerator.kt | 3 +- .../core/smithy/generators/EnumGenerator.kt | 44 +-- .../smithy/generators/StructureGenerator.kt | 5 +- .../error/CombinedErrorGenerator.kt | 23 +- .../error/TopLevelErrorGenerator.kt | 19 +- .../generators/http/HttpBindingGenerator.kt | 20 +- .../codegen/core/smithy/protocols/AwsJson.kt | 10 +- .../codegen/core/smithy/protocols/AwsQuery.kt | 8 +- .../codegen/core/smithy/protocols/Ec2Query.kt | 8 +- .../HttpBoundProtocolPayloadGenerator.kt | 2 +- .../codegen/core/smithy/protocols/RestJson.kt | 8 +- .../codegen/core/smithy/protocols/RestXml.kt | 8 +- .../parse/EventStreamUnmarshallerGenerator.kt | 4 +- .../protocols/parse/JsonParserGenerator.kt | 26 +- .../parse/XmlBindingTraitParserGenerator.kt | 33 +-- .../EventStreamErrorMarshallerGenerator.kt | 4 +- .../EventStreamMarshallerGenerator.kt | 7 +- .../serialize/JsonSerializerGenerator.kt | 22 +- .../serialize/QuerySerializerGenerator.kt | 24 +- .../protocols/serialize/SerializerUtil.kt | 3 +- .../XmlBindingTraitSerializerGenerator.kt | 39 +-- .../smithy/rust/codegen/core/testutil/Rust.kt | 3 +- .../core/rustlang/InlineDependencyTest.kt | 14 +- .../codegen/core/rustlang/RustGenericsTest.kt | 12 +- .../codegen/core/rustlang/RustWriterTest.kt | 2 +- .../generators/CargoTomlGeneratorTest.kt | 6 +- .../smithy/generators/InstantiatorTest.kt | 5 +- .../generators/StructureGeneratorTest.kt | 58 ++-- .../smithy/generators/UnionGeneratorTest.kt | 3 +- .../error/CombinedErrorGeneratorTest.kt | 8 +- .../error/TopLevelErrorGeneratorTest.kt | 10 +- .../http/RequestBindingGeneratorTest.kt | 29 +- .../http/ResponseBindingGeneratorTest.kt | 4 +- .../parse/AwsQueryParserGeneratorTest.kt | 10 +- .../parse/Ec2QueryParserGeneratorTest.kt | 10 +- .../parse/JsonParserGeneratorTest.kt | 36 +-- .../XmlBindingTraitParserGeneratorTest.kt | 26 +- .../AwsQuerySerializerGeneratorTest.kt | 14 +- .../Ec2QuerySerializerGeneratorTest.kt | 14 +- .../serialize/JsonSerializerGeneratorTest.kt | 18 +- .../XmlBindingTraitSerializerGeneratorTest.kt | 18 +- .../smithy/PythonServerCodegenVisitor.kt | 12 +- .../generators/PythonServerModuleGenerator.kt | 4 +- .../PythonServerServiceGenerator.kt | 4 +- .../server/smithy/ServerCodegenVisitor.kt | 14 +- .../generators/ServerServiceGenerator.kt | 25 +- .../protocol/ServerProtocolTestGenerator.kt | 251 +++++++++++++----- .../ServerHttpBoundProtocolGenerator.kt | 26 +- .../ServerCombinedErrorGeneratorTest.kt | 10 +- .../ServerHttpSensitivityGeneratorTest.kt | 36 +-- .../smithy/protocols/EventStreamTestTools.kt | 14 +- .../EventStreamUnmarshallerGeneratorTest.kt | 48 ++-- .../EventStreamMarshallerGeneratorTest.kt | 32 +-- 84 files changed, 727 insertions(+), 598 deletions(-) diff --git a/.editorconfig b/.editorconfig index 270f4735460..db30a6257e8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,6 +1,10 @@ [*.{kt,kts}] ij_kotlin_allow_trailing_comma = true ij_kotlin_allow_trailing_comma_on_call_site = true +ij_java_use_single_class_imports = true +ij_groovy_use_single_class_imports = true +ij_kotlin_name_count_to_use_star_import = 100 +ij_kotlin_name_count_to_use_star_import_for_members = 100 indent_size = 4 indent_style = space insert_final_newline = true diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt index 4c69d140dbe..822dca09a1c 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsEndpointDecorator.kt @@ -257,7 +257,7 @@ class EndpointResolverGenerator(codegenContext: CodegenContext, private val endp val rest = partitions.drop(1) val fnName = "endpoint_resolver" return RuntimeType.forInlineFun(fnName, RustModule.private("aws_endpoint")) { - it.rustBlockTemplate("pub fn $fnName() -> impl #{ResolveAwsEndpoint}", *codegenScope) { + rustBlockTemplate("pub fn $fnName() -> impl #{ResolveAwsEndpoint}", *codegenScope) { withBlockTemplate("#{PartitionResolver}::new(", ")", *codegenScope) { renderPartition(base) rust(",") diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt index 52443b23a73..bbdb9d80a56 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsFluentClientDecorator.kt @@ -108,11 +108,11 @@ class AwsFluentClientDecorator : RustCodegenDecorator - renderCustomizableOperationSendMethod(runtimeConfig, generics, writer) + rustCrate.withNonRootModule(CustomizableOperationGenerator.CUSTOMIZE_MODULE) { + renderCustomizableOperationSendMethod(runtimeConfig, generics, this) } - rustCrate.withModule(FluentClientGenerator.clientModule) { writer -> - AwsFluentClientExtensions(types).render(writer) + rustCrate.withModule(FluentClientGenerator.clientModule) { + AwsFluentClientExtensions(types).render(this) } val awsSmithyClient = "aws-smithy-client" rustCrate.mergeFeature(Feature("rustls", default = true, listOf("$awsSmithyClient/rustls"))) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsReadmeDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsReadmeDecorator.kt index 05175db3d66..666fc342e1e 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsReadmeDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/AwsReadmeDecorator.kt @@ -57,7 +57,7 @@ internal class AwsSdkReadmeGenerator { internal fun generateReadme(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { val awsConfigVersion = SdkSettings.from(codegenContext.settings).awsConfigVersion ?: throw IllegalStateException("missing `awsConfigVersion` codegen setting") - rustCrate.withFile("README.md") { writer -> + rustCrate.withFile("README.md") { val description = normalizeDescription( codegenContext.moduleName, codegenContext.settings.getService(codegenContext.model).getTrait()?.value ?: "", @@ -66,7 +66,7 @@ internal class AwsSdkReadmeGenerator { val snakeCaseModuleName = moduleName.replace('-', '_') val shortModuleName = moduleName.removePrefix("aws-sdk-") - writer.raw( + raw( """ # $moduleName diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CrateLicenseDecorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CrateLicenseDecorator.kt index 2f5baf4c0d4..b1847809ed5 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CrateLicenseDecorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/CrateLicenseDecorator.kt @@ -20,7 +20,7 @@ class CrateLicenseDecorator : RustCodegenDecorator for Builder { fn from(input: &#{SdkConfig}) -> Self { diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt index 86fa17c6004..230cf8491ae 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/customize/s3/S3Decorator.kt @@ -103,7 +103,7 @@ class S3(codegenContext: CodegenContext) : RestXml(codegenContext) { override fun parseHttpGenericError(operationShape: OperationShape): RuntimeType { return RuntimeType.forInlineFun("parse_http_generic_error", RustModule.private("xml_deser")) { - it.rustBlockTemplate( + rustBlockTemplate( "pub fn parse_http_generic_error(response: &#{Response}<#{Bytes}>) -> Result<#{Error}, #{XmlError}>", *errorScope, ) { diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt index d91f98267b0..99185116f32 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/EndpointConfigCustomizationTest.kt @@ -175,7 +175,7 @@ internal class EndpointConfigCustomizationTest { fun `support region-specific endpoint overrides`() { validateEndpointCustomizationForService("test#TestService") { crate -> crate.lib { - it.unitTest("region_override") { + unitTest("region_override") { rustTemplate( """ let conf = crate::config::Config::builder().build(); @@ -194,7 +194,7 @@ internal class EndpointConfigCustomizationTest { fun `support region-agnostic services`() { validateEndpointCustomizationForService("test#NoRegions") { crate -> crate.lib { - it.unitTest("global_services") { + unitTest("global_services") { rustTemplate( """ let conf = crate::config::Config::builder().build(); diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/SigV4SigningCustomizationTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/SigV4SigningCustomizationTest.kt index bf934a0a3e8..9de7c91f654 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/SigV4SigningCustomizationTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/SigV4SigningCustomizationTest.kt @@ -24,7 +24,7 @@ internal class SigV4SigningCustomizationTest { TestWorkspace.testProject(), ) project.lib { - it.unitTest( + unitTest( "signing_service_override", """ let conf = crate::config::Config::builder().build(); diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt index 4a7e6cae11b..80026b8659f 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/CodegenVisitor.kt @@ -190,12 +190,12 @@ class CodegenVisitor( */ override fun structureShape(shape: StructureShape) { logger.fine("generating a structure...") - rustCrate.useShapeWriter(shape) { writer -> - StructureGenerator(model, symbolProvider, writer, shape).render() + rustCrate.useShapeWriter(shape) { + StructureGenerator(model, symbolProvider, this, shape).render() if (!shape.hasTrait()) { val builderGenerator = BuilderGenerator(codegenContext.model, codegenContext.symbolProvider, shape) - builderGenerator.render(writer) - writer.implBlock(shape, symbolProvider) { + builderGenerator.render(this) + this.implBlock(shape, symbolProvider) { builderGenerator.renderConvenienceMethod(this) } } @@ -209,8 +209,8 @@ class CodegenVisitor( */ override fun stringShape(shape: StringShape) { shape.getTrait()?.also { enum -> - rustCrate.useShapeWriter(shape) { writer -> - EnumGenerator(model, symbolProvider, writer, shape, enum).render() + rustCrate.useShapeWriter(shape) { + EnumGenerator(model, symbolProvider, this, shape, enum).render() } } } @@ -224,7 +224,7 @@ class CodegenVisitor( */ override fun unionShape(shape: UnionShape) { rustCrate.useShapeWriter(shape) { - UnionGenerator(model, symbolProvider, it, shape, renderUnknownVariant = true).render() + UnionGenerator(model, symbolProvider, this, shape, renderUnknownVariant = true).render() } } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt index aeaa693f5df..40131d517ae 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/customizations/ResiliencyConfigCustomization.kt @@ -227,8 +227,8 @@ class ResiliencyConfigCustomization(codegenContext: CodegenContext) : ConfigCust class ResiliencyReExportCustomization(private val runtimeConfig: RuntimeConfig) { fun extras(rustCrate: RustCrate) { - rustCrate.withModule(RustModule.Config) { writer -> - writer.rustTemplate( + rustCrate.withModule(RustModule.Config) { + rustTemplate( """ pub use #{sleep}::{AsyncSleep, Sleep}; diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt index ad97f369ab4..ad01544e303 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingGenerator.kt @@ -86,7 +86,7 @@ class EndpointTraitBindings( ) "${label.content} = $field" } - writer.rustTemplate( + rustTemplate( "#{EndpointPrefix}::new(format!($formatLiteral, ${args.joinToString()}))", "EndpointPrefix" to endpointPrefix, ) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/NestedAccessorGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/NestedAccessorGenerator.kt index d0fabc932a0..8b7672fe8f6 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/NestedAccessorGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/NestedAccessorGenerator.kt @@ -34,7 +34,7 @@ class NestedAccessorGenerator(private val symbolProvider: RustSymbolProvider) { val baseType = symbolProvider.toSymbol(path.last()) val fnName = symbolProvider.lensName("", root, path) return RuntimeType.forInlineFun(fnName, module) { - it.rustTemplate( + rustTemplate( """ pub(crate) fn $fnName(input: #{Input}) -> #{Output} { #{body:W} @@ -54,7 +54,7 @@ class NestedAccessorGenerator(private val symbolProvider: RustSymbolProvider) { val fnName = symbolProvider.lensName("ref", root, path) val referencedType = baseType.mapRustType { (it as RustType.Option).referenced(lifetime = null) } return RuntimeType.forInlineFun(fnName, module) { - it.rustTemplate( + rustTemplate( """ pub(crate) fn $fnName(input: &#{Input}) -> #{Output} { #{body:W} diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt index ca459a503f8..2f3f994b952 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/PaginatorGenerator.kt @@ -257,7 +257,7 @@ class PaginatorGenerator private constructor( null } else { RuntimeType.forInlineFun("${paginatorName}Items", module) { - it.rustTemplate( + rustTemplate( """ /// Flattened paginator for `$paginatorName` /// diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceGenerator.kt index 8f971da3fb3..c86934a87fa 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ServiceGenerator.kt @@ -40,34 +40,34 @@ class ServiceGenerator( fun render() { val operations = index.getContainedOperations(clientCodegenContext.serviceShape).sortedBy { it.id } operations.map { operation -> - rustCrate.useShapeWriter(operation) { operationWriter -> - rustCrate.useShapeWriter(operation.inputShape(clientCodegenContext.model)) { inputWriter -> + rustCrate.useShapeWriter(operation) operationWriter@{ + rustCrate.useShapeWriter(operation.inputShape(clientCodegenContext.model)) inputWriter@{ // Render the operation shape & serializers input `input.rs` protocolGenerator.renderOperation( - operationWriter, - inputWriter, + this@operationWriter, + this@inputWriter, operation, decorator.operationCustomizations(clientCodegenContext, operation, listOf()), ) // render protocol tests into `operation.rs` (note operationWriter vs. inputWriter) - ProtocolTestGenerator(clientCodegenContext, protocolSupport, operation, operationWriter).render() + ProtocolTestGenerator(clientCodegenContext, protocolSupport, operation, this@operationWriter).render() } } } TopLevelErrorGenerator(clientCodegenContext, operations).render(rustCrate) - rustCrate.withModule(RustModule.Config) { writer -> + rustCrate.withModule(RustModule.Config) { ServiceConfigGenerator.withBaseBehavior( clientCodegenContext, extraCustomizations = decorator.configCustomizations(clientCodegenContext, listOf()), - ).render(writer) + ).render(this) } rustCrate.lib { - Attribute.DocInline.render(it) - it.write("pub use config::Config;") + Attribute.DocInline.render(this) + write("pub use config::Config;") } } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt index c6e4d7a0e71..1c8ba17ca61 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/CustomizableOperationGenerator.kt @@ -35,13 +35,13 @@ class CustomizableOperationGenerator( private val smithyTypes = CargoDependency.SmithyTypes(runtimeConfig).asType() fun render(crate: RustCrate) { - crate.withModule(RustModule.operation(Visibility.PUBLIC)) { writer -> - writer.docs("Operation customization and supporting types") - writer.rust("pub mod customize;") + crate.withModule(RustModule.operation(Visibility.PUBLIC)) { + docs("Operation customization and supporting types") + rust("pub mod customize;") } - crate.withNonRootModule(CUSTOMIZE_MODULE) { writer -> - writer.rustTemplate( + crate.withNonRootModule(CUSTOMIZE_MODULE) { + rustTemplate( """ pub use #{Operation}; pub use #{ClassifyRetry}; @@ -51,10 +51,10 @@ class CustomizableOperationGenerator( "ClassifyRetry" to smithyHttp.member("retry::ClassifyRetry"), "RetryKind" to smithyTypes.member("retry::RetryKind"), ) - renderCustomizableOperationModule(writer) + renderCustomizableOperationModule(this) if (includeFluentClient) { - renderCustomizableOperationSend(writer) + renderCustomizableOperationSend(this) } } } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt index 4fe0f8eb9f2..1890a34302c 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/client/FluentClientGenerator.kt @@ -86,8 +86,8 @@ class FluentClientGenerator( private val core = FluentClientCore(model) fun render(crate: RustCrate) { - crate.withModule(clientModule) { writer -> - renderFluentClient(writer) + crate.withModule(clientModule) { + renderFluentClient(this) } CustomizableOperationGenerator( @@ -195,7 +195,7 @@ class FluentClientGenerator( outputFieldsHead += " with field(s):" } - rustTemplate( + writer.rustTemplate( """ /// Constructs a fluent builder for the [`$name`]($fullPath) operation.$maybePaginated /// @@ -207,7 +207,7 @@ class FluentClientGenerator( """, ) - rust( + writer.rust( """ pub fn ${ clientOperationFnName( @@ -221,7 +221,7 @@ class FluentClientGenerator( ) } } - writer.withModule("fluent_builders") { + writer.withModule(RustModule.public("fluent_builders")) { docs( """ Utilities to ergonomically construct a request to the service. diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGenerator.kt index 926eef97935..00179b3216c 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGenerator.kt @@ -133,7 +133,7 @@ class ServiceConfigGenerator(private val customizations: List) -> std::fmt::Result { let mut config = f.debug_struct("Config"); @@ -144,7 +144,7 @@ class ServiceConfigGenerator(private val customizations: List Builder { Builder::default() } @@ -163,8 +163,8 @@ class ServiceConfigGenerator(private val customizations: List Self { Self::default() }") + writer.docs("Constructs a config builder.") + writer.rustTemplate("pub fn new() -> Self { Self::default() }") customizations.forEach { it.section(ServiceConfig.BuilderImpl)(this) } diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt index 4bf70a2f7c2..a3e1ed6f9d2 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt @@ -22,8 +22,10 @@ import software.amazon.smithy.protocoltests.traits.HttpResponseTestsTrait import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.escape import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -103,7 +105,7 @@ class ProtocolTestGenerator( Attribute.Custom("allow(unreachable_code, unused_variables)"), ), ) - writer.withModule(testModuleName, moduleMeta) { + writer.withModule(RustModule(testModuleName, moduleMeta)) { renderAllTestCases(allTests) } } @@ -137,7 +139,7 @@ class ProtocolTestGenerator( private fun renderTestCaseBlock( testCase: HttpMessageTestCase, testModuleWriter: RustWriter, - block: RustWriter.() -> Unit, + block: Writable, ) { testModuleWriter.setNewlinePrefix("/// ") testCase.documentation.map { @@ -452,9 +454,9 @@ class ProtocolTestGenerator( /** * wraps `inner` in a call to `aws_smithy_protocol_test::assert_ok`, a convenience wrapper - * for pretty prettying protocol test helper results + * for pretty printing protocol test helper results */ - private fun assertOk(rustWriter: RustWriter, inner: RustWriter.() -> Unit) { + private fun assertOk(rustWriter: RustWriter, inner: Writable) { rustWriter.write("#T(", RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "assert_ok")) inner(rustWriter) rustWriter.write(");") diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt index f461f957cb7..1e44de1aa6e 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt @@ -169,8 +169,8 @@ class HttpBoundProtocolTraitImplGenerator( val outputSymbol = symbolProvider.toSymbol(outputShape) val errorSymbol = operationShape.errorSymbol(model, symbolProvider, codegenContext.target) return RuntimeType.forInlineFun(fnName, operationDeserModule) { - Attribute.Custom("allow(clippy::unnecessary_wraps)").render(it) - it.rustBlockTemplate( + Attribute.Custom("allow(clippy::unnecessary_wraps)").render(this) + rustBlockTemplate( "pub fn $fnName(response: &#{http}::Response<#{Bytes}>) -> std::result::Result<#{O}, #{E}>", *codegenScope, "O" to outputSymbol, @@ -243,15 +243,15 @@ class HttpBoundProtocolTraitImplGenerator( val outputSymbol = symbolProvider.toSymbol(outputShape) val errorSymbol = operationShape.errorSymbol(model, symbolProvider, codegenContext.target) return RuntimeType.forInlineFun(fnName, operationDeserModule) { - Attribute.Custom("allow(clippy::unnecessary_wraps)").render(it) - it.rustBlockTemplate( + Attribute.Custom("allow(clippy::unnecessary_wraps)").render(this) + rustBlockTemplate( "pub fn $fnName(op_response: &mut #{operation}::Response) -> std::result::Result<#{O}, #{E}>", *codegenScope, "O" to outputSymbol, "E" to errorSymbol, ) { // Not all implementations will use the property bag, but some will - Attribute.Custom("allow(unused_variables)").render(it) + Attribute.Custom("allow(unused_variables)").render(this) rust("let (response, properties) = op_response.parts_mut();") withBlock("Ok({", "})") { renderShapeParser( @@ -272,8 +272,8 @@ class HttpBoundProtocolTraitImplGenerator( val outputSymbol = symbolProvider.toSymbol(outputShape) val errorSymbol = operationShape.errorSymbol(model, symbolProvider, codegenContext.target) return RuntimeType.forInlineFun(fnName, operationDeserModule) { - Attribute.Custom("allow(clippy::unnecessary_wraps)").render(it) - it.rustBlockTemplate( + Attribute.Custom("allow(clippy::unnecessary_wraps)").render(this) + rustBlockTemplate( "pub fn $fnName(response: &#{http}::Response<#{Bytes}>) -> std::result::Result<#{O}, #{E}>", *codegenScope, "O" to outputSymbol, diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestConfigCustomization.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestConfigCustomization.kt index 3a239facab4..da2362a195a 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestConfigCustomization.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/testutil/TestConfigCustomization.kt @@ -75,8 +75,8 @@ fun stubConfigProject(customization: ConfigCustomization, project: TestWriterDel val customizations = listOf(stubConfigCustomization("a")) + customization + stubConfigCustomization("b") val generator = ServiceConfigGenerator(customizations = customizations.toList()) project.withModule(RustModule.Config) { - generator.render(it) - it.unitTest( + generator.render(this) + unitTest( "config_send_sync", """ fn assert_send_sync() {} @@ -84,6 +84,6 @@ fun stubConfigProject(customization: ConfigCustomization, project: TestWriterDel """, ) } - project.lib { it.rust("pub use config::Config;") } + project.lib { rust("pub use config::Config;") } return project } diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt index d63b87e7ed1..872402c6efe 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/EndpointTraitBindingsTest.kt @@ -68,15 +68,15 @@ internal class EndpointTraitBindingsTest { ) val project = TestWorkspace.testProject() project.withModule(RustModule.default("test", visibility = Visibility.PRIVATE)) { - it.rust( + rust( """ struct GetStatusInput { foo: Option } """, ) - it.implBlock(model.lookup("test#GetStatusInput"), sym) { - it.rustBlock( + implBlock(model.lookup("test#GetStatusInput"), sym) { + rustBlock( "fn endpoint_prefix(&self) -> std::result::Result<#T::endpoint::EndpointPrefix, #T>", TestRuntimeConfig.smithyHttp(), TestRuntimeConfig.operationBuildError(), @@ -84,7 +84,7 @@ internal class EndpointTraitBindingsTest { endpointBindingGenerator.render(this, "self") } } - it.unitTest( + unitTest( "valid_prefix", """ let inp = GetStatusInput { foo: Some("test_value".to_string()) }; @@ -92,7 +92,7 @@ internal class EndpointTraitBindingsTest { assert_eq!(prefix.as_str(), "test_valuea.data."); """, ) - it.unitTest( + unitTest( "invalid_prefix", """ // not a valid URI component @@ -101,7 +101,7 @@ internal class EndpointTraitBindingsTest { """, ) - it.unitTest( + unitTest( "unset_prefix", """ // unset is invalid @@ -110,7 +110,7 @@ internal class EndpointTraitBindingsTest { """, ) - it.unitTest( + unitTest( "empty_prefix", """ // empty is invalid @@ -153,8 +153,8 @@ internal class EndpointTraitBindingsTest { override fun extras(codegenContext: ClientCodegenContext, rustCrate: RustCrate) { rustCrate.withFile("tests/validate_errors.rs") { - TokioTest.render(it) - it.rust( + TokioTest.render(this) + rust( """ async fn test_endpoint_prefix() { let conf = $moduleName::Config::builder().build(); diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGeneratorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGeneratorTest.kt index b2002a953ac..0241133f231 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGeneratorTest.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/config/ServiceConfigGeneratorTest.kt @@ -103,8 +103,8 @@ internal class ServiceConfigGeneratorTest { val symbolProvider = testSymbolProvider("namespace empty".asSmithyModel()) val project = TestWorkspace.testProject(symbolProvider) project.withModule(RustModule.Config) { - sut.render(it) - it.unitTest( + sut.render(this) + unitTest( "set_config_fields", """ let mut builder = Config::builder(); diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/testutil/AddRustTestsDecorator.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/testutil/AddRustTestsDecorator.kt index 0bb1a6c7ce5..7a7a45a735d 100644 --- a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/testutil/AddRustTestsDecorator.kt +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/testutil/AddRustTestsDecorator.kt @@ -17,8 +17,8 @@ open class AddRustTestsDecorator( override val order: Byte = 0 override fun extras(codegenContext: C, rustCrate: RustCrate) { - rustCrate.withFile("tests/$testsFileName.rs") { writer -> - writer.testWritable() + rustCrate.withFile("tests/$testsFileName.rs") { + testWritable() } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt index 62361e4863b..bd231f8094a 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/CargoDependency.kt @@ -56,7 +56,7 @@ class InlineDependency( name: String, val module: RustModule, private val extraDependencies: List = listOf(), - val renderer: (RustWriter) -> Unit, + val renderer: Writable, ) : RustDependency(name) { override fun version(): String { // just need a version that won't crash @@ -87,8 +87,8 @@ class InlineDependency( // The inline crate is loaded as a dependency on the runtime classpath val rustFile = this::class.java.getResource("/$baseDir/src/$filename") check(rustFile != null) { "Rust file /$baseDir/src/$filename was missing from the resource bundle!" } - return InlineDependency(name, module, additionalDependencies.toList()) { writer -> - writer.raw(rustFile.readText()) + return InlineDependency(name, module, additionalDependencies.toList()) { + raw(rustFile.readText()) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt index 8cfbcb206c4..4860b627d2c 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustModule.kt @@ -5,7 +5,7 @@ package software.amazon.smithy.rust.codegen.core.rustlang -data class RustModule(val name: String, val rustMetadata: RustMetadata, val documentation: String?) { +data class RustModule(val name: String, val rustMetadata: RustMetadata, val documentation: String? = null) { fun render(writer: RustWriter) { documentation?.let { docs -> writer.docs(docs) } rustMetadata.render(writer) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt index 24344b57c7b..6ff484bbaa7 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustType.kt @@ -51,7 +51,7 @@ sealed class RustType { * // Then, invoke the writable directly * t.invoke(writer) * // OR template it out - * writer.rustInlineTemplate("#{t:W}", "t" to t) + *rustInlineTemplate("#{t:W}", "t" to t) * ``` * * When formatted, the converted type will appear as such: @@ -378,15 +378,17 @@ sealed class Attribute { abstract fun render(writer: RustWriter) companion object { + val AllowDeadCode = Custom("allow(dead_code)") + val AllowDeprecated = Custom("allow(deprecated)") + val AllowUnusedMut = Custom("allow(unused_mut)") + val DocHidden = Custom("doc(hidden)") + val DocInline = Custom("doc(inline)") + /** * [non_exhaustive](https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute) * indicates that more fields may be added in the future */ val NonExhaustive = Custom("non_exhaustive") - val AllowUnusedMut = Custom("allow(unused_mut)") - val AllowDeadCode = Custom("allow(dead_code)") - val DocHidden = Custom("doc(hidden)") - val DocInline = Custom("doc(inline)") } data class Derives(val derives: Set) : Attribute() { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriter.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriter.kt index f733003217a..8ef035f042b 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriter.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriter.kt @@ -424,7 +424,7 @@ class RustWriter private constructor( return "${prefix}_$n" } - fun first(preWriter: RustWriter.() -> Unit) { + fun first(preWriter: Writable) { preamble.add(preWriter) } @@ -434,7 +434,7 @@ class RustWriter private constructor( * Callers must take care to use [this] when writing to ensure code is written to the right place: * ```kotlin * val writer = RustWriter.forModule("model") - * writer.withModule("nested") { + * writer.withModule(RustModule.public("nested")) { * Generator(...).render(this) // GOOD * Generator(...).render(writer) // WRONG! * } @@ -443,17 +443,16 @@ class RustWriter private constructor( * The returned writer will inject any local imports into the module as needed. */ fun withModule( - moduleName: String, - rustMetadata: RustMetadata = RustMetadata(visibility = Visibility.PUBLIC), - moduleWriter: RustWriter.() -> Unit, + module: RustModule, + moduleWriter: Writable, ): RustWriter { // In Rust, modules must specify their own imports—they don't have access to the parent scope. // To easily handle this, create a new inner writer to collect imports, then dump it // into an inline module. - val innerWriter = RustWriter(this.filename, "${this.namespace}::$moduleName", printWarning = false) + val innerWriter = RustWriter(this.filename, "${this.namespace}::${module.name}", printWarning = false) moduleWriter(innerWriter) - rustMetadata.render(this) - rustBlock("mod $moduleName") { + module.rustMetadata.render(this) + rustBlock("mod ${module.name}") { writeWithNoFormatting(innerWriter.toString()) } innerWriter.dependencies.forEach { addDependency(it) } @@ -545,7 +544,8 @@ class RustWriter private constructor( */ inner class RustWriteableInjector : BiFunction { override fun apply(t: Any, u: String): String { - val func = t as? RustWriter.() -> Unit ?: throw CodegenException("RustWriteableInjector.apply choked on non-function t ($t)") + @Suppress("UNCHECKED_CAST") + val func = t as? Writable ?: throw CodegenException("RustWriteableInjector.apply choked on non-function t ($t)") val innerWriter = RustWriter(filename, namespace, printWarning = false) func(innerWriter) innerWriter.dependencies.forEach { addDependency(it) } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/Writable.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/Writable.kt index f1ed5ad9443..5cf2180ee2f 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/Writable.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/Writable.kt @@ -108,12 +108,9 @@ fun rustTypeParameters( ) else -> { // Check if it's a writer. If it is, invoke it; Else, throw a codegen error. - val func = typeParameter as? RustWriter.() -> Unit - if (func != null) { - func.invoke(this) - } else { - throw CodegenException("Unhandled type '$typeParameter' encountered by rustTypeParameters writer") - } + @Suppress("UNCHECKED_CAST") + val func = typeParameter as? Writable ?: throw CodegenException("Unhandled type '$typeParameter' encountered by rustTypeParameters writer") + func.invoke(this) } } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt index 32ba37f3d33..bbd77b7c74b 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/CodegenDelegator.kt @@ -16,6 +16,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.InlineDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.smithy.generators.CargoTomlGenerator import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsCustomization import software.amazon.smithy.rust.codegen.core.smithy.generators.LibRsGenerator @@ -55,14 +56,14 @@ open class RustCrate( /** * Write into the module that this shape is [locatedIn] */ - fun useShapeWriter(shape: Shape, f: (RustWriter) -> Unit) { + fun useShapeWriter(shape: Shape, f: Writable) { inner.useShapeWriter(shape, f) } /** * Write directly into lib.rs */ - fun lib(moduleWriter: (RustWriter) -> Unit) { + fun lib(moduleWriter: Writable) { inner.useFileWriter("src/lib.rs", "crate", moduleWriter) } @@ -119,7 +120,7 @@ open class RustCrate( unloadedDependencies().forEach { dep -> writtenDependencies.add(dep.key()) this.withModule(dep.module) { - dep.renderer(it) + dep.renderer(this) } } } @@ -130,7 +131,7 @@ open class RustCrate( */ fun withModule( module: RustModule, - moduleWriter: (RustWriter) -> Unit, + moduleWriter: Writable, ): RustCrate { val moduleName = module.name modules[moduleName] = module @@ -149,7 +150,7 @@ open class RustCrate( */ fun withNonRootModule( namespace: String, - moduleWriter: (RustWriter) -> Unit, + moduleWriter: Writable, ): RustCrate { val parts = namespace.split("::") require(parts.size > 2) { "Cannot create root modules using withNonRootModule" } @@ -163,7 +164,7 @@ open class RustCrate( /** * Create a new file directly */ - fun withFile(filename: String, fileWriter: (RustWriter) -> Unit) { + fun withFile(filename: String, fileWriter: Writable) { inner.useFileWriter(filename) { fileWriter(it) } @@ -184,8 +185,8 @@ fun WriterDelegator.finalize( features: List, requireDocs: Boolean, ) { - this.useFileWriter("src/lib.rs", "crate::lib") { writer -> - LibRsGenerator(settings, model, modules, libRsCustomizations, requireDocs).render(writer) + this.useFileWriter("src/lib.rs", "crate::lib") { + LibRsGenerator(settings, model, modules, libRsCustomizations, requireDocs).render(it) } val cargoDependencies = mergeDependencyFeatures( this.dependencies.map { RustDependency.fromSymbolDependency(it) } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt index 781014bd850..d79059065ff 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/RuntimeType.kt @@ -21,6 +21,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.RustDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustType import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.rustInlineTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable @@ -301,7 +302,7 @@ data class RuntimeType(val name: String?, val dependency: RustDependency?, val n fun forInlineDependency(inlineDependency: InlineDependency) = RuntimeType(inlineDependency.name, inlineDependency, namespace = "crate") - fun forInlineFun(name: String, module: RustModule, func: (RustWriter) -> Unit) = RuntimeType( + fun forInlineFun(name: String, module: RustModule, func: Writable) = RuntimeType( name = name, dependency = InlineDependency(name, module, listOf(), func), namespace = "crate::${module.name}", diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt index c561b04c396..5ff4f33dd1a 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt @@ -9,6 +9,7 @@ import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.StructureShape +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords import software.amazon.smithy.rust.codegen.core.rustlang.RustType import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter @@ -72,7 +73,7 @@ class BuilderGenerator( val symbol = symbolProvider.toSymbol(shape) writer.docs("See #D.", symbol) val segments = shape.builderSymbol(symbolProvider).namespace.split("::") - writer.withModule(segments.last()) { + writer.withModule(RustModule.public(segments.last())) { renderBuilder(this) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt index f2b25032b5a..e735ec5e115 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/EnumGenerator.kt @@ -5,11 +5,13 @@ package software.amazon.smithy.rust.codegen.core.smithy.generators +import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.StringShape import software.amazon.smithy.model.traits.DocumentationTrait import software.amazon.smithy.model.traits.EnumDefinition import software.amazon.smithy.model.traits.EnumTrait +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.deprecatedShape import software.amazon.smithy.rust.codegen.core.rustlang.docs @@ -51,7 +53,7 @@ class EnumMemberModel(private val definition: EnumDefinition, private val symbol private fun renderDeprecated(writer: RustWriter) { if (definition.isDeprecated) { - writer.rust("##[deprecated]") + Attribute.Custom.deprecated().render(writer) } } @@ -86,8 +88,8 @@ open class EnumGenerator( private val shape: StringShape, private val enumTrait: EnumTrait, ) { - protected val symbol = symbolProvider.toSymbol(shape) - protected val enumName = symbol.name + protected val symbol: Symbol = symbolProvider.toSymbol(shape) + protected val enumName: String = symbol.name protected val meta = symbol.expectRustMetadata() protected val sortedMembers: List = enumTrait.values.sortedBy { it.value }.map { EnumMemberModel(it, symbolProvider) } @@ -114,7 +116,7 @@ open class EnumGenerator( // impl Blah { pub fn as_str(&self) -> &str implBlock() writer.rustBlock("impl AsRef for $enumName") { - writer.rustBlock("fn as_ref(&self) -> &str") { + rustBlock("fn as_ref(&self) -> &str") { rust("self.as_str()") } } @@ -129,23 +131,23 @@ open class EnumGenerator( meta.render(writer) writer.write("struct $enumName(String);") writer.rustBlock("impl $enumName") { - rust("/// Returns the `&str` value of the enum member.") + docs("Returns the `&str` value of the enum member.") rustBlock("pub fn as_str(&self) -> &str") { - write("&self.0") + rust("&self.0") } - rust("/// Returns all the `&str` representations of the enum members.") + docs("Returns all the `&str` representations of the enum members.") rustBlock("pub fn $Values() -> &'static [&'static str]") { withBlock("&[", "]") { - val memberList = sortedMembers.joinToString(", ") { it.value.doubleQuote() } - write(memberList) + val memberList = sortedMembers.joinToString(", ") { it.value.dq() } + rust(memberList) } } } writer.rustBlock("impl #T for $enumName where T: #T", RuntimeType.From, RuntimeType.AsRef) { - writer.rustBlock("fn from(s: T) -> Self") { - write("$enumName(s.as_ref().to_owned())") + rustBlock("fn from(s: T) -> Self") { + rust("$enumName(s.as_ref().to_owned())") } } } @@ -167,7 +169,7 @@ open class EnumGenerator( sortedMembers.forEach { member -> member.render(writer) } if (target == CodegenTarget.CLIENT) { docs("$UnknownVariant contains new variants that have been added since this code was generated.") - write("$UnknownVariant(String)") + rust("$UnknownVariant(String)") } } } @@ -175,19 +177,19 @@ open class EnumGenerator( private fun implBlock() { writer.rustBlock("impl $enumName") { rust("/// Returns the `&str` value of the enum member.") - writer.rustBlock("pub fn as_str(&self) -> &str") { - writer.rustBlock("match self") { + rustBlock("pub fn as_str(&self) -> &str") { + rustBlock("match self") { sortedMembers.forEach { member -> - write("""$enumName::${member.derivedName()} => ${member.value.dq()},""") + rust("""$enumName::${member.derivedName()} => ${member.value.dq()},""") } if (target == CodegenTarget.CLIENT) { - write("$enumName::$UnknownVariant(s) => s.as_ref()") + rust("$enumName::$UnknownVariant(s) => s.as_ref()") } } } rust("/// Returns all the `&str` values of the enum members.") - writer.rustBlock("pub fn $Values() -> &'static [&'static str]") { + rustBlock("pub fn $Values() -> &'static [&'static str]") { withBlock("&[", "]") { val memberList = sortedMembers.joinToString(", ") { it.value.doubleQuote() } write(memberList) @@ -198,12 +200,12 @@ open class EnumGenerator( protected open fun renderFromForStr() { writer.rustBlock("impl #T<&str> for $enumName", RuntimeType.From) { - writer.rustBlock("fn from(s: &str) -> Self") { - writer.rustBlock("match s") { + rustBlock("fn from(s: &str) -> Self") { + rustBlock("match s") { sortedMembers.forEach { member -> - write("""${member.value.dq()} => $enumName::${member.derivedName()},""") + rust("""${member.value.dq()} => $enumName::${member.derivedName()},""") } - write("other => $enumName::$UnknownVariant(other.to_owned())") + rust("other => $enumName::$UnknownVariant(other.to_owned())") } } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt index 96f508c5d03..9af2df80911 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt @@ -15,6 +15,7 @@ import software.amazon.smithy.model.traits.ErrorTrait import software.amazon.smithy.model.traits.SensitiveTrait import software.amazon.smithy.rust.codegen.core.rustlang.RustType import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.asDeref import software.amazon.smithy.rust.codegen.core.rustlang.asRef import software.amazon.smithy.rust.codegen.core.rustlang.deprecatedShape @@ -39,9 +40,9 @@ import software.amazon.smithy.rust.codegen.core.util.getTrait import software.amazon.smithy.rust.codegen.core.util.hasTrait import software.amazon.smithy.rust.codegen.core.util.redactIfNecessary -fun RustWriter.implBlock(structureShape: Shape, symbolProvider: SymbolProvider, block: RustWriter.() -> Unit) { +fun RustWriter.implBlock(structureShape: Shape, symbolProvider: SymbolProvider, block: Writable) { rustBlock("impl ${symbolProvider.toSymbol(structureShape).name}") { - block(this) + block() } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt index 9c973ff0925..e1307e45fd0 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt @@ -53,8 +53,9 @@ import software.amazon.smithy.rust.codegen.core.util.toSnakeCase generator: KClass ): RuntimeType { val symbol = symbolProvider.toSymbol(this) - return RuntimeType.forInlineFun("${symbol.name}Error", RustModule.Error) { writer -> - generator.java.newInstance().render(writer, + return RuntimeType.forInlineFun("${symbol.name}Error", RustModule.Error) { + generator.java.newInstance().render( + this, model, symbolProvider, symbol, @@ -71,20 +72,20 @@ fun OperationShape.errorSymbol( target: CodegenTarget, ): RuntimeType { val symbol = symbolProvider.toSymbol(this) - return RuntimeType.forInlineFun("${symbol.name}Error", RustModule.Error) { writer -> + return RuntimeType.forInlineFun("${symbol.name}Error", RustModule.Error) { when (target) { CodegenTarget.CLIENT -> CombinedErrorGenerator( model, symbolProvider, symbol, - this.operationErrors(model).map { it.asStructureShape().get() }, - ).render(writer) + operationErrors(model).map { it.asStructureShape().get() }, + ).render(this) CodegenTarget.SERVER -> ServerCombinedErrorGenerator( model, symbolProvider, symbol, - this.operationErrors(model).map { it.asStructureShape().get() }, - ).render(writer) + operationErrors(model).map { it.asStructureShape().get() }, + ).render(this) } } } @@ -92,18 +93,18 @@ fun OperationShape.errorSymbol( fun UnionShape.eventStreamErrorSymbol(model: Model, symbolProvider: RustSymbolProvider, target: CodegenTarget): RuntimeType { val symbol = symbolProvider.toSymbol(this) val errorSymbol = RuntimeType("${symbol.name}Error", null, "crate::error") - return RuntimeType.forInlineFun("${symbol.name}Error", RustModule.Error) { writer -> - val errors = this.eventStreamErrors().map { model.expectShape(it.asMemberShape().get().target, StructureShape::class.java) } + return RuntimeType.forInlineFun("${symbol.name}Error", RustModule.Error) { + val errors = this@eventStreamErrorSymbol.eventStreamErrors().map { model.expectShape(it.asMemberShape().get().target, StructureShape::class.java) } when (target) { CodegenTarget.CLIENT -> CombinedErrorGenerator(model, symbolProvider, symbol, errors).renderErrors( - writer, + this, errorSymbol, symbol, ) CodegenTarget.SERVER -> ServerCombinedErrorGenerator(model, symbolProvider, symbol, errors).renderErrors( - writer, + this, errorSymbol, symbol, ) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt index 4253622fffd..f83b8b4b3bc 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGenerator.kt @@ -8,6 +8,7 @@ package software.amazon.smithy.rust.codegen.core.smithy.generators.error import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata import software.amazon.smithy.rust.codegen.core.rustlang.RustModule @@ -51,20 +52,20 @@ class TopLevelErrorGenerator(private val codegenContext: CodegenContext, private private val sdkError = CargoDependency.SmithyHttp(codegenContext.runtimeConfig).asType().member("result::SdkError") fun render(crate: RustCrate) { - crate.withModule(RustModule.default("error_meta", visibility = Visibility.PRIVATE)) { writer -> - writer.renderDefinition() - writer.renderImplDisplay() + crate.withModule(RustModule.private("error_meta")) { + renderDefinition() + renderImplDisplay() // Every operation error can be converted into service::Error operations.forEach { operationShape -> // operation errors - writer.renderImplFrom(operationShape.errorSymbol(model, symbolProvider, codegenContext.target), operationShape.errors) + renderImplFrom(operationShape.errorSymbol(model, symbolProvider, codegenContext.target), operationShape.errors) } // event stream errors operations.map { it.eventStreamErrors(codegenContext.model) } .flatMap { it.entries } .associate { it.key to it.value } .forEach { (unionShape, errors) -> - writer.renderImplFrom( + renderImplFrom( unionShape.eventStreamErrorSymbol( model, symbolProvider, @@ -73,9 +74,9 @@ class TopLevelErrorGenerator(private val codegenContext: CodegenContext, private errors.map { it.id }, ) } - writer.rust("impl #T for Error {}", RuntimeType.StdError) + rust("impl #T for Error {}", RuntimeType.StdError) } - crate.lib { it.rust("pub use error_meta::Error;") } + crate.lib { rust("pub use error_meta::Error;") } } private fun RustWriter.renderImplDisplay() { @@ -125,8 +126,8 @@ class TopLevelErrorGenerator(private val codegenContext: CodegenContext, private private fun RustWriter.renderDefinition() { rust("/// All possible error types for this service.") RustMetadata( - additionalAttributes = listOf(software.amazon.smithy.rust.codegen.core.rustlang.Attribute.NonExhaustive), - visibility = software.amazon.smithy.rust.codegen.core.rustlang.Visibility.PUBLIC, + additionalAttributes = listOf(Attribute.NonExhaustive), + visibility = Visibility.PUBLIC, ).withDerives(RuntimeType.Debug).render(this) rustBlock("enum Error") { allErrors.forEach { error -> diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt index e76ed60ac99..f52f4d38afd 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt @@ -118,8 +118,8 @@ class HttpBindingGenerator( check(binding.location == HttpLocation.HEADER) val outputT = symbolProvider.toSymbol(binding.member).makeOptional() val fnName = "deser_header_${fnName(operationShape, binding)}" - return RuntimeType.forInlineFun(fnName, httpSerdeModule) { writer -> - writer.rustBlock( + return RuntimeType.forInlineFun(fnName, httpSerdeModule) { + rustBlock( "pub fn $fnName(header_map: &#T::HeaderMap) -> std::result::Result<#T, #T::ParseError>", RuntimeType.http, outputT, @@ -139,7 +139,7 @@ class HttpBindingGenerator( check(target is MapShape) val fnName = "deser_prefix_header_${fnName(operationShape, binding)}" val inner = RuntimeType.forInlineFun("${fnName}_inner", httpSerdeModule) { - it.rustBlock( + rustBlock( "pub fn ${fnName}_inner(headers: #T::header::ValueIter) -> std::result::Result, #T::ParseError>", RuntimeType.http, symbolProvider.toSymbol(model.expectShape(target.value.target)), @@ -149,8 +149,8 @@ class HttpBindingGenerator( } } val returnTypeSymbol = outputSymbol.mapRustType { it.asOptional() } - return RuntimeType.forInlineFun(fnName, httpSerdeModule) { writer -> - writer.rustBlock( + return RuntimeType.forInlineFun(fnName, httpSerdeModule) { + rustBlock( "pub fn $fnName(header_map: &#T::HeaderMap) -> std::result::Result<#T, #T::ParseError>", RuntimeType.http, returnTypeSymbol, @@ -185,10 +185,10 @@ class HttpBindingGenerator( ): RuntimeType { check(binding.location == HttpBinding.Location.PAYLOAD) val fnName = "deser_payload_${fnName(operationShape, binding)}" - return RuntimeType.forInlineFun(fnName, httpSerdeModule) { rustWriter -> + return RuntimeType.forInlineFun(fnName, httpSerdeModule) { if (binding.member.isStreaming(model)) { val outputT = symbolProvider.toSymbol(binding.member) - rustWriter.rustBlock( + rustBlock( "pub fn $fnName(body: &mut #T) -> std::result::Result<#T, #T>", RuntimeType.sdkBody(runtimeConfig), outputT, @@ -206,7 +206,7 @@ class HttpBindingGenerator( // The output needs to be Optional when deserializing the payload body or the caller signature // will not match. val outputT = symbolProvider.toSymbol(binding.member).makeOptional() - rustWriter.rustBlock("pub fn $fnName(body: &[u8]) -> std::result::Result<#T, #T>", outputT, errorT) { + rustBlock("pub fn $fnName(body: &[u8]) -> std::result::Result<#T, #T>", outputT, errorT) { deserializePayloadBody( binding, errorT, @@ -433,7 +433,7 @@ class HttpBindingGenerator( } val fnName = "add_headers_${shape.id.getName(service).toSnakeCase()}" - return RuntimeType.forInlineFun(fnName, httpSerdeModule) { rustWriter -> + return RuntimeType.forInlineFun(fnName, httpSerdeModule) { // If the shape is an operation shape, the input symbol of the generated function is the input or output // shape, which is the shape holding the header-bound data. val shapeSymbol = symbolProvider.toSymbol( @@ -452,7 +452,7 @@ class HttpBindingGenerator( HttpMessageType.RESPONSE.name to RuntimeType.HttpResponseBuilder, "Shape" to shapeSymbol, ) - rustWriter.rustBlockTemplate( + rustBlockTemplate( """ pub fn $fnName( input: &#{Shape}, diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt index 8c9588ada55..5869e77f89a 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsJson.kt @@ -92,7 +92,7 @@ class AwsJsonSerializerGenerator( val inputShape = operationShape.inputShape(codegenContext.model) val fnName = codegenContext.symbolProvider.serializeFunctionName(operationShape) serializer = RuntimeType.forInlineFun(fnName, RustModule.private("operation_ser")) { - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(_input: &#{target}) -> Result<#{SdkBody}, #{Error}>", *codegenScope, "target" to codegenContext.symbolProvider.toSymbol(inputShape), ) { @@ -136,8 +136,8 @@ open class AwsJson( AwsJsonSerializerGenerator(codegenContext, httpBindingResolver) override fun parseHttpGenericError(operationShape: OperationShape): RuntimeType = - RuntimeType.forInlineFun("parse_http_generic_error", jsonDeserModule) { writer -> - writer.rustTemplate( + RuntimeType.forInlineFun("parse_http_generic_error", jsonDeserModule) { + rustTemplate( """ pub fn parse_http_generic_error(response: &#{Response}<#{Bytes}>) -> Result<#{Error}, #{JsonError}> { #{json_errors}::parse_generic_error(response.body(), response.headers()) @@ -148,8 +148,8 @@ open class AwsJson( } override fun parseEventStreamGenericError(operationShape: OperationShape): RuntimeType = - RuntimeType.forInlineFun("parse_event_stream_generic_error", jsonDeserModule) { writer -> - writer.rustTemplate( + RuntimeType.forInlineFun("parse_event_stream_generic_error", jsonDeserModule) { + rustTemplate( """ pub fn parse_event_stream_generic_error(payload: &#{Bytes}) -> Result<#{Error}, #{JsonError}> { // Note: HeaderMap::new() doesn't allocate diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt index d9d42244404..d2bd4eb9fc1 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/AwsQuery.kt @@ -62,8 +62,8 @@ class AwsQueryProtocol(private val codegenContext: CodegenContext) : Protocol { AwsQuerySerializerGenerator(codegenContext) override fun parseHttpGenericError(operationShape: OperationShape): RuntimeType = - RuntimeType.forInlineFun("parse_http_generic_error", xmlDeserModule) { writer -> - writer.rustBlockTemplate( + RuntimeType.forInlineFun("parse_http_generic_error", xmlDeserModule) { + rustBlockTemplate( "pub fn parse_http_generic_error(response: &#{Response}<#{Bytes}>) -> Result<#{Error}, #{XmlError}>", *errorScope, ) { @@ -72,8 +72,8 @@ class AwsQueryProtocol(private val codegenContext: CodegenContext) : Protocol { } override fun parseEventStreamGenericError(operationShape: OperationShape): RuntimeType = - RuntimeType.forInlineFun("parse_event_stream_generic_error", xmlDeserModule) { writer -> - writer.rustBlockTemplate( + RuntimeType.forInlineFun("parse_event_stream_generic_error", xmlDeserModule) { + rustBlockTemplate( "pub fn parse_event_stream_generic_error(payload: &#{Bytes}) -> Result<#{Error}, #{XmlError}>", *errorScope, ) { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt index 3500dfcab2f..3f9dca4ca6a 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/Ec2Query.kt @@ -53,8 +53,8 @@ class Ec2QueryProtocol(private val codegenContext: CodegenContext) : Protocol { Ec2QuerySerializerGenerator(codegenContext) override fun parseHttpGenericError(operationShape: OperationShape): RuntimeType = - RuntimeType.forInlineFun("parse_http_generic_error", xmlDeserModule) { writer -> - writer.rustBlockTemplate( + RuntimeType.forInlineFun("parse_http_generic_error", xmlDeserModule) { + rustBlockTemplate( "pub fn parse_http_generic_error(response: &#{Response}<#{Bytes}>) -> Result<#{Error}, #{XmlError}>", *errorScope, ) { @@ -63,8 +63,8 @@ class Ec2QueryProtocol(private val codegenContext: CodegenContext) : Protocol { } override fun parseEventStreamGenericError(operationShape: OperationShape): RuntimeType = - RuntimeType.forInlineFun("parse_event_stream_generic_error", xmlDeserModule) { writer -> - writer.rustBlockTemplate( + RuntimeType.forInlineFun("parse_event_stream_generic_error", xmlDeserModule) { + rustBlockTemplate( "pub fn parse_event_stream_generic_error(payload: &#{Bytes}) -> Result<#{Error}, #{XmlError}>", *errorScope, ) { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt index b7bf02f8f56..17319765ffe 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt @@ -246,7 +246,7 @@ class HttpBoundProtocolPayloadGenerator( val ref = if (payloadMetadata.takesOwnership) "" else "&" val serializer = RuntimeType.forInlineFun(fnName, operationSerModule) { val outputT = if (member.isStreaming(model)) symbolProvider.toSymbol(member) else RuntimeType.ByteSlab.toSymbol() - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(payload: $ref#{Member}) -> Result<#{outputT}, #{BuildError}>", "Member" to symbolProvider.toSymbol(member), "outputT" to outputT, diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt index 67edb3b7fa4..7a25fabfdb6 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestJson.kt @@ -92,8 +92,8 @@ open class RestJson(val codegenContext: CodegenContext) : Protocol { JsonSerializerGenerator(codegenContext, httpBindingResolver, ::restJsonFieldName) override fun parseHttpGenericError(operationShape: OperationShape): RuntimeType = - RuntimeType.forInlineFun("parse_http_generic_error", jsonDeserModule) { writer -> - writer.rustTemplate( + RuntimeType.forInlineFun("parse_http_generic_error", jsonDeserModule) { + rustTemplate( """ pub fn parse_http_generic_error(response: &#{Response}<#{Bytes}>) -> Result<#{Error}, #{JsonError}> { #{json_errors}::parse_generic_error(response.body(), response.headers()) @@ -104,8 +104,8 @@ open class RestJson(val codegenContext: CodegenContext) : Protocol { } override fun parseEventStreamGenericError(operationShape: OperationShape): RuntimeType = - RuntimeType.forInlineFun("parse_event_stream_generic_error", jsonDeserModule) { writer -> - writer.rustTemplate( + RuntimeType.forInlineFun("parse_event_stream_generic_error", jsonDeserModule) { + rustTemplate( """ pub fn parse_event_stream_generic_error(payload: &#{Bytes}) -> Result<#{Error}, #{JsonError}> { // Note: HeaderMap::new() doesn't allocate diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt index b09092f4672..268abc0d668 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/RestXml.kt @@ -53,8 +53,8 @@ open class RestXml(val codegenContext: CodegenContext) : Protocol { } override fun parseHttpGenericError(operationShape: OperationShape): RuntimeType = - RuntimeType.forInlineFun("parse_http_generic_error", xmlDeserModule) { writer -> - writer.rustBlockTemplate( + RuntimeType.forInlineFun("parse_http_generic_error", xmlDeserModule) { + rustBlockTemplate( "pub fn parse_http_generic_error(response: &#{Response}<#{Bytes}>) -> Result<#{Error}, #{XmlError}>", *errorScope, ) { @@ -63,8 +63,8 @@ open class RestXml(val codegenContext: CodegenContext) : Protocol { } override fun parseEventStreamGenericError(operationShape: OperationShape): RuntimeType = - RuntimeType.forInlineFun("parse_event_stream_generic_error", xmlDeserModule) { writer -> - writer.rustBlockTemplate( + RuntimeType.forInlineFun("parse_event_stream_generic_error", xmlDeserModule) { + rustBlockTemplate( "pub fn parse_event_stream_generic_error(payload: &#{Bytes}) -> Result<#{Error}, #{XmlError}>", *errorScope, ) { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt index 97d6bb1c832..2d3e07957fa 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/EventStreamUnmarshallerGenerator.kt @@ -79,8 +79,8 @@ class EventStreamUnmarshallerGenerator( fun render(): RuntimeType { val unmarshallerType = unionShape.eventStreamUnmarshallerType() - return RuntimeType.forInlineFun("${unmarshallerType.name}::new", eventStreamSerdeModule) { inlineWriter -> - inlineWriter.renderUnmarshaller(unmarshallerType, unionSymbol) + return RuntimeType.forInlineFun("${unmarshallerType.name}::new", eventStreamSerdeModule) { + renderUnmarshaller(unmarshallerType, unionSymbol) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt index 5169242adde..c56484e969c 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt @@ -20,9 +20,11 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.SparseTrait import software.amazon.smithy.model.traits.TimestampFormatTrait +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.escape import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -97,7 +99,7 @@ class JsonParserGenerator( ): RuntimeType { return RuntimeType.forInlineFun(fnName, jsonDeserModule) { val unusedMut = if (includedMembers.isEmpty()) "##[allow(unused_mut)] " else "" - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(value: &[u8], ${unusedMut}mut builder: #{Builder}) -> Result<#{Builder}, #{Error}>", "Builder" to structureShape.builderSymbol(symbolProvider), *codegenScope, @@ -122,7 +124,7 @@ class JsonParserGenerator( check(shape is UnionShape || shape is StructureShape || shape is DocumentShape) { "payload parser should only be used on structures & unions" } val fnName = symbolProvider.deserializeFunctionName(shape) + "_payload" return RuntimeType.forInlineFun(fnName, jsonDeserModule) { - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(input: &[u8]) -> Result<#{Shape}, #{Error}>", *codegenScope, "Shape" to symbolProvider.toSymbol(shape), @@ -169,7 +171,7 @@ class JsonParserGenerator( } private fun orEmptyJson(): RuntimeType = RuntimeType.forInlineFun("or_empty_doc", jsonDeserModule) { - it.rust( + rust( """ pub fn or_empty_doc(data: &[u8]) -> &[u8] { if data.is_empty() { @@ -312,7 +314,7 @@ class JsonParserGenerator( val parser = RuntimeType.forInlineFun(fnName, jsonDeserModule) { // Allow non-snake-case since some SDK models have lists with names prefixed with `__listOf__`, // which become `__list_of__`, and the Rust compiler warning doesn't like multiple adjacent underscores. - it.rustBlockTemplate( + rustBlockTemplate( """ ##[allow(clippy::type_complexity, non_snake_case)] pub fn $fnName<'a, I>(tokens: &mut #{Peekable}) -> Result, #{Error}> @@ -358,7 +360,7 @@ class JsonParserGenerator( val parser = RuntimeType.forInlineFun(fnName, jsonDeserModule) { // Allow non-snake-case since some SDK models have maps with names prefixed with `__mapOf__`, // which become `__map_of__`, and the Rust compiler warning doesn't like multiple adjacent underscores. - it.rustBlockTemplate( + rustBlockTemplate( """ ##[allow(clippy::type_complexity, non_snake_case)] pub fn $fnName<'a, I>(tokens: &mut #{Peekable}) -> Result, #{Error}> @@ -398,7 +400,7 @@ class JsonParserGenerator( val fnName = symbolProvider.deserializeFunctionName(shape) val symbol = symbolProvider.toSymbol(shape) val nestedParser = RuntimeType.forInlineFun(fnName, jsonDeserModule) { - it.rustBlockTemplate( + rustBlockTemplate( """ pub fn $fnName<'a, I>(tokens: &mut #{Peekable}) -> Result, #{Error}> where I: Iterator, #{Error}>> @@ -407,7 +409,7 @@ class JsonParserGenerator( *codegenScope, ) { startObjectOrNull { - software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) + Attribute.AllowUnusedMut.render(this) rustTemplate("let mut builder = #{Shape}::builder();", *codegenScope, "Shape" to symbol) deserializeStructInner(shape.members()) withBlock("Ok(Some(builder.build()", "))") { @@ -430,7 +432,7 @@ class JsonParserGenerator( val fnName = symbolProvider.deserializeFunctionName(shape) val symbol = symbolProvider.toSymbol(shape) val nestedParser = RuntimeType.forInlineFun(fnName, jsonDeserModule) { - it.rustBlockTemplate( + rustBlockTemplate( """ pub fn $fnName<'a, I>(tokens: &mut #{Peekable}) -> Result, #{Error}> where I: Iterator, #{Error}>> @@ -508,7 +510,7 @@ class JsonParserGenerator( } } - private fun RustWriter.objectKeyLoop(hasMembers: Boolean, inner: RustWriter.() -> Unit) { + private fun RustWriter.objectKeyLoop(hasMembers: Boolean, inner: Writable) { if (!hasMembers) { rustTemplate("#{skip_to_end}(tokens)?;", *codegenScope) } else { @@ -532,9 +534,9 @@ class JsonParserGenerator( } } - private fun RustWriter.startArrayOrNull(inner: RustWriter.() -> Unit) = startOrNull("array", inner) - private fun RustWriter.startObjectOrNull(inner: RustWriter.() -> Unit) = startOrNull("object", inner) - private fun RustWriter.startOrNull(objectOrArray: String, inner: RustWriter.() -> Unit) { + private fun RustWriter.startArrayOrNull(inner: Writable) = startOrNull("array", inner) + private fun RustWriter.startObjectOrNull(inner: Writable) = startOrNull("object", inner) + private fun RustWriter.startOrNull(objectOrArray: String, inner: Writable) { rustBlockTemplate("match tokens.next().transpose()?", *codegenScope) { rustBlockTemplate( """ diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt index 92ab1a4971b..3805c67c80d 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt @@ -28,6 +28,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.conditionalBlock import software.amazon.smithy.rust.codegen.core.rustlang.escape @@ -132,7 +133,7 @@ class XmlBindingTraitParserGenerator( check(shape is UnionShape || shape is StructureShape) { "payload parser should only be used on structures & unions" } val fnName = symbolProvider.deserializeFunctionName(member) return RuntimeType.forInlineFun(fnName, xmlDeserModule) { - it.rustBlock( + rustBlock( "pub fn $fnName(inp: &[u8]) -> Result<#1T, #2T>", symbolProvider.toSymbol(shape), xmlError, @@ -183,8 +184,8 @@ class XmlBindingTraitParserGenerator( return null } return RuntimeType.forInlineFun(fnName, xmlDeserModule) { - Attribute.AllowUnusedMut.render(it) - it.rustBlock( + Attribute.AllowUnusedMut.render(this) + rustBlock( "pub fn $fnName(inp: &[u8], mut builder: #1T) -> Result<#1T, #2T>", outputShape.builderSymbol(symbolProvider), xmlError, @@ -216,8 +217,8 @@ class XmlBindingTraitParserGenerator( override fun errorParser(errorShape: StructureShape): RuntimeType { val fnName = symbolProvider.deserializeFunctionName(errorShape) + "_xml_err" return RuntimeType.forInlineFun(fnName, xmlDeserModule) { - Attribute.AllowUnusedMut.render(it) - it.rustBlock( + Attribute.AllowUnusedMut.render(this) + rustBlock( "pub fn $fnName(inp: &[u8], mut builder: #1T) -> Result<#1T, #2T>", errorShape.builderSymbol(symbolProvider), xmlError, @@ -250,8 +251,8 @@ class XmlBindingTraitParserGenerator( return null } return RuntimeType.forInlineFun(fnName, xmlDeserModule) { - Attribute.AllowUnusedMut.render(it) - it.rustBlock( + Attribute.AllowUnusedMut.render(this) + rustBlock( "pub fn $fnName(inp: &[u8], mut builder: #1T) -> Result<#1T, #2T>", inputShape.builderSymbol(symbolProvider), xmlError, @@ -409,7 +410,7 @@ class XmlBindingTraitParserGenerator( val fnName = symbolProvider.deserializeFunctionName(shape) val symbol = symbolProvider.toSymbol(shape) val nestedParser = RuntimeType.forInlineFun(fnName, xmlDeserModule) { - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(decoder: &mut #{ScopedDecoder}) -> Result<#{Shape}, #{XmlError}>", *codegenScope, "Shape" to symbol, ) { @@ -447,7 +448,7 @@ class XmlBindingTraitParserGenerator( /** * The match clause to check if the tag matches a given member */ - private fun RustWriter.case(member: MemberShape, inner: RustWriter.() -> Unit) { + private fun RustWriter.case(member: MemberShape, inner: Writable) { rustBlock( "s if ${ member.xmlName().matchExpression("s") @@ -462,11 +463,11 @@ class XmlBindingTraitParserGenerator( val fnName = symbolProvider.deserializeFunctionName(shape) val symbol = symbolProvider.toSymbol(shape) val nestedParser = RuntimeType.forInlineFun(fnName, xmlDeserModule) { - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(decoder: &mut #{ScopedDecoder}) -> Result<#{Shape}, #{XmlError}>", *codegenScope, "Shape" to symbol, ) { - software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) + Attribute.AllowUnusedMut.render(this) rustTemplate("let mut builder = #{Shape}::builder();", *codegenScope, "Shape" to symbol) val members = shape.xmlMembers() if (members.isNotEmpty()) { @@ -494,7 +495,7 @@ class XmlBindingTraitParserGenerator( val fnName = symbolProvider.deserializeFunctionName(target) val member = target.member val listParser = RuntimeType.forInlineFun(fnName, xmlDeserModule) { - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(decoder: &mut #{ScopedDecoder}) -> Result<#{List}, #{XmlError}>", *codegenScope, "List" to symbolProvider.toSymbol(target), @@ -528,7 +529,7 @@ class XmlBindingTraitParserGenerator( private fun RustWriter.parseMap(target: MapShape, ctx: Ctx) { val fnName = symbolProvider.deserializeFunctionName(target) val mapParser = RuntimeType.forInlineFun(fnName, xmlDeserModule) { - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(decoder: &mut #{ScopedDecoder}) -> Result<#{Map}, #{XmlError}>", *codegenScope, "Map" to symbolProvider.toSymbol(target), @@ -565,7 +566,7 @@ class XmlBindingTraitParserGenerator( private fun mapEntryParser(target: MapShape, ctx: Ctx): RuntimeType { val fnName = symbolProvider.deserializeFunctionName(target) + "_entry" return RuntimeType.forInlineFun(fnName, xmlDeserModule) { - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(decoder: &mut #{ScopedDecoder}, out: &mut #{Map}) -> Result<(), #{XmlError}>", *codegenScope, "Map" to symbolProvider.toSymbol(target), @@ -606,7 +607,7 @@ class XmlBindingTraitParserGenerator( * Parse a simple member from a data field * [provider] generates code for the inner data field */ - private fun RustWriter.parsePrimitiveInner(member: MemberShape, provider: RustWriter.() -> Unit) { + private fun RustWriter.parsePrimitiveInner(member: MemberShape, provider: Writable) { when (val shape = model.expectShape(member.target)) { is StringShape -> parseStringInner(shape, provider) is NumberShape, is BooleanShape -> { @@ -655,7 +656,7 @@ class XmlBindingTraitParserGenerator( } } - private fun RustWriter.parseStringInner(shape: StringShape, provider: RustWriter.() -> Unit) { + private fun RustWriter.parseStringInner(shape: StringShape, provider: Writable) { withBlock("Result::<#T, #T>::Ok(", ")", symbolProvider.toSymbol(shape), xmlError) { if (shape.hasTrait()) { val enumSymbol = symbolProvider.toSymbol(shape) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt index 3d06da554c2..f71b4a96e14 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamErrorMarshallerGenerator.kt @@ -65,8 +65,8 @@ class EventStreamErrorMarshallerGenerator( val marshallerType = unionShape.eventStreamMarshallerType() val unionSymbol = symbolProvider.toSymbol(unionShape) - return RuntimeType.forInlineFun("${marshallerType.name}::new", eventStreamSerdeModule) { inlineWriter -> - inlineWriter.renderMarshaller(marshallerType, unionSymbol) + return RuntimeType.forInlineFun("${marshallerType.name}::new", eventStreamSerdeModule) { + renderMarshaller(marshallerType, unionSymbol) } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt index 133f2b9bb6b..918bb189259 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/EventStreamMarshallerGenerator.kt @@ -24,6 +24,7 @@ import software.amazon.smithy.model.traits.EventPayloadTrait import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.render import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock @@ -66,8 +67,8 @@ open class EventStreamMarshallerGenerator( val marshallerType = unionShape.eventStreamMarshallerType() val unionSymbol = symbolProvider.toSymbol(unionShape) - return RuntimeType.forInlineFun("${marshallerType.name}::new", eventStreamSerdeModule) { inlineWriter -> - inlineWriter.renderMarshaller(marshallerType, unionSymbol) + return RuntimeType.forInlineFun("${marshallerType.name}::new", eventStreamSerdeModule) { + renderMarshaller(marshallerType, unionSymbol) } } @@ -227,7 +228,7 @@ open class EventStreamMarshallerGenerator( inputExpr: String, someName: String, writeSomeCase: RustWriter.(String) -> Unit, - writeNoneCase: (RustWriter.() -> Unit)? = null, + writeNoneCase: (Writable)? = null, ) { if (optional) { rustBlock("if let Some($someName) = $inputExpr") { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt index e9501ecdddd..bd527f5caea 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGenerator.kt @@ -176,7 +176,7 @@ class JsonSerializerGenerator( includedMembers: List, ): RuntimeType { return RuntimeType.forInlineFun(fnName, operationSerModule) { - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(value: &#{target}) -> Result", *codegenScope, "target" to symbolProvider.toSymbol(structureShape), @@ -194,8 +194,8 @@ class JsonSerializerGenerator( override fun payloadSerializer(member: MemberShape): RuntimeType { val fnName = symbolProvider.serializeFunctionName(member) val target = model.expectShape(member.target) - return RuntimeType.forInlineFun(fnName, operationSerModule) { writer -> - writer.rustBlockTemplate( + return RuntimeType.forInlineFun(fnName, operationSerModule) { + rustBlockTemplate( "pub fn $fnName(input: &#{target}) -> std::result::Result<#{ByteSlab}, #{Error}>", *codegenScope, "target" to symbolProvider.toSymbol(target), @@ -215,8 +215,8 @@ class JsonSerializerGenerator( override fun unsetStructure(structure: StructureShape): RuntimeType { val fnName = "rest_json_unsetpayload" - return RuntimeType.forInlineFun(fnName, operationSerModule) { writer -> - writer.rustTemplate( + return RuntimeType.forInlineFun(fnName, operationSerModule) { + rustTemplate( """ pub fn $fnName() -> #{ByteSlab} { b"{}"[..].into() @@ -237,7 +237,7 @@ class JsonSerializerGenerator( val inputShape = operationShape.inputShape(model) val fnName = symbolProvider.serializeFunctionName(operationShape) return RuntimeType.forInlineFun(fnName, operationSerModule) { - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(input: &#{target}) -> Result<#{SdkBody}, #{Error}>", *codegenScope, "target" to symbolProvider.toSymbol(inputShape), ) { @@ -253,7 +253,7 @@ class JsonSerializerGenerator( override fun documentSerializer(): RuntimeType { val fnName = "serialize_document" return RuntimeType.forInlineFun(fnName, operationSerModule) { - it.rustTemplate( + rustTemplate( """ pub fn $fnName(input: &#{Document}) -> #{ByteSlab} { let mut out = String::new(); @@ -303,8 +303,8 @@ class JsonSerializerGenerator( ) { val fnName = symbolProvider.serializeFunctionName(context.shape) val structureSymbol = symbolProvider.toSymbol(context.shape) - val structureSerializer = RuntimeType.forInlineFun(fnName, jsonSerModule) { writer -> - writer.rustBlockTemplate( + val structureSerializer = RuntimeType.forInlineFun(fnName, jsonSerModule) { + rustBlockTemplate( "pub fn $fnName(object: &mut #{JsonObjectWriter}, input: &#{Input}) -> Result<(), #{Error}>", "Input" to structureSymbol, *codegenScope, @@ -435,8 +435,8 @@ class JsonSerializerGenerator( private fun RustWriter.serializeUnion(context: Context) { val fnName = symbolProvider.serializeFunctionName(context.shape) val unionSymbol = symbolProvider.toSymbol(context.shape) - val unionSerializer = RuntimeType.forInlineFun(fnName, jsonSerModule) { writer -> - writer.rustBlockTemplate( + val unionSerializer = RuntimeType.forInlineFun(fnName, jsonSerModule) { + rustBlockTemplate( "pub fn $fnName(${context.writerExpression}: &mut #{JsonObjectWriter}, input: &#{Input}) -> Result<(), #{Error}>", "Input" to unionSymbol, *codegenScope, diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt index 518da051a35..70808148df7 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/QuerySerializerGenerator.kt @@ -127,8 +127,8 @@ abstract class QuerySerializerGenerator(codegenContext: CodegenContext) : Struct override fun operationInputSerializer(operationShape: OperationShape): RuntimeType? { val fnName = symbolProvider.serializeFunctionName(operationShape) val inputShape = operationShape.inputShape(model) - return RuntimeType.forInlineFun(fnName, operationSerModule) { writer -> - writer.rustBlockTemplate( + return RuntimeType.forInlineFun(fnName, operationSerModule) { + rustBlockTemplate( "pub fn $fnName(input: &#{target}) -> Result<#{SdkBody}, #{Error}>", *codegenScope, "target" to symbolProvider.toSymbol(inputShape), ) { @@ -139,7 +139,7 @@ abstract class QuerySerializerGenerator(codegenContext: CodegenContext) : Struct rust("let _ = input;") } rust("let mut out = String::new();") - Attribute.AllowUnusedMut.render(writer) + Attribute.AllowUnusedMut.render(this) rustTemplate( "let mut writer = #{QueryWriter}::new(&mut out, ${action.dq()}, ${version.dq()});", *codegenScope, @@ -154,9 +154,9 @@ abstract class QuerySerializerGenerator(codegenContext: CodegenContext) : Struct private fun RustWriter.serializeStructure(context: Context) { val fnName = symbolProvider.serializeFunctionName(context.shape) val structureSymbol = symbolProvider.toSymbol(context.shape) - val structureSerializer = RuntimeType.forInlineFun(fnName, querySerModule) { writer -> - software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(writer) - writer.rustBlockTemplate( + val structureSerializer = RuntimeType.forInlineFun(fnName, querySerModule) { + Attribute.AllowUnusedMut.render(this) + rustBlockTemplate( "pub fn $fnName(mut writer: #{QueryValueWriter}, input: &#{Input}) -> Result<(), #{Error}>", "Input" to structureSymbol, *codegenScope, @@ -248,7 +248,7 @@ abstract class QuerySerializerGenerator(codegenContext: CodegenContext) : Struct private fun RustWriter.structWriter(context: MemberContext, inner: RustWriter.(String) -> Unit) { val prefix = context.shape.queryKeyName() safeName("scope").also { scopeName -> - software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) + Attribute.AllowUnusedMut.render(this) rust("let mut $scopeName = ${context.writerExpression}.prefix(${prefix.dq()});") inner(scopeName) } @@ -265,7 +265,7 @@ abstract class QuerySerializerGenerator(codegenContext: CodegenContext) : Struct rust("let mut $listName = ${context.writerExpression}.start_list($flat, $memberOverride);") rustBlock("for $itemName in ${context.valueExpression.asRef()}") { val entryName = safeName("entry") - software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) + Attribute.AllowUnusedMut.render(this) rust("let mut $entryName = $listName.entry();") val targetShape = model.expectShape(context.shape.member.target) serializeMemberValue( @@ -292,7 +292,7 @@ abstract class QuerySerializerGenerator(codegenContext: CodegenContext) : Struct else -> keyName } val entryName = safeName("entry") - software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) + Attribute.AllowUnusedMut.render(this) rust("let mut $entryName = $mapName.entry($keyExpression);") serializeMember(MemberContext(entryName, ValueExpression.Reference(valueName), context.shape.value)) } @@ -303,9 +303,9 @@ abstract class QuerySerializerGenerator(codegenContext: CodegenContext) : Struct private fun RustWriter.serializeUnion(context: Context) { val fnName = symbolProvider.serializeFunctionName(context.shape) val unionSymbol = symbolProvider.toSymbol(context.shape) - val unionSerializer = RuntimeType.forInlineFun(fnName, querySerModule) { writer -> - software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(writer) - writer.rustBlockTemplate( + val unionSerializer = RuntimeType.forInlineFun(fnName, querySerModule) { + Attribute.AllowUnusedMut.render(this) + rustBlockTemplate( "pub fn $fnName(mut writer: #{QueryValueWriter}, input: &#{Input}) -> Result<(), #{Error}>", "Input" to unionSymbol, *codegenScope, diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/SerializerUtil.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/SerializerUtil.kt index a780218e892..98bdc80aa0b 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/SerializerUtil.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/SerializerUtil.kt @@ -13,10 +13,11 @@ import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.NumberShape import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock class SerializerUtil(private val model: Model) { - fun RustWriter.ignoreZeroValues(shape: MemberShape, value: ValueExpression, inner: RustWriter.() -> Unit) { + fun RustWriter.ignoreZeroValues(shape: MemberShape, value: ValueExpression, inner: Writable) { val expr = when (model.expectShape(shape.target)) { is FloatShape, is DoubleShape -> "${value.asValue()} != 0.0" is NumberShape -> "${value.asValue()} != 0" diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt index 285f362f363..2ca848e075a 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGenerator.kt @@ -22,6 +22,7 @@ import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.TimestampFormatTrait import software.amazon.smithy.model.traits.XmlFlattenedTrait import software.amazon.smithy.model.traits.XmlNamespaceTrait +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustType @@ -111,13 +112,14 @@ class XmlBindingTraitSerializerGenerator( val operationXmlName = xmlIndex.operationInputShapeName(operationShape) ?: throw CodegenException("operation must have a name if it has members") return RuntimeType.forInlineFun(fnName, operationSerModule) { - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(input: &#{target}) -> Result<#{SdkBody}, #{Error}>", *codegenScope, "target" to symbolProvider.toSymbol(inputShape), ) { rust("let mut out = String::new();") - // create a scope for writer. This ensure that writer has been dropped before returning the - // string and ensures that all closing tags get written + // Create a scope for writer. This ensures that: + // - The writer is dropped before returning the string + // - All closing tags get written rustBlock("") { rustTemplate( """ @@ -143,13 +145,14 @@ class XmlBindingTraitSerializerGenerator( val target = model.expectShape(member.target) return RuntimeType.forInlineFun(fnName, xmlSerModule) { val t = symbolProvider.toSymbol(member).rustType().stripOuter().render(true) - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(input: &$t) -> std::result::Result, #{Error}>", *codegenScope, ) { rust("let mut out = String::new();") - // create a scope for writer. This ensure that writer has been dropped before returning the - // string and ensures that all closing tags get written + // Create a scope for writer. This ensures that: + // - The writer is dropped before returning the string + // - All closing tags get written rustBlock("") { rustTemplate( """ @@ -178,8 +181,8 @@ class XmlBindingTraitSerializerGenerator( override fun unsetStructure(structure: StructureShape): RuntimeType { val fnName = "rest_xml_unset_payload" - return RuntimeType.forInlineFun(fnName, operationSerModule) { writer -> - writer.rustTemplate( + return RuntimeType.forInlineFun(fnName, operationSerModule) { + rustTemplate( """ pub fn $fnName() -> #{ByteSlab} { Vec::new() @@ -200,13 +203,14 @@ class XmlBindingTraitSerializerGenerator( val operationXmlName = xmlIndex.operationOutputShapeName(operationShape) ?: throw CodegenException("operation must have a name if it has members") return RuntimeType.forInlineFun(fnName, operationSerModule) { - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(output: &#{target}) -> Result", *codegenScope, "target" to symbolProvider.toSymbol(outputShape), ) { rust("let mut out = String::new();") - // create a scope for writer. This ensure that writer has been dropped before returning the - // string and ensures that all closing tags get written + // Create a scope for writer. This ensures that: + // - The writer is dropped before returning the string + // - All closing tags get written rustBlock("") { rustTemplate( """ @@ -230,13 +234,14 @@ class XmlBindingTraitSerializerGenerator( .map { it.member } val fnName = symbolProvider.serializeFunctionName(errorShape) return RuntimeType.forInlineFun(fnName, operationSerModule) { - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(error: &#{target}) -> Result", *codegenScope, "target" to symbolProvider.toSymbol(errorShape), ) { rust("let mut out = String::new();") - // create a scope for writer. This ensure that writer has been dropped before returning the - // string and ensures that all closing tags get written + // Create a scope for writer. This ensures that: + // - The writer is dropped before returning the string + // - All closing tags get written rustBlock("") { rustTemplate( """ @@ -274,7 +279,7 @@ class XmlBindingTraitSerializerGenerator( } } } - software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) + Attribute.AllowUnusedMut.render(this) rust("let mut scope = ${ctx.elementWriter}.finish();") val scopeCtx = Ctx.Scope("scope", ctx.input) members.dataMembers.forEach { member -> @@ -359,7 +364,7 @@ class XmlBindingTraitSerializerGenerator( val structureSymbol = symbolProvider.toSymbol(structureShape) val fnName = symbolProvider.serializeFunctionName(structureShape) val structureSerializer = RuntimeType.forInlineFun(fnName, xmlSerModule) { - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(input: &#{Input}, writer: #{ElementWriter}) -> Result<(), #{Error}>", "Input" to structureSymbol, *codegenScope, @@ -379,7 +384,7 @@ class XmlBindingTraitSerializerGenerator( val fnName = symbolProvider.serializeFunctionName(unionShape) val unionSymbol = symbolProvider.toSymbol(unionShape) val structureSerializer = RuntimeType.forInlineFun(fnName, xmlSerModule) { - it.rustBlockTemplate( + rustBlockTemplate( "pub fn $fnName(input: &#{Input}, writer: #{ElementWriter}) -> Result<(), #{Error}>", "Input" to unionSymbol, *codegenScope, diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt index b45b014c0e8..b8868151ae9 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/Rust.kt @@ -20,6 +20,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.raw import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock import software.amazon.smithy.rust.codegen.core.smithy.CoreCodegenConfig @@ -183,7 +184,7 @@ fun RustWriter.unitTest( fun RustWriter.unitTest( name: String, vararg args: Any, - block: RustWriter.() -> Unit, + block: Writable, ): RustWriter { raw("#[test]") return rustBlock("fn $name()", *args, block = block) diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/InlineDependencyTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/InlineDependencyTest.kt index 121578abd18..1d8448c3060 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/InlineDependencyTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/InlineDependencyTest.kt @@ -12,17 +12,17 @@ import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest internal class InlineDependencyTest { private fun makeDep(name: String) = InlineDependency(name, RustModule.private("module")) { - it.rustBlock("fn foo()") {} + rustBlock("fn foo()") {} } @Test fun `equal dependencies should be equal`() { - val depa = makeDep("func") - val depb = makeDep("func") - depa.renderer shouldBe depb.renderer - depa.key() shouldBe depb.key() + val depA = makeDep("func") + val depB = makeDep("func") + depA.renderer shouldBe depB.renderer + depA.key() shouldBe depB.key() - depa.key() shouldNotBe makeDep("func2").key() + depA.key() shouldNotBe makeDep("func2").key() } @Test @@ -30,7 +30,7 @@ internal class InlineDependencyTest { val dep = InlineDependency.idempotencyToken() val testWriter = RustWriter.root() testWriter.addDependency(CargoDependency.FastRand) - testWriter.withModule(dep.module.name) { + testWriter.withModule(dep.module.copy(rustMetadata = RustMetadata(visibility = Visibility.PUBLIC))) { dep.renderer(this) } testWriter.compileAndTest( diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustGenericsTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustGenericsTest.kt index 5b711dafa69..87004473c4d 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustGenericsTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustGenericsTest.kt @@ -109,19 +109,19 @@ class RustGenericsTest { val ggB = RustGenerics( GenericTypeArg("B", testRT("Banana")), ) - RustWriter.forModule("model").let { writer -> - writer.rustTemplate("#{bounds:W}", "bounds" to (ggA + ggB).bounds()) + RustWriter.forModule("model").let { + it.rustTemplate("#{bounds:W}", "bounds" to (ggA + ggB).bounds()) - writer.toString() shouldContain """ + it.toString() shouldContain """ A: test::Apple, B: test::Banana, """.trimIndent() } - RustWriter.forModule("model").let { writer -> - writer.rustTemplate("#{decl:W}", "decl" to (ggA + ggB).declaration()) + RustWriter.forModule("model").let { + it.rustTemplate("#{decl:W}", "decl" to (ggA + ggB).declaration()) - writer.toString() shouldContain "" + it.toString() shouldContain "" } } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt index e090bd385fb..a721b9ad66b 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/rustlang/RustWriterTest.kt @@ -27,7 +27,7 @@ class RustWriterTest { fun `inner modules correctly handle dependencies`() { val sut = RustWriter.forModule("parent") val requestBuilder = RuntimeType.HttpRequestBuilder - sut.withModule("inner") { + sut.withModule(RustModule.public("inner")) { rustBlock("fn build(builder: #T)", requestBuilder) { } } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGeneratorTest.kt index a60f32c92e9..c57ebdc727f 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/CargoTomlGeneratorTest.kt @@ -19,9 +19,9 @@ class CargoTomlGeneratorTest { @Test fun `adds codegen version to package metadata`() { val project = TestWorkspace.testProject() - project.lib { writer -> - writer.addDependency(CargoMetadata) - writer.unitTest( + project.lib { + addDependency(CargoMetadata) + unitTest( "smithy_codegen_version_in_package_metadata", """ let metadata = cargo_metadata::MetadataCommand::new() diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/InstantiatorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/InstantiatorTest.kt index 9bf232cc600..c6f592adeb8 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/InstantiatorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/InstantiatorTest.kt @@ -13,6 +13,7 @@ import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.raw import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock @@ -107,10 +108,10 @@ class InstantiatorTest { private val symbolProvider = testSymbolProvider(model) private val runtimeConfig = TestRuntimeConfig - fun RustWriter.test(block: RustWriter.() -> Unit) { + fun RustWriter.test(block: Writable) { raw("#[test]") rustBlock("fn inst()") { - block(this) + block() } } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGeneratorTest.kt index 944c9a17382..110e7f35a98 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGeneratorTest.kt @@ -11,9 +11,8 @@ import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.rust.codegen.core.rustlang.Attribute -import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.Visibility import software.amazon.smithy.rust.codegen.core.rustlang.docs import software.amazon.smithy.rust.codegen.core.rustlang.raw import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -82,17 +81,17 @@ class StructureGeneratorTest { fun `generate basic structures`() { val provider = testSymbolProvider(model) val project = TestWorkspace.testProject(provider) - project.useShapeWriter(inner) { writer -> - StructureGenerator(model, provider, writer, inner).render() - StructureGenerator(model, provider, writer, struct).render() - writer.unitTest( + project.useShapeWriter(inner) { + StructureGenerator(model, provider, this, inner).render() + StructureGenerator(model, provider, this, struct).render() + unitTest( "struct_fields_optional", """ let s: Option = None; s.map(|i|println!("{:?}, {:?}", i.ts, i.byte_value)); """, ) - writer.toString().shouldContainInOrder( + toString().shouldContainInOrder( "this documents the shape", "#[non_exhaustive]", "pub", "struct MyStruct", ) } @@ -104,17 +103,17 @@ class StructureGeneratorTest { val provider = testSymbolProvider(model) val writer = RustWriter.root() writer.rust("##![allow(deprecated)]") - writer.withModule("model") { + writer.withModule(RustModule.public("model")) { val innerGenerator = StructureGenerator(model, provider, this, inner) innerGenerator.render() } - writer.withModule("structs") { + writer.withModule(RustModule.public("structs")) { val generator = StructureGenerator(model, provider, this, struct) generator.render() } // By putting the test in another module, it can't access the struct // fields if they are private - writer.withModule("inline") { + writer.withModule(RustModule.public("inline")) { raw("#[test]") rustBlock("fn test_public_fields()") { write( @@ -182,18 +181,11 @@ class StructureGeneratorTest { val provider = testSymbolProvider(model) val writer = RustWriter.root() writer.docs("module docs") - writer - .withModule( - "model", - RustMetadata( - // By attaching this lint, any missing documentation becomes a compiler error. - additionalAttributes = listOf(Attribute.Custom("deny(missing_docs)")), - visibility = Visibility.PUBLIC, - ), - ) { - StructureGenerator(model, provider, this, model.lookup("com.test#Inner")).render() - StructureGenerator(model, provider, this, model.lookup("com.test#MyStruct")).render() - } + Attribute.Custom("deny(missing_docs)").render(writer) + writer.withModule(RustModule.public("model")) { + StructureGenerator(model, provider, this, model.lookup("com.test#Inner")).render() + StructureGenerator(model, provider, this, model.lookup("com.test#MyStruct")).render() + } writer.compileAndTest() } @@ -234,7 +226,7 @@ class StructureGeneratorTest { val provider = testSymbolProvider(model) val writer = RustWriter.root() writer.rust("##![allow(deprecated)]") - writer.withModule("model") { + writer.withModule(RustModule.public("model")) { StructureGenerator(model, provider, this, model.lookup("test#Foo")).render() StructureGenerator(model, provider, this, model.lookup("test#Bar")).render() StructureGenerator(model, provider, this, model.lookup("test#Baz")).render() @@ -267,7 +259,7 @@ class StructureGeneratorTest { val provider = testSymbolProvider(model) val writer = RustWriter.root() writer.rust("##![allow(deprecated)]") - writer.withModule("model") { + writer.withModule(RustModule.public("model")) { StructureGenerator(model, provider, this, model.lookup("test#Nested")).render() StructureGenerator(model, provider, this, model.lookup("test#Foo")).render() StructureGenerator(model, provider, this, model.lookup("test#Bar")).render() @@ -316,13 +308,11 @@ class StructureGeneratorTest { val provider = testSymbolProvider(testModel) val project = TestWorkspace.testProject(provider) - project.useShapeWriter(inner) { writer -> - writer.withModule("model") { - StructureGenerator(testModel, provider, writer, testModel.lookup("test#One")).render() - StructureGenerator(testModel, provider, writer, testModel.lookup("test#Two")).render() - } + project.useShapeWriter(inner) { + StructureGenerator(testModel, provider, this, testModel.lookup("test#One")).render() + StructureGenerator(testModel, provider, this, testModel.lookup("test#Two")).render() - writer.rustBlock("fn compile_test_one(one: &crate::model::One)") { + rustBlock("fn compile_test_one(one: &crate::model::One)") { rust( """ let _: Option<&str> = one.field_string(); @@ -350,7 +340,7 @@ class StructureGeneratorTest { """, ) } - writer.rustBlock("fn compile_test_two(two: &crate::model::Two)") { + rustBlock("fn compile_test_two(two: &crate::model::Two)") { rust( """ let _: Option<&crate::model::One> = two.one(); @@ -376,9 +366,9 @@ class StructureGeneratorTest { val struct = model.lookup("com.test#MyStruct") val provider = testSymbolProvider(model) - RustWriter.forModule("test").let { writer -> - StructureGenerator(model, provider, writer, struct).render() - assertEquals(6, writer.toString().split("#[doc(hidden)]").size, "there should be 5 doc-hiddens") + RustWriter.forModule("test").let { + StructureGenerator(model, provider, it, struct).render() + assertEquals(6, it.toString().split("#[doc(hidden)]").size, "there should be 5 doc-hiddens") } } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGeneratorTest.kt index 15a733b0d7b..043941bfe18 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/UnionGeneratorTest.kt @@ -8,6 +8,7 @@ package software.amazon.smithy.rust.codegen.core.smithy.generators import io.kotest.matchers.string.shouldContain import org.junit.jupiter.api.Test import software.amazon.smithy.codegen.core.SymbolProvider +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel @@ -114,7 +115,7 @@ class UnionGeneratorTest { val provider: SymbolProvider = testSymbolProvider(model) val writer = RustWriter.root() writer.rust("##![allow(deprecated)]") - writer.withModule("model") { + writer.withModule(RustModule.public("model")) { UnionGenerator(model, provider, this, model.lookup("test#Nested")).render() UnionGenerator(model, provider, this, model.lookup("test#Foo")).render() UnionGenerator(model, provider, this, model.lookup("test#Bar")).render() diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGeneratorTest.kt index 24f0e85f9c3..d84e50b5cc5 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGeneratorTest.kt @@ -50,15 +50,15 @@ class CombinedErrorGeneratorTest { @Test fun `generates combined error enums`() { val project = TestWorkspace.testProject(symbolProvider) - project.withModule(RustModule.public("error")) { writer -> + project.withModule(RustModule.public("error")) { listOf("FooException", "ComplexError", "InvalidGreeting", "Deprecated").forEach { - model.lookup("error#$it").renderWithModelBuilder(model, symbolProvider, writer) + model.lookup("error#$it").renderWithModelBuilder(model, symbolProvider, this) } val errors = listOf("FooException", "ComplexError", "InvalidGreeting").map { model.lookup("error#$it") } val generator = CombinedErrorGenerator(model, symbolProvider, symbolProvider.toSymbol(model.lookup("error#Greeting")), errors) - generator.render(writer) + generator.render(this) - writer.unitTest( + unitTest( name = "generates_combined_error_enums", test = """ let kind = GreetingErrorKind::InvalidGreeting(InvalidGreeting::builder().message("an error").build()); diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGeneratorTest.kt index b17e48cd921..d407af3fe44 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/TopLevelErrorGeneratorTest.kt @@ -8,8 +8,8 @@ package software.amazon.smithy.rust.codegen.core.smithy.generators.error import org.junit.jupiter.api.Test import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId +import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.RustModule -import software.amazon.smithy.rust.codegen.core.rustlang.rust import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings @@ -79,13 +79,13 @@ internal class TopLevelErrorGeneratorTest { codegenContext.settings.codegenConfig, ) - rustCrate.lib { writer -> - writer.rust("##![allow(deprecated)]") + rustCrate.lib { + Attribute.AllowDeprecated.copy(container = true).render(this) } - rustCrate.withModule(RustModule.Error) { writer -> + rustCrate.withModule(RustModule.Error) { for (shape in model.structureShapes) { if (shape.id.namespace == "com.example") { - StructureGenerator(model, symbolProvider, writer, shape).render(CodegenTarget.CLIENT) + StructureGenerator(model, symbolProvider, this, shape).render(CodegenTarget.CLIENT) } } } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt index b1eeab627b8..c9e292cdb71 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/RequestBindingGeneratorTest.kt @@ -163,11 +163,10 @@ class RequestBindingGeneratorTest { @Test fun `generates valid request bindings`() { val project = TestWorkspace.testProject(symbolProvider) - project.withModule(RustModule.public("input")) { writer -> - // Currently rendering the operation renders the protocols—I want to separate that at some point. - renderOperation(writer) + project.withModule(RustModule.public("input")) { // Currently rendering the operation renders the protocols—I want to separate that at some point. + renderOperation(this) - writer.unitTest( + unitTest( name = "generate_uris", test = """ let ts = aws_smithy_types::DateTime::from_secs(10123125); @@ -186,7 +185,7 @@ class RequestBindingGeneratorTest { """, ) - writer.unitTest( + unitTest( name = "serialize_non_zero_values", test = """ let ts = aws_smithy_types::DateTime::from_secs(10123125); @@ -202,7 +201,7 @@ class RequestBindingGeneratorTest { """, ) - writer.unitTest( + unitTest( name = "build_http_requests", test = """ use std::collections::HashMap; @@ -235,7 +234,7 @@ class RequestBindingGeneratorTest { """, ) - writer.unitTest( + unitTest( name = "invalid_header_name_produces_error", test = """ use std::collections::HashMap; @@ -250,7 +249,7 @@ class RequestBindingGeneratorTest { """, ) - writer.unitTest( + unitTest( name = "invalid_prefix_header_value_produces_an_error", test = """ use std::collections::HashMap; @@ -265,7 +264,7 @@ class RequestBindingGeneratorTest { """, ) - writer.unitTest( + unitTest( name = "invalid_header_value_produces_an_error", test = """ let ts = aws_smithy_types::DateTime::from_secs(10123125); @@ -280,7 +279,7 @@ class RequestBindingGeneratorTest { """, ) - writer.unitTest( + unitTest( name = "missing_uri_label_produces_an_error", test = """ let ts = aws_smithy_types::DateTime::from_secs(10123125); @@ -290,11 +289,11 @@ class RequestBindingGeneratorTest { .key(ts.clone()) .build().unwrap(); let err = inp.test_request_builder_base().expect_err("can't build request with bucket unset"); - assert!(matches!(err, ${writer.format(TestRuntimeConfig.operationBuildError())}::MissingField { .. })) + assert!(matches!(err, ${format(TestRuntimeConfig.operationBuildError())}::MissingField { .. })) """, ) - writer.unitTest( + unitTest( name = "missing_timestamp_uri_label_produces_an_error", test = """ let ts = aws_smithy_types::DateTime::from_secs(10123125); @@ -304,11 +303,11 @@ class RequestBindingGeneratorTest { // .key(ts.clone()) .build().unwrap(); let err = inp.test_request_builder_base().expect_err("can't build request with bucket unset"); - assert!(matches!(err, ${writer.format(TestRuntimeConfig.operationBuildError())}::MissingField { .. })) + assert!(matches!(err, ${format(TestRuntimeConfig.operationBuildError())}::MissingField { .. })) """, ) - writer.unitTest( + unitTest( name = "empty_uri_label_produces_an_error", test = """ let ts = aws_smithy_types::DateTime::from_secs(10123125); @@ -317,7 +316,7 @@ class RequestBindingGeneratorTest { .key(ts.clone()) .build().unwrap(); let err = inp.test_request_builder_base().expect_err("can't build request with bucket unset"); - assert!(matches!(err, ${writer.format(TestRuntimeConfig.operationBuildError())}::MissingField { .. })) + assert!(matches!(err, ${format(TestRuntimeConfig.operationBuildError())}::MissingField { .. })) """, ) } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/ResponseBindingGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/ResponseBindingGeneratorTest.kt index 5a56ec35460..12822e2077b 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/ResponseBindingGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/ResponseBindingGeneratorTest.kt @@ -93,8 +93,8 @@ class ResponseBindingGeneratorTest { fun deserializeHeadersIntoOutputShape() { val testProject = TestWorkspace.testProject(symbolProvider) testProject.withModule(RustModule.public("output")) { - it.renderOperation() - it.unitTest( + renderOperation() + unitTest( "http_header_deser", """ use crate::http_serde; diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/AwsQueryParserGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/AwsQueryParserGeneratorTest.kt index a655ef9ffbf..9b62daf7216 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/AwsQueryParserGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/AwsQueryParserGeneratorTest.kt @@ -51,8 +51,8 @@ class AwsQueryParserGeneratorTest { val operationParser = parserGenerator.operationParser(model.lookup("test#SomeOperation"))!! val project = TestWorkspace.testProject(testSymbolProvider(model)) - project.lib { writer -> - writer.unitTest( + project.lib { + unitTest( name = "valid_input", test = """ let xml = br#" @@ -62,7 +62,7 @@ class AwsQueryParserGeneratorTest { "#; - let output = ${writer.format(operationParser)}(xml, output::some_operation_output::Builder::default()).unwrap().build(); + let output = ${format(operationParser)}(xml, output::some_operation_output::Builder::default()).unwrap().build(); assert_eq!(output.some_attribute, Some(5)); assert_eq!(output.some_val, Some("Some value".to_string())); """, @@ -70,12 +70,12 @@ class AwsQueryParserGeneratorTest { } project.withModule(RustModule.public("model")) { - model.lookup("test#SomeOutput").renderWithModelBuilder(model, symbolProvider, it) + model.lookup("test#SomeOutput").renderWithModelBuilder(model, symbolProvider, this) } project.withModule(RustModule.public("output")) { model.lookup("test#SomeOperation").outputShape(model) - .renderWithModelBuilder(model, symbolProvider, it) + .renderWithModelBuilder(model, symbolProvider, this) } project.compileAndTest() } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/Ec2QueryParserGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/Ec2QueryParserGeneratorTest.kt index a4a10592adb..1b78bd1be0a 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/Ec2QueryParserGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/Ec2QueryParserGeneratorTest.kt @@ -51,8 +51,8 @@ class Ec2QueryParserGeneratorTest { val operationParser = parserGenerator.operationParser(model.lookup("test#SomeOperation"))!! val project = TestWorkspace.testProject(testSymbolProvider(model)) - project.lib { writer -> - writer.unitTest( + project.lib { + unitTest( "valid_input", """ let xml = br#" @@ -60,7 +60,7 @@ class Ec2QueryParserGeneratorTest { Some value "#; - let output = ${writer.format(operationParser)}(xml, output::some_operation_output::Builder::default()).unwrap().build(); + let output = ${format(operationParser)}(xml, output::some_operation_output::Builder::default()).unwrap().build(); assert_eq!(output.some_attribute, Some(5)); assert_eq!(output.some_val, Some("Some value".to_string())); """, @@ -68,12 +68,12 @@ class Ec2QueryParserGeneratorTest { } project.withModule(RustModule.public("model")) { - model.lookup("test#SomeOutput").renderWithModelBuilder(model, symbolProvider, it) + model.lookup("test#SomeOutput").renderWithModelBuilder(model, symbolProvider, this) } project.withModule(RustModule.public("output")) { model.lookup("test#SomeOperation").outputShape(model) - .renderWithModelBuilder(model, symbolProvider, it) + .renderWithModelBuilder(model, symbolProvider, this) } project.compileAndTest() } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGeneratorTest.kt index 81804625b7a..5c14080da65 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGeneratorTest.kt @@ -124,14 +124,14 @@ class JsonParserGeneratorTest { val errorParser = parserGenerator.errorParser(model.lookup("test#Error")) val project = TestWorkspace.testProject(testSymbolProvider(model)) - project.lib { writer -> - writer.unitTest( + project.lib { + unitTest( "json_parser", """ use model::Choice; // Generate the document serializer even though it's not tested directly - // ${writer.format(payloadGenerator)} + // ${format(payloadGenerator)} let json = br#" { "top": @@ -143,62 +143,62 @@ class JsonParserGeneratorTest { } "#; - let output = ${writer.format(operationGenerator!!)}(json, output::op_output::Builder::default()).unwrap().build(); + let output = ${format(operationGenerator!!)}(json, output::op_output::Builder::default()).unwrap().build(); let top = output.top.expect("top"); assert_eq!(Some(45), top.extra); assert_eq!(Some("something".to_string()), top.field); assert_eq!(Some(Choice::Int(5)), top.choice); """, ) - writer.unitTest( + unitTest( "empty_body", """ // empty body - let output = ${writer.format(operationGenerator)}(b"", output::op_output::Builder::default()).unwrap().build(); + let output = ${format(operationGenerator)}(b"", output::op_output::Builder::default()).unwrap().build(); assert_eq!(output.top, None); """, ) - writer.unitTest( + unitTest( "unknown_variant", """ // unknown variant let input = br#"{ "top": { "choice": { "somenewvariant": "data" } } }"#; - let output = ${writer.format(operationGenerator)}(input, output::op_output::Builder::default()).unwrap().build(); + let output = ${format(operationGenerator)}(input, output::op_output::Builder::default()).unwrap().build(); assert!(output.top.unwrap().choice.unwrap().is_unknown()); """, ) - writer.unitTest( + unitTest( "empty_error", """ // empty error - let error_output = ${writer.format(errorParser!!)}(b"", error::error::Builder::default()).unwrap().build(); + let error_output = ${format(errorParser!!)}(b"", error::error::Builder::default()).unwrap().build(); assert_eq!(error_output.message, None); """, ) - writer.unitTest( + unitTest( "error_with_message", """ // error with message - let error_output = ${writer.format(errorParser)}(br#"{"message": "hello"}"#, error::error::Builder::default()).unwrap().build(); + let error_output = ${format(errorParser)}(br#"{"message": "hello"}"#, error::error::Builder::default()).unwrap().build(); assert_eq!(error_output.message.expect("message should be set"), "hello"); """, ) } project.withModule(RustModule.public("model")) { - model.lookup("test#Top").renderWithModelBuilder(model, symbolProvider, it) - model.lookup("test#EmptyStruct").renderWithModelBuilder(model, symbolProvider, it) - UnionGenerator(model, symbolProvider, it, model.lookup("test#Choice")).render() + model.lookup("test#Top").renderWithModelBuilder(model, symbolProvider, this) + model.lookup("test#EmptyStruct").renderWithModelBuilder(model, symbolProvider, this) + UnionGenerator(model, symbolProvider, this, model.lookup("test#Choice")).render() val enum = model.lookup("test#FooEnum") - EnumGenerator(model, symbolProvider, it, enum, enum.expectTrait()).render() + EnumGenerator(model, symbolProvider, this, enum, enum.expectTrait()).render() } project.withModule(RustModule.public("output")) { - model.lookup("test#Op").outputShape(model).renderWithModelBuilder(model, symbolProvider, it) + model.lookup("test#Op").outputShape(model).renderWithModelBuilder(model, symbolProvider, this) } project.withModule(RustModule.public("error")) { - model.lookup("test#Error").renderWithModelBuilder(model, symbolProvider, it) + model.lookup("test#Error").renderWithModelBuilder(model, symbolProvider, this) } project.compileAndTest() } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGeneratorTest.kt index ae1fdfc02f7..323b64847cb 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGeneratorTest.kt @@ -98,8 +98,8 @@ internal class XmlBindingTraitParserGeneratorTest { ) { _, inner -> inner("decoder") } val operationParser = parserGenerator.operationParser(model.lookup("test#Op"))!! val project = TestWorkspace.testProject(testSymbolProvider(model)) - project.lib { writer -> - writer.unitTest( + project.lib { + unitTest( name = "valid_input", test = """ let xml = br#" @@ -114,7 +114,7 @@ internal class XmlBindingTraitParserGeneratorTest { hey "#; - let output = ${writer.format(operationParser)}(xml, output::op_output::Builder::default()).unwrap().build(); + let output = ${format(operationParser)}(xml, output::op_output::Builder::default()).unwrap().build(); let mut map = std::collections::HashMap::new(); map.insert("some key".to_string(), model::Choice::S("hello".to_string())); assert_eq!(output.choice, Some(model::Choice::FlatMap(map))); @@ -122,7 +122,7 @@ internal class XmlBindingTraitParserGeneratorTest { """, ) - writer.unitTest( + unitTest( name = "ignore_extras", test = """ let xml = br#" @@ -142,14 +142,14 @@ internal class XmlBindingTraitParserGeneratorTest { "#; - let output = ${writer.format(operationParser)}(xml, output::op_output::Builder::default()).unwrap().build(); + let output = ${format(operationParser)}(xml, output::op_output::Builder::default()).unwrap().build(); let mut map = std::collections::HashMap::new(); map.insert("some key".to_string(), model::Choice::S("hello".to_string())); assert_eq!(output.choice, Some(model::Choice::FlatMap(map))); """, ) - writer.unitTest( + unitTest( name = "nopanics_on_invalid", test = """ let xml = br#" @@ -169,10 +169,10 @@ internal class XmlBindingTraitParserGeneratorTest { "#; - ${writer.format(operationParser)}(xml, output::op_output::Builder::default()).expect("unknown union variant does not cause failure"); + ${format(operationParser)}(xml, output::op_output::Builder::default()).expect("unknown union variant does not cause failure"); """, ) - writer.unitTest( + unitTest( name = "unknown_union_variant", test = """ let xml = br#" @@ -186,20 +186,20 @@ internal class XmlBindingTraitParserGeneratorTest { "#; - let output = ${writer.format(operationParser)}(xml, output::op_output::Builder::default()).unwrap().build(); + let output = ${format(operationParser)}(xml, output::op_output::Builder::default()).unwrap().build(); assert!(output.choice.unwrap().is_unknown()); """, ) } project.withModule(RustModule.public("model")) { - model.lookup("test#Top").renderWithModelBuilder(model, symbolProvider, it) - UnionGenerator(model, symbolProvider, it, model.lookup("test#Choice")).render() + model.lookup("test#Top").renderWithModelBuilder(model, symbolProvider, this) + UnionGenerator(model, symbolProvider, this, model.lookup("test#Choice")).render() val enum = model.lookup("test#FooEnum") - EnumGenerator(model, symbolProvider, it, enum, enum.expectTrait()).render() + EnumGenerator(model, symbolProvider, this, enum, enum.expectTrait()).render() } project.withModule(RustModule.public("output")) { - model.lookup("test#Op").outputShape(model).renderWithModelBuilder(model, symbolProvider, it) + model.lookup("test#Op").outputShape(model).renderWithModelBuilder(model, symbolProvider, this) } project.compileAndTest() } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/AwsQuerySerializerGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/AwsQuerySerializerGeneratorTest.kt index 88a32316ee1..c200f897477 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/AwsQuerySerializerGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/AwsQuerySerializerGeneratorTest.kt @@ -99,8 +99,8 @@ class AwsQuerySerializerGeneratorTest { val operationGenerator = parserGenerator.operationInputSerializer(model.lookup("test#Op")) val project = TestWorkspace.testProject(testSymbolProvider(model)) - project.lib { writer -> - writer.unitTest( + project.lib { + unitTest( "query_serializer", """ use model::Top; @@ -116,7 +116,7 @@ class AwsQuerySerializerGeneratorTest { .boolean(true) .build() .unwrap(); - let serialized = ${writer.format(operationGenerator!!)}(&input).unwrap(); + let serialized = ${format(operationGenerator!!)}(&input).unwrap(); let output = std::str::from_utf8(serialized.bytes().unwrap()).unwrap(); assert_eq!( output, @@ -133,14 +133,14 @@ class AwsQuerySerializerGeneratorTest { ) } project.withModule(RustModule.public("model")) { - model.lookup("test#Top").renderWithModelBuilder(model, symbolProvider, it) - UnionGenerator(model, symbolProvider, it, model.lookup("test#Choice"), renderUnknownVariant = generateUnknownVariant).render() + model.lookup("test#Top").renderWithModelBuilder(model, symbolProvider, this) + UnionGenerator(model, symbolProvider, this, model.lookup("test#Choice"), renderUnknownVariant = generateUnknownVariant).render() val enum = model.lookup("test#FooEnum") - EnumGenerator(model, symbolProvider, it, enum, enum.expectTrait()).render() + EnumGenerator(model, symbolProvider, this, enum, enum.expectTrait()).render() } project.withModule(RustModule.public("input")) { - model.lookup("test#Op").inputShape(model).renderWithModelBuilder(model, symbolProvider, it) + model.lookup("test#Op").inputShape(model).renderWithModelBuilder(model, symbolProvider, this) } project.compileAndTest() } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/Ec2QuerySerializerGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/Ec2QuerySerializerGeneratorTest.kt index 6ae6fea2074..b84219da507 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/Ec2QuerySerializerGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/Ec2QuerySerializerGeneratorTest.kt @@ -91,8 +91,8 @@ class Ec2QuerySerializerGeneratorTest { val operationGenerator = parserGenerator.operationInputSerializer(model.lookup("test#Op")) val project = TestWorkspace.testProject(testSymbolProvider(model)) - project.lib { writer -> - writer.unitTest( + project.lib { + unitTest( "ec2query_serializer", """ use model::Top; @@ -108,7 +108,7 @@ class Ec2QuerySerializerGeneratorTest { .boolean(true) .build() .unwrap(); - let serialized = ${writer.format(operationGenerator!!)}(&input).unwrap(); + let serialized = ${format(operationGenerator!!)}(&input).unwrap(); let output = std::str::from_utf8(serialized.bytes().unwrap()).unwrap(); assert_eq!( output, @@ -125,14 +125,14 @@ class Ec2QuerySerializerGeneratorTest { ) } project.withModule(RustModule.public("model")) { - model.lookup("test#Top").renderWithModelBuilder(model, symbolProvider, it) - UnionGenerator(model, symbolProvider, it, model.lookup("test#Choice")).render() + model.lookup("test#Top").renderWithModelBuilder(model, symbolProvider, this) + UnionGenerator(model, symbolProvider, this, model.lookup("test#Choice")).render() val enum = model.lookup("test#FooEnum") - EnumGenerator(model, symbolProvider, it, enum, enum.expectTrait()).render() + EnumGenerator(model, symbolProvider, this, enum, enum.expectTrait()).render() } project.withModule(RustModule.public("input")) { - model.lookup("test#Op").inputShape(model).renderWithModelBuilder(model, symbolProvider, it) + model.lookup("test#Op").inputShape(model).renderWithModelBuilder(model, symbolProvider, this) } project.compileAndTest() } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGeneratorTest.kt index d9f16ff56fb..4d64daa31d4 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/JsonSerializerGeneratorTest.kt @@ -111,14 +111,14 @@ class JsonSerializerGeneratorTest { val documentGenerator = parserSerializer.documentSerializer() val project = TestWorkspace.testProject(testSymbolProvider(model)) - project.lib { writer -> - writer.unitTest( + project.lib { + unitTest( "json_serializers", """ use model::{Top, Choice}; // Generate the document serializer even though it's not tested directly - // ${writer.format(documentGenerator)} + // ${format(documentGenerator)} let input = crate::input::OpInput::builder().top( Top::builder() @@ -127,7 +127,7 @@ class JsonSerializerGeneratorTest { .recursive(Top::builder().extra(55).build()) .build() ).build().unwrap(); - let serialized = ${writer.format(operationGenerator!!)}(&input).unwrap(); + let serialized = ${format(operationGenerator!!)}(&input).unwrap(); let output = std::str::from_utf8(serialized.bytes().unwrap()).unwrap(); assert_eq!(output, r#"{"top":{"field":"hello!","extra":45,"rec":[{"extra":55}]}}"#); @@ -136,19 +136,19 @@ class JsonSerializerGeneratorTest { .choice(Choice::Unknown) .build() ).build().unwrap(); - let serialized = ${writer.format(operationGenerator)}(&input).expect_err("cannot serialize unknown variant"); + let serialized = ${format(operationGenerator)}(&input).expect_err("cannot serialize unknown variant"); """, ) } project.withModule(RustModule.public("model")) { - model.lookup("test#Top").renderWithModelBuilder(model, symbolProvider, it) - UnionGenerator(model, symbolProvider, it, model.lookup("test#Choice")).render() + model.lookup("test#Top").renderWithModelBuilder(model, symbolProvider, this) + UnionGenerator(model, symbolProvider, this, model.lookup("test#Choice")).render() val enum = model.lookup("test#FooEnum") - EnumGenerator(model, symbolProvider, it, enum, enum.expectTrait()).render() + EnumGenerator(model, symbolProvider, this, enum, enum.expectTrait()).render() } project.withModule(RustModule.public("input")) { - model.lookup("test#Op").inputShape(model).renderWithModelBuilder(model, symbolProvider, it) + model.lookup("test#Op").inputShape(model).renderWithModelBuilder(model, symbolProvider, this) } project.compileAndTest() } diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGeneratorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGeneratorTest.kt index d4cdc7740f2..c04303e6861 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGeneratorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/serialize/XmlBindingTraitSerializerGeneratorTest.kt @@ -113,8 +113,8 @@ internal class XmlBindingTraitSerializerGeneratorTest { val operationSerializer = parserGenerator.payloadSerializer(model.lookup("test#OpInput\$payload")) val project = TestWorkspace.testProject(testSymbolProvider(model)) - project.lib { writer -> - writer.unitTest( + project.lib { + unitTest( "serialize_xml", """ use model::Top; @@ -125,12 +125,12 @@ internal class XmlBindingTraitSerializerGeneratorTest { .recursive(Top::builder().extra(55).build()) .build() ).build().unwrap(); - let serialized = ${writer.format(operationSerializer)}(&inp.payload.unwrap()).unwrap(); + let serialized = ${format(operationSerializer)}(&inp.payload.unwrap()).unwrap(); let output = std::str::from_utf8(&serialized).unwrap(); assert_eq!(output, "hello!"); """, ) - writer.unitTest( + unitTest( "unknown_variants", """ use model::{Top, Choice}; @@ -139,19 +139,19 @@ internal class XmlBindingTraitSerializerGeneratorTest { .choice(Choice::Unknown) .build() ).build().unwrap(); - ${writer.format(operationSerializer)}(&input.payload.unwrap()).expect_err("cannot serialize unknown variant"); + ${format(operationSerializer)}(&input.payload.unwrap()).expect_err("cannot serialize unknown variant"); """, ) } project.withModule(RustModule.public("model")) { - model.lookup("test#Top").renderWithModelBuilder(model, symbolProvider, it) - UnionGenerator(model, symbolProvider, it, model.lookup("test#Choice")).render() + model.lookup("test#Top").renderWithModelBuilder(model, symbolProvider, this) + UnionGenerator(model, symbolProvider, this, model.lookup("test#Choice")).render() val enum = model.lookup("test#FooEnum") - EnumGenerator(model, symbolProvider, it, enum, enum.expectTrait()).render() + EnumGenerator(model, symbolProvider, this, enum, enum.expectTrait()).render() } project.withModule(RustModule.public("input")) { - model.lookup("test#Op").inputShape(model).renderWithModelBuilder(model, symbolProvider, it) + model.lookup("test#Op").inputShape(model).renderWithModelBuilder(model, symbolProvider, this) } project.compileAndTest() } diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt index 0edc5a0878c..32a6fe3887c 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/PythonServerCodegenVisitor.kt @@ -85,14 +85,14 @@ class PythonServerCodegenVisitor( */ override fun structureShape(shape: StructureShape) { logger.info("[python-server-codegen] Generating a structure $shape") - rustCrate.useShapeWriter(shape) { writer -> + rustCrate.useShapeWriter(shape) { // Use Python specific structure generator that adds the #[pyclass] attribute // and #[pymethods] implementation. - PythonServerStructureGenerator(model, symbolProvider, writer, shape).render(CodegenTarget.SERVER) + PythonServerStructureGenerator(model, symbolProvider, this, shape).render(CodegenTarget.SERVER) val builderGenerator = BuilderGenerator(codegenContext.model, codegenContext.symbolProvider, shape) - builderGenerator.render(writer) - writer.implBlock(shape, symbolProvider) { + builderGenerator.render(this) + implBlock(shape, symbolProvider) { builderGenerator.renderConvenienceMethod(this) } } @@ -106,8 +106,8 @@ class PythonServerCodegenVisitor( override fun stringShape(shape: StringShape) { logger.info("[rust-server-codegen] Generating an enum $shape") shape.getTrait()?.also { enum -> - rustCrate.useShapeWriter(shape) { writer -> - PythonServerEnumGenerator(model, symbolProvider, writer, shape, enum, codegenContext.runtimeConfig).render() + rustCrate.useShapeWriter(shape) { + PythonServerEnumGenerator(model, symbolProvider, this, shape, enum, codegenContext.runtimeConfig).render() } } } diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt index 9b2ca49b2bc..4736719cecb 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerModuleGenerator.kt @@ -35,8 +35,8 @@ class PythonServerModuleGenerator( fun render() { rustCrate.withModule( RustModule.public("python_module_export", "Export PyO3 symbols in the shared library"), - ) { writer -> - writer.rustBlockTemplate( + ) { + rustBlockTemplate( """ ##[#{pyo3}::pymodule] ##[#{pyo3}(name = "$libName")] diff --git a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerServiceGenerator.kt b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerServiceGenerator.kt index 56e119a87e7..30aa0bf0aa9 100644 --- a/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerServiceGenerator.kt +++ b/codegen-server/python/src/main/kotlin/software/amazon/smithy/rust/codegen/server/python/smithy/generators/PythonServerServiceGenerator.kt @@ -38,9 +38,9 @@ class PythonServerServiceGenerator( } override fun renderExtras(operations: List) { - rustCrate.withModule(RustModule.public("python_server_application", "Python server and application implementation.")) { writer -> + rustCrate.withModule(RustModule.public("python_server_application", "Python server and application implementation.")) { PythonApplicationGenerator(context, protocol, operations) - .render(writer) + .render(this) } } } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt index 712d930b424..de10207c53b 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/ServerCodegenVisitor.kt @@ -179,12 +179,12 @@ open class ServerCodegenVisitor( */ override fun structureShape(shape: StructureShape) { logger.info("[rust-server-codegen] Generating a structure $shape") - rustCrate.useShapeWriter(shape) { writer -> - StructureGenerator(model, symbolProvider, writer, shape).render(CodegenTarget.SERVER) + rustCrate.useShapeWriter(shape) { + StructureGenerator(model, symbolProvider, this, shape).render(CodegenTarget.SERVER) val builderGenerator = BuilderGenerator(codegenContext.model, codegenContext.symbolProvider, shape) - builderGenerator.render(writer) - writer.implBlock(shape, symbolProvider) { + builderGenerator.render(this) + this.implBlock(shape, symbolProvider) { builderGenerator.renderConvenienceMethod(this) } } @@ -198,8 +198,8 @@ open class ServerCodegenVisitor( override fun stringShape(shape: StringShape) { logger.info("[rust-server-codegen] Generating an enum $shape") shape.getTrait()?.also { enum -> - rustCrate.useShapeWriter(shape) { writer -> - ServerEnumGenerator(model, symbolProvider, writer, shape, enum, codegenContext.runtimeConfig).render() + rustCrate.useShapeWriter(shape) { + ServerEnumGenerator(model, symbolProvider, this, shape, enum, codegenContext.runtimeConfig).render() } } } @@ -214,7 +214,7 @@ open class ServerCodegenVisitor( override fun unionShape(shape: UnionShape) { logger.info("[rust-server-codegen] Generating an union $shape") rustCrate.useShapeWriter(shape) { - UnionGenerator(model, symbolProvider, it, shape, renderUnknownVariant = false).render() + UnionGenerator(model, symbolProvider, this, shape, renderUnknownVariant = false).render() } } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt index 2e659adc263..0715629d531 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerServiceGenerator.kt @@ -40,19 +40,19 @@ open class ServerServiceGenerator( * which assigns a symbol location to each shape. */ fun render() { - rustCrate.withModule(RustModule.operation(Visibility.PRIVATE)) { writer -> - ServerProtocolTestGenerator(codegenContext, protocolSupport, protocolGenerator).render(writer) + rustCrate.withModule(RustModule.operation(Visibility.PRIVATE)) { + ServerProtocolTestGenerator(codegenContext, protocolSupport, protocolGenerator).render(this) } for (operation in operations) { if (operation.errors.isNotEmpty()) { - rustCrate.withModule(RustModule.Error) { writer -> - renderCombinedErrors(writer, operation) + rustCrate.withModule(RustModule.Error) { + renderCombinedErrors(this, operation) } } } - rustCrate.withModule(RustModule.private("operation_handler", "Operation handlers definition and implementation.")) { writer -> - renderOperationHandler(writer, operations) + rustCrate.withModule(RustModule.private("operation_handler", "Operation handlers definition and implementation.")) { + renderOperationHandler(this, operations) } rustCrate.withModule( RustModule.public( @@ -62,8 +62,8 @@ open class ServerServiceGenerator( you can register your service's operation implementations. """, ), - ) { writer -> - renderOperationRegistry(writer, operations) + ) { + renderOperationRegistry(this, operations) } // TODO(https://github.com/awslabs/smithy-rs/issues/1707): Remove, this is temporary. @@ -76,22 +76,21 @@ open class ServerServiceGenerator( Attribute.DocHidden, ), ), - null, ), - ) { writer -> + ) { for (operation in operations) { - ServerOperationGenerator(codegenContext, operation).render(writer) + ServerOperationGenerator(codegenContext, operation).render(this) } } // TODO(https://github.com/awslabs/smithy-rs/issues/1707): Remove, this is temporary. rustCrate.withModule( RustModule("service", RustMetadata(visibility = Visibility.PUBLIC, additionalAttributes = listOf(Attribute.DocHidden)), null), - ) { writer -> + ) { ServerServiceGeneratorV2( codegenContext, protocol, - ).render(writer) + ).render(this) } renderExtras(operations) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt index f4b3bab27af..d68e1cb605d 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt @@ -26,9 +26,11 @@ import software.amazon.smithy.protocoltests.traits.HttpResponseTestsTrait import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.RustReservedWords import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter import software.amazon.smithy.rust.codegen.core.rustlang.Visibility +import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.escape import software.amazon.smithy.rust.codegen.core.rustlang.rust @@ -76,7 +78,8 @@ class ServerProtocolTestGenerator( private val operationIndex = OperationIndex.of(codegenContext.model) private val serviceName = codegenContext.serviceShape.id.name.toPascalCase() - private val operations = TopDownIndex.of(codegenContext.model).getContainedOperations(codegenContext.serviceShape).sortedBy { it.id } + private val operations = + TopDownIndex.of(codegenContext.model).getContainedOperations(codegenContext.serviceShape).sortedBy { it.id } private val operationInputOutputTypes = operations.associateWith { val inputSymbol = symbolProvider.toSymbol(it.inputShape(model)) @@ -175,15 +178,18 @@ class ServerProtocolTestGenerator( } } - val moduleMeta = RustMetadata( - additionalAttributes = listOf( - Attribute.Cfg("test"), - Attribute.AllowDeadCode, + val module = RustModule( + PROTOCOL_TEST_HELPER_MODULE_NAME, + RustMetadata( + additionalAttributes = listOf( + Attribute.Cfg("test"), + Attribute.AllowDeadCode, + ), + visibility = Visibility.PUBCRATE, ), - - visibility = Visibility.PUBCRATE, ) - writer.withModule(PROTOCOL_TEST_HELPER_MODULE_NAME, moduleMeta) { + + writer.withModule(module) { rustTemplate( """ use #{Tower}::Service as _; @@ -245,15 +251,17 @@ class ServerProtocolTestGenerator( if (allTests.isNotEmpty()) { val operationName = operationSymbol.name - val testModuleName = "server_${operationName.toSnakeCase()}_test" - val moduleMeta = RustMetadata( - additionalAttributes = listOf( - Attribute.Cfg("test"), - Attribute.Custom("allow(unreachable_code, unused_variables)"), + val module = RustModule( + "server_${operationName.toSnakeCase()}_test", + RustMetadata( + additionalAttributes = listOf( + Attribute.Cfg("test"), + Attribute.Custom("allow(unreachable_code, unused_variables)"), + ), + visibility = Visibility.PRIVATE, ), - visibility = Visibility.PRIVATE, ) - writer.withModule(testModuleName, moduleMeta) { + writer.withModule(module) { renderAllTestCases(operationShape, allTests) } } @@ -264,15 +272,30 @@ class ServerProtocolTestGenerator( val operationSymbol = symbolProvider.toSymbol(operationShape) renderTestCaseBlock(it, this) { when (it) { - is TestCase.RequestTest -> this.renderHttpRequestTestCase(it.testCase, operationShape, operationSymbol) - is TestCase.ResponseTest -> this.renderHttpResponseTestCase(it.testCase, it.targetShape, operationShape, operationSymbol) - is TestCase.MalformedRequestTest -> this.renderHttpMalformedRequestTestCase(it.testCase, operationSymbol) + is TestCase.RequestTest -> this.renderHttpRequestTestCase( + it.testCase, + operationShape, + operationSymbol, + ) + + is TestCase.ResponseTest -> this.renderHttpResponseTestCase( + it.testCase, + it.targetShape, + operationShape, + operationSymbol, + ) + + is TestCase.MalformedRequestTest -> this.renderHttpMalformedRequestTestCase( + it.testCase, + operationSymbol, + ) } } } } - private fun OperationShape.toName(): String = RustReservedWords.escapeIfNeeded(symbolProvider.toSymbol(this).name.toSnakeCase()) + private fun OperationShape.toName(): String = + RustReservedWords.escapeIfNeeded(symbolProvider.toSymbol(this).name.toSnakeCase()) /** * Filter out test cases that are disabled or don't match the service protocol @@ -302,6 +325,7 @@ class ServerProtocolTestGenerator( TestCase.RequestTest(fixed, it.operationShape) } } + is TestCase.ResponseTest -> { val howToFixIt = BrokenResponseTests[Pair(codegenContext.serviceShape.id.toString(), it.id)] if (howToFixIt == null) { @@ -311,6 +335,7 @@ class ServerProtocolTestGenerator( TestCase.ResponseTest(fixed, it.targetShape) } } + is TestCase.MalformedRequestTest -> { // We haven't found any broken `HttpMalformedRequestTest`s yet. it @@ -321,15 +346,16 @@ class ServerProtocolTestGenerator( private fun renderTestCaseBlock( testCase: TestCase, testModuleWriter: RustWriter, - block: RustWriter.() -> Unit, + block: Writable, ) { - testModuleWriter.setNewlinePrefix("/// ") + testModuleWriter.newlinePrefix = "/// " if (testCase.documentation != null) { testModuleWriter.writeWithNoFormatting(testCase.documentation) } testModuleWriter.write("Test ID: ${testCase.id}") - testModuleWriter.setNewlinePrefix("") + testModuleWriter.newlinePrefix = "" + TokioTest.render(testModuleWriter) if (expectFail(testCase)) { @@ -403,7 +429,8 @@ class ServerProtocolTestGenerator( operationShape: OperationShape, operationSymbol: Symbol, ) { - val operationImplementationName = "${operationSymbol.name}${ServerHttpBoundProtocolGenerator.OPERATION_OUTPUT_WRAPPER_SUFFIX}" + val operationImplementationName = + "${operationSymbol.name}${ServerHttpBoundProtocolGenerator.OPERATION_OUTPUT_WRAPPER_SUFFIX}" val operationErrorName = "crate::error::${operationSymbol.name}Error" if (!protocolSupport.responseSerialization || ( @@ -441,7 +468,10 @@ class ServerProtocolTestGenerator( * We are given a request definition and a response definition, and we have to assert that the request is rejected * with the given response. */ - private fun RustWriter.renderHttpMalformedRequestTestCase(testCase: HttpMalformedRequestTestCase, operationSymbol: Symbol) { + private fun RustWriter.renderHttpMalformedRequestTestCase( + testCase: HttpMalformedRequestTestCase, + operationSymbol: Symbol, + ) { with(testCase.request) { // TODO(https://github.com/awslabs/smithy/issues/1102): `uri` should probably not be an `Optional`. renderHttpRequest(uri.get(), method, headers, body.orNull(), queryParams, host.orNull()) @@ -491,7 +521,9 @@ class ServerProtocolTestGenerator( // corresponding Unicode code point. That is the "form feed" 0x0c character. When printing it, // it gets written as "\f", which is an invalid Rust escape sequence: https://static.rust-lang.org/doc/master/reference.html#literals // So we need to write the corresponding Rust Unicode escape sequence to make the program compile. - "#{SmithyHttpServer}::body::Body::from(#{Bytes}::from_static(${body.replace("\u000c", "\\u{000c}").dq()}.as_bytes()))" + "#{SmithyHttpServer}::body::Body::from(#{Bytes}::from_static(${ + body.replace("\u000c", "\\u{000c}").dq() + }.as_bytes()))" } else { "#{SmithyHttpServer}::body::Body::empty()" } @@ -509,31 +541,42 @@ class ServerProtocolTestGenerator( } /** Returns the body of the request test. */ - private fun checkRequestHandler(operationShape: OperationShape, httpRequestTestCase: HttpRequestTestCase) = writable { - val inputShape = operationShape.inputShape(codegenContext.model) - val outputShape = operationShape.outputShape(codegenContext.model) - - // Construct expected request. - withBlock("let expected = ", ";") { - instantiator.render(this, inputShape, httpRequestTestCase.params) - } + private fun checkRequestHandler(operationShape: OperationShape, httpRequestTestCase: HttpRequestTestCase) = + writable { + val inputShape = operationShape.inputShape(codegenContext.model) + val outputShape = operationShape.outputShape(codegenContext.model) + + // Construct expected request. + withBlock("let expected = ", ";") { + instantiator.render(this, inputShape, httpRequestTestCase.params) + } - checkRequestParams(inputShape, this) + checkRequestParams(inputShape, this) - // Construct a dummy response. - withBlock("let response = ", ";") { - instantiator.render(this, outputShape, Node.objectNode(), Instantiator.defaultContext().copy(defaultsForRequiredFields = true)) - } + // Construct a dummy response. + withBlock("let response = ", ";") { + instantiator.render( + this, + outputShape, + Node.objectNode(), + Instantiator.defaultContext().copy(defaultsForRequiredFields = true), + ) + } - if (operationShape.errors.isEmpty()) { - write("response") - } else { - write("Ok(response)") + if (operationShape.errors.isEmpty()) { + write("response") + } else { + write("Ok(response)") + } } - } /** Checks the request using the `OperationRegistryBuilder`. */ - private fun checkRequest(operationShape: OperationShape, operationSymbol: Symbol, httpRequestTestCase: HttpRequestTestCase, rustWriter: RustWriter) { + private fun checkRequest( + operationShape: OperationShape, + operationSymbol: Symbol, + httpRequestTestCase: HttpRequestTestCase, + rustWriter: RustWriter, + ) { val (inputT, outputT) = operationInputOutputTypes[operationShape]!! rustWriter.withBlock( @@ -553,7 +596,12 @@ class ServerProtocolTestGenerator( } /** Checks the request using the new service builder. */ - private fun checkRequest2(operationShape: OperationShape, operationSymbol: Symbol, httpRequestTestCase: HttpRequestTestCase, rustWriter: RustWriter) { + private fun checkRequest2( + operationShape: OperationShape, + operationSymbol: Symbol, + httpRequestTestCase: HttpRequestTestCase, + rustWriter: RustWriter, + ) { val (inputT, _) = operationInputOutputTypes[operationShape]!! val operationName = RustReservedWords.escapeIfNeeded(operationSymbol.name.toSnakeCase()) rustWriter.rustTemplate( @@ -682,7 +730,11 @@ class ServerProtocolTestGenerator( // member must be set. // if (httpMalformedResponseBodyDefinition.contents.isPresent) { - checkBody(rustWriter, httpMalformedResponseBodyDefinition.contents.get(), httpMalformedResponseBodyDefinition.mediaType) + checkBody( + rustWriter, + httpMalformedResponseBodyDefinition.contents.get(), + httpMalformedResponseBodyDefinition.mediaType, + ) } else { check(httpMalformedResponseBodyDefinition.messageRegex.isPresent) // There aren't any restJson1 protocol tests that make use of `messageRegex`. @@ -784,7 +836,7 @@ class ServerProtocolTestGenerator( strSlice(this, params) } assertOk(rustWriter) { - write( + rustWriter.write( "#T($actualExpression, $expectedVariableName)", RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, checkFunction), ) @@ -793,9 +845,9 @@ class ServerProtocolTestGenerator( /** * wraps `inner` in a call to `aws_smithy_protocol_test::assert_ok`, a convenience wrapper - * for pretty prettying protocol test helper results + * for pretty printing protocol test helper results */ - private fun assertOk(rustWriter: RustWriter, inner: RustWriter.() -> Unit) { + private fun assertOk(rustWriter: RustWriter, inner: Writable) { rustWriter.write("#T(", RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "assert_ok")) inner(rustWriter) rustWriter.write(");") @@ -845,7 +897,11 @@ class ServerProtocolTestGenerator( FailingTest(RestJson, "RestJsonBodyMalformedMapNullValue", TestType.MalformedRequest), FailingTest(RestJson, "RestJsonMalformedSetDuplicateItems", TestType.MalformedRequest), FailingTest(RestJson, "RestJsonMalformedSetNullItem", TestType.MalformedRequest), - FailingTest(RestJson, "RestJsonHeaderMalformedStringInvalidBase64MediaType_case1", TestType.MalformedRequest), + FailingTest( + RestJson, + "RestJsonHeaderMalformedStringInvalidBase64MediaType_case1", + TestType.MalformedRequest, + ), FailingTest(RestJson, "RestJsonMalformedUnionNoFieldsSet", TestType.MalformedRequest), FailingTest(RestJson, "RestJsonMalformedSetDuplicateBlobs", TestType.MalformedRequest), @@ -887,8 +943,16 @@ class ServerProtocolTestGenerator( FailingTest(RestJsonValidation, "RestJsonMalformedPatternListOverride_case1", TestType.MalformedRequest), FailingTest(RestJsonValidation, "RestJsonMalformedPatternMapKeyOverride_case0", TestType.MalformedRequest), FailingTest(RestJsonValidation, "RestJsonMalformedPatternMapKeyOverride_case1", TestType.MalformedRequest), - FailingTest(RestJsonValidation, "RestJsonMalformedPatternMapValueOverride_case0", TestType.MalformedRequest), - FailingTest(RestJsonValidation, "RestJsonMalformedPatternMapValueOverride_case1", TestType.MalformedRequest), + FailingTest( + RestJsonValidation, + "RestJsonMalformedPatternMapValueOverride_case0", + TestType.MalformedRequest, + ), + FailingTest( + RestJsonValidation, + "RestJsonMalformedPatternMapValueOverride_case1", + TestType.MalformedRequest, + ), FailingTest(RestJsonValidation, "RestJsonMalformedPatternStringOverride_case0", TestType.MalformedRequest), FailingTest(RestJsonValidation, "RestJsonMalformedPatternStringOverride_case1", TestType.MalformedRequest), FailingTest(RestJsonValidation, "RestJsonMalformedPatternUnionOverride_case0", TestType.MalformedRequest), @@ -950,7 +1014,11 @@ class ServerProtocolTestGenerator( FailingTest("aws.protocoltests.json#JsonProtocol", "AwsJson11EndpointTrait", TestType.Request), FailingTest("aws.protocoltests.json#JsonProtocol", "parses_httpdate_timestamps", TestType.Response), FailingTest("aws.protocoltests.json#JsonProtocol", "parses_iso8601_timestamps", TestType.Response), - FailingTest("aws.protocoltests.json#JsonProtocol", "parses_the_request_id_from_the_response", TestType.Response), + FailingTest( + "aws.protocoltests.json#JsonProtocol", + "parses_the_request_id_from_the_response", + TestType.Response, + ), ) private val RunOnly: Set? = null @@ -959,7 +1027,10 @@ class ServerProtocolTestGenerator( // or because they are flaky private val DisableTests = setOf() - private fun fixRestJsonSupportsNaNFloatQueryValues(testCase: HttpRequestTestCase, operationShape: OperationShape): HttpRequestTestCase { + private fun fixRestJsonSupportsNaNFloatQueryValues( + testCase: HttpRequestTestCase, + operationShape: OperationShape, + ): HttpRequestTestCase { val params = Node.parse( """ { @@ -975,7 +1046,11 @@ class ServerProtocolTestGenerator( return testCase.toBuilder().params(params).build() } - private fun fixRestJsonSupportsInfinityFloatQueryValues(testCase: HttpRequestTestCase, operationShape: OperationShape): HttpRequestTestCase = + + private fun fixRestJsonSupportsInfinityFloatQueryValues( + testCase: HttpRequestTestCase, + operationShape: OperationShape, + ): HttpRequestTestCase = testCase.toBuilder().params( Node.parse( """ @@ -990,7 +1065,11 @@ class ServerProtocolTestGenerator( """.trimMargin(), ).asObjectNode().get(), ).build() - private fun fixRestJsonSupportsNegativeInfinityFloatQueryValues(testCase: HttpRequestTestCase, operationShape: OperationShape): HttpRequestTestCase = + + private fun fixRestJsonSupportsNegativeInfinityFloatQueryValues( + testCase: HttpRequestTestCase, + operationShape: OperationShape, + ): HttpRequestTestCase = testCase.toBuilder().params( Node.parse( """ @@ -1005,7 +1084,11 @@ class ServerProtocolTestGenerator( """.trimMargin(), ).asObjectNode().get(), ).build() - private fun fixRestJsonAllQueryStringTypes(testCase: HttpRequestTestCase, operationShape: OperationShape): HttpRequestTestCase = + + private fun fixRestJsonAllQueryStringTypes( + testCase: HttpRequestTestCase, + operationShape: OperationShape, + ): HttpRequestTestCase = testCase.toBuilder().params( Node.parse( """ @@ -1052,7 +1135,11 @@ class ServerProtocolTestGenerator( """.trimMargin(), ).asObjectNode().get(), ).build() - private fun fixRestJsonQueryStringEscaping(testCase: HttpRequestTestCase, operationShape: OperationShape): HttpRequestTestCase = + + private fun fixRestJsonQueryStringEscaping( + testCase: HttpRequestTestCase, + operationShape: OperationShape, + ): HttpRequestTestCase = testCase.toBuilder().params( Node.parse( """ @@ -1066,7 +1153,10 @@ class ServerProtocolTestGenerator( ).asObjectNode().get(), ).build() - private fun fixAwsJson11MissingHeaderXAmzTarget(testCase: HttpRequestTestCase, operationShape: OperationShape): HttpRequestTestCase = + private fun fixAwsJson11MissingHeaderXAmzTarget( + testCase: HttpRequestTestCase, + operationShape: OperationShape, + ): HttpRequestTestCase = testCase.toBuilder().putHeader("x-amz-target", "JsonProtocol.${operationShape.id.name}").build() // These are tests whose definitions in the `awslabs/smithy` repository are wrong. @@ -1076,7 +1166,10 @@ class ServerProtocolTestGenerator( // https://github.com/awslabs/smithy/pull/1040 Pair(RestJson, "RestJsonSupportsNaNFloatQueryValues") to ::fixRestJsonSupportsNaNFloatQueryValues, Pair(RestJson, "RestJsonSupportsInfinityFloatQueryValues") to ::fixRestJsonSupportsInfinityFloatQueryValues, - Pair(RestJson, "RestJsonSupportsNegativeInfinityFloatQueryValues") to ::fixRestJsonSupportsNegativeInfinityFloatQueryValues, + Pair( + RestJson, + "RestJsonSupportsNegativeInfinityFloatQueryValues", + ) to ::fixRestJsonSupportsNegativeInfinityFloatQueryValues, Pair(RestJson, "RestJsonAllQueryStringTypes") to ::fixRestJsonAllQueryStringTypes, Pair(RestJson, "RestJsonQueryStringEscaping") to ::fixRestJsonQueryStringEscaping, @@ -1085,10 +1178,19 @@ class ServerProtocolTestGenerator( Pair(AwsJson11, "AwsJson11Enums") to ::fixAwsJson11MissingHeaderXAmzTarget, Pair(AwsJson11, "AwsJson11ListsSerializeNull") to ::fixAwsJson11MissingHeaderXAmzTarget, Pair(AwsJson11, "AwsJson11MapsSerializeNullValues") to ::fixAwsJson11MissingHeaderXAmzTarget, - Pair(AwsJson11, "AwsJson11ServersDontDeserializeNullStructureValues") to ::fixAwsJson11MissingHeaderXAmzTarget, + Pair( + AwsJson11, + "AwsJson11ServersDontDeserializeNullStructureValues", + ) to ::fixAwsJson11MissingHeaderXAmzTarget, Pair(AwsJson11, "PutAndGetInlineDocumentsInput") to ::fixAwsJson11MissingHeaderXAmzTarget, - Pair(AwsJson11, "json_1_1_client_sends_empty_payload_for_no_input_shape") to ::fixAwsJson11MissingHeaderXAmzTarget, - Pair(AwsJson11, "json_1_1_service_supports_empty_payload_for_no_input_shape") to ::fixAwsJson11MissingHeaderXAmzTarget, + Pair( + AwsJson11, + "json_1_1_client_sends_empty_payload_for_no_input_shape", + ) to ::fixAwsJson11MissingHeaderXAmzTarget, + Pair( + AwsJson11, + "json_1_1_service_supports_empty_payload_for_no_input_shape", + ) to ::fixAwsJson11MissingHeaderXAmzTarget, Pair(AwsJson11, "sends_requests_to_slash") to ::fixAwsJson11MissingHeaderXAmzTarget, Pair(AwsJson11, "serializes_blob_shapes") to ::fixAwsJson11MissingHeaderXAmzTarget, Pair(AwsJson11, "serializes_boolean_shapes_false") to ::fixAwsJson11MissingHeaderXAmzTarget, @@ -1111,15 +1213,28 @@ class ServerProtocolTestGenerator( Pair(AwsJson11, "serializes_recursive_structure_shapes") to ::fixAwsJson11MissingHeaderXAmzTarget, Pair(AwsJson11, "serializes_string_shapes") to ::fixAwsJson11MissingHeaderXAmzTarget, Pair(AwsJson11, "serializes_string_shapes_with_jsonvalue_trait") to ::fixAwsJson11MissingHeaderXAmzTarget, - Pair(AwsJson11, "serializes_structure_members_with_locationname_traits") to ::fixAwsJson11MissingHeaderXAmzTarget, + Pair( + AwsJson11, + "serializes_structure_members_with_locationname_traits", + ) to ::fixAwsJson11MissingHeaderXAmzTarget, Pair(AwsJson11, "serializes_structure_shapes") to ::fixAwsJson11MissingHeaderXAmzTarget, Pair(AwsJson11, "serializes_structure_which_have_no_members") to ::fixAwsJson11MissingHeaderXAmzTarget, Pair(AwsJson11, "serializes_timestamp_shapes") to ::fixAwsJson11MissingHeaderXAmzTarget, - Pair(AwsJson11, "serializes_timestamp_shapes_with_httpdate_timestampformat") to ::fixAwsJson11MissingHeaderXAmzTarget, - Pair(AwsJson11, "serializes_timestamp_shapes_with_iso8601_timestampformat") to ::fixAwsJson11MissingHeaderXAmzTarget, - Pair(AwsJson11, "serializes_timestamp_shapes_with_unixtimestamp_timestampformat") to ::fixAwsJson11MissingHeaderXAmzTarget, + Pair( + AwsJson11, + "serializes_timestamp_shapes_with_httpdate_timestampformat", + ) to ::fixAwsJson11MissingHeaderXAmzTarget, + Pair( + AwsJson11, + "serializes_timestamp_shapes_with_iso8601_timestampformat", + ) to ::fixAwsJson11MissingHeaderXAmzTarget, + Pair( + AwsJson11, + "serializes_timestamp_shapes_with_unixtimestamp_timestampformat", + ) to ::fixAwsJson11MissingHeaderXAmzTarget, ) - private val BrokenResponseTests: Map, KFunction1> = mapOf() + private val BrokenResponseTests: Map, KFunction1> = + mapOf() } } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt index 952a0dc73a8..e98f156f5a6 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt @@ -402,9 +402,9 @@ private class ServerHttpBoundProtocolTraitImplGenerator( val inputSymbol = symbolProvider.toSymbol(inputShape) return RuntimeType.forInlineFun(fnName, operationDeserModule) { - Attribute.Custom("allow(clippy::unnecessary_wraps)").render(it) + Attribute.Custom("allow(clippy::unnecessary_wraps)").render(this) // The last conversion trait bound is needed by the `hyper::body::to_bytes(body).await?` call. - it.rustBlockTemplate( + rustBlockTemplate( """ pub async fn $fnName( ##[allow(unused_variables)] request: &mut #{SmithyHttpServer}::request::RequestParts @@ -437,12 +437,12 @@ private class ServerHttpBoundProtocolTraitImplGenerator( val outputSymbol = symbolProvider.toSymbol(outputShape) return RuntimeType.forInlineFun(fnName, operationSerModule) { - Attribute.Custom("allow(clippy::unnecessary_wraps)").render(it) + Attribute.Custom("allow(clippy::unnecessary_wraps)").render(this) // Note we only need to take ownership of the output in the case that it contains streaming members. - // However we currently always take ownership here, but worth noting in case in the future we want + // However, we currently always take ownership here, but worth noting in case in the future we want // to generate different signatures for streaming vs non-streaming for some reason. - it.rustBlockTemplate( + rustBlockTemplate( """ pub fn $fnName( ##[allow(unused_variables)] output: #{O} @@ -468,8 +468,8 @@ private class ServerHttpBoundProtocolTraitImplGenerator( val fnName = "serialize_${operationShape.id.name.toSnakeCase()}_error" val errorSymbol = operationShape.errorSymbol(model, symbolProvider, CodegenTarget.SERVER) return RuntimeType.forInlineFun(fnName, operationSerModule) { - Attribute.Custom("allow(clippy::unnecessary_wraps)").render(it) - it.rustBlockTemplate( + Attribute.Custom("allow(clippy::unnecessary_wraps)").render(this) + rustBlockTemplate( "pub fn $fnName(error: &#{E}) -> std::result::Result<#{SmithyHttpServer}::response::Response, #{ResponseRejection}>", *codegenScope, "E" to errorSymbol, @@ -508,7 +508,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( val bindings = httpBindingResolver.errorResponseBindings(it) - software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) + Attribute.AllowUnusedMut.render(this) rustTemplate("let mut builder = #{http}::Response::builder();", *codegenScope) serverRenderResponseHeaders(operationShape, variantShape) @@ -544,7 +544,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( operationShape: OperationShape, bindings: List, ) { - software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) + Attribute.AllowUnusedMut.render(this) rustTemplate("let mut builder = #{http}::Response::builder();", *codegenScope) serverRenderResponseHeaders(operationShape) bindings.find { it.location == HttpLocation.RESPONSE_CODE } @@ -711,7 +711,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( ) { val httpBindingGenerator = ServerRequestBindingGenerator(protocol, codegenContext, operationShape) val structuredDataParser = protocol.structuredDataParser(operationShape) - software.amazon.smithy.rust.codegen.core.rustlang.Attribute.AllowUnusedMut.render(this) + Attribute.AllowUnusedMut.render(this) rust("let mut input = #T::default();", inputShape.builderSymbol(symbolProvider)) val parser = structuredDataParser.serverInputParser(operationShape) val noInputs = model.expectShape(operationShape.inputShape).expectTrait().originalId == null @@ -1116,8 +1116,8 @@ private class ServerHttpBoundProtocolTraitImplGenerator( val output = symbolProvider.toSymbol(binding.member) val fnName = generateParseStrFnName(binding) val symbol = output.extractSymbolFromOption() - return RuntimeType.forInlineFun(fnName, operationDeserModule) { writer -> - writer.rustBlockTemplate( + return RuntimeType.forInlineFun(fnName, operationDeserModule) { + rustBlockTemplate( "pub fn $fnName(value: &str) -> std::result::Result<#{O}, #{RequestRejection}>", *codegenScope, "O" to output, @@ -1188,7 +1188,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( } } - writer.write( + rust( """ Ok(${symbolProvider.wrapOptional(binding.member, "value")}) """, diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerCombinedErrorGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerCombinedErrorGeneratorTest.kt index c96fabb5692..da3ea23d8e2 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerCombinedErrorGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerCombinedErrorGeneratorTest.kt @@ -53,15 +53,15 @@ class ServerCombinedErrorGeneratorTest { @Test fun `generates combined error enums`() { val project = TestWorkspace.testProject(symbolProvider) - project.withModule(RustModule.public("error")) { writer -> + project.withModule(RustModule.public("error")) { listOf("FooException", "ComplexError", "InvalidGreeting", "Deprecated").forEach { - model.lookup("error#$it").renderWithModelBuilder(model, symbolProvider, writer, CodegenTarget.SERVER) + model.lookup("error#$it").renderWithModelBuilder(model, symbolProvider, this, CodegenTarget.SERVER) } val errors = listOf("FooException", "ComplexError", "InvalidGreeting").map { model.lookup("error#$it") } val generator = ServerCombinedErrorGenerator(model, symbolProvider, symbolProvider.toSymbol(model.lookup("error#Greeting")), errors) - generator.render(writer) + generator.render(this) - writer.unitTest( + unitTest( name = "generates_combined_error_enums", test = """ let variant = InvalidGreeting::builder().message("an error").build(); @@ -87,7 +87,7 @@ class ServerCombinedErrorGeneratorTest { """, ) - writer.unitTest( + unitTest( name = "generates_converters_into_combined_error_enums", test = """ let variant = InvalidGreeting { message: String::from("an error") }; diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt index cfc0e0d35cc..55b7c462ac6 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerHttpSensitivityGeneratorTest.kt @@ -58,8 +58,8 @@ class ServerHttpSensitivityGeneratorTest { assertEquals(listOf("query_b"), (querySensitivity as QuerySensitivity.NotSensitiveMapValue).queryKeys) val testProject = TestWorkspace.testProject(serverTestSymbolProvider(model)) - testProject.lib { writer -> - writer.unitTest("query_closure") { + testProject.lib { + unitTest("query_closure") { rustTemplate( """ let closure = #{Closure:W}; @@ -105,8 +105,8 @@ class ServerHttpSensitivityGeneratorTest { querySensitivity as QuerySensitivity.SensitiveMapValue val testProject = TestWorkspace.testProject(serverTestSymbolProvider(model)) - testProject.lib { writer -> - writer.unitTest("query_params_closure") { + testProject.lib { + unitTest("query_params_closure") { rustTemplate( """ let closure = #{Closure:W}; @@ -153,8 +153,8 @@ class ServerHttpSensitivityGeneratorTest { assert((querySensitivity as QuerySensitivity.NotSensitiveMapValue).queryKeys.isEmpty()) val testProject = TestWorkspace.testProject(serverTestSymbolProvider(model)) - testProject.lib { writer -> - writer.unitTest("query_params_special_closure") { + testProject.lib { + unitTest("query_params_special_closure") { rustTemplate( """ let closure = #{Closure:W}; @@ -201,8 +201,8 @@ class ServerHttpSensitivityGeneratorTest { querySensitivity as QuerySensitivity.SensitiveMapValue val testProject = TestWorkspace.testProject(serverTestSymbolProvider(model)) - testProject.lib { writer -> - writer.unitTest("query_params_special_closure") { + testProject.lib { + unitTest("query_params_special_closure") { rustTemplate( """ let closure = #{Closure:W}; @@ -278,8 +278,8 @@ class ServerHttpSensitivityGeneratorTest { assertEquals(null, (headerData as HeaderSensitivity.NotSensitiveMapValue).prefixHeader) val testProject = TestWorkspace.testProject(serverTestSymbolProvider(model)) - testProject.lib { writer -> - writer.unitTest("header_closure") { + testProject.lib { + unitTest("header_closure") { rustTemplate( """ let closure = #{Closure:W}; @@ -326,8 +326,8 @@ class ServerHttpSensitivityGeneratorTest { assertEquals("prefix-", (headerData as HeaderSensitivity.SensitiveMapValue).prefixHeader) val testProject = TestWorkspace.testProject(serverTestSymbolProvider(model)) - testProject.lib { writer -> - writer.unitTest("prefix_headers_closure") { + testProject.lib { + unitTest("prefix_headers_closure") { rustTemplate( """ let closure = #{Closure:W}; @@ -409,8 +409,8 @@ class ServerHttpSensitivityGeneratorTest { assertEquals("prefix-", asMapValue.prefixHeader) val testProject = TestWorkspace.testProject(serverTestSymbolProvider(model)) - testProject.lib { writer -> - writer.unitTest("prefix_headers_special_closure") { + testProject.lib { + unitTest("prefix_headers_special_closure") { rustTemplate( """ let closure = #{Closure:W}; @@ -463,8 +463,8 @@ class ServerHttpSensitivityGeneratorTest { assert(!asSensitiveMapValue.keySensitive) val testProject = TestWorkspace.testProject(serverTestSymbolProvider(model)) - testProject.lib { writer -> - writer.unitTest("prefix_headers_special_closure") { + testProject.lib { + unitTest("prefix_headers_special_closure") { rustTemplate( """ let closure = #{Closure:W}; @@ -515,8 +515,8 @@ class ServerHttpSensitivityGeneratorTest { assertEquals(listOf(1, 2), labelData.labelIndexes) val testProject = TestWorkspace.testProject(serverTestSymbolProvider(model)) - testProject.lib { writer -> - writer.unitTest("uri_closure") { + testProject.lib { + unitTest("uri_closure") { rustTemplate( """ let closure = #{Closure:W}; diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/EventStreamTestTools.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/EventStreamTestTools.kt index 3e551f239ec..3a917af0dc6 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/EventStreamTestTools.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/EventStreamTestTools.kt @@ -357,24 +357,24 @@ object EventStreamTestTools { .map { it.asStructureShape().get() } .toList() when (testCase.target) { - CodegenTarget.CLIENT -> CombinedErrorGenerator(model, symbolProvider, operationSymbol, errors).render(it) - CodegenTarget.SERVER -> ServerCombinedErrorGenerator(model, symbolProvider, operationSymbol, errors).render(it) + CodegenTarget.CLIENT -> CombinedErrorGenerator(model, symbolProvider, operationSymbol, errors).render(this) + CodegenTarget.SERVER -> ServerCombinedErrorGenerator(model, symbolProvider, operationSymbol, errors).render(this) } for (shape in model.shapes().filter { shape -> shape.isStructureShape && shape.hasTrait() }) { - StructureGenerator(model, symbolProvider, it, shape as StructureShape).render(testCase.target) + StructureGenerator(model, symbolProvider, this, shape as StructureShape).render(testCase.target) val builderGen = BuilderGenerator(model, symbolProvider, shape) - builderGen.render(it) - it.implBlock(shape, symbolProvider) { + builderGen.render(this) + implBlock(shape, symbolProvider) { builderGen.renderConvenienceMethod(this) } } } project.withModule(RustModule.public("model")) { val inputOutput = model.lookup("test#TestStreamInputOutput") - recursivelyGenerateModels(model, symbolProvider, inputOutput, it, testCase.target) + recursivelyGenerateModels(model, symbolProvider, inputOutput, this, testCase.target) } project.withModule(RustModule.public("output")) { - operationShape.outputShape(model).renderWithModelBuilder(model, symbolProvider, it) + operationShape.outputShape(model).renderWithModelBuilder(model, symbolProvider, this) } return TestEventStreamProject(model, serviceShape, operationShape, unionShape, symbolProvider, project) } diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/parse/EventStreamUnmarshallerGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/parse/EventStreamUnmarshallerGeneratorTest.kt index 419df695983..b2521012177 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/parse/EventStreamUnmarshallerGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/parse/EventStreamUnmarshallerGeneratorTest.kt @@ -44,8 +44,8 @@ class EventStreamUnmarshallerGeneratorTest { target = testCase.target, ) - test.project.lib { writer -> - writer.rust( + test.project.lib { + rust( """ use aws_smithy_eventstream::frame::{Header, HeaderValue, Message, UnmarshallMessage, UnmarshalledMessage}; use aws_smithy_types::{Blob, DateTime}; @@ -82,11 +82,11 @@ class EventStreamUnmarshallerGeneratorTest { """, ) - writer.unitTest( + unitTest( name = "message_with_blob", test = """ let message = msg("event", "MessageWithBlob", "application/octet-stream", b"hello, world!"); - let result = ${writer.format(generator.render())}().unmarshall(&message); + let result = ${format(generator.render())}().unmarshall(&message); assert!(result.is_ok(), "expected ok, got: {:?}", result); assert_eq!( TestStream::MessageWithBlob( @@ -98,11 +98,11 @@ class EventStreamUnmarshallerGeneratorTest { ) if (testCase.target == CodegenTarget.CLIENT) { - writer.unitTest( + unitTest( "unknown_message", """ let message = msg("event", "NewUnmodeledMessageType", "application/octet-stream", b"hello, world!"); - let result = ${writer.format(generator.render())}().unmarshall(&message); + let result = ${format(generator.render())}().unmarshall(&message); assert!(result.is_ok(), "expected ok, got: {:?}", result); assert_eq!( TestStream::Unknown, @@ -112,11 +112,11 @@ class EventStreamUnmarshallerGeneratorTest { ) } - writer.unitTest( + unitTest( "message_with_string", """ let message = msg("event", "MessageWithString", "text/plain", b"hello, world!"); - let result = ${writer.format(generator.render())}().unmarshall(&message); + let result = ${format(generator.render())}().unmarshall(&message); assert!(result.is_ok(), "expected ok, got: {:?}", result); assert_eq!( TestStream::MessageWithString(MessageWithString::builder().data("hello, world!").build()), @@ -125,7 +125,7 @@ class EventStreamUnmarshallerGeneratorTest { """, ) - writer.unitTest( + unitTest( "message_with_struct", """ let message = msg( @@ -134,7 +134,7 @@ class EventStreamUnmarshallerGeneratorTest { "${testCase.responseContentType}", br#"${testCase.validTestStruct}"# ); - let result = ${writer.format(generator.render())}().unmarshall(&message); + let result = ${format(generator.render())}().unmarshall(&message); assert!(result.is_ok(), "expected ok, got: {:?}", result); assert_eq!( TestStream::MessageWithStruct(MessageWithStruct::builder().some_struct( @@ -148,7 +148,7 @@ class EventStreamUnmarshallerGeneratorTest { """, ) - writer.unitTest( + unitTest( "message_with_union", """ let message = msg( @@ -157,7 +157,7 @@ class EventStreamUnmarshallerGeneratorTest { "${testCase.responseContentType}", br#"${testCase.validTestUnion}"# ); - let result = ${writer.format(generator.render())}().unmarshall(&message); + let result = ${format(generator.render())}().unmarshall(&message); assert!(result.is_ok(), "expected ok, got: {:?}", result); assert_eq!( TestStream::MessageWithUnion(MessageWithUnion::builder().some_union( @@ -168,7 +168,7 @@ class EventStreamUnmarshallerGeneratorTest { """, ) - writer.unitTest( + unitTest( "message_with_headers", """ let message = msg("event", "MessageWithHeaders", "application/octet-stream", b"") @@ -180,7 +180,7 @@ class EventStreamUnmarshallerGeneratorTest { .add_header(Header::new("short", HeaderValue::Int16(16_000i16))) .add_header(Header::new("string", HeaderValue::String("test".into()))) .add_header(Header::new("timestamp", HeaderValue::Timestamp(DateTime::from_secs(5)))); - let result = ${writer.format(generator.render())}().unmarshall(&message); + let result = ${format(generator.render())}().unmarshall(&message); assert!(result.is_ok(), "expected ok, got: {:?}", result); assert_eq!( TestStream::MessageWithHeaders(MessageWithHeaders::builder() @@ -199,12 +199,12 @@ class EventStreamUnmarshallerGeneratorTest { """, ) - writer.unitTest( + unitTest( "message_with_header_and_payload", """ let message = msg("event", "MessageWithHeaderAndPayload", "application/octet-stream", b"payload") .add_header(Header::new("header", HeaderValue::String("header".into()))); - let result = ${writer.format(generator.render())}().unmarshall(&message); + let result = ${format(generator.render())}().unmarshall(&message); assert!(result.is_ok(), "expected ok, got: {:?}", result); assert_eq!( TestStream::MessageWithHeaderAndPayload(MessageWithHeaderAndPayload::builder() @@ -217,7 +217,7 @@ class EventStreamUnmarshallerGeneratorTest { """, ) - writer.unitTest( + unitTest( "message_with_no_header_payload_traits", """ let message = msg( @@ -226,7 +226,7 @@ class EventStreamUnmarshallerGeneratorTest { "${testCase.responseContentType}", br#"${testCase.validMessageWithNoHeaderPayloadTraits}"# ); - let result = ${writer.format(generator.render())}().unmarshall(&message); + let result = ${format(generator.render())}().unmarshall(&message); assert!(result.is_ok(), "expected ok, got: {:?}", result); assert_eq!( TestStream::MessageWithNoHeaderPayloadTraits(MessageWithNoHeaderPayloadTraits::builder() @@ -243,7 +243,7 @@ class EventStreamUnmarshallerGeneratorTest { CodegenTarget.CLIENT -> listOf("TestStreamErrorKind::SomeError", ".kind") CodegenTarget.SERVER -> listOf("TestStreamError::SomeError", "") } - writer.unitTest( + unitTest( "some_error", """ let message = msg( @@ -252,7 +252,7 @@ class EventStreamUnmarshallerGeneratorTest { "${testCase.responseContentType}", br#"${testCase.validSomeError}"# ); - let result = ${writer.format(generator.render())}().unmarshall(&message); + let result = ${format(generator.render())}().unmarshall(&message); assert!(result.is_ok(), "expected ok, got: {:?}", result); match expect_error(result.unwrap())$kindSuffix { $someError(err) => assert_eq!(Some("some error"), err.message()), @@ -262,7 +262,7 @@ class EventStreamUnmarshallerGeneratorTest { ) if (testCase.target == CodegenTarget.CLIENT) { - writer.unitTest( + unitTest( "generic_error", """ let message = msg( @@ -271,7 +271,7 @@ class EventStreamUnmarshallerGeneratorTest { "${testCase.responseContentType}", br#"${testCase.validUnmodeledError}"# ); - let result = ${writer.format(generator.render())}().unmarshall(&message); + let result = ${format(generator.render())}().unmarshall(&message); assert!(result.is_ok(), "expected ok, got: {:?}", result); match expect_error(result.unwrap())$kindSuffix { TestStreamErrorKind::Unhandled(err) => { @@ -283,7 +283,7 @@ class EventStreamUnmarshallerGeneratorTest { ) } - writer.unitTest( + unitTest( "bad_content_type", """ let message = msg( @@ -292,7 +292,7 @@ class EventStreamUnmarshallerGeneratorTest { "wrong-content-type", br#"${testCase.validTestStruct}"# ); - let result = ${writer.format(generator.render())}().unmarshall(&message); + let result = ${format(generator.render())}().unmarshall(&message); assert!(result.is_err(), "expected error, got: {:?}", result); assert!(format!("{}", result.err().unwrap()).contains("expected :content-type to be")); """, diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt index 15dc788d4dd..9b87304554d 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/serialize/EventStreamMarshallerGeneratorTest.kt @@ -46,10 +46,10 @@ class EventStreamMarshallerGeneratorTest { testCase.requestContentType, ) - test.project.lib { writer -> + test.project.lib { val protocolTestHelpers = CargoDependency.SmithyProtocolTestHelpers(TestRuntimeConfig) .copy(scope = DependencyScope.Compile) - writer.rustTemplate( + rustTemplate( """ use aws_smithy_eventstream::frame::{Message, Header, HeaderValue, MarshallMessage}; use std::collections::HashMap; @@ -76,13 +76,13 @@ class EventStreamMarshallerGeneratorTest { "MediaType" to protocolTestHelpers.rustName("MediaType"), ) - writer.unitTest( + unitTest( "message_with_blob", """ let event = TestStream::MessageWithBlob( MessageWithBlob::builder().data(Blob::new(&b"hello, world!"[..])).build() ); - let result = ${writer.format(generator.render())}().marshall(event); + let result = ${format(generator.render())}().marshall(event); assert!(result.is_ok(), "expected ok, got: {:?}", result); let message = result.unwrap(); let headers = headers_to_map(message.headers()); @@ -93,13 +93,13 @@ class EventStreamMarshallerGeneratorTest { """, ) - writer.unitTest( + unitTest( "message_with_string", """ let event = TestStream::MessageWithString( MessageWithString::builder().data("hello, world!").build() ); - let result = ${writer.format(generator.render())}().marshall(event); + let result = ${format(generator.render())}().marshall(event); assert!(result.is_ok(), "expected ok, got: {:?}", result); let message = result.unwrap(); let headers = headers_to_map(message.headers()); @@ -110,7 +110,7 @@ class EventStreamMarshallerGeneratorTest { """, ) - writer.unitTest( + unitTest( "message_with_struct", """ let event = TestStream::MessageWithStruct( @@ -121,7 +121,7 @@ class EventStreamMarshallerGeneratorTest { .build() ).build() ); - let result = ${writer.format(generator.render())}().marshall(event); + let result = ${format(generator.render())}().marshall(event); assert!(result.is_ok(), "expected ok, got: {:?}", result); let message = result.unwrap(); let headers = headers_to_map(message.headers()); @@ -137,13 +137,13 @@ class EventStreamMarshallerGeneratorTest { """, ) - writer.unitTest( + unitTest( "message_with_union", """ let event = TestStream::MessageWithUnion(MessageWithUnion::builder().some_union( TestUnion::Foo("hello".into()) ).build()); - let result = ${writer.format(generator.render())}().marshall(event); + let result = ${format(generator.render())}().marshall(event); assert!(result.is_ok(), "expected ok, got: {:?}", result); let message = result.unwrap(); let headers = headers_to_map(message.headers()); @@ -159,7 +159,7 @@ class EventStreamMarshallerGeneratorTest { """, ) - writer.unitTest( + unitTest( "message_with_headers", """ let event = TestStream::MessageWithHeaders(MessageWithHeaders::builder() @@ -173,7 +173,7 @@ class EventStreamMarshallerGeneratorTest { .timestamp(DateTime::from_secs(5)) .build() ); - let result = ${writer.format(generator.render())}().marshall(event); + let result = ${format(generator.render())}().marshall(event); assert!(result.is_ok(), "expected ok, got: {:?}", result); let actual_message = result.unwrap(); let expected_message = Message::new(&b""[..]) @@ -191,7 +191,7 @@ class EventStreamMarshallerGeneratorTest { """, ) - writer.unitTest( + unitTest( "message_with_header_and_payload", """ let event = TestStream::MessageWithHeaderAndPayload(MessageWithHeaderAndPayload::builder() @@ -199,7 +199,7 @@ class EventStreamMarshallerGeneratorTest { .payload(Blob::new(&b"payload"[..])) .build() ); - let result = ${writer.format(generator.render())}().marshall(event); + let result = ${format(generator.render())}().marshall(event); assert!(result.is_ok(), "expected ok, got: {:?}", result); let actual_message = result.unwrap(); let expected_message = Message::new(&b"payload"[..]) @@ -211,7 +211,7 @@ class EventStreamMarshallerGeneratorTest { """, ) - writer.unitTest( + unitTest( "message_with_no_header_payload_traits", """ let event = TestStream::MessageWithNoHeaderPayloadTraits(MessageWithNoHeaderPayloadTraits::builder() @@ -219,7 +219,7 @@ class EventStreamMarshallerGeneratorTest { .some_string("hello") .build() ); - let result = ${writer.format(generator.render())}().marshall(event); + let result = ${format(generator.render())}().marshall(event); assert!(result.is_ok(), "expected ok, got: {:?}", result); let message = result.unwrap(); let headers = headers_to_map(message.headers()); From ab703195bbef400be9d88b0adf558ce2a0f1d8f9 Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Tue, 18 Oct 2022 12:39:12 -0700 Subject: [PATCH 44/57] Fix case sensitivity bug in `changelogger` (#1866) --- tools/changelogger/Cargo.lock | 1 + tools/changelogger/Cargo.toml | 1 + tools/changelogger/src/render.rs | 19 +++++++++++++------ tools/changelogger/tests/e2e_test.rs | 2 +- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/tools/changelogger/Cargo.lock b/tools/changelogger/Cargo.lock index 24955c08d87..4ee3df2db4a 100644 --- a/tools/changelogger/Cargo.lock +++ b/tools/changelogger/Cargo.lock @@ -87,6 +87,7 @@ version = "0.1.0" dependencies = [ "anyhow", "clap", + "once_cell", "ordinal", "pretty_assertions", "serde", diff --git a/tools/changelogger/Cargo.toml b/tools/changelogger/Cargo.toml index 62cf3551c15..fd4d4e5c8c6 100644 --- a/tools/changelogger/Cargo.toml +++ b/tools/changelogger/Cargo.toml @@ -17,6 +17,7 @@ opt-level = 0 [dependencies] anyhow = "1.0.57" clap = { version = "~3.2.1", features = ["derive"] } +once_cell = "1.15.0" ordinal = "0.3.2" serde = { version = "1", features = ["derive"]} serde_json = "1" diff --git a/tools/changelogger/src/render.rs b/tools/changelogger/src/render.rs index 9bb8e765a4d..5f1585b1151 100644 --- a/tools/changelogger/src/render.rs +++ b/tools/changelogger/src/render.rs @@ -6,6 +6,7 @@ use crate::entry::{ChangeSet, ChangelogEntries, ChangelogEntry}; use anyhow::{bail, Context, Result}; use clap::Parser; +use once_cell::sync::Lazy; use ordinal::Ordinal; use serde::Serialize; use smithy_rs_tool_common::changelog::{ @@ -35,10 +36,16 @@ pub const EXAMPLE_ENTRY: &str = r#" pub const USE_UPDATE_CHANGELOGS: &str = ""; -fn maintainers() -> Vec<&'static str> { +static MAINTAINERS: Lazy> = Lazy::new(|| { include_str!("../smithy-rs-maintainers.txt") .lines() + .map(|name| name.to_ascii_lowercase()) .collect() +}); + +fn is_maintainer(name: &str) -> bool { + let name_lower = name.to_ascii_lowercase(); + MAINTAINERS.iter().any(|name| *name == name_lower) } #[derive(Parser, Debug, Eq, PartialEq)] @@ -181,8 +188,8 @@ fn render_entry(entry: &HandAuthoredEntry, mut out: &mut String) { .map(|t| t.to_string()) .chain(entry.references.iter().map(to_md_link)) .collect::>(); - if !maintainers().contains(&entry.author.to_ascii_lowercase().as_str()) { - references.push(format!("@{}", entry.author.to_ascii_lowercase())); + if !is_maintainer(&entry.author) { + references.push(format!("@{}", entry.author)); }; if !references.is_empty() { write!(meta, "({}) ", references.join(", ")).unwrap(); @@ -345,8 +352,8 @@ fn render(entries: &[ChangelogEntry], release_header: &str) -> (String, String) let mut external_contribs = entries .iter() - .filter_map(|entry| entry.hand_authored().map(|e| e.author.to_ascii_lowercase())) - .filter(|author| !maintainers().contains(&author.as_str())) + .filter_map(|entry| entry.hand_authored().map(|e| &e.author)) + .filter(|author| !is_maintainer(author)) .collect::>(); external_contribs.sort(); external_contribs.dedup(); @@ -375,7 +382,7 @@ fn render(entries: &[ChangelogEntry], release_header: &str) -> (String, String) contribution_references.dedup(); let contribution_references = contribution_references.as_slice().join(", "); out.push_str("- @"); - out.push_str(&contributor_handle); + out.push_str(contributor_handle); if !contribution_references.is_empty() { write!(&mut out, " ({})", contribution_references) // The `Write` implementation for `String` is infallible, diff --git a/tools/changelogger/tests/e2e_test.rs b/tools/changelogger/tests/e2e_test.rs index ee07e7445be..8d51a3e7a1d 100644 --- a/tools/changelogger/tests/e2e_test.rs +++ b/tools/changelogger/tests/e2e_test.rs @@ -432,7 +432,7 @@ author = "rcoh" message = "Fourth change - client" references = ["smithy-rs#4"] meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client" } -author = "rcoh" +author = "LukeMathWalker" "#; let tmp_dir = TempDir::new().unwrap(); let source_path = tmp_dir.path().join("source.toml"); From 374a0a25f83f5bae92bfac785cf783891bbb1937 Mon Sep 17 00:00:00 2001 From: Kevin Park Date: Tue, 18 Oct 2022 18:23:25 -0400 Subject: [PATCH 45/57] Ability to override the IMDS client in `DefaultCredentialsChain` (#1867) --- CHANGELOG.next.toml | 6 ++++++ .../aws-config/src/default_provider/credentials.rs | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 6932247c3fc..eed807e7da4 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -180,3 +180,9 @@ message = "Enable local maven repo dependency override." references = ["smithy-rs#1852"] meta = { "breaking" = false, "tada" = false, "bug" = false } author = "ogudavid" + +[[aws-sdk-rust]] +message = "Ability to override the IMDS client in `DefaultCredentialsChain`" +references = ["aws-sdk-rust#625"] +meta = { "breaking" = false, "tada" = false, "bug" = false } +author = "kevinpark1217" diff --git a/aws/rust-runtime/aws-config/src/default_provider/credentials.rs b/aws/rust-runtime/aws-config/src/default_provider/credentials.rs index 8ebffc6b8a9..78f0e026b60 100644 --- a/aws/rust-runtime/aws-config/src/default_provider/credentials.rs +++ b/aws/rust-runtime/aws-config/src/default_provider/credentials.rs @@ -212,6 +212,14 @@ impl Builder { self } + /// Override the IMDS client used for this provider + /// + /// When unset, the default IMDS client will be used. + pub fn imds_client(mut self, client: crate::imds::Client) -> Self { + self.imds_builder = self.imds_builder.imds_client(client); + self + } + /// Override the configuration used for this provider pub fn configure(mut self, config: ProviderConfig) -> Self { self.region_chain = self.region_chain.configure(&config); From 521fa8d0dc76f182f64fa5d7be781f284a62506d Mon Sep 17 00:00:00 2001 From: ysaito1001 Date: Tue, 18 Oct 2022 21:28:46 -0500 Subject: [PATCH 46/57] Fix aws-sigv4 canonical request formatting fallibility (#1656) * Fix panic occurred in formatting CanonicalRequest This commit addresses panic in the case of formatting a CanonicalRequest containing invalid UTF-8 in the header value. The commit aims for the least disturbance to the codebase in order to pass a given failing test in the PR. We want to quickly determine if this low-cost approach addresses the problem before we commit ourselves to start refactoring CanonicalRequest to have a special format function. Fixes #711 * Update test_signing_utf8_headers to proptest This commit converts test_signing_utf8_headers to a proptest. The original test only specified hardcoded non-UTF8 bytes in a request header. To ensure that `crate::http_request::sign` does not panic no matter what valid byte sequence for HeaderValue is, the proptest covers a wider range of inputs. For consistency, the test has been moved from `canonical_request.rs` to `sign.rs`. * Add InvalidHeaderError to make the error explicit This commit introduces an error type InvalidHeaderError to indicate that we ran into a problem in handling a HeaderValue within CanonicalRequest. The error type contains a source error such as Utf8Error so a diagnostic message can be printed if needed. * Remove InvalidHeaderError for error refactoring This commit effectively reverts 739b32c. Knowing that we will be cleaning up error types, having InvalidHeaderError is too narrow a solution and does not add value to the codebase. * Update CHANGELOG.next.toml Co-authored-by: Russell Cohen Co-authored-by: Saito --- CHANGELOG.next.toml | 6 ++ .../src/http_request/canonical_request.rs | 20 ++++--- .../aws-sigv4/src/http_request/sign.rs | 57 +++++++++++++++++++ 3 files changed, 76 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index eed807e7da4..3715ae298c7 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -186,3 +186,9 @@ message = "Ability to override the IMDS client in `DefaultCredentialsChain`" references = ["aws-sdk-rust#625"] meta = { "breaking" = false, "tada" = false, "bug" = false } author = "kevinpark1217" + +[[aws-sdk-rust]] +message = "Fix aws-sigv4 canonical request formatting fallibility." +references = ["smithy-rs#1656"] +meta = { "breaking" = false, "tada" = false, "bug" = true } +author = "ysaito1001" diff --git a/aws/rust-runtime/aws-sigv4/src/http_request/canonical_request.rs b/aws/rust-runtime/aws-sigv4/src/http_request/canonical_request.rs index b1c37fdfa1a..8bd0e0b9313 100644 --- a/aws/rust-runtime/aws-sigv4/src/http_request/canonical_request.rs +++ b/aws/rust-runtime/aws-sigv4/src/http_request/canonical_request.rs @@ -196,7 +196,7 @@ impl<'a> CanonicalRequest<'a> { // Using append instead of insert means this will not clobber headers that have the same lowercased name canonical_headers.append( HeaderName::from_str(&name.as_str().to_lowercase())?, - normalize_header_value(value), + normalize_header_value(value)?, ); } @@ -373,11 +373,11 @@ fn trim_spaces_from_byte_string(bytes: &[u8]) -> &[u8] { &bytes[starting_index..ending_index] } -/// Works just like [trim_all] but acts on HeaderValues instead of bytes -fn normalize_header_value(header_value: &HeaderValue) -> HeaderValue { +/// Works just like [trim_all] but acts on HeaderValues instead of bytes. +/// Will ensure that the underlying bytes are valid UTF-8. +fn normalize_header_value(header_value: &HeaderValue) -> Result { let trimmed_value = trim_all(header_value.as_bytes()); - // This can't fail because we started with a valid HeaderValue and then only trimmed spaces - HeaderValue::from_bytes(&trimmed_value).unwrap() + HeaderValue::from_str(std::str::from_utf8(&trimmed_value)?).map_err(Error::from) } #[derive(Debug, PartialEq, Default)] @@ -738,9 +738,9 @@ mod tests { } #[test] - fn test_normalize_header_value_doesnt_panic(v in (".*")) { + fn test_normalize_header_value_works_on_valid_header_value(v in (".*")) { if let Ok(header_value) = HeaderValue::from_maybe_shared(v) { - let _ = normalize_header_value(&header_value); + assert!(normalize_header_value(&header_value).is_ok()); } } @@ -749,4 +749,10 @@ mod tests { assert_eq!(trim_all(s.as_bytes()).as_ref(), s.as_bytes()); } } + + #[test] + fn test_normalize_header_value_returns_expected_error_on_invalid_utf8() { + let header_value = HeaderValue::from_bytes(&[0xC0, 0xC1]).unwrap(); + assert!(normalize_header_value(&header_value).is_err()); + } } diff --git a/aws/rust-runtime/aws-sigv4/src/http_request/sign.rs b/aws/rust-runtime/aws-sigv4/src/http_request/sign.rs index ea22d18a774..d67c6cabe18 100644 --- a/aws/rust-runtime/aws-sigv4/src/http_request/sign.rs +++ b/aws/rust-runtime/aws-sigv4/src/http_request/sign.rs @@ -311,6 +311,7 @@ mod tests { use crate::http_request::{SignatureLocation, SigningParams, SigningSettings}; use http::{HeaderMap, HeaderValue}; use pretty_assertions::assert_eq; + use proptest::proptest; use std::borrow::Cow; use std::time::Duration; @@ -515,6 +516,62 @@ mod tests { assert_req_eq!(expected, signed); } + #[test] + fn test_sign_headers_returning_expected_error_on_invalid_utf8() { + let settings = SigningSettings::default(); + let params = SigningParams { + access_key: "123", + secret_key: "asdf", + security_token: None, + region: "us-east-1", + service_name: "foo", + time: std::time::SystemTime::now(), + settings, + }; + + let req = http::Request::builder() + .uri("https://foo.com/") + .header("x-sign-me", HeaderValue::from_bytes(&[0xC0, 0xC1]).unwrap()) + .body(&[]) + .unwrap(); + + let creq = crate::http_request::sign(SignableRequest::from(&req), ¶ms); + assert!(creq.is_err()); + } + + proptest! { + #[test] + // Only byte values between 32 and 255 (inclusive) are permitted, excluding byte 127, for + // [HeaderValue](https://docs.rs/http/latest/http/header/struct.HeaderValue.html#method.from_bytes). + fn test_sign_headers_no_panic( + left in proptest::collection::vec(32_u8..=126, 0..100), + right in proptest::collection::vec(128_u8..=255, 0..100), + ) { + let settings = SigningSettings::default(); + let params = SigningParams { + access_key: "123", + secret_key: "asdf", + security_token: None, + region: "us-east-1", + service_name: "foo", + time: std::time::SystemTime::now(), + settings, + }; + + let bytes = left.iter().chain(right.iter()).cloned().collect::>(); + let req = http::Request::builder() + .uri("https://foo.com/") + .header("x-sign-me", HeaderValue::from_bytes(&bytes).unwrap()) + .body(&[]) + .unwrap(); + + // The test considered a pass if the creation of `creq` does not panic. + let _creq = crate::http_request::sign( + SignableRequest::from(&req), + ¶ms); + } + } + #[test] fn apply_signing_instructions_headers() { let mut headers = HeaderMap::new(); From 007f1bfc7c5755a9ba590765fb4a1139ce4f4b5f Mon Sep 17 00:00:00 2001 From: Julian Antonielli Date: Wed, 19 Oct 2022 10:28:56 +0100 Subject: [PATCH 47/57] Use pin-utils crate instead of vendoring pin_mut (#1862) --- rust-runtime/aws-smithy-http/Cargo.toml | 1 + .../aws-smithy-http/src/byte_stream.rs | 2 +- rust-runtime/aws-smithy-http/src/lib.rs | 1 - .../aws-smithy-http/src/middleware.rs | 2 +- rust-runtime/aws-smithy-http/src/pin_util.rs | 30 ------------------- 5 files changed, 3 insertions(+), 33 deletions(-) delete mode 100644 rust-runtime/aws-smithy-http/src/pin_util.rs diff --git a/rust-runtime/aws-smithy-http/Cargo.toml b/rust-runtime/aws-smithy-http/Cargo.toml index 3593989fd65..23bb28437d4 100644 --- a/rust-runtime/aws-smithy-http/Cargo.toml +++ b/rust-runtime/aws-smithy-http/Cargo.toml @@ -24,6 +24,7 @@ http-body = "0.4.4" once_cell = "1.10" percent-encoding = "2.1.0" pin-project-lite = "0.2.9" +pin-utils = "0.1.0" tracing = "0.1" # We are using hyper for our streaming body implementation, but this is an internal detail. diff --git a/rust-runtime/aws-smithy-http/src/byte_stream.rs b/rust-runtime/aws-smithy-http/src/byte_stream.rs index 6c58a591198..09ab48df9e1 100644 --- a/rust-runtime/aws-smithy-http/src/byte_stream.rs +++ b/rust-runtime/aws-smithy-http/src/byte_stream.rs @@ -544,7 +544,7 @@ impl Inner { { let mut output = SegmentedBuf::new(); let body = self.body; - crate::pin_mut!(body); + pin_utils::pin_mut!(body); while let Some(buf) = body.data().await { output.push(buf?); } diff --git a/rust-runtime/aws-smithy-http/src/lib.rs b/rust-runtime/aws-smithy-http/src/lib.rs index 2b7e6b9c0ed..1e47d7e1230 100644 --- a/rust-runtime/aws-smithy-http/src/lib.rs +++ b/rust-runtime/aws-smithy-http/src/lib.rs @@ -36,5 +36,4 @@ pub mod event_stream; pub mod byte_stream; -mod pin_util; mod urlencode; diff --git a/rust-runtime/aws-smithy-http/src/middleware.rs b/rust-runtime/aws-smithy-http/src/middleware.rs index 672c30cb36a..c3013f9f551 100644 --- a/rust-runtime/aws-smithy-http/src/middleware.rs +++ b/rust-runtime/aws-smithy-http/src/middleware.rs @@ -10,11 +10,11 @@ use crate::body::SdkBody; use crate::operation; -use crate::pin_mut; use crate::response::ParseHttpResponse; use crate::result::{SdkError, SdkSuccess}; use bytes::{Buf, Bytes}; use http_body::Body; +use pin_utils::pin_mut; use std::error::Error; use std::future::Future; use tracing::trace; diff --git a/rust-runtime/aws-smithy-http/src/pin_util.rs b/rust-runtime/aws-smithy-http/src/pin_util.rs deleted file mode 100644 index 7c39f4f1161..00000000000 --- a/rust-runtime/aws-smithy-http/src/pin_util.rs +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -/// Pins a value on the stack. -/// -/// # Examples -/// -/// ```rust -/// # use core::pin::Pin; -/// # struct Foo {} -/// # use aws_smithy_http::pin_mut; -/// let foo = Foo { /* ... */ }; -/// pin_mut!(foo); -/// let _: Pin<&mut Foo> = foo; -/// ``` -#[macro_export] -macro_rules! pin_mut { - ($($x:ident),* $(,)?) => { $( - // Move the value to ensure that it is owned - let mut $x = $x; - // Shadow the original binding so that it can't be directly accessed - // ever again. - #[allow(unused_mut)] - let mut $x = unsafe { - core::pin::Pin::new_unchecked(&mut $x) - }; - )* } -} From a5040e35441719007d48bbdbe6ccd4443eabdb52 Mon Sep 17 00:00:00 2001 From: Julian Antonielli Date: Wed, 19 Oct 2022 14:51:00 +0100 Subject: [PATCH 48/57] Add rust-toolchain.toml (#1861) --- rust-toolchain.toml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 rust-toolchain.toml diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000000..04c0fe7fbfb --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "1.62.0" + From e798104c7130b0a27491e70fc9a3238f36f49040 Mon Sep 17 00:00:00 2001 From: david-perez Date: Wed, 19 Oct 2022 16:37:19 +0200 Subject: [PATCH 49/57] Refactor `Instantiator` (#1863) The `Instantiator` is a rather old part of the codebase that has been accumulating a bit of technical debt. This commit refactors `Instantiator.kt`. * Removes dependency on `CodegenTarget`; the instantiator is now client and server agnostic. `ClientInstantiator` and `ServerInstantiator` instantiate the underlying instantiator with the settings needed by each project. * The test suite has been completely rewritten to make use of the newer testing infrastructure (`TestWorkspace.testProject()`), and coverage around enum generation has been improved. * `Instantiator.Ctx` and its uses have been simplified. * The modified code has been reformatted to adhere to our styling conventions. This commit also renames `StructureGenerator.fallibleBuilder` to `StructureGenerator.hasFallibleBuilder`. This commit also changes usages of `RustWriter::write` to `RustWriter::rust` in `ServerProtocolTestGenerator`, where applicable. All in all this commit will make the diff of #1342 lighter, where deviations among clients and servers regarding structure instantiation substantially increase. --- .../smithy/generators/ClientInstantiator.kt | 25 ++ .../protocol/ProtocolTestGenerator.kt | 7 +- .../protocols/HttpBoundProtocolGenerator.kt | 2 +- .../generators/ClientInstantiatorTest.kt | 87 +++++ .../smithy/generators/BuilderGenerator.kt | 2 +- .../core/smithy/generators/Instantiator.kt | 160 +++++---- .../smithy/generators/StructureGenerator.kt | 2 +- .../protocols/parse/JsonParserGenerator.kt | 2 +- .../parse/XmlBindingTraitParserGenerator.kt | 2 +- .../rust/codegen/core/testutil/TestHelpers.kt | 7 +- .../smithy/generators/InstantiatorTest.kt | 306 +++++++----------- .../smithy/generators/ServerInstantiator.kt | 34 ++ .../protocol/ServerProtocolTestGenerator.kt | 36 +-- .../ServerHttpBoundProtocolGenerator.kt | 2 +- .../smithy/testutil/ServerTestHelpers.kt | 3 +- .../generators/ServerInstantiatorTest.kt | 221 +++++++++++++ 16 files changed, 594 insertions(+), 304 deletions(-) create mode 100644 codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientInstantiator.kt create mode 100644 codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientInstantiatorTest.kt create mode 100644 codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerInstantiator.kt create mode 100644 codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerInstantiatorTest.kt diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientInstantiator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientInstantiator.kt new file mode 100644 index 00000000000..5e47701f550 --- /dev/null +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientInstantiator.kt @@ -0,0 +1,25 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rust.codegen.client.smithy.generators + +import software.amazon.smithy.codegen.core.Symbol +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.generators.Instantiator + +private fun enumFromStringFn(enumSymbol: Symbol, data: String): Writable = writable { + rust("#T::from($data)", enumSymbol) +} + +fun clientInstantiator(codegenContext: CodegenContext) = + Instantiator( + codegenContext.symbolProvider, + codegenContext.model, + codegenContext.runtimeConfig, + ::enumFromStringFn, + ) diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt index a3e1ed6f9d2..6f670b641f7 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/protocol/ProtocolTestGenerator.kt @@ -19,6 +19,7 @@ import software.amazon.smithy.protocoltests.traits.HttpRequestTestCase import software.amazon.smithy.protocoltests.traits.HttpRequestTestsTrait import software.amazon.smithy.protocoltests.traits.HttpResponseTestCase import software.amazon.smithy.protocoltests.traits.HttpResponseTestsTrait +import software.amazon.smithy.rust.codegen.client.smithy.generators.clientInstantiator import software.amazon.smithy.rust.codegen.core.rustlang.Attribute import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustMetadata @@ -33,9 +34,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext -import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.core.smithy.generators.Instantiator import software.amazon.smithy.rust.codegen.core.smithy.generators.error.errorSymbol import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.core.testutil.TokioTest @@ -66,9 +65,7 @@ class ProtocolTestGenerator( private val operationSymbol = codegenContext.symbolProvider.toSymbol(operationShape) private val operationIndex = OperationIndex.of(codegenContext.model) - private val instantiator = with(codegenContext) { - Instantiator(symbolProvider, model, runtimeConfig, CodegenTarget.CLIENT) - } + private val instantiator = clientInstantiator(codegenContext) private val codegenScope = arrayOf( "SmithyHttp" to CargoDependency.SmithyHttp(codegenContext.runtimeConfig).asType(), diff --git a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt index 1e44de1aa6e..912a0f668a5 100644 --- a/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt +++ b/codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/protocols/HttpBoundProtocolGenerator.kt @@ -332,7 +332,7 @@ class HttpBoundProtocolTraitImplGenerator( } } - val err = if (StructureGenerator.fallibleBuilder(outputShape, symbolProvider)) { + val err = if (StructureGenerator.hasFallibleBuilder(outputShape, symbolProvider)) { ".map_err(${format(errorSymbol)}::unhandled)?" } else "" diff --git a/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientInstantiatorTest.kt b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientInstantiatorTest.kt new file mode 100644 index 00000000000..e55f98c0d31 --- /dev/null +++ b/codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/smithy/generators/ClientInstantiatorTest.kt @@ -0,0 +1,87 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ + +package software.amazon.smithy.rust.codegen.client.smithy.generators + +import org.junit.jupiter.api.Test +import software.amazon.smithy.model.node.Node +import software.amazon.smithy.model.shapes.StringShape +import software.amazon.smithy.rust.codegen.client.testutil.testCodegenContext +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.util.dq +import software.amazon.smithy.rust.codegen.core.util.expectTrait +import software.amazon.smithy.rust.codegen.core.util.lookup + +internal class ClientInstantiatorTest { + private val model = """ + namespace com.test + + @enum([ + { value: "t2.nano" }, + { value: "t2.micro" }, + ]) + string UnnamedEnum + + @enum([ + { + value: "t2.nano", + name: "T2_NANO", + }, + { + value: "t2.micro", + name: "T2_MICRO", + }, + ]) + string NamedEnum + """.asSmithyModel() + + private val codegenContext = testCodegenContext(model) + private val symbolProvider = codegenContext.symbolProvider + + @Test + fun `generate named enums`() { + val shape = model.lookup("com.test#NamedEnum") + val sut = clientInstantiator(codegenContext) + val data = Node.parse("t2.nano".dq()) + + val project = TestWorkspace.testProject() + project.withModule(RustModule.Model) { + EnumGenerator(model, symbolProvider, this, shape, shape.expectTrait()).render() + unitTest("generate_named_enums") { + withBlock("let result = ", ";") { + sut.render(this, shape, data) + } + rust("assert_eq!(result, NamedEnum::T2Nano);") + } + } + project.compileAndTest() + } + + @Test + fun `generate unnamed enums`() { + val shape = model.lookup("com.test#UnnamedEnum") + val sut = clientInstantiator(codegenContext) + val data = Node.parse("t2.nano".dq()) + + val project = TestWorkspace.testProject() + project.withModule(RustModule.Model) { + EnumGenerator(model, symbolProvider, this, shape, shape.expectTrait()).render() + unitTest("generate_unnamed_enums") { + withBlock("let result = ", ";") { + sut.render(this, shape, data) + } + rust("""assert_eq!(result, UnnamedEnum("t2.nano".to_owned()));""") + } + } + project.compileAndTest() + } +} diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt index 5ff4f33dd1a..9ae2da62adc 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/BuilderGenerator.kt @@ -79,7 +79,7 @@ class BuilderGenerator( } private fun renderBuildFn(implBlockWriter: RustWriter) { - val fallibleBuilder = StructureGenerator.fallibleBuilder(shape, symbolProvider) + val fallibleBuilder = StructureGenerator.hasFallibleBuilder(shape, symbolProvider) val outputSymbol = symbolProvider.toSymbol(shape) val returnType = when (fallibleBuilder) { true -> "Result<${implBlockWriter.format(outputSymbol)}, ${implBlockWriter.format(runtimeConfig.operationBuildError())}>" diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt index a869e732559..a58c0c65bec 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/Instantiator.kt @@ -6,6 +6,7 @@ package software.amazon.smithy.rust.codegen.core.smithy.generators import software.amazon.smithy.codegen.core.CodegenException +import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.Model import software.amazon.smithy.model.node.ArrayNode import software.amazon.smithy.model.node.Node @@ -29,9 +30,11 @@ import software.amazon.smithy.model.shapes.TimestampShape import software.amazon.smithy.model.shapes.UnionShape import software.amazon.smithy.model.traits.EnumTrait import software.amazon.smithy.model.traits.HttpPrefixHeadersTrait +import software.amazon.smithy.model.traits.StreamingTrait import software.amazon.smithy.rust.codegen.core.rustlang.CargoDependency import software.amazon.smithy.rust.codegen.core.rustlang.RustType import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter +import software.amazon.smithy.rust.codegen.core.rustlang.Writable import software.amazon.smithy.rust.codegen.core.rustlang.asType import software.amazon.smithy.rust.codegen.core.rustlang.conditionalBlock import software.amazon.smithy.rust.codegen.core.rustlang.escape @@ -40,7 +43,6 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.stripOuter import software.amazon.smithy.rust.codegen.core.rustlang.withBlock -import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider @@ -49,57 +51,48 @@ import software.amazon.smithy.rust.codegen.core.smithy.rustType import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.expectMember import software.amazon.smithy.rust.codegen.core.util.hasTrait -import software.amazon.smithy.rust.codegen.core.util.isStreaming import software.amazon.smithy.rust.codegen.core.util.letIf /** - * Instantiator generates code to instantiate a given Shape given a `Node` representing the value + * Instantiator generates code to instantiate a given Shape given a `Node` representing the value. * - * This is primarily used during Protocol test generation + * This is only used during protocol test generation. */ -class Instantiator( +open class Instantiator( private val symbolProvider: RustSymbolProvider, private val model: Model, private val runtimeConfig: RuntimeConfig, - private val target: CodegenTarget, + /** + * A function that given a symbol for an enum shape and a string, returns a writable to instantiate the enum with + * the string value. + **/ + private val enumFromStringFn: (Symbol, String) -> Writable, + /** Fill out required fields with a default value **/ + private val defaultsForRequiredFields: Boolean = false, ) { data class Ctx( - // The Rust HTTP library lower cases headers but Smithy protocol tests - // contain httpPrefix headers with uppercase keys - val lowercaseMapKeys: Boolean, - val streaming: Boolean, - // Whether we are instantiating with a Builder, in which case all setters take Option - val builder: Boolean, - // Fill out `required` fields with a default value. - val defaultsForRequiredFields: Boolean, + // The `http` crate requires that headers be lowercase, but Smithy protocol tests + // contain headers with uppercase keys. + val lowercaseMapKeys: Boolean = false, ) - companion object { - fun defaultContext() = Ctx(lowercaseMapKeys = false, streaming = false, builder = false, defaultsForRequiredFields = false) - } - - fun render( - writer: RustWriter, - shape: Shape, - arg: Node, - ctx: Ctx = defaultContext(), - ) { + fun render(writer: RustWriter, shape: Shape, data: Node, ctx: Ctx = Ctx()) { when (shape) { // Compound Shapes - is StructureShape -> renderStructure(writer, shape, arg as ObjectNode, ctx.copy(builder = true)) - is UnionShape -> renderUnion(writer, shape, arg as ObjectNode, ctx) + is StructureShape -> renderStructure(writer, shape, data as ObjectNode, ctx) + is UnionShape -> renderUnion(writer, shape, data as ObjectNode, ctx) // Collections - is ListShape -> renderList(writer, shape, arg as ArrayNode, ctx) - is MapShape -> renderMap(writer, shape, arg as ObjectNode, ctx) - is SetShape -> renderSet(writer, shape, arg as ArrayNode, ctx) + is ListShape -> renderList(writer, shape, data as ArrayNode, ctx) + is MapShape -> renderMap(writer, shape, data as ObjectNode, ctx) + is SetShape -> renderSet(writer, shape, data as ArrayNode, ctx) // Members, supporting potentially optional members - is MemberShape -> renderMember(writer, shape, arg, ctx) + is MemberShape -> renderMember(writer, shape, data, ctx) // Wrapped Shapes - is TimestampShape -> writer.write( - "#T::from_secs(${(arg as NumberNode).value})", + is TimestampShape -> writer.rust( + "#T::from_secs(${(data as NumberNode).value})", RuntimeType.DateTime(runtimeConfig), ) @@ -108,38 +101,40 @@ class Instantiator( * Blob::new("arg") * ``` */ - is BlobShape -> if (ctx.streaming) { - writer.write( - "#T::from_static(b${(arg as StringNode).value.dq()})", + is BlobShape -> if (shape.hasTrait()) { + writer.rust( + "#T::from_static(b${(data as StringNode).value.dq()})", RuntimeType.ByteStream(runtimeConfig), ) } else { - writer.write( - "#T::new(${(arg as StringNode).value.dq()})", + writer.rust( + "#T::new(${(data as StringNode).value.dq()})", RuntimeType.Blob(runtimeConfig), ) } // Simple Shapes - is StringShape -> renderString(writer, shape, arg as StringNode) - is NumberShape -> when (arg) { + is StringShape -> renderString(writer, shape, data as StringNode) + is NumberShape -> when (data) { is StringNode -> { val numberSymbol = symbolProvider.toSymbol(shape) // support Smithy custom values, such as Infinity writer.rust( - """<#T as #T>::parse_smithy_primitive(${arg.value.dq()}).expect("invalid string for number")""", + """<#T as #T>::parse_smithy_primitive(${data.value.dq()}).expect("invalid string for number")""", numberSymbol, CargoDependency.SmithyTypes(runtimeConfig).asType().member("primitive::Parse"), ) } - is NumberNode -> writer.write(arg.value) + + is NumberNode -> writer.write(data.value) } - is BooleanShape -> writer.write(arg.asBooleanNode().get().toString()) + + is BooleanShape -> writer.rust(data.asBooleanNode().get().toString()) is DocumentShape -> writer.rustBlock("") { val smithyJson = CargoDependency.smithyJson(runtimeConfig).asType() rustTemplate( """ - let json_bytes = br##"${Node.prettyPrintJson(arg)}"##; + let json_bytes = br##"${Node.prettyPrintJson(data)}"##; let mut tokens = #{json_token_iter}(json_bytes).peekable(); #{expect_document}(&mut tokens).expect("well formed json") """, @@ -147,26 +142,30 @@ class Instantiator( "json_token_iter" to smithyJson.member("deserialize::json_token_iter"), ) } - else -> writer.writeWithNoFormatting("todo!() /* $shape $arg */") + + else -> writer.writeWithNoFormatting("todo!() /* $shape $data */") } } /** - * If the shape is optional: `Some(inner)` or `None` - * otherwise: `inner` + * If the shape is optional: `Some(inner)` or `None`. + * Otherwise: `inner`. */ - private fun renderMember(writer: RustWriter, shape: MemberShape, arg: Node, ctx: Ctx) { - val target = model.expectShape(shape.target) - val symbol = symbolProvider.toSymbol(shape) - if (arg is NullNode) { - check( - symbol.isOptional(), - ) { "A null node was provided for $shape but the symbol was not optional. This is invalid input data." } - writer.write("None") + private fun renderMember(writer: RustWriter, memberShape: MemberShape, data: Node, ctx: Ctx) { + val targetShape = model.expectShape(memberShape.target) + val symbol = symbolProvider.toSymbol(memberShape) + if (data is NullNode) { + check(symbol.isOptional()) { + "A null node was provided for $memberShape but the symbol was not optional. This is invalid input data." + } + writer.rust("None") } else { + // Structure builder setters for structure shape members _always_ take in `Option`. + // Other aggregate shapes' members are optional only when their symbol is. writer.conditionalBlock( - "Some(", ")", - conditional = ctx.builder || symbol.isOptional(), + "Some(", + ")", + conditional = model.expectShape(memberShape.container) is StructureShape || symbol.isOptional(), ) { writer.conditionalBlock( "Box::new(", @@ -175,13 +174,11 @@ class Instantiator( ) { render( this, - target, - arg, - ctx.copy(builder = false) - .letIf(shape.getMemberTrait(model, HttpPrefixHeadersTrait::class.java).isPresent) { + targetShape, + data, + ctx.copy() + .letIf(memberShape.hasTrait()) { it.copy(lowercaseMapKeys = true) - }.letIf(shape.isStreaming(model)) { - it.copy(streaming = true) }, ) } @@ -189,9 +186,7 @@ class Instantiator( } } - private fun renderSet(writer: RustWriter, shape: SetShape, data: ArrayNode, ctx: Ctx) { - renderList(writer, shape, data, ctx) - } + private fun renderSet(writer: RustWriter, shape: SetShape, data: ArrayNode, ctx: Ctx) = renderList(writer, shape, data, ctx) /** * ```rust @@ -201,13 +196,14 @@ class Instantiator( * ret.insert("k2", ...); * ret * } + * ``` */ private fun renderMap(writer: RustWriter, shape: MapShape, data: ObjectNode, ctx: Ctx) { if (data.members.isEmpty()) { - writer.write("#T::new()", RustType.HashMap.RuntimeType) + writer.rust("#T::new()", RustType.HashMap.RuntimeType) } else { writer.rustBlock("") { - write("let mut ret = #T::new();", RustType.HashMap.RuntimeType) + rust("let mut ret = #T::new();", RustType.HashMap.RuntimeType) for ((key, value) in data.members) { withBlock("ret.insert(", ");") { renderMember(this, shape.key, key, ctx) @@ -218,7 +214,7 @@ class Instantiator( renderMember(this, shape.value, value, ctx) } } - write("ret") + rust("ret") } } } @@ -231,7 +227,7 @@ class Instantiator( private fun renderUnion(writer: RustWriter, shape: UnionShape, data: ObjectNode, ctx: Ctx) { val unionSymbol = symbolProvider.toSymbol(shape) - val variant = if (ctx.defaultsForRequiredFields && data.members.isEmpty()) { + val variant = if (defaultsForRequiredFields && data.members.isEmpty()) { val (name, memberShape) = shape.allMembers.entries.first() val targetShape = model.expectShape(memberShape.target) Node.from(name) to fillDefaultValue(targetShape) @@ -243,8 +239,8 @@ class Instantiator( val memberName = variant.first.value val member = shape.expectMember(memberName) - writer.write("#T::${symbolProvider.toMemberName(member)}", unionSymbol) - // unions should specify exactly one member + writer.rust("#T::${symbolProvider.toMemberName(member)}", unionSymbol) + // Unions should specify exactly one member. writer.withBlock("(", ")") { renderMember(this, member, variant.second, ctx) } @@ -259,7 +255,7 @@ class Instantiator( writer.withBlock("vec![", "]") { data.elements.forEach { v -> renderMember(this, shape.member, v, ctx) - write(",") + rust(",") } } } @@ -267,14 +263,10 @@ class Instantiator( private fun renderString(writer: RustWriter, shape: StringShape, arg: StringNode) { val data = writer.escape(arg.value).dq() if (!shape.hasTrait()) { - writer.rust("$data.to_string()") + writer.rust("$data.to_owned()") } else { val enumSymbol = symbolProvider.toSymbol(shape) - if (target == CodegenTarget.SERVER) { - writer.rust("""#T::try_from($data).expect("This is used in tests ONLY")""", enumSymbol) - } else { - writer.rust("#T::from($data)", enumSymbol) - } + writer.rustTemplate("#{EnumFromStringFn:W}", "EnumFromStringFn" to enumFromStringFn(enumSymbol, data)) } } @@ -290,11 +282,11 @@ class Instantiator( } } - writer.write("#T::builder()", symbolProvider.toSymbol(shape)) - if (ctx.defaultsForRequiredFields) { + writer.rust("#T::builder()", symbolProvider.toSymbol(shape)) + if (defaultsForRequiredFields) { shape.allMembers.entries .filter { (name, memberShape) -> - memberShape.isRequired && !data.members.containsKey(Node.from(name)) + !symbolProvider.toSymbol(memberShape).isOptional() && !data.members.containsKey(Node.from(name)) } .forEach { (_, memberShape) -> renderMemberHelper(memberShape, fillDefaultValue(memberShape)) @@ -305,9 +297,9 @@ class Instantiator( val memberShape = shape.expectMember(key.value) renderMemberHelper(memberShape, value) } - writer.write(".build()") - if (StructureGenerator.fallibleBuilder(shape, symbolProvider)) { - writer.write(".unwrap()") + writer.rust(".build()") + if (StructureGenerator.hasFallibleBuilder(shape, symbolProvider)) { + writer.rust(".unwrap()") } } diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt index 9af2df80911..cbd0a1395c0 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/StructureGenerator.kt @@ -70,7 +70,7 @@ open class StructureGenerator( companion object { /** Returns whether a structure shape requires a fallible builder to be generated. */ - fun fallibleBuilder(structureShape: StructureShape, symbolProvider: SymbolProvider): Boolean = + fun hasFallibleBuilder(structureShape: StructureShape, symbolProvider: SymbolProvider): Boolean = // All operation inputs should have fallible builders in case a new required field is added in the future. structureShape.hasTrait() || structureShape diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt index c56484e969c..43c18287a50 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/JsonParserGenerator.kt @@ -413,7 +413,7 @@ class JsonParserGenerator( rustTemplate("let mut builder = #{Shape}::builder();", *codegenScope, "Shape" to symbol) deserializeStructInner(shape.members()) withBlock("Ok(Some(builder.build()", "))") { - if (StructureGenerator.fallibleBuilder(shape, symbolProvider)) { + if (StructureGenerator.hasFallibleBuilder(shape, symbolProvider)) { rustTemplate( """.map_err(|err| #{Error}::new( #{ErrorReason}::Custom(format!("{}", err).into()), None) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt index 3805c67c80d..841975c2293 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/parse/XmlBindingTraitParserGenerator.kt @@ -476,7 +476,7 @@ class XmlBindingTraitParserGenerator( rust("let _ = decoder;") } withBlock("Ok(builder.build()", ")") { - if (StructureGenerator.fallibleBuilder(shape, symbolProvider)) { + if (StructureGenerator.hasFallibleBuilder(shape, symbolProvider)) { // NOTE:(rcoh) This branch is unreachable given the current nullability rules. // Only synthetic inputs can have fallible builders, but synthetic inputs can never be parsed // (because they're inputs, only outputs will be parsed!) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt index 848762ff183..f5f08e9076d 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/testutil/TestHelpers.kt @@ -101,7 +101,12 @@ internal fun testCodegenContext( /** * In tests, we frequently need to generate a struct, a builder, and an impl block to access said builder. */ -fun StructureShape.renderWithModelBuilder(model: Model, symbolProvider: RustSymbolProvider, writer: RustWriter, forWhom: CodegenTarget = CodegenTarget.CLIENT) { +fun StructureShape.renderWithModelBuilder( + model: Model, + symbolProvider: RustSymbolProvider, + writer: RustWriter, + forWhom: CodegenTarget = CodegenTarget.CLIENT, +) { StructureGenerator(model, symbolProvider, writer, this).render(forWhom) val modelBuilder = BuilderGenerator(model, symbolProvider, this) modelBuilder.render(writer) diff --git a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/InstantiatorTest.kt b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/InstantiatorTest.kt index c6f592adeb8..73dbe86d5bc 100644 --- a/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/InstantiatorTest.kt +++ b/codegen-core/src/test/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/InstantiatorTest.kt @@ -6,31 +6,32 @@ package software.amazon.smithy.rust.codegen.core.smithy.generators import org.junit.jupiter.api.Test +import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.model.node.Node import software.amazon.smithy.model.node.StringNode import software.amazon.smithy.model.shapes.BlobShape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.shapes.StructureShape import software.amazon.smithy.model.shapes.UnionShape -import software.amazon.smithy.rust.codegen.core.rustlang.RustWriter -import software.amazon.smithy.rust.codegen.core.rustlang.Writable -import software.amazon.smithy.rust.codegen.core.rustlang.raw +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule import software.amazon.smithy.rust.codegen.core.rustlang.rust -import software.amazon.smithy.rust.codegen.core.rustlang.rustBlock import software.amazon.smithy.rust.codegen.core.rustlang.withBlock -import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer import software.amazon.smithy.rust.codegen.core.testutil.TestRuntimeConfig +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder import software.amazon.smithy.rust.codegen.core.testutil.testSymbolProvider +import software.amazon.smithy.rust.codegen.core.testutil.unitTest import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.lookup class InstantiatorTest { private val model = """ namespace com.test + @documentation("this documents the shape") structure MyStruct { foo: String, @@ -69,29 +70,6 @@ class InstantiatorTest { value: Integer } - structure MyStructRequired { - @required - str: String, - @required - primitiveInt: PrimitiveInteger, - @required - int: Integer, - @required - ts: Timestamp, - @required - byte: Byte - @required - union: NestedUnion, - @required - structure: NestedStruct, - @required - list: MyList, - @required - map: NestedMap, - @required - doc: Document - } - union NestedUnion { struct: NestedStruct, int: Integer @@ -108,216 +86,176 @@ class InstantiatorTest { private val symbolProvider = testSymbolProvider(model) private val runtimeConfig = TestRuntimeConfig - fun RustWriter.test(block: Writable) { - raw("#[test]") - rustBlock("fn inst()") { - block() - } - } + private fun enumFromStringFn(symbol: Symbol, data: String) = writable { } @Test fun `generate unions`() { val union = model.lookup("com.test#MyUnion") - val sut = Instantiator(symbolProvider, model, runtimeConfig, CodegenTarget.CLIENT) - val data = Node.parse( - """{ - "stringVariant": "ok!" - }""", - ) - val writer = RustWriter.forModule("model") - UnionGenerator(model, symbolProvider, writer, union).render() - writer.test { - writer.withBlock("let result = ", ";") { - sut.render(this, union, data) + val sut = Instantiator(symbolProvider, model, runtimeConfig, ::enumFromStringFn) + val data = Node.parse("""{ "stringVariant": "ok!" }""") + + val project = TestWorkspace.testProject() + project.withModule(RustModule.Model) { + UnionGenerator(model, symbolProvider, this, union).render() + unitTest("generate_unions") { + withBlock("let result = ", ";") { + sut.render(this, union, data) + } + rust("assert_eq!(result, MyUnion::StringVariant(\"ok!\".to_owned()));") } - writer.write("assert_eq!(result, MyUnion::StringVariant(\"ok!\".to_string()));") } + project.compileAndTest() } @Test fun `generate struct builders`() { val structure = model.lookup("com.test#MyStruct") - val sut = Instantiator(symbolProvider, model, runtimeConfig, CodegenTarget.CLIENT) + val sut = Instantiator(symbolProvider, model, runtimeConfig, ::enumFromStringFn) val data = Node.parse("""{ "bar": 10, "foo": "hello" }""") - val writer = RustWriter.forModule("model") - structure.renderWithModelBuilder(model, symbolProvider, writer) - writer.test { - writer.withBlock("let result = ", ";") { - sut.render(this, structure, data) + + val project = TestWorkspace.testProject() + project.withModule(RustModule.Model) { + structure.renderWithModelBuilder(model, symbolProvider, this) + unitTest("generate_struct_builders") { + withBlock("let result = ", ";") { + sut.render(this, structure, data) + } + rust( + """ + assert_eq!(result.bar, 10); + assert_eq!(result.foo.unwrap(), "hello"); + """, + ) } - writer.write("assert_eq!(result.bar, 10);") - writer.write("assert_eq!(result.foo.unwrap(), \"hello\");") } - writer.compileAndTest() + project.compileAndTest() } @Test fun `generate builders for boxed structs`() { val structure = model.lookup("com.test#WithBox") - val sut = Instantiator(symbolProvider, model, runtimeConfig, CodegenTarget.CLIENT) + val sut = Instantiator(symbolProvider, model, runtimeConfig, ::enumFromStringFn) val data = Node.parse( - """ { - "member": { - "member": { } - }, "value": 10 + """ + { + "member": { + "member": { } + }, + "value": 10 } - """.trimIndent(), + """, ) - val writer = RustWriter.forModule("model") - structure.renderWithModelBuilder(model, symbolProvider, writer) - writer.test { - withBlock("let result = ", ";") { - sut.render(this, structure, data) + + val project = TestWorkspace.testProject() + project.withModule(RustModule.Model) { + structure.renderWithModelBuilder(model, symbolProvider, this) + unitTest("generate_builders_for_boxed_structs") { + withBlock("let result = ", ";") { + sut.render(this, structure, data) + } + rust( + """ + assert_eq!(result, WithBox { + value: Some(10), + member: Some(Box::new(WithBox { + value: None, + member: Some(Box::new(WithBox { value: None, member: None })), + })) + }); + """, + ) } - rust( - """ - assert_eq!(result, WithBox { - value: Some(10), - member: Some(Box::new(WithBox { - value: None, - member: Some(Box::new(WithBox { value: None, member: None })), - })) - }); - """, - ) } - writer.compileAndTest() + project.compileAndTest() } @Test fun `generate lists`() { - val data = Node.parse( - """ [ - "bar", - "foo" - ] - """, - ) - val writer = RustWriter.forModule("lib") - val sut = Instantiator(symbolProvider, model, runtimeConfig, CodegenTarget.CLIENT) - writer.test { - writer.withBlock("let result = ", ";") { - sut.render(writer, model.lookup("com.test#MyList"), data) + val data = Node.parse("""["bar", "foo"]""") + val sut = Instantiator(symbolProvider, model, runtimeConfig, ::enumFromStringFn) + + val project = TestWorkspace.testProject() + project.withModule(RustModule.Model) { + unitTest("generate_lists") { + withBlock("let result = ", ";") { + sut.render(this, model.lookup("com.test#MyList"), data) + } + rust("""assert_eq!(result, vec!["bar".to_owned(), "foo".to_owned()]);""") } - writer.write("""assert_eq!(result, vec!["bar".to_string(), "foo".to_string()]);""") } - writer.compileAndTest() + project.compileAndTest() } @Test fun `generate sparse lists`() { - val data = Node.parse( - """ [ - "bar", - "foo", - null - ] - """, - ) - val writer = RustWriter.forModule("lib") - val sut = Instantiator(symbolProvider, model, runtimeConfig, CodegenTarget.CLIENT) - writer.test { - writer.withBlock("let result = ", ";") { - sut.render(writer, model.lookup("com.test#MySparseList"), data) + val data = Node.parse(""" [ "bar", "foo", null ] """) + val sut = Instantiator(symbolProvider, model, runtimeConfig, ::enumFromStringFn) + + val project = TestWorkspace.testProject() + project.withModule(RustModule.Model) { + unitTest("generate_sparse_lists") { + withBlock("let result = ", ";") { + sut.render(this, model.lookup("com.test#MySparseList"), data) + } + rust("""assert_eq!(result, vec![Some("bar".to_owned()), Some("foo".to_owned()), None]);""") } - writer.write("""assert_eq!(result, vec![Some("bar".to_string()), Some("foo".to_string()), None]);""") } - writer.compileAndTest() + project.compileAndTest() } @Test fun `generate maps of maps`() { val data = Node.parse( - """{ - "k1": { "map": {} }, - "k2": { "map": { "k3": {} } }, - "k3": { } + """ + { + "k1": { "map": {} }, + "k2": { "map": { "k3": {} } }, + "k3": { } } """, ) - val writer = RustWriter.forModule("model") - val sut = Instantiator(symbolProvider, model, runtimeConfig, CodegenTarget.CLIENT) - val inner: StructureShape = model.lookup("com.test#Inner") - inner.renderWithModelBuilder(model, symbolProvider, writer) - writer.test { - writer.withBlock("let result = ", ";") { - sut.render(writer, model.lookup("com.test#NestedMap"), data) + val sut = Instantiator(symbolProvider, model, runtimeConfig, ::enumFromStringFn) + val inner = model.lookup("com.test#Inner") + + val project = TestWorkspace.testProject() + project.withModule(RustModule.Model) { + inner.renderWithModelBuilder(model, symbolProvider, this) + unitTest("generate_maps_of_maps") { + withBlock("let result = ", ";") { + sut.render(this, model.lookup("com.test#NestedMap"), data) + } + rust( + """ + assert_eq!(result.len(), 3); + assert_eq!(result.get("k1").unwrap().map.as_ref().unwrap().len(), 0); + assert_eq!(result.get("k2").unwrap().map.as_ref().unwrap().len(), 1); + assert_eq!(result.get("k3").unwrap().map, None); + """, + ) } - writer.write( - """ - assert_eq!(result.len(), 3); - assert_eq!(result.get("k1").unwrap().map.as_ref().unwrap().len(), 0); - assert_eq!(result.get("k2").unwrap().map.as_ref().unwrap().len(), 1); - assert_eq!(result.get("k3").unwrap().map, None); - """, - ) } - writer.compileAndTest(clippy = true) + project.compileAndTest(runClippy = true) } @Test fun `blob inputs are binary data`() { // "Parameter values that contain binary data MUST be defined using values // that can be represented in plain text (for example, use "foo" and not "Zm9vCg==")." - val writer = RustWriter.forModule("lib") - val sut = Instantiator(symbolProvider, model, runtimeConfig, CodegenTarget.CLIENT) - writer.test { - withBlock("let blob = ", ";") { - sut.render( - this, - BlobShape.builder().id(ShapeId.from("com.example#Blob")).build(), - StringNode.parse("foo".dq()), - ) - } - write("assert_eq!(std::str::from_utf8(blob.as_ref()).unwrap(), \"foo\");") - } - writer.compileAndTest() - } + val sut = Instantiator(symbolProvider, model, runtimeConfig, ::enumFromStringFn) - @Test - fun `generate struct with missing required members`() { - val structure = model.lookup("com.test#MyStructRequired") - val inner = model.lookup("com.test#Inner") - val nestedStruct = model.lookup("com.test#NestedStruct") - val union = model.lookup("com.test#NestedUnion") - val sut = Instantiator(symbolProvider, model, runtimeConfig, CodegenTarget.SERVER) - val data = Node.parse("{}") - val writer = RustWriter.forModule("model") - structure.renderWithModelBuilder(model, symbolProvider, writer) - inner.renderWithModelBuilder(model, symbolProvider, writer) - nestedStruct.renderWithModelBuilder(model, symbolProvider, writer) - UnionGenerator(model, symbolProvider, writer, union).render() - writer.test { - writer.withBlock("let result = ", ";") { - sut.render(this, structure, data, Instantiator.defaultContext().copy(defaultsForRequiredFields = true)) + val project = TestWorkspace.testProject() + project.withModule(RustModule.Model) { + unitTest("blob_inputs_are_binary_data") { + withBlock("let blob = ", ";") { + sut.render( + this, + BlobShape.builder().id(ShapeId.from("com.example#Blob")).build(), + StringNode.parse("foo".dq()), + ) + } + rust("assert_eq!(std::str::from_utf8(blob.as_ref()).unwrap(), \"foo\");") } - writer.write( - """ - use std::collections::HashMap; - use aws_smithy_types::{DateTime, Document}; - - let expected = MyStructRequired { - str: Some("".into()), - primitive_int: 0, - int: Some(0), - ts: Some(DateTime::from_secs(0)), - byte: Some(0), - union: Some(NestedUnion::Struct(NestedStruct { - str: Some("".into()), - num: Some(0), - })), - structure: Some(NestedStruct { - str: Some("".into()), - num: Some(0), - }), - list: Some(vec![]), - map: Some(HashMap::new()), - doc: Some(Document::Object(HashMap::new())), - }; - assert_eq!(result, expected); - """, - ) } - writer.compileAndTest() + project.compileAndTest() } } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerInstantiator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerInstantiator.kt new file mode 100644 index 00000000000..9189380ddef --- /dev/null +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerInstantiator.kt @@ -0,0 +1,34 @@ +/* + * 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.codegen.core.Symbol +import software.amazon.smithy.rust.codegen.core.rustlang.Writable +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.writable +import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext +import software.amazon.smithy.rust.codegen.core.smithy.generators.Instantiator + +/** + * Server enums do not have an `Unknown` variant like client enums do, so constructing an enum from + * a string is a fallible operation (hence `try_from`). It's ok to panic here if construction fails, + * since this is only used in protocol tests. + */ +private fun enumFromStringFn(enumSymbol: Symbol, data: String): Writable = writable { + rust( + """#T::try_from($data).expect("This is used in tests ONLY")""", + enumSymbol, + ) +} + +fun serverInstantiator(codegenContext: CodegenContext) = + Instantiator( + codegenContext.symbolProvider, + codegenContext.model, + codegenContext.runtimeConfig, + ::enumFromStringFn, + defaultsForRequiredFields = true, + ) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt index d68e1cb605d..cf709651074 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/protocol/ServerProtocolTestGenerator.kt @@ -39,9 +39,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.withBlock import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.CodegenContext -import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType -import software.amazon.smithy.rust.codegen.core.smithy.generators.Instantiator import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport import software.amazon.smithy.rust.codegen.core.smithy.transformers.allErrors import software.amazon.smithy.rust.codegen.core.testutil.TokioTest @@ -57,6 +55,7 @@ import software.amazon.smithy.rust.codegen.core.util.toPascalCase import software.amazon.smithy.rust.codegen.core.util.toSnakeCase import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency import software.amazon.smithy.rust.codegen.server.smithy.ServerRuntimeType +import software.amazon.smithy.rust.codegen.server.smithy.generators.serverInstantiator import software.amazon.smithy.rust.codegen.server.smithy.protocols.ServerHttpBoundProtocolGenerator import java.util.logging.Logger import kotlin.reflect.KFunction1 @@ -99,9 +98,7 @@ class ServerProtocolTestGenerator( inputT to outputT } - private val instantiator = with(codegenContext) { - Instantiator(symbolProvider, model, runtimeConfig, CodegenTarget.SERVER) - } + private val instantiator = serverInstantiator(codegenContext) private val codegenScope = arrayOf( "Bytes" to RuntimeType.Bytes, @@ -174,7 +171,7 @@ class ServerProtocolTestGenerator( operations.withIndex().forEach { val (inputT, outputT) = operationInputOutputTypes[it.value]!! val operationName = operationNames[it.index] - write(".$operationName((|_| Box::pin(async { todo!() })) as Fun<$inputT, $outputT> )") + rust(".$operationName((|_| Box::pin(async { todo!() })) as Fun<$inputT, $outputT> )") } } @@ -353,7 +350,7 @@ class ServerProtocolTestGenerator( testModuleWriter.writeWithNoFormatting(testCase.documentation) } - testModuleWriter.write("Test ID: ${testCase.id}") + testModuleWriter.rust("Test ID: ${testCase.id}") testModuleWriter.newlinePrefix = "" TokioTest.render(testModuleWriter) @@ -442,7 +439,7 @@ class ServerProtocolTestGenerator( } writeInline("let output =") instantiator.render(this, shape, testCase.params) - write(";") + rust(";") val operationImpl = if (operationShape.allErrors(model).isNotEmpty()) { if (shape.hasTrait()) { val variant = symbolProvider.toSymbol(shape).name @@ -555,18 +552,13 @@ class ServerProtocolTestGenerator( // Construct a dummy response. withBlock("let response = ", ";") { - instantiator.render( - this, - outputShape, - Node.objectNode(), - Instantiator.defaultContext().copy(defaultsForRequiredFields = true), - ) + instantiator.render(this, outputShape, Node.objectNode()) } if (operationShape.errors.isEmpty()) { - write("response") + rust("response") } else { - write("Ok(response)") + rust("Ok(response)") } } @@ -759,7 +751,7 @@ class ServerProtocolTestGenerator( ) } else { assertOk(rustWriter) { - rustWriter.write( + rustWriter.rust( "#T(&body, ${ rustWriter.escape(body).dq() }, #T::from(${(mediaType ?: "unknown").dq()}))", @@ -815,7 +807,7 @@ class ServerProtocolTestGenerator( ) } assertOk(rustWriter) { - write( + rust( "#T($actualExpression, $variableName)", RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "validate_headers"), ) @@ -836,7 +828,7 @@ class ServerProtocolTestGenerator( strSlice(this, params) } assertOk(rustWriter) { - rustWriter.write( + rustWriter.rust( "#T($actualExpression, $expectedVariableName)", RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, checkFunction), ) @@ -848,14 +840,14 @@ class ServerProtocolTestGenerator( * for pretty printing protocol test helper results */ private fun assertOk(rustWriter: RustWriter, inner: Writable) { - rustWriter.write("#T(", RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "assert_ok")) + rustWriter.rust("#T(", RuntimeType.ProtocolTestHelper(codegenContext.runtimeConfig, "assert_ok")) inner(rustWriter) - rustWriter.write(");") + rustWriter.rust(");") } private fun strSlice(writer: RustWriter, args: List) { writer.withBlock("&[", "]") { - write(args.joinToString(",") { it.dq() }) + rust(args.joinToString(",") { it.dq() }) } } diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt index e98f156f5a6..2cf86be5eb1 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/protocols/ServerHttpBoundProtocolGenerator.kt @@ -750,7 +750,7 @@ private class ServerHttpBoundProtocolTraitImplGenerator( ) } } - val err = if (StructureGenerator.fallibleBuilder(inputShape, symbolProvider)) { + val err = if (StructureGenerator.hasFallibleBuilder(inputShape, symbolProvider)) { "?" } else "" rustTemplate("input.build()$err", *codegenScope) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt index 4159e732c79..0ac168801ce 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/testutil/ServerTestHelpers.kt @@ -10,7 +10,6 @@ import software.amazon.smithy.model.knowledge.NullableIndex import software.amazon.smithy.model.node.ObjectNode import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.rust.codegen.client.testutil.testSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider import software.amazon.smithy.rust.codegen.core.smithy.SymbolVisitorConfig @@ -70,7 +69,7 @@ fun serverTestCodegenContext( protocolShapeId: ShapeId? = null, ): ServerCodegenContext = ServerCodegenContext( model, - testSymbolProvider(model), + serverTestSymbolProvider(model), serviceShape ?: model.serviceShapes.firstOrNull() ?: ServiceShape.builder().version("test").id("test#Service").build(), diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerInstantiatorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerInstantiatorTest.kt new file mode 100644 index 00000000000..ae50d8a0a52 --- /dev/null +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerInstantiatorTest.kt @@ -0,0 +1,221 @@ +/* + * 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 org.junit.jupiter.api.Test +import software.amazon.smithy.model.node.Node +import software.amazon.smithy.model.shapes.StringShape +import software.amazon.smithy.model.shapes.StructureShape +import software.amazon.smithy.model.shapes.UnionShape +import software.amazon.smithy.rust.codegen.core.rustlang.RustModule +import software.amazon.smithy.rust.codegen.core.rustlang.rust +import software.amazon.smithy.rust.codegen.core.rustlang.withBlock +import software.amazon.smithy.rust.codegen.core.smithy.CodegenTarget +import software.amazon.smithy.rust.codegen.core.smithy.generators.EnumGenerator +import software.amazon.smithy.rust.codegen.core.smithy.generators.UnionGenerator +import software.amazon.smithy.rust.codegen.core.smithy.transformers.RecursiveShapeBoxer +import software.amazon.smithy.rust.codegen.core.testutil.TestWorkspace +import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel +import software.amazon.smithy.rust.codegen.core.testutil.compileAndTest +import software.amazon.smithy.rust.codegen.core.testutil.renderWithModelBuilder +import software.amazon.smithy.rust.codegen.core.testutil.unitTest +import software.amazon.smithy.rust.codegen.core.util.dq +import software.amazon.smithy.rust.codegen.core.util.expectTrait +import software.amazon.smithy.rust.codegen.core.util.lookup +import software.amazon.smithy.rust.codegen.server.smithy.testutil.serverTestCodegenContext + +class ServerInstantiatorTest { + // This model started off from the one in `InstantiatorTest.kt` from `codegen-core`. + private val model = """ + namespace com.test + + use smithy.framework#ValidationException + + @documentation("this documents the shape") + structure MyStruct { + foo: String, + @documentation("This *is* documentation about the member.") + bar: PrimitiveInteger, + baz: Integer, + ts: Timestamp, + byteValue: Byte + } + + list MyList { + member: String + } + + @sparse + list MySparseList { + member: String + } + + union MyUnion { + stringVariant: String, + numVariant: Integer + } + + structure Inner { + map: NestedMap + } + + map NestedMap { + key: String, + value: Inner + } + + structure WithBox { + member: WithBox, + value: Integer + } + + union NestedUnion { + struct: NestedStruct, + int: Integer + } + + structure NestedStruct { + @required + str: String, + @required + num: Integer + } + + structure MyStructRequired { + @required + str: String, + @required + primitiveInt: PrimitiveInteger, + @required + int: Integer, + @required + ts: Timestamp, + @required + byte: Byte + @required + union: NestedUnion, + @required + structure: NestedStruct, + @required + list: MyList, + @required + map: NestedMap, + @required + doc: Document + } + + @enum([ + { value: "t2.nano" }, + { value: "t2.micro" }, + ]) + string UnnamedEnum + + @enum([ + { + value: "t2.nano", + name: "T2_NANO", + }, + { + value: "t2.micro", + name: "T2_MICRO", + }, + ]) + string NamedEnum + """.asSmithyModel().let { RecursiveShapeBoxer.transform(it) } + + private val codegenContext = serverTestCodegenContext(model) + private val symbolProvider = codegenContext.symbolProvider + + @Test + fun `generate struct with missing required members`() { + val structure = model.lookup("com.test#MyStructRequired") + val inner = model.lookup("com.test#Inner") + val nestedStruct = model.lookup("com.test#NestedStruct") + val union = model.lookup("com.test#NestedUnion") + val sut = serverInstantiator(codegenContext) + val data = Node.parse("{}") + + val project = TestWorkspace.testProject() + project.withModule(RustModule.Model) { + structure.renderWithModelBuilder(model, symbolProvider, this, CodegenTarget.SERVER) + inner.renderWithModelBuilder(model, symbolProvider, this, CodegenTarget.SERVER) + nestedStruct.renderWithModelBuilder(model, symbolProvider, this, CodegenTarget.SERVER) + UnionGenerator(model, symbolProvider, this, union).render() + + unitTest("server_instantiator_test") { + withBlock("let result = ", ";") { + sut.render(this, structure, data) + } + + rust( + """ + use std::collections::HashMap; + use aws_smithy_types::{DateTime, Document}; + + let expected = MyStructRequired { + str: "".to_owned(), + primitive_int: 0, + int: 0, + ts: DateTime::from_secs(0), + byte: 0, + union: NestedUnion::Struct(NestedStruct { + str: "".to_owned(), + num: 0, + }), + structure: NestedStruct { + str: "".to_owned(), + num: 0, + }, + list: Vec::new(), + map: HashMap::new(), + doc: Document::Object(HashMap::new()), + }; + assert_eq!(result, expected); + """, + ) + } + } + project.compileAndTest() + } + + @Test + fun `generate named enums`() { + val shape = model.lookup("com.test#NamedEnum") + val sut = serverInstantiator(codegenContext) + val data = Node.parse("t2.nano".dq()) + + val project = TestWorkspace.testProject() + project.withModule(RustModule.Model) { + EnumGenerator(model, symbolProvider, this, shape, shape.expectTrait()).render() + unitTest("generate_named_enums") { + withBlock("let result = ", ";") { + sut.render(this, shape, data) + } + rust("assert_eq!(result, NamedEnum::T2Nano);") + } + } + project.compileAndTest() + } + + @Test + fun `generate unnamed enums`() { + val shape = model.lookup("com.test#UnnamedEnum") + val sut = serverInstantiator(codegenContext) + val data = Node.parse("t2.nano".dq()) + + val project = TestWorkspace.testProject() + project.withModule(RustModule.Model) { + EnumGenerator(model, symbolProvider, this, shape, shape.expectTrait()).render() + unitTest("generate_unnamed_enums") { + withBlock("let result = ", ";") { + sut.render(this, shape, data) + } + rust("""assert_eq!(result, UnnamedEnum("t2.nano".to_owned()));""") + } + } + project.compileAndTest() + } +} From b4f0b28b5c960235096bfd3829726f3bd3d60448 Mon Sep 17 00:00:00 2001 From: Zelda Hessler Date: Wed, 19 Oct 2022 13:45:31 -0500 Subject: [PATCH 50/57] update: aws-smithy-xml "xmlparser" dep to v0.13.5 (#1880) rename: aws-smithy-xml test with misleading name Co-authored-by: dvc94ch --- rust-runtime/aws-smithy-xml/Cargo.toml | 2 +- rust-runtime/aws-smithy-xml/src/decode.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rust-runtime/aws-smithy-xml/Cargo.toml b/rust-runtime/aws-smithy-xml/Cargo.toml index 04187b90b67..1563fa0ed76 100644 --- a/rust-runtime/aws-smithy-xml/Cargo.toml +++ b/rust-runtime/aws-smithy-xml/Cargo.toml @@ -8,7 +8,7 @@ license = "Apache-2.0" repository = "https://github.com/awslabs/smithy-rs" [dependencies] -xmlparser = "=0.13.3" +xmlparser = "0.13.5" [dev-dependencies] aws-smithy-protocol-test = { path = "../aws-smithy-protocol-test" } diff --git a/rust-runtime/aws-smithy-xml/src/decode.rs b/rust-runtime/aws-smithy-xml/src/decode.rs index 936d4c3d32e..d30358bfe26 100644 --- a/rust-runtime/aws-smithy-xml/src/decode.rs +++ b/rust-runtime/aws-smithy-xml/src/decode.rs @@ -540,7 +540,7 @@ mod test { } #[test] - fn escape_data() { + fn unescape_data() { let xml = r#">"#; let mut doc = Document::new(xml); let mut root = doc.root_element().unwrap(); From e74ecf348b67134a8f0a9abde5cf5b6f964a1327 Mon Sep 17 00:00:00 2001 From: david-perez Date: Thu, 20 Oct 2022 15:29:56 +0200 Subject: [PATCH 51/57] Simplify implementation of rendering prefix headers (#1841) The implementation that binds the target of `@httpPrefixHeaders`-annotated member shapes is overly complex in that it accounts for the possibility of it targeting a list shape. However, `@httpPrefixHeaders` can only be applied to structure members targeting map shapes: * https://awslabs.github.io/smithy/1.0/spec/core/http-traits.html#httpprefixheaders-trait * https://awslabs.github.io/smithy/2.0/spec/http-bindings.html#httpprefixheaders-trait The existing implementation likely came to be by copy-pasting the `RustWriter.renderHeaders` extension function. I've also taken the liberty of reformatting and renaming variables for clarity and consistency. --- .../generators/http/HttpBindingGenerator.kt | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt index f52f4d38afd..47e1240a091 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt @@ -471,13 +471,15 @@ class HttpBindingGenerator( } private fun RustWriter.renderHeaders(httpBinding: HttpBinding) { + check(httpBinding.location == HttpLocation.HEADER) val memberShape = httpBinding.member - val memberType = model.expectShape(memberShape.target) + val targetShape = model.expectShape(memberShape.target) val memberSymbol = symbolProvider.toSymbol(memberShape) val memberName = symbolProvider.toMemberName(memberShape) - ifSet(memberType, memberSymbol, "&input.$memberName") { field -> - val isListHeader = memberType is CollectionShape - listForEach(memberType, field) { innerField, targetId -> + + ifSet(targetShape, memberSymbol, "&input.$memberName") { field -> + val isListHeader = targetShape is CollectionShape + listForEach(targetShape, field) { innerField, targetId -> val innerMemberType = model.expectShape(targetId) if (innerMemberType.isPrimitive()) { val encoder = CargoDependency.SmithyTypes(runtimeConfig).asType().member("primitive::Encoder") @@ -491,9 +493,14 @@ class HttpBindingGenerator( """ let header_value = $safeName; let header_value = http::header::HeaderValue::try_from(&*header_value).map_err(|err| { - #{build_error}::InvalidField { field: "$memberName", details: format!("`{}` cannot be used as a header value: {}", &${ - memberShape.redactIfNecessary(model, "header_value") - }, err)} + #{build_error}::InvalidField { + field: "$memberName", + details: format!( + "`{}` cannot be used as a header value: {}", + &${memberShape.redactIfNecessary(model, "header_value")}, + err, + ) + } })?; builder = builder.header("${httpBinding.locationName}", header_value); """, @@ -505,17 +512,14 @@ class HttpBindingGenerator( } private fun RustWriter.renderPrefixHeader(httpBinding: HttpBinding) { + check(httpBinding.location == HttpLocation.PREFIX_HEADERS) val memberShape = httpBinding.member - val memberType = model.expectShape(memberShape.target) + val targetShape = model.expectShape(memberShape.target, MapShape::class.java) val memberSymbol = symbolProvider.toSymbol(memberShape) val memberName = symbolProvider.toMemberName(memberShape) - val target = when (memberType) { - is CollectionShape -> model.expectShape(memberType.member.target) - is MapShape -> model.expectShape(memberType.value.target) - else -> UNREACHABLE("unexpected member for prefix headers: $memberType") - } - ifSet(memberType, memberSymbol, "&input.$memberName") { field -> - val listHeader = memberType is CollectionShape + val valueTargetShape = model.expectShape(targetShape.value.target) + + ifSet(targetShape, memberSymbol, "&input.$memberName") { field -> rustTemplate( """ for (k, v) in $field { @@ -523,17 +527,19 @@ class HttpBindingGenerator( let header_name = http::header::HeaderName::from_str(&format!("{}{}", "${httpBinding.locationName}", &k)).map_err(|err| { #{build_error}::InvalidField { field: "$memberName", details: format!("`{}` cannot be used as a header name: {}", k, err)} })?; - let header_value = ${headerFmtFun(this, target, memberShape, "v", listHeader)}; + let header_value = ${headerFmtFun(this, valueTargetShape, memberShape, "v", isListHeader = false)}; let header_value = http::header::HeaderValue::try_from(&*header_value).map_err(|err| { #{build_error}::InvalidField { field: "$memberName", - details: format!("`{}` cannot be used as a header value: {}", ${ - memberShape.redactIfNecessary(model, "v") - }, err)} + details: format!( + "`{}` cannot be used as a header value: {}", + ${memberShape.redactIfNecessary(model, "v")}, + err, + ) + } })?; builder = builder.header(header_name, header_value); } - """, "build_error" to runtimeConfig.operationBuildError(), ) From 03b83473ff5ba7aaedd9033ddc1e1337dab35f7d Mon Sep 17 00:00:00 2001 From: John DiSanti Date: Fri, 21 Oct 2022 07:40:28 -0700 Subject: [PATCH 52/57] Pin `derive_arbitrary` version (#1887) --- rust-runtime/aws-smithy-eventstream/Cargo.toml | 5 +++-- rust-runtime/aws-smithy-eventstream/fuzz/Cargo.toml | 3 ++- .../fuzz/fuzz_targets/corrected_prelude_crc.rs | 3 +-- .../aws-smithy-eventstream/fuzz/fuzz_targets/prelude.rs | 3 +-- rust-runtime/aws-smithy-eventstream/src/frame.rs | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/rust-runtime/aws-smithy-eventstream/Cargo.toml b/rust-runtime/aws-smithy-eventstream/Cargo.toml index c36cc9713a8..a77aff9e856 100644 --- a/rust-runtime/aws-smithy-eventstream/Cargo.toml +++ b/rust-runtime/aws-smithy-eventstream/Cargo.toml @@ -8,10 +8,11 @@ license = "Apache-2.0" repository = "https://github.com/awslabs/smithy-rs" [features] -derive-arbitrary = ["arbitrary"] +derive-arbitrary = ["arbitrary", "derive_arbitrary"] [dependencies] -arbitrary = { version = "=1.1.3", optional = true, features = ["derive"] } # 1.1.4 requires Rust 1.63 to compile +derive_arbitrary = { version = "=1.1.6", optional = true } # 1.2.0 requires Rust 1.63 to compile +arbitrary = { version = "=1.1.3", optional = true } # 1.1.4 requires Rust 1.63 to compile aws-smithy-types = { path = "../aws-smithy-types" } bytes = "1" crc32fast = "1.3" diff --git a/rust-runtime/aws-smithy-eventstream/fuzz/Cargo.toml b/rust-runtime/aws-smithy-eventstream/fuzz/Cargo.toml index d6301e76df6..d43627339bc 100644 --- a/rust-runtime/aws-smithy-eventstream/fuzz/Cargo.toml +++ b/rust-runtime/aws-smithy-eventstream/fuzz/Cargo.toml @@ -9,7 +9,8 @@ edition = "2021" cargo-fuzz = true [dependencies] -arbitrary = { version = "=1.1.3", optional = true, features = ["derive"] } # 1.1.4 requires Rust 1.63 to compile +derive_arbitrary = "=1.1.6" # 1.2.0 requires Rust 1.63 to compile +arbitrary = "=1.1.3" # 1.1.4 requires Rust 1.63 to compile aws-smithy-types = { path = "../../aws-smithy-types" } bytes = "1" crc32fast = "1" diff --git a/rust-runtime/aws-smithy-eventstream/fuzz/fuzz_targets/corrected_prelude_crc.rs b/rust-runtime/aws-smithy-eventstream/fuzz/fuzz_targets/corrected_prelude_crc.rs index d326b9097a6..56ffed401bc 100644 --- a/rust-runtime/aws-smithy-eventstream/fuzz/fuzz_targets/corrected_prelude_crc.rs +++ b/rust-runtime/aws-smithy-eventstream/fuzz/fuzz_targets/corrected_prelude_crc.rs @@ -5,13 +5,12 @@ #![no_main] -use arbitrary::Arbitrary; use aws_smithy_eventstream::frame::Message; use bytes::BufMut; use crc32fast::Hasher as Crc; use libfuzzer_sys::fuzz_target; -#[derive(Arbitrary, Debug)] +#[derive(derive_arbitrary::Arbitrary, Debug)] struct Input { headers: Vec, payload: Vec, diff --git a/rust-runtime/aws-smithy-eventstream/fuzz/fuzz_targets/prelude.rs b/rust-runtime/aws-smithy-eventstream/fuzz/fuzz_targets/prelude.rs index 746c4f69418..fde6f224d79 100644 --- a/rust-runtime/aws-smithy-eventstream/fuzz/fuzz_targets/prelude.rs +++ b/rust-runtime/aws-smithy-eventstream/fuzz/fuzz_targets/prelude.rs @@ -5,13 +5,12 @@ #![no_main] -use arbitrary::Arbitrary; use aws_smithy_eventstream::frame::{Header, HeaderValue, Message}; use bytes::{Buf, BufMut}; use crc32fast::Hasher as Crc; use libfuzzer_sys::fuzz_target; -#[derive(Arbitrary, Debug)] +#[derive(derive_arbitrary::Arbitrary, Debug)] struct Input { total_len: u32, header_len: u32, diff --git a/rust-runtime/aws-smithy-eventstream/src/frame.rs b/rust-runtime/aws-smithy-eventstream/src/frame.rs index dbe0a638a36..0e8eeae1d00 100644 --- a/rust-runtime/aws-smithy-eventstream/src/frame.rs +++ b/rust-runtime/aws-smithy-eventstream/src/frame.rs @@ -301,7 +301,7 @@ pub use value::HeaderValue; /// Event Stream header. #[non_exhaustive] #[derive(Clone, Debug, PartialEq)] -#[cfg_attr(feature = "derive-arbitrary", derive(arbitrary::Arbitrary))] +#[cfg_attr(feature = "derive-arbitrary", derive(derive_arbitrary::Arbitrary))] pub struct Header { name: StrBytes, value: HeaderValue, From aaf75fbceb39d8240b98b7a76bf2589bdcc864b3 Mon Sep 17 00:00:00 2001 From: david-perez Date: Fri, 21 Oct 2022 17:13:35 +0200 Subject: [PATCH 53/57] Remove TODO about required `httpHeader`-bound collection shapes (#1397) We do support required `httpHeader`-bound collection shapes, as evidenced by the test operation this commit adds, which is generated by the server, that does not use `Option` for `required` member shapes. This is because even though the deserialization always returns an optional collection, we return `None` if no headers are found (as opposed to an empty collection), so the call that sets the member field on the operation structure does nothing; when `build()` gets called, a `BuildError` is raised because the member is required. --- codegen-core/common-test-models/misc.smithy | 35 ++++++++++++++++--- .../generators/http/HttpBindingGenerator.kt | 1 - 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/codegen-core/common-test-models/misc.smithy b/codegen-core/common-test-models/misc.smithy index c3449feb28e..a98c0fa21fe 100644 --- a/codegen-core/common-test-models/misc.smithy +++ b/codegen-core/common-test-models/misc.smithy @@ -14,7 +14,8 @@ use smithy.test#httpResponseTests service MiscService { operations: [ TypeComplexityOperation, - InnerRequiredShapeOperation, + RequiredInnerShapeOperation, + RequiredHeaderCollectionOperation, ResponseCodeRequiredOperation, ResponseCodeHttpFallbackOperation, ResponseCodeDefaultOperation, @@ -54,12 +55,12 @@ map MapA { /// This operation tests that (de)serializing required values from a nested /// shape works correctly. @http(uri: "/innerRequiredShapeOperation", method: "POST") -operation InnerRequiredShapeOperation { - input: InnerRequiredShapeOperationInputOutput, - output: InnerRequiredShapeOperationInputOutput, +operation RequiredInnerShapeOperation { + input: RequiredInnerShapeOperationInputOutput, + output: RequiredInnerShapeOperationInputOutput, } -structure InnerRequiredShapeOperationInputOutput { +structure RequiredInnerShapeOperationInputOutput { inner: InnerShape } @@ -230,3 +231,27 @@ structure ResponseCodeRequiredOutput { } ]) operation AcceptHeaderStarService {} + +@http(uri: "/required-header-collection-operation", method: "GET") +operation RequiredHeaderCollectionOperation { + input: RequiredHeaderCollectionOperationInputOutput, + output: RequiredHeaderCollectionOperationInputOutput, +} + +structure RequiredHeaderCollectionOperationInputOutput { + @required + @httpHeader("X-Required-List") + requiredHeaderList: HeaderList, + + @required + @httpHeader("X-Required-Set") + requiredHeaderSet: HeaderSet, +} + +list HeaderList { + member: String +} + +set HeaderSet { + member: String +} diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt index 47e1240a091..8d089ef8bce 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt @@ -365,7 +365,6 @@ class HttpBindingGenerator( rust("let $parsedValue = $parsedValue?;") } } - // TODO(https://github.com/awslabs/smithy-rs/issues/837): this doesn't support non-optional vectors when (rustType) { is RustType.Vec -> rust( From ca2c7883e7c252b7686314b404ecc11d408460f5 Mon Sep 17 00:00:00 2001 From: ysaito1001 Date: Fri, 21 Oct 2022 15:47:48 -0500 Subject: [PATCH 54/57] Add test to exercise excluded headers in aws-sigv4 (#1890) * Add test for excluded headers list This commit adds a test for the functionality added in #1381. Technically, there was an existing test `presigning_header_exclusion` that exercised the said functionality but it only covered the behavior partially, i.e. only a case where the `excluded_headers` field in `SigningSettings` contained just `user-agent`. The new test will randomly add headers to `excluded_headers` and verify the functionality works as expected. * Update CHANGELOG.next.toml * Update CHANGELOG.next.toml Co-authored-by: John DiSanti Co-authored-by: Saito Co-authored-by: John DiSanti --- CHANGELOG.next.toml | 6 +++ .../src/http_request/canonical_request.rs | 45 ++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index 3715ae298c7..b09f7fb805d 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -192,3 +192,9 @@ message = "Fix aws-sigv4 canonical request formatting fallibility." references = ["smithy-rs#1656"] meta = { "breaking" = false, "tada" = false, "bug" = true } author = "ysaito1001" + +[[aws-sdk-rust]] +message = "Add test to exercise excluded headers in aws-sigv4." +references = ["smithy-rs#1890"] +meta = { "breaking" = false, "tada" = false, "bug" = false } +author = "ysaito1001" diff --git a/aws/rust-runtime/aws-sigv4/src/http_request/canonical_request.rs b/aws/rust-runtime/aws-sigv4/src/http_request/canonical_request.rs index 8bd0e0b9313..75413bfd5a8 100644 --- a/aws/rust-runtime/aws-sigv4/src/http_request/canonical_request.rs +++ b/aws/rust-runtime/aws-sigv4/src/http_request/canonical_request.rs @@ -507,10 +507,10 @@ mod tests { }; use crate::http_request::{SignatureLocation, SigningParams}; use crate::sign::sha256_hex_string; - use http::HeaderValue; use http::Uri; + use http::{header::HeaderName, HeaderValue}; use pretty_assertions::assert_eq; - use proptest::proptest; + use proptest::{prelude::*, proptest}; use std::time::Duration; fn signing_params(settings: SigningSettings) -> SigningParams<'static> { @@ -707,6 +707,47 @@ mod tests { ); } + proptest! { + #[test] + fn presigning_header_exclusion_with_explicit_exclusion_list_specified( + excluded_headers in prop::collection::vec("[a-z]{1,20}", 1..10), + ) { + let mut request_builder = http::Request::builder() + .uri("https://some-endpoint.some-region.amazonaws.com") + .header("content-type", "application/xml") + .header("content-length", "0"); + for key in &excluded_headers { + request_builder = request_builder.header(key, "value"); + } + let request = request_builder.body("").unwrap(); + + let request = SignableRequest::from(&request); + + let settings = SigningSettings { + signature_location: SignatureLocation::QueryParams, + expires_in: Some(Duration::from_secs(30)), + excluded_headers: Some( + excluded_headers + .into_iter() + .map(|header_string| { + HeaderName::from_static(Box::leak(header_string.into_boxed_str())) + }) + .collect(), + ), + ..Default::default() + }; + + let signing_params = signing_params(settings); + let canonical = CanonicalRequest::from(&request, &signing_params).unwrap(); + + let values = canonical.values.into_query_params().unwrap(); + assert_eq!( + "content-length;content-type;host", + values.signed_headers.as_str() + ); + } + } + #[test] fn test_trim_all_handles_spaces_correctly() { // Can't compare a byte array to a Cow so we convert both to slices before comparing From 79b7274d180085a70cbcb565ea406a88b6f3cecb Mon Sep 17 00:00:00 2001 From: david-perez Date: Mon, 24 Oct 2022 18:10:17 +0200 Subject: [PATCH 55/57] Version bump smithy-rs (#1894) --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 480b4148597..cb73ffe2b60 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ rust.msrv=1.62.0 org.gradle.jvmargs=-Xmx1024M # Version number to use for the generated runtime crates -smithy.rs.runtime.crate.version=0.50.0 +smithy.rs.runtime.crate.version=0.51.0 kotlin.code.style=official From 3e24477ae7a0a2b3853962a064bc8333a016af54 Mon Sep 17 00:00:00 2001 From: AWS SDK Rust Bot Date: Mon, 24 Oct 2022 17:47:44 +0000 Subject: [PATCH 56/57] Update changelog --- CHANGELOG.md | 29 ++++++ CHANGELOG.next.toml | 190 +----------------------------------- aws/SDK_CHANGELOG.next.json | 168 ++++++++++++++++++++++++++++--- 3 files changed, 186 insertions(+), 201 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5f086d86d48..d1c97e2ffb7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,33 @@ +October 24th, 2022 +================== +**Breaking Changes:** +- ⚠ (all, [smithy-rs#1825](https://github.com/awslabs/smithy-rs/issues/1825)) Bump MSRV to be 1.62.0. +- ⚠ (server, [smithy-rs#1825](https://github.com/awslabs/smithy-rs/issues/1825)) Bump pyo3 and pyo3-asyncio from 0.16.x to 0.17.0 for aws-smithy-http-server-python. +- ⚠ (client, [smithy-rs#1811](https://github.com/awslabs/smithy-rs/issues/1811)) Replace all usages of `AtomicU64` with `AtomicUsize` to support 32bit targets. +- ⚠ (server, [smithy-rs#1803](https://github.com/awslabs/smithy-rs/issues/1803)) Mark `operation` and `operation_handler` modules as private in the generated server crate. + Both modules did not contain any public types, therefore there should be no actual breakage when updating. +- ⚠ (client, [smithy-rs#1740](https://github.com/awslabs/smithy-rs/issues/1740), [smithy-rs#256](https://github.com/awslabs/smithy-rs/issues/256)) A large list of breaking changes were made to accomodate default timeouts in the AWS SDK. + See [the smithy-rs upgrade guide](https://github.com/awslabs/smithy-rs/issues/1760) for a full list + of breaking changes and how to resolve them. +- ⚠ (server, [smithy-rs#1829](https://github.com/awslabs/smithy-rs/issues/1829)) Remove `Protocol` enum, removing an obstruction to extending smithy to third-party protocols. +- ⚠ (server, [smithy-rs#1829](https://github.com/awslabs/smithy-rs/issues/1829)) Convert the `protocol` argument on `PyMiddlewares::new` constructor to a type parameter. + +**New this release:** +- (server, [smithy-rs#1811](https://github.com/awslabs/smithy-rs/issues/1811)) Replace all usages of `AtomicU64` with `AtomicUsize` to support 32bit targets. +- 🐛 (all, [smithy-rs#1802](https://github.com/awslabs/smithy-rs/issues/1802)) Sensitive fields in errors now respect @sensitive trait and are properly redacted. +- (server, [smithy-rs#1727](https://github.com/awslabs/smithy-rs/issues/1727), @GeneralSwiss) Pokémon Service example code now runs clippy during build. +- (server, [smithy-rs#1734](https://github.com/awslabs/smithy-rs/issues/1734)) Implement support for pure Python request middleware. Improve idiomatic logging support over tracing. +- 🐛 (client, [aws-sdk-rust#620](https://github.com/awslabs/aws-sdk-rust/issues/620), [smithy-rs#1748](https://github.com/awslabs/smithy-rs/issues/1748)) Paginators now stop on encountering a duplicate token by default rather than panic. This behavior can be customized by toggling the `stop_on_duplicate_token` property on the paginator before calling `send`. +- 🐛 (all, [smithy-rs#1817](https://github.com/awslabs/smithy-rs/issues/1817), @ethyi) Update aws-types zeroize to flexible version to prevent downstream version conflicts. +- (all, [smithy-rs#1852](https://github.com/awslabs/smithy-rs/issues/1852), @ogudavid) Enable local maven repo dependency override. + +**Contributors** +Thank you for your contributions! ❤ +- @GeneralSwiss ([smithy-rs#1727](https://github.com/awslabs/smithy-rs/issues/1727)) +- @ethyi ([smithy-rs#1817](https://github.com/awslabs/smithy-rs/issues/1817)) +- @ogudavid ([smithy-rs#1852](https://github.com/awslabs/smithy-rs/issues/1852)) + September 20th, 2022 ==================== **Breaking Changes:** diff --git a/CHANGELOG.next.toml b/CHANGELOG.next.toml index b09f7fb805d..fc4c4c2578b 100644 --- a/CHANGELOG.next.toml +++ b/CHANGELOG.next.toml @@ -9,192 +9,4 @@ # message = "Fix typos in module documentation for generated crates" # references = ["smithy-rs#920"] # meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"} -# author = "rcoh" - - -[[smithy-rs]] -message = "Bump MSRV to be 1.62.0." -references = ["smithy-rs#1825"] -meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "all" } -author = "LukeMathWalker" - -[[smithy-rs]] -message = "Bump pyo3 and pyo3-asyncio from 0.16.x to 0.17.0 for aws-smithy-http-server-python." -references = ["smithy-rs#1825"] -meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" } -author = "LukeMathWalker" - -[[aws-sdk-rust]] -message = "Bump MSRV to be 1.62.0." -references = ["smithy-rs#1825"] -meta = { "breaking" = true, "tada" = false, "bug" = false } -author = "LukeMathWalker" - -[[smithy-rs]] -message = """ -Replace all usages of `AtomicU64` with `AtomicUsize` to support 32bit targets. -""" -references = ["smithy-rs#1811"] -meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "server"} -author = "LukeMathWalker" - -[[smithy-rs]] -message = """ -Replace all usages of `AtomicU64` with `AtomicUsize` to support 32bit targets. -""" -references = ["smithy-rs#1811"] -meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client"} -author = "LukeMathWalker" - -[[smithy-rs]] -message = """ -Mark `operation` and `operation_handler` modules as private in the generated server crate. -Both modules did not contain any public types, therefore there should be no actual breakage when updating. -""" -references = ["smithy-rs#1803"] -meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server"} -author = "LukeMathWalker" - -[[smithy-rs]] -message = "Sensitive fields in errors now respect @sensitive trait and are properly redacted." -references = ["smithy-rs#1802"] -meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "all" } -author = "jjant" - -[[smithy-rs]] -message = "Pokémon Service example code now runs clippy during build." -references = ["smithy-rs#1727"] -meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "server" } -author = "GeneralSwiss" - -[[smithy-rs]] -message = "Implement support for pure Python request middleware. Improve idiomatic logging support over tracing." -references = ["smithy-rs#1734"] -meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "server" } -author = "crisidev" - -[[aws-sdk-rust]] -message = """ -The SDK, by default, now times out if socket connect or time to first byte read takes longer than -3.1 seconds. There are a large number of breaking changes that come with this change that may -affect you if you customize the client configuration at all. -See [the upgrade guide](https://github.com/awslabs/aws-sdk-rust/issues/622) for information -on how to configure timeouts, and how to resolve compilation issues after upgrading. -""" -references = ["smithy-rs#1740", "smithy-rs#256"] -meta = { "breaking" = true, "tada" = false, "bug" = false } -author = "jdisanti" - -[[aws-sdk-rust]] -message = """ -Setting connect/read timeouts with `SdkConfig` now works. Previously, these timeout config values -were lost during connector creation, so the only reliable way to set them was to manually override -the HTTP connector. -""" -references = ["smithy-rs#1740", "smithy-rs#256"] -meta = { "breaking" = false, "tada" = false, "bug" = true } -author = "jdisanti" - -[[smithy-rs]] -message = """ -A large list of breaking changes were made to accomodate default timeouts in the AWS SDK. -See [the smithy-rs upgrade guide](https://github.com/awslabs/smithy-rs/issues/1760) for a full list -of breaking changes and how to resolve them. -""" -references = ["smithy-rs#1740", "smithy-rs#256"] -meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "client" } -author = "jdisanti" - -[[aws-sdk-rust]] -message = """ -It is now possible to programmatically customize the locations of the profile config/credentials files in `aws-config`: -```rust -use aws_config::profile::{ProfileFileCredentialsProvider, ProfileFileRegionProvider}; -use aws_config::profile::profile_file::{ProfileFiles, ProfileFileKind}; - -let profile_files = ProfileFiles::builder() - .with_file(ProfileFileKind::Credentials, "some/path/to/credentials-file") - .build(); -let credentials_provider = ProfileFileCredentialsProvider::builder() - .profile_files(profile_files.clone()) - .build(); -let region_provider = ProfileFileRegionProvider::builder() - .profile_files(profile_files) - .build(); - -let sdk_config = aws_config::from_env() - .credentials_provider(credentials_provider) - .region(region_provider) - .load() - .await; -``` -""" -references = ["aws-sdk-rust#237", "smithy-rs#1770"] -meta = { "breaking" = false, "tada" = true, "bug" = false } -author = "jdisanti" - -[[aws-sdk-rust]] -message = "Paginators now stop on encountering a duplicate token by default rather than panic. This behavior can be customized by toggling the `stop_on_duplicate_token` property on the paginator before calling `send`." -references = ["aws-sdk-rust#620", "smithy-rs#1748"] -meta = { "breaking" = false, "tada" = false, "bug" = true } -author = "jdisanti" - -[[smithy-rs]] -message = "Paginators now stop on encountering a duplicate token by default rather than panic. This behavior can be customized by toggling the `stop_on_duplicate_token` property on the paginator before calling `send`." -references = ["aws-sdk-rust#620", "smithy-rs#1748"] -meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "client" } -author = "jdisanti" - -[[aws-sdk-rust]] -message = "The client Config now has getters for every value that it holds." -references = ["smithy-rs#1747"] -meta = { "breaking" = false, "tada" = false, "bug" = true } -author = "kastolars" - -[[aws-sdk-rust]] -message = "Fix regression where `connect_timeout` and `read_timeout` fields are unused in the IMDS client" -references = ["smithy-rs#1822"] -meta = { "breaking" = false, "tada" = false, "bug" = true } -author = "kevinpark1217" - -[[smithy-rs]] -message = "Remove `Protocol` enum, removing an obstruction to extending smithy to third-party protocols." -references = ["smithy-rs#1829"] -meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" } -author = "hlbarber" - -[[smithy-rs]] -message = "Convert the `protocol` argument on `PyMiddlewares::new` constructor to a type parameter." -references = ["smithy-rs#1829"] -meta = { "breaking" = true, "tada" = false, "bug" = false, "target" = "server" } -author = "hlbarber" - -[[smithy-rs]] -message = "Update aws-types zeroize to flexible version to prevent downstream version conflicts." -references = ["smithy-rs#1817"] -meta = { "breaking" = false, "tada" = false, "bug" = true } -author = "ethyi" - -[[smithy-rs]] -message = "Enable local maven repo dependency override." -references = ["smithy-rs#1852"] -meta = { "breaking" = false, "tada" = false, "bug" = false } -author = "ogudavid" - -[[aws-sdk-rust]] -message = "Ability to override the IMDS client in `DefaultCredentialsChain`" -references = ["aws-sdk-rust#625"] -meta = { "breaking" = false, "tada" = false, "bug" = false } -author = "kevinpark1217" - -[[aws-sdk-rust]] -message = "Fix aws-sigv4 canonical request formatting fallibility." -references = ["smithy-rs#1656"] -meta = { "breaking" = false, "tada" = false, "bug" = true } -author = "ysaito1001" - -[[aws-sdk-rust]] -message = "Add test to exercise excluded headers in aws-sigv4." -references = ["smithy-rs#1890"] -meta = { "breaking" = false, "tada" = false, "bug" = false } -author = "ysaito1001" +# author = "rcoh" \ No newline at end of file diff --git a/aws/SDK_CHANGELOG.next.json b/aws/SDK_CHANGELOG.next.json index a49e76d1080..9fb8b3ef9d3 100644 --- a/aws/SDK_CHANGELOG.next.json +++ b/aws/SDK_CHANGELOG.next.json @@ -17,7 +17,7 @@ "smithy-rs#1641" ], "since-commit": "6e96137ca79b592960881b140ab17717b1ebb780", - "age": 1 + "age": 2 }, { "message": "Service configs are now generated with new accessors for:\n- `Config::retry_config()` - Returns a reference to the inner retry configuration.\n- `Config::timeout_config()` - Returns a reference to the inner timeout configuration.\n- `Config::sleep_impl()` - Returns a clone of the inner async sleep implementation.\n\nPreviously, these were only accessible through `SdkConfig`.\n", @@ -31,7 +31,7 @@ "smithy-rs#1598" ], "since-commit": "6e96137ca79b592960881b140ab17717b1ebb780", - "age": 1 + "age": 2 }, { "message": "Lossy converters into integer types for `aws_smithy_types::Number` have been\nremoved. Lossy converters into floating point types for\n`aws_smithy_types::Number` have been suffixed with `_lossy`. If you were\ndirectly using the integer lossy converters, we recommend you use the safe\nconverters.\n_Before:_\n```rust\nfn f1(n: aws_smithy_types::Number) {\n let foo: f32 = n.to_f32(); // Lossy conversion!\n let bar: u32 = n.to_u32(); // Lossy conversion!\n}\n```\n_After:_\n```rust\nfn f1(n: aws_smithy_types::Number) {\n use std::convert::TryInto; // Unnecessary import if you're using Rust 2021 edition.\n let foo: f32 = n.try_into().expect(\"lossy conversion detected\"); // Or handle the error instead of panicking.\n // You can still do lossy conversions, but only into floating point types.\n let foo: f32 = n.to_f32_lossy();\n // To lossily convert into integer types, use an `as` cast directly.\n let bar: u32 = n as u32; // Lossy conversion!\n}\n```\n", @@ -45,7 +45,7 @@ "smithy-rs#1274" ], "since-commit": "6e96137ca79b592960881b140ab17717b1ebb780", - "age": 1 + "age": 2 }, { "message": "Bump [MSRV](https://github.com/awslabs/aws-sdk-rust#supported-rust-versions-msrv) from 1.58.1 to 1.61.0 per our policy.", @@ -59,7 +59,7 @@ "smithy-rs#1699" ], "since-commit": "6e96137ca79b592960881b140ab17717b1ebb780", - "age": 1 + "age": 2 }, { "message": "The AWS S3 `GetObjectAttributes` operation will no longer fail with an XML error.", @@ -73,7 +73,7 @@ "aws-sdk-rust#609" ], "since-commit": "6e96137ca79b592960881b140ab17717b1ebb780", - "age": 1 + "age": 2 }, { "message": "`aws_config::RetryConfig` no longer implements `Default`, and its `new` function has been replaced with `standard`.", @@ -88,7 +88,7 @@ "aws-sdk-rust#586" ], "since-commit": "3952a10c44ec1f2eed4a8d5e401d36e07e8a2c73", - "age": 1 + "age": 2 }, { "message": "Direct configuration of `aws_config::SdkConfig` now defaults to retries being disabled.\nIf you're using `aws_config::load_from_env()` or `aws_config::from_env()` to configure\nthe SDK, then you are NOT affected by this change. If you use `SdkConfig::builder()` to\nconfigure the SDK, then you ARE affected by this change and should set the retry config\non that builder.\n", @@ -103,7 +103,7 @@ "aws-sdk-rust#586" ], "since-commit": "3952a10c44ec1f2eed4a8d5e401d36e07e8a2c73", - "age": 1 + "age": 2 }, { "message": "Client creation now panics if retries or timeouts are enabled without an async sleep\nimplementation set on the SDK config.\nIf you're using the Tokio runtime and have the `rt-tokio` feature enabled (which is enabled by default),\nthen you shouldn't notice this change at all.\nOtherwise, if using something other than Tokio as the async runtime, the `AsyncSleep` trait must be implemented,\nand that implementation given to the config builder via the `sleep_impl` method. Alternatively, retry can be\nexplicitly turned off by setting the retry config to `RetryConfig::disabled()`, which will result in successful\nclient creation without an async sleep implementation.\n", @@ -118,7 +118,7 @@ "aws-sdk-rust#586" ], "since-commit": "3952a10c44ec1f2eed4a8d5e401d36e07e8a2c73", - "age": 1 + "age": 2 }, { "message": "Implemented customizable operations per [RFC-0017](https://awslabs.github.io/smithy-rs/design/rfcs/rfc0017_customizable_client_operations.html).\n\nBefore this change, modifying operations before sending them required using lower-level APIs:\n\n```rust\nlet input = SomeOperationInput::builder().some_value(5).build()?;\n\nlet operation = {\n let op = input.make_operation(&service_config).await?;\n let (request, response) = op.into_request_response();\n\n let request = request.augment(|req, _props| {\n req.headers_mut().insert(\n HeaderName::from_static(\"x-some-header\"),\n HeaderValue::from_static(\"some-value\")\n );\n Result::<_, Infallible>::Ok(req)\n })?;\n\n Operation::from_parts(request, response)\n};\n\nlet response = smithy_client.call(operation).await?;\n```\n\nNow, users may easily modify operations before sending with the `customize` method:\n\n```rust\nlet response = client.some_operation()\n .some_value(5)\n .customize()\n .await?\n .mutate_request(|mut req| {\n req.headers_mut().insert(\n HeaderName::from_static(\"x-some-header\"),\n HeaderValue::from_static(\"some-value\")\n );\n })\n .send()\n .await?;\n```\n", @@ -133,7 +133,7 @@ "smithy-rs#1112" ], "since-commit": "3952a10c44ec1f2eed4a8d5e401d36e07e8a2c73", - "age": 1 + "age": 2 }, { "message": "The AWS STS SDK now automatically retries `IDPCommunicationError` when calling `AssumeRoleWithWebIdentity`", @@ -148,7 +148,7 @@ "smithy-rs#1718" ], "since-commit": "3952a10c44ec1f2eed4a8d5e401d36e07e8a2c73", - "age": 1 + "age": 2 }, { "message": "The `SdkError::ResponseError`, typically caused by a connection terminating before the full response is received, is now treated as a transient failure and retried.", @@ -163,7 +163,7 @@ "smithy-rs#1717" ], "since-commit": "3952a10c44ec1f2eed4a8d5e401d36e07e8a2c73", - "age": 1 + "age": 2 }, { "message": "`ClassifyResponse` was renamed to `ClassifyRetry` and is no longer implemented for the unit type.", @@ -178,7 +178,7 @@ "smithy-rs#1717" ], "since-commit": "3952a10c44ec1f2eed4a8d5e401d36e07e8a2c73", - "age": 1 + "age": 2 }, { "message": "The `with_retry_policy` and `retry_policy` functions on `aws_smithy_http::operation::Operation` have been\nrenamed to `with_retry_classifier` and `retry_classifier` respectively. Public member `retry_policy` on\n`aws_smithy_http::operation::Parts` has been renamed to `retry_classifier`.\n", @@ -193,6 +193,150 @@ "smithy-rs#1717" ], "since-commit": "3952a10c44ec1f2eed4a8d5e401d36e07e8a2c73", + "age": 2 + }, + { + "message": "Bump MSRV to be 1.62.0.", + "meta": { + "bug": false, + "breaking": true, + "tada": false + }, + "author": "LukeMathWalker", + "references": [ + "smithy-rs#1825" + ], + "since-commit": "79b7274d180085a70cbcb565ea406a88b6f3cecb", + "age": 1 + }, + { + "message": "The SDK, by default, now times out if socket connect or time to first byte read takes longer than\n3.1 seconds. There are a large number of breaking changes that come with this change that may\naffect you if you customize the client configuration at all.\nSee [the upgrade guide](https://github.com/awslabs/aws-sdk-rust/issues/622) for information\non how to configure timeouts, and how to resolve compilation issues after upgrading.\n", + "meta": { + "bug": false, + "breaking": true, + "tada": false + }, + "author": "jdisanti", + "references": [ + "smithy-rs#1740", + "smithy-rs#256" + ], + "since-commit": "79b7274d180085a70cbcb565ea406a88b6f3cecb", + "age": 1 + }, + { + "message": "Setting connect/read timeouts with `SdkConfig` now works. Previously, these timeout config values\nwere lost during connector creation, so the only reliable way to set them was to manually override\nthe HTTP connector.\n", + "meta": { + "bug": true, + "breaking": false, + "tada": false + }, + "author": "jdisanti", + "references": [ + "smithy-rs#1740", + "smithy-rs#256" + ], + "since-commit": "79b7274d180085a70cbcb565ea406a88b6f3cecb", + "age": 1 + }, + { + "message": "It is now possible to programmatically customize the locations of the profile config/credentials files in `aws-config`:\n```rust\nuse aws_config::profile::{ProfileFileCredentialsProvider, ProfileFileRegionProvider};\nuse aws_config::profile::profile_file::{ProfileFiles, ProfileFileKind};\n\nlet profile_files = ProfileFiles::builder()\n .with_file(ProfileFileKind::Credentials, \"some/path/to/credentials-file\")\n .build();\nlet credentials_provider = ProfileFileCredentialsProvider::builder()\n .profile_files(profile_files.clone())\n .build();\nlet region_provider = ProfileFileRegionProvider::builder()\n .profile_files(profile_files)\n .build();\n\nlet sdk_config = aws_config::from_env()\n .credentials_provider(credentials_provider)\n .region(region_provider)\n .load()\n .await;\n```\n", + "meta": { + "bug": false, + "breaking": false, + "tada": true + }, + "author": "jdisanti", + "references": [ + "aws-sdk-rust#237", + "smithy-rs#1770" + ], + "since-commit": "79b7274d180085a70cbcb565ea406a88b6f3cecb", + "age": 1 + }, + { + "message": "Paginators now stop on encountering a duplicate token by default rather than panic. This behavior can be customized by toggling the `stop_on_duplicate_token` property on the paginator before calling `send`.", + "meta": { + "bug": true, + "breaking": false, + "tada": false + }, + "author": "jdisanti", + "references": [ + "aws-sdk-rust#620", + "smithy-rs#1748" + ], + "since-commit": "79b7274d180085a70cbcb565ea406a88b6f3cecb", + "age": 1 + }, + { + "message": "The client Config now has getters for every value that it holds.", + "meta": { + "bug": true, + "breaking": false, + "tada": false + }, + "author": "kastolars", + "references": [ + "smithy-rs#1747" + ], + "since-commit": "79b7274d180085a70cbcb565ea406a88b6f3cecb", + "age": 1 + }, + { + "message": "Fix regression where `connect_timeout` and `read_timeout` fields are unused in the IMDS client", + "meta": { + "bug": true, + "breaking": false, + "tada": false + }, + "author": "kevinpark1217", + "references": [ + "smithy-rs#1822" + ], + "since-commit": "79b7274d180085a70cbcb565ea406a88b6f3cecb", + "age": 1 + }, + { + "message": "Ability to override the IMDS client in `DefaultCredentialsChain`", + "meta": { + "bug": false, + "breaking": false, + "tada": false + }, + "author": "kevinpark1217", + "references": [ + "aws-sdk-rust#625" + ], + "since-commit": "79b7274d180085a70cbcb565ea406a88b6f3cecb", + "age": 1 + }, + { + "message": "Fix aws-sigv4 canonical request formatting fallibility.", + "meta": { + "bug": true, + "breaking": false, + "tada": false + }, + "author": "ysaito1001", + "references": [ + "smithy-rs#1656" + ], + "since-commit": "79b7274d180085a70cbcb565ea406a88b6f3cecb", + "age": 1 + }, + { + "message": "Add test to exercise excluded headers in aws-sigv4.", + "meta": { + "bug": false, + "breaking": false, + "tada": false + }, + "author": "ysaito1001", + "references": [ + "smithy-rs#1890" + ], + "since-commit": "79b7274d180085a70cbcb565ea406a88b6f3cecb", "age": 1 } ], From 15c80de41dab4a6b798ce45d3e94fa91a40a3e58 Mon Sep 17 00:00:00 2001 From: 82marbag <69267416+82marbag@users.noreply.github.com> Date: Tue, 25 Oct 2022 04:59:05 -0400 Subject: [PATCH 57/57] Forbid list/map as paylods (#1897) * Forbid list/map as paylods ...and add tracking to the issue in unions in paylods Signed-off-by: Daniele Ahmed --- .../core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt index 17319765ffe..69b9b84e0dc 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/protocols/HttpBoundProtocolPayloadGenerator.kt @@ -272,6 +272,8 @@ class HttpBoundProtocolPayloadGenerator( """, ) is StructureShape -> rust("#T()", serializerGenerator.unsetStructure(targetShape)) + is UnionShape -> throw CodegenException("Currently unsupported. Tracking issue: https://github.com/awslabs/smithy-rs/issues/1896") + else -> throw CodegenException("`httpPayload` on member shapes targeting shapes of type ${targetShape.type} is unsupported") } } }