From 5b7aa7b803c967570404f367c92b84be65c0c6cd Mon Sep 17 00:00:00 2001 From: david-perez Date: Tue, 27 Sep 2022 14:33:50 +0200 Subject: [PATCH] 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 f63e7078d..aec623d22 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 7fd4d56a8..af3ae09c6 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 40ba2c6cf..52443b23a 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 e077de8bd..a65cb4fca 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 fe1f1db4e..05175db3d 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 a3f9e7170..eb87bf56d 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 de6f1f8dd..2f5baf4c0 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 4880a30fe..47e74d3ad 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 ba21e3bec..a14c9843c 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 ecc83f042..c695c5c40 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 30b3e3383..98c5ab0e9 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 4b0c479c2..76d42c825 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 8c4fa3d33..3a6aaf40a 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 30d3126f4..4d1aa4973 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 ee4f37f03..4d0489ef6 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 bf62ecb86..bdae9bf35 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 5077a8e4b..e8729060e 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 9f61d1f06..97b8813bf 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 c3a1d5fee..f18c9cd06 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 449b74b4a..23d489a5c 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 ced0423b2..57acccd6a 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 c9400a419..630ac0af0 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 af0460cad..a10174251 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 9d29cd826..8bc2d3b06 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 27ba93680..166ca7e3b 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 54a910055..f762ffe2e 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 4db45856d..adff13cf8 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 d64672d96..e99ef76e5 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 d3ef7f8f7..874fd3979 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 3489bc7c9..11dd45f2b 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 86a35f1a3..c71ddb638 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 c80a0cff3..61d6558a1 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 10aedcab2..a836fd910 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 1464a2e60..03eeeb24a 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 252422dc5..6450c9a71 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 87f1974fe..0e66b6ba3 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 2f9d42819..6802d444c 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 66c4061f0..9a30b3caf 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 0ca4dae06..ffa48f68f 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 3b8791db2..69404e961 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 88e1ba951..cd362accc 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 752f90100..f96b21336 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 3037e97ad..6ff57e85a 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 9a2503c52..adfb3b872 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 3de97eed5..d3b350ed0 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 309784c73..7809ccffb 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 892aba050..110ca580c 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 5a3ee39e5..75feb396f 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 ff2c1079f..8550adcef 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 d0bc823a7..049b92a25 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 bb4e5f88d..aeaa693f5 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 94aa83456..f605e3a71 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 b6280b750..f4cfce389 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 d792847b9..3ae662bfc 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 edb96225c..2b22ed040 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 074272543..ad97f369a 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 0c6b88978..d0fabc932 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 b0ae73399..8e3df9d58 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 219d8d08f..8f971da3f 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 7e795be72..d3d43563f 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 a3b812693..fb9750119 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 91535206d..8e8cf8f8b 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 ae83e920a..4fe0f8eb9 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 e5300d1a0..f85515682 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 55f86c299..665150342 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 b33ac66a1..59c983bdd 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 68eb2c000..926eef979 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 000000000..9b66e0118 --- /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 8a788196f..000000000 --- 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 efc452973..52fb86d93 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 a50da4220..ae2d8e058 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 d0f4ca0c1..4a95ea126 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 000000000..d97f52c26 --- /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 8af691bfe..cd19cf233 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 1d63ce1f0..55e4fe518 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 123acd4f5..02f880d1b 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 09de07407..cb3a82674 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 bfb4163af..7e69ce699 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 cf45c94ec..9340d0e27 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 f2f850e35..d91ea1f6d 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 88ead1eb7..ffd625fe1 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 96437c614..640cfc46f 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 ef5188e9b..d36fdac07 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 8cb3506f7..fc30f13dc 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 f499693c9..6450e40c7 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 24855a631..031600f1a 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 ea269e87d..73fd5500e 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 00fac0b01..7f9b771a0 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 a05f219b2..f770df48b 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 e17e79dde..e2bbad162 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 03486aab4..dd7af8de6 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 972bfbd92..52103a35d 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 ba0849d1c..36904eab7 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 9f9dafc0c..b9f36e356 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 aa88fca2f..a09066cc8 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 da53e8a05..0d88defca 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 329cb463f..f770d5be6 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 f2de82808..c2e47b699 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 87adb5f0f..4f9fd8223 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 d85bd0e97..074a2f83e 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 2af307a94..584e09756 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 d9c98427a..a941f7218 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 39492f974..c31aecfaf 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 099b8a452..92f44feb4 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 6a9e859e5..920faba4b 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 b164a32a6..6d47fff4c 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 2f7fbf656..3afcc7d08 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 03d271530..ef5631068 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 996d44534..623b4d1ac 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 9e3258e8e..638e4bc59 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 8ad627385..aac9f12ed 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 dd757fefa..ad94eb210 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 6cb3b5aba..b5dea3f9f 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 e31e0ea27..400d4c6b8 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 ca9bb6fd6..512fcd9aa 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 56bc924f7..be3341700 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 d4ad16fb3..e352da919 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 a24c57945..90564e81a 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 e21107792..0fde36acb 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 4ec569e8a..2327b3fa0 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 00574e930..67b73e77c 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 c923aea37..0bb1a6c7c 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 a2058bc83..1feaf4966 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 f1c349b2e..4cb3e06fe 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 18aa5a319..62361e486 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 64235ee48..b5de87b76 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 382bd1811..0ec62243d 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 becc7c0c1..33f15aa89 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 60819a4c5..24344b57c 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 24d59c01a..f73300321 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 c2e511509..4e409bf12 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 c453fe065..f1ed5ad94 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 75c109d36..743eb63eb 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 db3398978..53473cb67 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 5ff7fe5cf..27ea5dcc6 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 10e91a599..ffe91eb17 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 66de796b8..781014bd8 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 8c7d7e70c..8c5a56b57 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 0100fbd39..3b2024fae 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 8bbbbc7f7..516bfc428 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 c59b62ebd..a7dd176a9 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 d9a6d8eda..c561b04c3 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 a6000ad0d..cceced878 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 1d5447caf..f2b25032b 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 3cf94d8b7..a869e7325 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 7da60fe44..3be719808 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 91dd67d87..5bf6e0a6b 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 9ae2f63f5..dd46fcba4 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 388dc2e14..5075430ed 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 86f1c37fd..9c973ff09 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 748e0bff8..8f9382b5a 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 77196149a..de6c09a5a 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 db7c3a6e6..4253622ff 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 c2590675e..e76ed60ac 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 84e3f7721..9a55d74a4 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 7eeeb2b5c..1de4cd289 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 ce0293730..df401f763 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 a18be2d44..cda444132 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 000000000..025df135a --- /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 000000000..c66dae4ce --- /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 461504812..cf14e07e2 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 c8f7e855b..b7bf02f8f 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 16d1c2866..6b21fd211 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 1be6d8ec1..c5d93ae3b 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 000000000..5bf333ab8 --- /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 a153ba7c6..e3f1be1ff 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 3649cd093..cb0569c22 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 1cb756c6c..c33e25737 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 2036ca246..97d6bb1c8 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 2fbf75ba8..5169242ad 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 b718071c5..ed41cfd85 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 7b1a6f491..2bd6c923e 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 051631d67..92ab1a497 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 25961611e..8e84f5b0b 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 f340ee05c..ed3a83c66 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 de02c7561..3d06da554 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 2b3e46164..133f2b9bb 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 650b079ef..e9501ecdd 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 4d59e3877..518da051a 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 323e1ad93..a780218e8 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 dc18a21eb..962b9c872 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 2d259c05b..4d7a2ce3e 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 e4270443e..8f83d8fe6 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 000000000..7bc3fdacb --- /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 206de8872..2d5a31340 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 4195891a3..508ea0fab 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 1fae090fd..1a00d431a 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 f14c0e990..4b47801a8 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 c4b547658..448107af0 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 1f2c99cac..f0746701e 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 82fa706d7..3a235ec5b 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 d92482f32..6fd3b430c 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 24d293118..a3a5159d1 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 4863a4f04..0452dacdf 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 ba298b536..1e6f2b7ea 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 9ab914f01..9718d88f0 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 8854a0944..1f3e3e197 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 014e43470..53d4713aa 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 68aa31539..b804d12bb 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 654e7c10e..2e0901778 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 a158d6772..6f814d7ee 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 3798148cf..ce1bf6a36 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 03e512d12..faea82110 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 15f402123..e2ca3e8d2 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 061d8b1c8..42c81072c 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 012c78a91..6058519ab 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 82f3cbf74..9e1e60980 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 3ae6c6282..4b7f18ba8 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 b4033fe7a..2d8ff6ed5 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 b6ab91fe5..4cd48a05c 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 6ace15f02..323a40ebf 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 f765f9565..2da280f83 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 62eabeee9..438164235 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 9e07d4bc4..38e1a1140 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 b11b3a74a..aa549b455 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 3afd9cb8d..a9670d013 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 64f09b753..9486b4748 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 401901c48..55ff0fbe7 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 09e4bb65d..1967e4304 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 5c55e2c2b..a85b59c24 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 000000000..f46ade2f6 --- /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 237b38aa4..08ecdc979 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 c93caca67..66587f6c9 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 ce2614212..5df9709e4 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 827230f2c..4fb304b49 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 88b299a64..39f1e9947 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 6adf59900..96e6b06a0 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 e6e930e63..8972fd029 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 bbbdf07ba..3b496f1d2 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 a1d1a7d7a..0727a2154 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 bbd64783c..1406573d8 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 1f972cb31..85f4b2e3f 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 42bfdc782..1b3575a5f 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 ebf9b67ab..3f3de4522 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 868a2898e..6a7227c65 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 b10b3f4f6..bce3bfab2 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 97c57d461..9fbbe47f5 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 3d6affbbc..8277de48a 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() -- GitLab