From 1e99683c2390570a54bf1150d042a20a4a093283 Mon Sep 17 00:00:00 2001 From: Aaron Todd Date: Thu, 14 Dec 2023 20:08:41 -0500 Subject: [PATCH] refactor: split AWS SDK specific customizations into new module (#1151) First step to separating AWS protocol support from AWS SDK specific customizations. Specifically we introduce a new module aws-sdk-codegen which is everything AWS SDK for Kotlin specific. The existing smithy-aws-kotlin-codegen now only contains AWS protocol support. refactor: Split out AWS SDK for Kotlin specific customizations into a new module aws-sdk-codegen refactor: Use the software.amazon.smithy.kotlin.codegen.aws namespace for AWS protocol support instead of aws.sdk.kotlin.codegen to better align with the rest of the code generation in smithy-kotlin refactor: Remove S3Generator in favor of overriding sections fix: Fix route53 customization to only apply to the operation it is meant to refactor: Migrate flow utils to smithy-kotlin runtime. --- .github/scripts/codegen-diff-revisions.py | 108 +++++----- .github/workflows/codegen-preview.yml | 13 +- aws-runtime/aws-config/build.gradle.kts | 6 +- aws-runtime/aws-core/api/aws-core.api | 3 - .../src/aws/sdk/kotlin/runtime/FlowUtil.kt | 15 -- .../aws/sdk/kotlin/runtime/FlowUtilTest.kt | 58 ------ codegen/aws-sdk-codegen/build.gradle.kts | 104 ++++++++++ .../AddUserAgentMetadataIntegration.kt | 0 .../sdk/kotlin/codegen/AwsKotlinDependency.kt | 0 .../codegen/AwsRetryHeaderIntegration.kt | 0 .../aws/sdk/kotlin/codegen/AwsRuntimeTypes.kt | 3 +- .../codegen/AwsServiceConfigIntegration.kt | 42 +--- .../aws/sdk/kotlin/codegen/AwsServiceUtils.kt | 14 -- .../aws/sdk/kotlin/codegen/GradleGenerator.kt | 0 .../sdk/kotlin/codegen/PresignerGenerator.kt | 0 .../aws/sdk/kotlin/codegen/SdkIdTransform.kt | 0 .../ServiceClientCompanionObjectWriter.kt | 0 .../AccountIdEndpointBuiltinCustomization.kt | 2 +- .../customization/AddAwsSpanAttributes.kt | 27 +++ .../customization/BackfillOptionalAuth.kt | 0 .../customization/DefaultMiddleware.kt | 27 +++ .../customization/PresignableOperations.kt | 0 .../codegen/customization/RemoveDefaults.kt | 0 .../ReplaceServiceExceptionBase.kt | 42 ++++ .../apigateway/ApiGatewayAddAcceptHeader.kt | 2 +- .../ec2/EC2MakePrimitivesOptional.kt | 0 .../FlexibleChecksumsRequest.kt | 0 .../FlexibleChecksumsResponse.kt | 0 .../glacier/GlacierAccountIdDefault.kt | 0 .../glacier/GlacierAddVersionHeader.kt | 2 +- .../glacier/GlacierBodyChecksum.kt | 0 .../MachineLearningEndpointCustomization.kt | 0 .../customization/polly/PollyPresigner.kt | 0 ...ourceRecordSetsUnmarshallingIntegration.kt | 42 ++++ .../route53/TrimResourcePrefix.kt | 0 .../s3/ClientConfigIntegration.kt | 0 .../customization/s3/ContinueIntegration.kt | 0 ...jectResponseLengthValidationIntegration.kt | 0 .../s3/HostPrefixRequestRouteFilter.kt | 0 .../customization/s3/HttpPathFilter.kt | 0 .../s3/S3ErrorMetadataIntegration.kt | 8 +- .../s3/S3ErrorWith200StatusIntegration.kt | 0 .../codegen/customization/s3/S3ModelUtils.kt | 0 .../s3/S3OperationErrorHandler.kt} | 27 +-- .../customization/s3/S3SigningConfig.kt | 6 +- .../s3/TruncatablePaginationIntegration.kt | 0 .../s3/UnwrappedXmlOutputIntegration.kt | 0 .../s3control/ClientConfigIntegration.kt | 0 .../s3control/HostPrefixFilter.kt | 0 .../endpoints/AddAwsEndpointFunctions.kt | 54 +++++ .../kotlin/codegen/endpoints/AwsBuiltins.kt} | 4 +- .../endpoints/BindAwsEndpointBuiltins.kt | 60 ++++-- .../codegen}/endpoints/PartitionsGenerator.kt | 2 +- .../AwsSpanInterceptorMiddleware.kt | 2 +- .../RecursionDetectionMiddleware.kt | 2 +- .../middleware/UserAgentMiddleware.kt | 2 +- .../codegen/model/traits/Presignable.kt | 0 ...tlin.codegen.integration.KotlinIntegration | 38 ++++ .../aws/sdk/kotlin/codegen/endpoints.json | 0 .../aws/sdk/kotlin/codegen/partitions.json | 0 .../codegen/sdk-default-configuration.json | 0 .../AddUserAgentMetadataIntegrationTest.kt | 0 .../AwsServiceConfigIntegrationTest.kt | 0 .../codegen/EndpointUrlConfigNamesTest.kt | 0 .../kotlin/codegen/PresignerGeneratorTest.kt | 0 .../ServiceClientCompanionObjectWriterTest.kt | 0 .../PresignableModelIntegrationTest.kt | 0 .../customization/RemoveDefaultsTest.kt | 0 .../ec2/EC2MakePrimitivesOptionalTest.kt | 0 ...eRecordSetsUnmarshallingIntegrationTest.kt | 0 .../s3/ContinueIntegrationTest.kt | 0 ...ResponseLengthValidationIntegrationTest.kt | 0 .../s3/UnwrappedXmlOutputIntegrationTest.kt | 0 .../sdk/kotlin/codegen/testutil/ModelUtil.kt | 0 .../sdk/kotlin/codegen/testutil/StringExt.kt | 0 codegen/sdk/build.gradle.kts | 2 +- .../build.gradle.kts | 28 --- .../kotlin/codegen/AwsEndpointDelegator.kt | 92 --------- ...ourceRecordSetsUnmarshallingIntegration.kt | 31 --- .../core/AwsHttpBindingProtocolGenerator.kt | 186 ------------------ .../core/AwsHttpProtocolClientGenerator.kt | 132 ------------- .../endpoints/DefaultEndpointProviderExt.kt | 84 -------- .../middleware/MutateHeadersMiddleware.kt | 41 ---- ...AwsHttpProtocolUnitTestRequestGenerator.kt | 68 ------- ...wsHttpProtocolUnitTestResponseGenerator.kt | 42 ---- .../codegen/transforms/IncludeOperations.kt | 35 ---- .../transforms/RemoveDeprecatedShapes.kt | 56 ------ .../aws}/SdkProtocolGeneratorSupplier.kt | 15 +- .../aws/customization/RegionSupport.kt | 109 ++++++++++ .../codegen/aws/middleware}/ClockSkew.kt | 2 +- .../codegen/aws}/protocols/AwsJson1_0.kt | 12 +- .../codegen/aws}/protocols/AwsJson1_1.kt | 12 +- .../kotlin/codegen/aws}/protocols/AwsQuery.kt | 10 +- .../kotlin/codegen/aws}/protocols/Ec2Query.kt | 8 +- .../codegen/aws}/protocols/RestJson1.kt | 8 +- .../kotlin/codegen/aws}/protocols/RestXml.kt | 6 +- .../core/AwsHttpBindingProtocolGenerator.kt | 179 +++++++++++++++++ .../core/QueryHttpBindingProtocolGenerator.kt | 4 +- .../core/StaticHttpBindingResolver.kt | 2 +- .../eventstream/EventStreamParserGenerator.kt | 7 +- .../EventStreamSerializerGenerator.kt | 5 +- .../QuerySerdeFormUrlDescriptorGenerator.kt | 2 +- .../json/AwsJsonHttpBindingResolver.kt | 4 +- .../json/AwsJsonProtocolMiddleware.kt | 2 +- .../json/AwsJsonProtocolParserGenerator.kt | 2 +- ...AwsJsonProtocolSerdeDescriptorGenerator.kt | 2 +- .../json/JsonHttpBindingProtocolGenerator.kt | 4 +- .../xml/RestXmlSerdeDescriptorGenerator.kt | 2 +- ....amazon.smithy.build.ProjectionTransformer | 2 - ...tlin.codegen.integration.KotlinIntegration | 39 +--- .../AwsHttpProtocolClientGeneratorTest.kt | 50 ----- .../transforms/RemoveDeprecatedShapesTest.kt | 54 ----- .../AwsHttpBindingProtocolGeneratorTest.kt | 2 +- .../json/AwsJsonHttpBindingResolverTest.kt | 2 +- ...sonProtocolSerdeDescriptorGeneratorTest.kt | 2 +- .../RestXmlSerdeDescriptorGeneratorTest.kt | 2 +- gradle/libs.versions.toml | 4 +- .../gradle/codegen/tasks/SmithyTasks.kt | 4 +- settings.gradle.kts | 1 + 119 files changed, 824 insertions(+), 1247 deletions(-) delete mode 100644 aws-runtime/aws-core/common/src/aws/sdk/kotlin/runtime/FlowUtil.kt delete mode 100644 aws-runtime/aws-core/common/test/aws/sdk/kotlin/runtime/FlowUtilTest.kt create mode 100644 codegen/aws-sdk-codegen/build.gradle.kts rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/AddUserAgentMetadataIntegration.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/AwsKotlinDependency.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/AwsRetryHeaderIntegration.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/AwsRuntimeTypes.kt (96%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt (78%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceUtils.kt (52%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/PresignerGenerator.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/SdkIdTransform.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriter.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/AccountIdEndpointBuiltinCustomization.kt (97%) create mode 100644 codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/AddAwsSpanAttributes.kt rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/BackfillOptionalAuth.kt (100%) create mode 100644 codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/DefaultMiddleware.kt rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/PresignableOperations.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/RemoveDefaults.kt (100%) create mode 100644 codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/ReplaceServiceExceptionBase.kt rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/apigateway/ApiGatewayAddAcceptHeader.kt (93%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/ec2/EC2MakePrimitivesOptional.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/flexiblechecksums/FlexibleChecksumsRequest.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/flexiblechecksums/FlexibleChecksumsResponse.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierAccountIdDefault.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierAddVersionHeader.kt (94%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierBodyChecksum.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/machinelearning/MachineLearningEndpointCustomization.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/polly/PollyPresigner.kt (100%) create mode 100644 codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegration.kt rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/TrimResourcePrefix.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/ClientConfigIntegration.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/ContinueIntegration.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/GetObjectResponseLengthValidationIntegration.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/HostPrefixRequestRouteFilter.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/HttpPathFilter.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorMetadataIntegration.kt (85%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorWith200StatusIntegration.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ModelUtils.kt (100%) rename codegen/{smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3Generator.kt => aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3OperationErrorHandler.kt} (78%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3SigningConfig.kt (86%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/TruncatablePaginationIntegration.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnwrappedXmlOutputIntegration.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3control/ClientConfigIntegration.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3control/HostPrefixFilter.kt (100%) create mode 100644 codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/AddAwsEndpointFunctions.kt rename codegen/{smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/endpoints/Builtins.kt => aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/AwsBuiltins.kt} (84%) rename codegen/{smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols => aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen}/endpoints/BindAwsEndpointBuiltins.kt (65%) rename codegen/{smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols => aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen}/endpoints/PartitionsGenerator.kt (98%) rename codegen/{smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols => aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen}/middleware/AwsSpanInterceptorMiddleware.kt (95%) rename codegen/{smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols => aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen}/middleware/RecursionDetectionMiddleware.kt (95%) rename codegen/{smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols => aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen}/middleware/UserAgentMiddleware.kt (97%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/Presignable.kt (100%) create mode 100644 codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/resources/aws/sdk/kotlin/codegen/endpoints.json (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/resources/aws/sdk/kotlin/codegen/partitions.json (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/main/resources/aws/sdk/kotlin/codegen/sdk-default-configuration.json (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/test/kotlin/aws/sdk/kotlin/codegen/AddUserAgentMetadataIntegrationTest.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/test/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegrationTest.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/test/kotlin/aws/sdk/kotlin/codegen/EndpointUrlConfigNamesTest.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/test/kotlin/aws/sdk/kotlin/codegen/PresignerGeneratorTest.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/test/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriterTest.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/test/kotlin/aws/sdk/kotlin/codegen/customization/PresignableModelIntegrationTest.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/test/kotlin/aws/sdk/kotlin/codegen/customization/RemoveDefaultsTest.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/test/kotlin/aws/sdk/kotlin/codegen/customization/ec2/EC2MakePrimitivesOptionalTest.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/test/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegrationTest.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/test/kotlin/aws/sdk/kotlin/codegen/customization/s3/ContinueIntegrationTest.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/test/kotlin/aws/sdk/kotlin/codegen/customization/s3/GetObjectResponseLengthValidationIntegrationTest.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/test/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnwrappedXmlOutputIntegrationTest.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/test/kotlin/aws/sdk/kotlin/codegen/testutil/ModelUtil.kt (100%) rename codegen/{smithy-aws-kotlin-codegen => aws-sdk-codegen}/src/test/kotlin/aws/sdk/kotlin/codegen/testutil/StringExt.kt (100%) delete mode 100644 codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsEndpointDelegator.kt delete mode 100644 codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegration.kt delete mode 100644 codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpBindingProtocolGenerator.kt delete mode 100644 codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpProtocolClientGenerator.kt delete mode 100644 codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/endpoints/DefaultEndpointProviderExt.kt delete mode 100644 codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/middleware/MutateHeadersMiddleware.kt delete mode 100644 codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/protocoltest/AwsHttpProtocolUnitTestRequestGenerator.kt delete mode 100644 codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/protocoltest/AwsHttpProtocolUnitTestResponseGenerator.kt delete mode 100644 codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/transforms/IncludeOperations.kt delete mode 100644 codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/transforms/RemoveDeprecatedShapes.kt rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/SdkProtocolGeneratorSupplier.kt (59%) create mode 100644 codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/customization/RegionSupport.kt rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen/customization => software/amazon/smithy/kotlin/codegen/aws/middleware}/ClockSkew.kt (94%) rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/AwsJson1_0.kt (76%) rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/AwsJson1_1.kt (76%) rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/AwsQuery.kt (93%) rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/Ec2Query.kt (93%) rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/RestJson1.kt (90%) rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/RestXml.kt (97%) create mode 100644 codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/AwsHttpBindingProtocolGenerator.kt rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/core/QueryHttpBindingProtocolGenerator.kt (98%) rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/core/StaticHttpBindingResolver.kt (98%) rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/eventstream/EventStreamParserGenerator.kt (98%) rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/eventstream/EventStreamSerializerGenerator.kt (98%) rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/formurl/QuerySerdeFormUrlDescriptorGenerator.kt (96%) rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/json/AwsJsonHttpBindingResolver.kt (84%) rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/json/AwsJsonProtocolMiddleware.kt (94%) rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/json/AwsJsonProtocolParserGenerator.kt (95%) rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/json/AwsJsonProtocolSerdeDescriptorGenerator.kt (96%) rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/json/JsonHttpBindingProtocolGenerator.kt (91%) rename codegen/smithy-aws-kotlin-codegen/src/main/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/xml/RestXmlSerdeDescriptorGenerator.kt (96%) delete mode 100644 codegen/smithy-aws-kotlin-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.ProjectionTransformer delete mode 100644 codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpProtocolClientGeneratorTest.kt delete mode 100644 codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/transforms/RemoveDeprecatedShapesTest.kt rename codegen/smithy-aws-kotlin-codegen/src/test/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/core/AwsHttpBindingProtocolGeneratorTest.kt (98%) rename codegen/smithy-aws-kotlin-codegen/src/test/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/json/AwsJsonHttpBindingResolverTest.kt (98%) rename codegen/smithy-aws-kotlin-codegen/src/test/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/json/AwsJsonProtocolSerdeDescriptorGeneratorTest.kt (97%) rename codegen/smithy-aws-kotlin-codegen/src/test/kotlin/{aws/sdk/kotlin/codegen => software/amazon/smithy/kotlin/codegen/aws}/protocols/xml/RestXmlSerdeDescriptorGeneratorTest.kt (96%) diff --git a/.github/scripts/codegen-diff-revisions.py b/.github/scripts/codegen-diff-revisions.py index eda9877bbb6..29f7cb233bb 100755 --- a/.github/scripts/codegen-diff-revisions.py +++ b/.github/scripts/codegen-diff-revisions.py @@ -5,24 +5,45 @@ # # This script can be run and tested locally. To do so, you should check out # a second aws-sdk-kotlin repository so that you can work on the script and still -# run it without it immediately bailing for an unclean working tree (and to avoid creating -# temporary branches). +# run it without it immediately bailing for an unclean working tree (and to avoid mutating +# your local repository). # # Example: -# `aws-sdk-kotlin/` - the main repo you're working out of +# `aws-sdk-kotlin/` - the main repo you're working out of below # `/tmp/aws-sdk-kotlin/` - the repo you're testing against # +# Generate code using the current HEAD of the repository. + # ``` -# $ cd test/aws-sdk-kotlin -# $ ../../aws-sdk-kotlin/.github/scripts/codegen-diff-revisions.py . +# $ cd /tmp/aws-sdk-kotlin +# $ /.github/scripts/codegen-diff-revisions.py codegen --bootstrap +s3,+dynamodb # ``` # -# It will diff the generated code from HEAD against any commit hash you feed it. If you want to test -# a specific range, change the HEAD of the test repository. # -# This script requires `diff2html-cli` to be installed from NPM: +# Generate diffs +# # ``` -# $ npm install -g diff2html-cli@5.2.5 +# $ cd /tmp/aws-sdk-kotlin +# HEAD_SHA=$(git rev-parse ) +# BASE_SHA=$(git rev-parse ) +# HEAD_BRANCH_NAME="__tmp-localonly-head" +# BASE_BRANCH_NAME="__tmp-localonly-base" +# +# /.github/scripts/codegen-diff-revisions.py --head-sha $HEAD_SHA generate-diffs --base-sha $BASE_SHA $BASE_BRANCH_NAME $HEAD_BRANCH_NAME +# ``` +# +# This script requires `difftags` to be installed from the smithy-rs repository. This requires installing a working +# rust toolchain (cargo, rustc, etc). +# ``` +# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh` +# ``` +# +# Install difftags from smithy-rs +# ``` +# git clone --depth 1 https://github.com/smithy-lang/smithy-rs.git +# cd smithy-rs/tools/ci-build/difftags +# cargo install --path . +# difftags -h # ``` # Make sure the local version matches the version referenced from the GitHub Actions workflow. @@ -33,7 +54,7 @@ import tempfile import shlex -OUTPUT_PATH = "tmp-codegen-diff/" +OUTPUT_PATH = "tmp-codegen-diff" COMMIT_AUTHOR_NAME = "GitHub Action (generated codegen diff)" COMMIT_AUTHOR_EMAIL = "generated-code-action@github.com" @@ -103,40 +124,7 @@ def generate_and_commit_generated_code(sha, services_to_bootstrap): run(f"git -c 'user.name={COMMIT_AUTHOR_NAME}' -c 'user.email={COMMIT_AUTHOR_EMAIL}' commit --no-verify -m 'Generated code for {sha}' --allow-empty") -# Writes an HTML template for diff2html so that we can add contextual information -def write_html_template(title, subtitle, tmp_file): - tmp_file.writelines(map(lambda line: line.encode(), [ - "", - "", - "", - ' ', - f' Codegen diff for the {title}: {subtitle}', - ' ', - ' ', - ' ', - ' ', - "", - '', - f"

Codegen diff for the {title}

", - f"

{subtitle}

", - '
', - ' ', - '
', - "", - "", - ])) - tmp_file.flush() - - -def make_diff(opts, title, path_to_diff, suffix, ignore_whitespace): +def make_diff(opts, title, path_to_diff, outsubdir, ignore_whitespace): base_sha = opts.base_sha head_sha = opts.head_sha ws_flag = "-b" if ignore_whitespace else "" @@ -146,19 +134,21 @@ def make_diff(opts, title, path_to_diff, suffix, ignore_whitespace): eprint(f"No diff output for {base_sha}..{head_sha}") return None - run(f'mkdir -p {OUTPUT_PATH}/{base_sha}/{head_sha}') - dest_path = f"{base_sha}/{head_sha}/diff-{suffix}.html" + dest_path = f"{base_sha}/{head_sha}/{outsubdir}" + run(f'mkdir -p {OUTPUT_PATH}/{dest_path}') whitespace_context = "(ignoring whitespace)" if ignore_whitespace else "" - with tempfile.NamedTemporaryFile() as tmp_file: - write_html_template(title, f"rev. {head_sha} {whitespace_context}", tmp_file) - - # Generate HTML diff. This uses the diff2html-cli, which defers to `git diff` under the hood. - # All arguments after the first `--` go to the `git diff` command. - diff_cmd = f"diff2html -s line -f html -d word -i command --hwt " \ - f"{tmp_file.name} -F {OUTPUT_PATH}/{dest_path} -- " \ - f"-U20 {ws_flag} {opts.base_branch} {opts.head_branch} -- {path_to_diff}" + + with tempfile.NamedTemporaryFile(mode='w') as tmp_file: + diff_cmd = f"git diff -U30 {ws_flag} {opts.base_branch} {opts.head_branch} -- {path_to_diff}" eprint(f"Running diff cmd: {diff_cmd}") - run(diff_cmd) + output = get_cmd_output(diff_cmd) + tmp_file.write(output) + + subtitle = f"rev. {base_sha}..{head_sha} {whitespace_context}" + generate_html_cmd = f"difftags --title \"{title}\" --subtitle \"{subtitle}\" --output-dir {OUTPUT_PATH}/{dest_path} {tmp_file.name}" + eprint(f"Running generate html cmd: {generate_html_cmd}") + run(generate_html_cmd) + return dest_path @@ -166,12 +156,14 @@ def diff_link(diff_text, empty_diff_text, diff_location, alternate_text, alterna if diff_location is None: return empty_diff_text - return f"[{diff_text}]({CDN_URL}/codegen-diff/{diff_location}) ([{alternate_text}]({CDN_URL}/codegen-diff/{alternate_location}))" + return f"[{diff_text}]({CDN_URL}/codegen-diff/{diff_location}/index.html) ([{alternate_text}]({CDN_URL}/codegen-diff/{alternate_location}/index.html))" def make_diffs(opts): - sdk_ws = make_diff(opts, 'AWS SDK', f'{OUTPUT_PATH}/services', 'aws-sdk', ignore_whitespace=False) - sdk_no_ws = make_diff(opts, 'AWS SDK', f'{OUTPUT_PATH}/services', 'aws-sdk-ignore-ws', ignore_whitespace=True) + path_to_diff = f"{OUTPUT_PATH}/services" + + sdk_ws = make_diff(opts, 'AWS SDK', path_to_diff, "aws-sdk", ignore_whitespace=False) + sdk_no_ws = make_diff(opts, 'AWS SDK', path_to_diff, "aws-sdk-ignore-ws", ignore_whitespace=True) sdk_links = diff_link('AWS SDK', 'No codegen difference in the AWS SDK', sdk_ws, 'ignoring whitespace', sdk_no_ws) return f'A new generated diff is ready to view.\\n\\n- {sdk_links}\\n' diff --git a/.github/workflows/codegen-preview.yml b/.github/workflows/codegen-preview.yml index be1d76acc21..8c6eeec2be4 100644 --- a/.github/workflows/codegen-preview.yml +++ b/.github/workflows/codegen-preview.yml @@ -55,6 +55,12 @@ jobs: repository: 'awslabs/smithy-kotlin' fetch-depth: 0 path: 'smithy-kotlin' + - uses: actions/checkout@v4 + with: + repository: 'smithy-lang/smithy-rs' + path: 'smithy-rs' + sparse-checkout: | + tools/ci-build/difftags - name: Set up JDK uses: actions/setup-java@v3 with: @@ -63,8 +69,6 @@ jobs: cache: 'gradle' - name: Install deps and setup environment run: | - npm install -g diff2html-cli@${{ env.DIFF2HTML_VERSION }} - env | sort # store off a copy of head ref of ci.py, otherwise base ref generation will use a different version of this script CODEGEN_DIFF_REVISIONS=${{ runner.temp }}/codegen-diff-revisions.py cp $GITHUB_WORKSPACE/aws-sdk-kotlin/.github/scripts/codegen-diff-revisions.py $CODEGEN_DIFF_REVISIONS @@ -72,6 +76,11 @@ jobs: echo "REPO_TOOLS=$GITHUB_WORKSPACE/aws-kotlin-repo-tools" >> "$GITHUB_ENV" echo "SMITHY_KOTLIN_DIR=$GITHUB_WORKSPACE/smithy-kotlin" >> "$GITHUB_ENV" echo "SDK_DIR=$GITHUB_WORKSPACE/aws-sdk-kotlin" >> "$GITHUB_ENV" + echo "installing smithy-rs diff tooling" + pushd $GITHUB_WORKSPACE/smithy-rs/tools/ci-build/difftags + cargo install --path . + difftags --version + popd - name: Generate code for head ref run: | diff --git a/aws-runtime/aws-config/build.gradle.kts b/aws-runtime/aws-config/build.gradle.kts index 8079078beec..f63ff328e44 100644 --- a/aws-runtime/aws-config/build.gradle.kts +++ b/aws-runtime/aws-config/build.gradle.kts @@ -101,7 +101,7 @@ codegen { transforms = listOf( """ { - "name": "awsSdkKotlinIncludeOperations", + "name": "awsSmithyKotlinIncludeOperations", "args": { "operations": [ "com.amazonaws.sts#AssumeRole", @@ -138,7 +138,7 @@ codegen { transforms = listOf( """ { - "name": "awsSdkKotlinIncludeOperations", + "name": "awsSmithyKotlinIncludeOperations", "args": { "operations": [ "com.amazonaws.sso#GetRoleCredentials" @@ -173,7 +173,7 @@ codegen { transforms = listOf( """ { - "name": "awsSdkKotlinIncludeOperations", + "name": "awsSmithyKotlinIncludeOperations", "args": { "operations": [ "com.amazonaws.ssooidc#CreateToken" diff --git a/aws-runtime/aws-core/api/aws-core.api b/aws-runtime/aws-core/api/aws-core.api index 39d9c553070..612389b04ac 100644 --- a/aws-runtime/aws-core/api/aws-core.api +++ b/aws-runtime/aws-core/api/aws-core.api @@ -26,9 +26,6 @@ public class aws/sdk/kotlin/runtime/ConfigurationException : aws/sdk/kotlin/runt public fun (Ljava/lang/Throwable;)V } -public final class aws/sdk/kotlin/runtime/FlowUtilKt { -} - public abstract interface annotation class aws/sdk/kotlin/runtime/InternalSdkApi : java/lang/annotation/Annotation { } diff --git a/aws-runtime/aws-core/common/src/aws/sdk/kotlin/runtime/FlowUtil.kt b/aws-runtime/aws-core/common/src/aws/sdk/kotlin/runtime/FlowUtil.kt deleted file mode 100644 index f18e8ec159d..00000000000 --- a/aws-runtime/aws-core/common/src/aws/sdk/kotlin/runtime/FlowUtil.kt +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.runtime - -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.emitAll -import kotlinx.coroutines.flow.flow - -// FIXME relocate to smithy-kotlin -@InternalSdkApi -public fun mergeSequential(vararg flows: Flow): Flow = flow { - flows.forEach { flow -> emitAll(flow) } -} diff --git a/aws-runtime/aws-core/common/test/aws/sdk/kotlin/runtime/FlowUtilTest.kt b/aws-runtime/aws-core/common/test/aws/sdk/kotlin/runtime/FlowUtilTest.kt deleted file mode 100644 index 47fa6d4487e..00000000000 --- a/aws-runtime/aws-core/common/test/aws/sdk/kotlin/runtime/FlowUtilTest.kt +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.runtime - -import kotlinx.coroutines.flow.Flow -import kotlinx.coroutines.flow.flowOf -import kotlinx.coroutines.flow.toList -import kotlinx.coroutines.test.runTest -import kotlin.test.Test -import kotlin.test.assertEquals - -@OptIn(InternalSdkApi::class) -class FlowUtilTest { - - @Test - fun testMergingFlows() = runTest { - val a = flowOf(1) - val b = flowOf(2, 3, 4) - val merged = mergeSequential(a, b).toList() - assertEquals(listOf(1, 2, 3, 4), merged) - } - - @Test - fun testMergingEmptyFlow() = runTest { - val a: Flow = flowOf() - val b: Flow = flowOf(4, 5, 6) - - val merged = mergeSequential(a, b).toList() - assertEquals(listOf(4, 5, 6), merged) - } - - @Test - fun testMergingOneFlow() = runTest { - val a = flowOf(1, 2, 3) - val merged = mergeSequential(a).toList() - - assertEquals(listOf(1, 2, 3), merged) - } - - @Test - fun testMergingSameFlow() = runTest { - val a = flowOf(1, 2, 3) - val merged = mergeSequential(a, a).toList() - assertEquals(listOf(1, 2, 3, 1, 2, 3), merged) - } - - @Test - fun testMergingMoreThanTwoFlows() = runTest { - val a = flowOf(1) - val b = flowOf(2) - val c = flowOf(3) - - val merged = mergeSequential(a, b, c).toList() - assertEquals(listOf(1, 2, 3), merged) - } -} diff --git a/codegen/aws-sdk-codegen/build.gradle.kts b/codegen/aws-sdk-codegen/build.gradle.kts new file mode 100644 index 00000000000..016d42acdcf --- /dev/null +++ b/codegen/aws-sdk-codegen/build.gradle.kts @@ -0,0 +1,104 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +plugins { + kotlin("jvm") + jacoco +} + +val sdkVersion: String by project +description = "Codegen support for AWS SDK for Kotlin" +group = "aws.sdk.kotlin" +version = sdkVersion + +dependencies { + + api(project(":codegen:smithy-aws-kotlin-codegen")) + implementation(libs.kotlin.stdlib.jdk8) + api(libs.smithy.kotlin.codegen) + + api(libs.smithy.aws.traits) + api(libs.smithy.aws.iam.traits) + api(libs.smithy.aws.cloudformation.traits) + api(libs.smithy.protocol.test.traits) + implementation(libs.smithy.aws.endpoints) + + testImplementation(libs.junit.jupiter) + testImplementation(libs.junit.jupiter.params) + testImplementation(libs.kotest.assertions.core.jvm) + testImplementation(libs.kotlin.test.junit5) + testImplementation(libs.smithy.kotlin.codegen.testutils) + + testImplementation(libs.slf4j.api) + testImplementation(libs.slf4j.simple) + testImplementation(libs.kotlinx.serialization.json) +} + +val generateSdkRuntimeVersion by tasks.registering { + // generate the version of the runtime to use as a resource. + // this keeps us from having to manually change version numbers in multiple places + val resourcesDir = "$buildDir/resources/main/aws/sdk/kotlin/codegen" + val versionFile = file("$resourcesDir/sdk-version.txt") + val gradlePropertiesFile = rootProject.file("gradle.properties") + inputs.file(gradlePropertiesFile) + outputs.file(versionFile) + sourceSets.main.get().output.dir(resourcesDir) + doLast { + versionFile.writeText("$version") + } +} + +val jvmTargetVersion = JavaVersion.VERSION_17.toString() + +tasks.compileKotlin { + kotlinOptions.jvmTarget = jvmTargetVersion + dependsOn(generateSdkRuntimeVersion) +} + +tasks.compileTestKotlin { + kotlinOptions.jvmTarget = jvmTargetVersion +} + +tasks.withType { + sourceCompatibility = jvmTargetVersion + targetCompatibility = jvmTargetVersion +} + +// Reusable license copySpec +val licenseSpec = copySpec { + from("${project.rootDir}/LICENSE") + from("${project.rootDir}/NOTICE") +} + +// Configure jars to include license related info +tasks.jar { + metaInf.with(licenseSpec) + inputs.property("moduleName", project.name) + manifest { + attributes["Automatic-Module-Name"] = project.name + } +} + +tasks.test { + useJUnitPlatform() + testLogging { + events("passed", "skipped", "failed") + showStandardStreams = true + showStackTraces = true + showExceptions = true + exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL + } +} + +// Configure jacoco (code coverage) to generate an HTML report +tasks.jacocoTestReport { + reports { + xml.isEnabled = false + csv.isEnabled = false + html.destination = file("$buildDir/reports/jacoco") + } +} + +// Always run the jacoco test report after testing. +tasks["test"].finalizedBy(tasks["jacocoTestReport"]) diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AddUserAgentMetadataIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AddUserAgentMetadataIntegration.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AddUserAgentMetadataIntegration.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AddUserAgentMetadataIntegration.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsKotlinDependency.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsKotlinDependency.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsKotlinDependency.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsKotlinDependency.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsRetryHeaderIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsRetryHeaderIntegration.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsRetryHeaderIntegration.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsRetryHeaderIntegration.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsRuntimeTypes.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsRuntimeTypes.kt similarity index 96% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsRuntimeTypes.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsRuntimeTypes.kt index 4385020b467..438eef7a95e 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsRuntimeTypes.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsRuntimeTypes.kt @@ -14,11 +14,10 @@ import software.amazon.smithy.kotlin.codegen.core.RuntimeTypePackage object AwsRuntimeTypes { object Core : RuntimeTypePackage(AwsKotlinDependency.AWS_CORE) { val AwsErrorMetadata = symbol("AwsErrorMetadata") + val AwsServiceException = symbol("AwsServiceException") val ClientException = symbol("ClientException") - val mergeSequential = symbol("mergeSequential") object Client : RuntimeTypePackage(AwsKotlinDependency.AWS_CORE, "client") { - val AwsClientOption = symbol("AwsClientOption") val AwsSdkClientConfig = symbol("AwsSdkClientConfig") } } diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt similarity index 78% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt index 385e74fc8dd..766ee91ebbc 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegration.kt @@ -20,6 +20,7 @@ import software.amazon.smithy.model.traits.HttpBearerAuthTrait class AwsServiceConfigIntegration : KotlinIntegration { companion object { + // Override the region property registered by AWS protocol support val RegionProp: ConfigProperty = ConfigProperty { name = "region" symbol = KotlinTypes.String.toBuilder().nullable().build() @@ -79,44 +80,6 @@ class AwsServiceConfigIntegration : KotlinIntegration { ) } - val UseFipsProp: ConfigProperty = ConfigProperty { - name = "useFips" - useSymbolWithNullableBuilder(KotlinTypes.Boolean, "false") - documentation = """ - Flag to toggle whether to use [FIPS](https://aws.amazon.com/compliance/fips/) endpoints when making requests. - ` Disabled by default. - """.trimIndent() - baseClass = AwsRuntimeTypes.Core.Client.AwsSdkClientConfig - useNestedBuilderBaseClass() - } - - val UseDualStackProp: ConfigProperty = ConfigProperty { - name = "useDualStack" - useSymbolWithNullableBuilder(KotlinTypes.Boolean, "false") - documentation = """ - Flag to toggle whether to use dual-stack endpoints when making requests. - See [https://docs.aws.amazon.com/sdkref/latest/guide/feature-endpoints.html] for more information. - ` Disabled by default. - """.trimIndent() - baseClass = AwsRuntimeTypes.Core.Client.AwsSdkClientConfig - useNestedBuilderBaseClass() - } - - val EndpointUrlProp = ConfigProperty { - name = "endpointUrl" - symbol = RuntimeTypes.Core.Net.Url.Url.asNullable() - documentation = """ - A custom endpoint to route requests to. The endpoint set here is passed to the configured - [endpointProvider], which may inspect and modify it as needed. - - Setting a custom endpointUrl should generally be preferred to overriding the [endpointProvider] and is - the recommended way to route requests to development or preview instances of a service. - - **This is an advanced config option.** - """.trimIndent() - propertyType = ConfigPropertyType.SymbolDefault - } - val AwsRetryPolicy = RuntimeConfigProperty .RetryPolicy .toBuilder() @@ -174,9 +137,6 @@ class AwsServiceConfigIntegration : KotlinIntegration { add(BearerTokenProviderProp) } - add(UseFipsProp) - add(UseDualStackProp) - add(EndpointUrlProp) add(AwsRetryPolicy) add(UserAgentAppId) } diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceUtils.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceUtils.kt similarity index 52% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceUtils.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceUtils.kt index 5d91bd5e089..f43640366ac 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceUtils.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsServiceUtils.kt @@ -14,17 +14,3 @@ import software.amazon.smithy.model.shapes.ServiceShape */ val ServiceShape.sdkId: String get() = expectTrait().sdkId - -/** - * Get the [arnNamespace](https://awslabs.github.io/smithy/1.0/spec/aws/aws-core.html#service-arn-namespace) - * from the (AWS) service shape - */ -val ServiceShape.arnNamespace: String - get() = expectTrait().arnNamespace - -/** - * Get the [endpointPrefix](https://awslabs.github.io/smithy/1.0/spec/aws/aws-core.html#endpointprefix) - * from the (AWS) service shape - */ -val ServiceShape.endpointPrefix: String - get() = expectTrait().endpointPrefix diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/GradleGenerator.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/PresignerGenerator.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/PresignerGenerator.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/PresignerGenerator.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/PresignerGenerator.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SdkIdTransform.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SdkIdTransform.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SdkIdTransform.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SdkIdTransform.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriter.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriter.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriter.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriter.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/AccountIdEndpointBuiltinCustomization.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/AccountIdEndpointBuiltinCustomization.kt similarity index 97% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/AccountIdEndpointBuiltinCustomization.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/AccountIdEndpointBuiltinCustomization.kt index 00ead3262a7..d14fe6bdf16 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/AccountIdEndpointBuiltinCustomization.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/AccountIdEndpointBuiltinCustomization.kt @@ -5,7 +5,7 @@ package aws.sdk.kotlin.codegen.customization import aws.sdk.kotlin.codegen.AwsRuntimeTypes -import aws.sdk.kotlin.codegen.protocols.endpoints.AwsBuiltins +import aws.sdk.kotlin.codegen.endpoints.AwsBuiltins import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.core.CodegenContext import software.amazon.smithy.kotlin.codegen.integration.AppendingSectionWriter diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/AddAwsSpanAttributes.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/AddAwsSpanAttributes.kt new file mode 100644 index 00000000000..e480829f026 --- /dev/null +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/AddAwsSpanAttributes.kt @@ -0,0 +1,27 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.codegen.customization + +import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes +import software.amazon.smithy.kotlin.codegen.core.withBlock +import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +import software.amazon.smithy.kotlin.codegen.integration.SectionWriter +import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding +import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpProtocolClientGenerator + +/** + * Set AWS specific span attributes for an operation + * See https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/instrumentation/aws-sdk/ + */ +class AddAwsSpanAttributes : KotlinIntegration { + override val sectionWriters: List + get() = listOf(SectionWriterBinding(HttpProtocolClientGenerator.OperationTelemetryBuilder, addAwsSpanAttrWriter)) + + private val addAwsSpanAttrWriter = SectionWriter { w, _ -> + w.withBlock("attributes = #T {", "}", RuntimeTypes.Core.Collections.attributesOf) { + write("#S to #S", "rpc.system", "aws-api") + } + } +} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/BackfillOptionalAuth.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/BackfillOptionalAuth.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/BackfillOptionalAuth.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/BackfillOptionalAuth.kt diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/DefaultMiddleware.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/DefaultMiddleware.kt new file mode 100644 index 00000000000..b480fa6bed8 --- /dev/null +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/DefaultMiddleware.kt @@ -0,0 +1,27 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.codegen.customization + +import aws.sdk.kotlin.codegen.middleware.AwsSpanInterceptorMiddleware +import aws.sdk.kotlin.codegen.middleware.RecursionDetectionMiddleware +import aws.sdk.kotlin.codegen.middleware.UserAgentMiddleware +import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator +import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolMiddleware + +/** + * Registers default HTTP protocol middleware used by every SDK + */ +class DefaultMiddleware : KotlinIntegration { + override fun customizeMiddleware( + ctx: ProtocolGenerator.GenerationContext, + resolved: List, + ): List = resolved + + listOf( + UserAgentMiddleware(), + RecursionDetectionMiddleware(), + AwsSpanInterceptorMiddleware(), + ) +} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/PresignableOperations.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/PresignableOperations.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/PresignableOperations.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/PresignableOperations.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/RemoveDefaults.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/RemoveDefaults.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/RemoveDefaults.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/RemoveDefaults.kt diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/ReplaceServiceExceptionBase.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/ReplaceServiceExceptionBase.kt new file mode 100644 index 00000000000..6e8cca55967 --- /dev/null +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/ReplaceServiceExceptionBase.kt @@ -0,0 +1,42 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.codegen.customization + +import aws.sdk.kotlin.codegen.AwsRuntimeTypes +import software.amazon.smithy.kotlin.codegen.core.CodegenContext +import software.amazon.smithy.kotlin.codegen.core.KotlinWriter +import software.amazon.smithy.kotlin.codegen.core.declareSection +import software.amazon.smithy.kotlin.codegen.core.getContextValue +import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +import software.amazon.smithy.kotlin.codegen.integration.SectionId +import software.amazon.smithy.kotlin.codegen.integration.SectionWriter +import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding +import software.amazon.smithy.kotlin.codegen.rendering.ExceptionBaseClassGenerator +import software.amazon.smithy.kotlin.codegen.rendering.ServiceExceptionBaseClassGenerator + +/** + * Integration that updates the generated service exception base class (e.g. `S3Exception`, `DynamoDbException`, etc) + * to inherit from `AwsServiceException` instead of just `ServiceException`. + */ +class ReplaceServiceExceptionBase : KotlinIntegration { + // S3 further customizes this by overriding the error metadata. See [aws.sdk.kotlin.codegen.customization.s3.S3ErrorMetadataIntegration] + override val order: Byte = -10 + override val sectionWriters: List + get() = listOf(SectionWriterBinding(ExceptionBaseClassGenerator.ExceptionBaseClassSection, exceptionSectionWriter)) + + private val exceptionSectionWriter = SectionWriter { writer, _ -> + val ctx = writer.getContextValue(ExceptionBaseClassGenerator.ExceptionBaseClassSection.CodegenContext) + AwsServiceExceptionBaseClassGenerator().render(ctx, writer) + } +} + +class AwsServiceExceptionBaseClassGenerator : ServiceExceptionBaseClassGenerator(AwsRuntimeTypes.Core.AwsServiceException) { + object Sections { + object RenderExtra : SectionId + } + override fun renderExtra(ctx: CodegenContext, writer: KotlinWriter) { + writer.declareSection(Sections.RenderExtra) + } +} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/apigateway/ApiGatewayAddAcceptHeader.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/apigateway/ApiGatewayAddAcceptHeader.kt similarity index 93% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/apigateway/ApiGatewayAddAcceptHeader.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/apigateway/ApiGatewayAddAcceptHeader.kt index ca1fd626743..1bf4a5a2a71 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/apigateway/ApiGatewayAddAcceptHeader.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/apigateway/ApiGatewayAddAcceptHeader.kt @@ -5,11 +5,11 @@ package aws.sdk.kotlin.codegen.customization.apigateway -import aws.sdk.kotlin.codegen.protocols.middleware.MutateHeadersMiddleware import aws.sdk.kotlin.codegen.sdkId import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration import software.amazon.smithy.kotlin.codegen.model.expectShape +import software.amazon.smithy.kotlin.codegen.rendering.protocol.MutateHeadersMiddleware import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolMiddleware import software.amazon.smithy.model.Model diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/ec2/EC2MakePrimitivesOptional.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/ec2/EC2MakePrimitivesOptional.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/ec2/EC2MakePrimitivesOptional.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/ec2/EC2MakePrimitivesOptional.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/flexiblechecksums/FlexibleChecksumsRequest.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/flexiblechecksums/FlexibleChecksumsRequest.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/flexiblechecksums/FlexibleChecksumsRequest.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/flexiblechecksums/FlexibleChecksumsRequest.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/flexiblechecksums/FlexibleChecksumsResponse.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/flexiblechecksums/FlexibleChecksumsResponse.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/flexiblechecksums/FlexibleChecksumsResponse.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/flexiblechecksums/FlexibleChecksumsResponse.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierAccountIdDefault.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierAccountIdDefault.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierAccountIdDefault.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierAccountIdDefault.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierAddVersionHeader.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierAddVersionHeader.kt similarity index 94% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierAddVersionHeader.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierAddVersionHeader.kt index 9c56e910a73..ac67c6874d2 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierAddVersionHeader.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierAddVersionHeader.kt @@ -4,11 +4,11 @@ */ package aws.sdk.kotlin.codegen.customization.glacier -import aws.sdk.kotlin.codegen.protocols.middleware.MutateHeadersMiddleware import aws.sdk.kotlin.codegen.sdkId import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration import software.amazon.smithy.kotlin.codegen.model.expectShape +import software.amazon.smithy.kotlin.codegen.rendering.protocol.MutateHeadersMiddleware import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolMiddleware import software.amazon.smithy.model.Model diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierBodyChecksum.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierBodyChecksum.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierBodyChecksum.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/glacier/GlacierBodyChecksum.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/machinelearning/MachineLearningEndpointCustomization.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/machinelearning/MachineLearningEndpointCustomization.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/machinelearning/MachineLearningEndpointCustomization.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/machinelearning/MachineLearningEndpointCustomization.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/polly/PollyPresigner.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/polly/PollyPresigner.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/polly/PollyPresigner.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/polly/PollyPresigner.kt diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegration.kt new file mode 100644 index 00000000000..b2fccd7a54b --- /dev/null +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegration.kt @@ -0,0 +1,42 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.codegen.customization.route53 + +import aws.sdk.kotlin.codegen.sdkId +import software.amazon.smithy.kotlin.codegen.KotlinSettings +import software.amazon.smithy.kotlin.codegen.aws.protocols.core.AwsHttpBindingProtocolGenerator +import software.amazon.smithy.kotlin.codegen.core.getContextValue +import software.amazon.smithy.kotlin.codegen.core.withBlock +import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding +import software.amazon.smithy.kotlin.codegen.model.expectShape +import software.amazon.smithy.model.Model +import software.amazon.smithy.model.shapes.ServiceShape +import software.amazon.smithy.model.shapes.ShapeId + +class ChangeResourceRecordSetsUnmarshallingIntegration : KotlinIntegration { + private val targetErrorShapeId = ShapeId.from("com.amazonaws.route53#InvalidChangeBatch") + + override val sectionWriters: List = listOf( + SectionWriterBinding(AwsHttpBindingProtocolGenerator.Sections.ProtocolErrorDeserialization) { writer, prevValue -> + val op = writer.getContextValue(AwsHttpBindingProtocolGenerator.Sections.RenderThrowOperationError.Operation) + + if (op.errors.any { it == targetErrorShapeId }) { + writer.withBlock("payload?.let {", "}") { + withBlock("aws.sdk.kotlin.services.route53.internal.parseRestXmlInvalidChangeBatchResponse(payload)?.let {", "}") { + write("setAseErrorMetadata(it.exception, wrappedResponse, it.errorDetails)") + write("throw it.exception") + } + } + writer.write("") + } else { + writer.write(prevValue) + } + }, + ) + + override fun enabledForService(model: Model, settings: KotlinSettings) = + model.expectShape(settings.service).sdkId.equals("route 53", ignoreCase = true) +} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/TrimResourcePrefix.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/TrimResourcePrefix.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/TrimResourcePrefix.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/TrimResourcePrefix.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/ClientConfigIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/ClientConfigIntegration.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/ClientConfigIntegration.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/ClientConfigIntegration.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/ContinueIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/ContinueIntegration.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/ContinueIntegration.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/ContinueIntegration.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/GetObjectResponseLengthValidationIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/GetObjectResponseLengthValidationIntegration.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/GetObjectResponseLengthValidationIntegration.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/GetObjectResponseLengthValidationIntegration.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/HostPrefixRequestRouteFilter.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/HostPrefixRequestRouteFilter.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/HostPrefixRequestRouteFilter.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/HostPrefixRequestRouteFilter.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/HttpPathFilter.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/HttpPathFilter.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/HttpPathFilter.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/HttpPathFilter.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorMetadataIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorMetadataIntegration.kt similarity index 85% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorMetadataIntegration.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorMetadataIntegration.kt index 685828a94e7..cde0f078d26 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorMetadataIntegration.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorMetadataIntegration.kt @@ -5,13 +5,13 @@ package aws.sdk.kotlin.codegen.customization.s3 import aws.sdk.kotlin.codegen.AwsRuntimeTypes +import aws.sdk.kotlin.codegen.customization.AwsServiceExceptionBaseClassGenerator import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.core.* +import software.amazon.smithy.kotlin.codegen.integration.AppendingSectionWriter import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration -import software.amazon.smithy.kotlin.codegen.integration.SectionWriter import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding import software.amazon.smithy.kotlin.codegen.model.expectShape -import software.amazon.smithy.kotlin.codegen.rendering.ExceptionBaseClassGenerator import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape @@ -21,7 +21,7 @@ import software.amazon.smithy.model.shapes.ServiceShape class S3ErrorMetadataIntegration : KotlinIntegration { override val sectionWriters: List - get() = listOf(SectionWriterBinding(ExceptionBaseClassGenerator.ExceptionBaseClassSection, addSdkErrorMetadataWriter)) + get() = listOf(SectionWriterBinding(AwsServiceExceptionBaseClassGenerator.Sections.RenderExtra, addSdkErrorMetadataWriter)) override fun enabledForService(model: Model, settings: KotlinSettings) = model.expectShape(settings.service).isS3 @@ -49,7 +49,7 @@ class S3ErrorMetadataIntegration : KotlinIntegration { } // SectionWriter to override the default sdkErrorMetadata for S3's version - private val addSdkErrorMetadataWriter = SectionWriter { writer, _ -> + private val addSdkErrorMetadataWriter = AppendingSectionWriter { writer -> writer.write("override val sdkErrorMetadata: S3ErrorMetadata = S3ErrorMetadata()") } } diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorWith200StatusIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorWith200StatusIntegration.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorWith200StatusIntegration.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ErrorWith200StatusIntegration.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ModelUtils.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ModelUtils.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ModelUtils.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3ModelUtils.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3Generator.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3OperationErrorHandler.kt similarity index 78% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3Generator.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3OperationErrorHandler.kt index b71427ed42d..56d7254580f 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3Generator.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3OperationErrorHandler.kt @@ -5,12 +5,15 @@ package aws.sdk.kotlin.codegen.customization.s3 -import aws.sdk.kotlin.codegen.protocols.RestXml import software.amazon.smithy.kotlin.codegen.KotlinSettings +import software.amazon.smithy.kotlin.codegen.aws.protocols.core.AwsHttpBindingProtocolGenerator import software.amazon.smithy.kotlin.codegen.core.KotlinWriter import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes +import software.amazon.smithy.kotlin.codegen.core.getContextValue import software.amazon.smithy.kotlin.codegen.core.withBlock import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +import software.amazon.smithy.kotlin.codegen.integration.SectionWriter +import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding import software.amazon.smithy.kotlin.codegen.model.buildSymbol import software.amazon.smithy.kotlin.codegen.model.expectShape import software.amazon.smithy.kotlin.codegen.rendering.ExceptionBaseClassGenerator @@ -20,25 +23,25 @@ import software.amazon.smithy.model.shapes.OperationShape import software.amazon.smithy.model.shapes.ServiceShape /** - * Supplies a customized protocol generator just for S3 + * Customized error handling for S3 */ -class S3GeneratorSupplier : KotlinIntegration { - override val order: Byte = -20 +class S3OperationErrorHandler : KotlinIntegration { override fun enabledForService(model: Model, settings: KotlinSettings): Boolean { val service = model.expectShape(settings.service) return service.isS3 } - override val protocolGenerators: List = listOf(S3Generator()) -} + override val sectionWriters: List + get() = listOf(SectionWriterBinding(AwsHttpBindingProtocolGenerator.Sections.RenderThrowOperationError, overrideThrowOperationErrors)) -/** - * Customized protocol generator just for S3 - */ -class S3Generator : RestXml() { + private val overrideThrowOperationErrors = SectionWriter { writer, _ -> + val ctx = writer.getContextValue(AwsHttpBindingProtocolGenerator.Sections.RenderThrowOperationError.Context) + val op = writer.getContextValue(AwsHttpBindingProtocolGenerator.Sections.RenderThrowOperationError.Operation) + renderThrowOperationError(ctx, op, writer) + } - override fun renderThrowOperationError( + private fun renderThrowOperationError( ctx: ProtocolGenerator.GenerationContext, op: OperationShape, writer: KotlinWriter, @@ -94,7 +97,7 @@ class S3Generator : RestXml() { name = "${errSymbol.name}Deserializer" namespace = ctx.settings.pkg.serde } - writer.write("#S -> #T().deserialize(context, wrappedCall)", getErrorCode(ctx, err), errDeserializerSymbol) + writer.write("#S -> #T().deserialize(context, wrappedCall)", err.name, errDeserializerSymbol) } write("else -> #T(errorDetails.message)", exceptionBaseSymbol) } diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3SigningConfig.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3SigningConfig.kt similarity index 86% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3SigningConfig.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3SigningConfig.kt index 2c4edafbec4..9009c0f2ff7 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3SigningConfig.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/S3SigningConfig.kt @@ -5,14 +5,14 @@ package aws.sdk.kotlin.codegen.customization.s3 -import aws.sdk.kotlin.codegen.protocols.core.AwsHttpProtocolClientGenerator -import aws.sdk.kotlin.codegen.protocols.core.putIfAbsent import software.amazon.smithy.kotlin.codegen.KotlinSettings import software.amazon.smithy.kotlin.codegen.core.KotlinWriter import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding import software.amazon.smithy.kotlin.codegen.model.expectShape +import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpProtocolClientGenerator +import software.amazon.smithy.kotlin.codegen.rendering.protocol.putIfAbsent import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape @@ -28,7 +28,7 @@ class S3SigningConfig : KotlinIntegration { model.expectShape(settings.service).isS3 override val sectionWriters: List = listOf( - SectionWriterBinding(AwsHttpProtocolClientGenerator.MergeServiceDefaults, ::renderDefaultSigningContext), + SectionWriterBinding(HttpProtocolClientGenerator.MergeServiceDefaults, ::renderDefaultSigningContext), ) private fun renderDefaultSigningContext(writer: KotlinWriter, previousValue: String?) { val signingAttrs = RuntimeTypes.Auth.Signing.AwsSigningCommon.AwsSigningAttributes diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/TruncatablePaginationIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/TruncatablePaginationIntegration.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/TruncatablePaginationIntegration.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/TruncatablePaginationIntegration.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnwrappedXmlOutputIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnwrappedXmlOutputIntegration.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnwrappedXmlOutputIntegration.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnwrappedXmlOutputIntegration.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3control/ClientConfigIntegration.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3control/ClientConfigIntegration.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3control/ClientConfigIntegration.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3control/ClientConfigIntegration.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3control/HostPrefixFilter.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3control/HostPrefixFilter.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3control/HostPrefixFilter.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/s3control/HostPrefixFilter.kt diff --git a/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/AddAwsEndpointFunctions.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/AddAwsEndpointFunctions.kt new file mode 100644 index 00000000000..787d4601cd7 --- /dev/null +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/AddAwsEndpointFunctions.kt @@ -0,0 +1,54 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package aws.sdk.kotlin.codegen.endpoints + +import aws.sdk.kotlin.codegen.AwsRuntimeTypes +import software.amazon.smithy.codegen.core.CodegenException +import software.amazon.smithy.codegen.core.Symbol +import software.amazon.smithy.kotlin.codegen.core.CodegenContext +import software.amazon.smithy.kotlin.codegen.core.KotlinDelegator +import software.amazon.smithy.kotlin.codegen.core.useFileWriter +import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +import software.amazon.smithy.kotlin.codegen.model.buildSymbol +import software.amazon.smithy.kotlin.codegen.rendering.endpoints.EndpointCustomization +import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator +import software.amazon.smithy.model.node.Node +import java.io.File + +internal const val PARTITIONS_JSON_ENV_VAR = "PARTITIONS_FILE" +internal const val PARTITIONS_JSON_SYS_PROP = "aws.partitions_file" +private const val PARTITIONS_RESOURCE = "aws/sdk/kotlin/codegen/partitions.json" + +/** + * Adds support for AWS specific endpoint functions + */ +class AddAwsEndpointFunctions : KotlinIntegration { + override fun customizeEndpointResolution(ctx: ProtocolGenerator.GenerationContext): EndpointCustomization = + object : EndpointCustomization { + override val externalFunctions: Map = mapOf( + "aws.parseArn" to AwsRuntimeTypes.Endpoint.Functions.parseArn, + "aws.isVirtualHostableS3Bucket" to AwsRuntimeTypes.Endpoint.Functions.isVirtualHostableS3Bucket, + "aws.partition" to buildSymbol { + name = "partition" + namespace = PartitionsGenerator.getSymbol(ctx.settings).namespace + }, + ) + } + + override fun writeAdditionalFiles(ctx: CodegenContext, delegator: KotlinDelegator) { + val partitionsData = getPartitionsJson() + val partitions = Node.parse(partitionsData).expectObjectNode() + val partitionsSymbol = PartitionsGenerator.getSymbol(ctx.settings) + + delegator.useFileWriter(partitionsSymbol) { + PartitionsGenerator(it, partitions).render() + } + } + private fun getPartitionsJson(): String = + System.getProperty(PARTITIONS_JSON_SYS_PROP)?.let { File(it).readText() } + ?: System.getenv(PARTITIONS_JSON_ENV_VAR)?.let { File(it).readText() } + ?: javaClass.classLoader.getResource(PARTITIONS_RESOURCE)?.readText() + ?: throw CodegenException("could not load partitions.json resource") +} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/endpoints/Builtins.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/AwsBuiltins.kt similarity index 84% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/endpoints/Builtins.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/AwsBuiltins.kt index 4eb068a5ebe..6d90b7b8f14 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/endpoints/Builtins.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/AwsBuiltins.kt @@ -2,14 +2,12 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.endpoints +package aws.sdk.kotlin.codegen.endpoints object AwsBuiltins { const val ACCOUNT_ID = "AWS::Auth::AccountId" - const val REGION = "AWS::Region" const val USE_FIPS = "AWS::UseFIPS" const val USE_DUAL_STACK = "AWS::UseDualStack" - const val SDK_ENDPOINT = "SDK::Endpoint" const val S3_ACCELERATE = "AWS::S3::Accelerate" const val S3_FORCE_PATH_STYLE = "AWS::S3::ForcePathStyle" const val S3_DISABLE_MRAP = "AWS::S3::DisableMultiRegionAccessPoints" diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/endpoints/BindAwsEndpointBuiltins.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/BindAwsEndpointBuiltins.kt similarity index 65% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/endpoints/BindAwsEndpointBuiltins.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/BindAwsEndpointBuiltins.kt index e8f1b2e3563..6643d3f8e77 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/endpoints/BindAwsEndpointBuiltins.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/BindAwsEndpointBuiltins.kt @@ -2,21 +2,24 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.endpoints +package aws.sdk.kotlin.codegen.endpoints import aws.sdk.kotlin.codegen.AwsRuntimeTypes -import aws.sdk.kotlin.codegen.AwsServiceConfigIntegration import aws.sdk.kotlin.codegen.customization.AccountIdEndpointBuiltinCustomization import software.amazon.smithy.codegen.core.Symbol +import software.amazon.smithy.kotlin.codegen.core.CodegenContext import software.amazon.smithy.kotlin.codegen.core.KotlinWriter import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes import software.amazon.smithy.kotlin.codegen.core.withBlock import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +import software.amazon.smithy.kotlin.codegen.lang.KotlinTypes import software.amazon.smithy.kotlin.codegen.model.buildSymbol import software.amazon.smithy.kotlin.codegen.model.defaultName +import software.amazon.smithy.kotlin.codegen.rendering.endpoints.EndpointCustomization import software.amazon.smithy.kotlin.codegen.rendering.endpoints.EndpointParametersGenerator import software.amazon.smithy.kotlin.codegen.rendering.endpoints.EndpointResolverAdapterGenerator import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator +import software.amazon.smithy.kotlin.codegen.rendering.util.ConfigProperty import software.amazon.smithy.rulesengine.language.EndpointRuleSet import software.amazon.smithy.rulesengine.language.syntax.parameters.Parameter import aws.sdk.kotlin.codegen.customization.s3.ClientConfigIntegration as S3ClientConfigIntegration @@ -26,13 +29,44 @@ import aws.sdk.kotlin.codegen.customization.s3control.ClientConfigIntegration as * Integration that renders binding AWS builtin endpoint parameters */ class BindAwsEndpointBuiltins : KotlinIntegration { - override fun renderBindEndpointBuiltins( - ctx: ProtocolGenerator.GenerationContext, - rules: EndpointRuleSet, - writer: KotlinWriter, - ) { - val builtins = rules.parameters?.toList()?.filter(Parameter::isBuiltIn) ?: return - writer.write("#T(config, request)", bindAwsBuiltinsSymbol(ctx, builtins)) + companion object { + val UseFipsProp: ConfigProperty = ConfigProperty { + name = "useFips" + useSymbolWithNullableBuilder(KotlinTypes.Boolean, "false") + documentation = """ + Flag to toggle whether to use [FIPS](https://aws.amazon.com/compliance/fips/) endpoints when making requests. + ` Disabled by default. + """.trimIndent() + baseClass = AwsRuntimeTypes.Core.Client.AwsSdkClientConfig + useNestedBuilderBaseClass() + } + + val UseDualStackProp: ConfigProperty = ConfigProperty { + name = "useDualStack" + useSymbolWithNullableBuilder(KotlinTypes.Boolean, "false") + documentation = """ + Flag to toggle whether to use dual-stack endpoints when making requests. + See [https://docs.aws.amazon.com/sdkref/latest/guide/feature-endpoints.html] for more information. + ` Disabled by default. + """.trimIndent() + baseClass = AwsRuntimeTypes.Core.Client.AwsSdkClientConfig + useNestedBuilderBaseClass() + } + } + override fun additionalServiceConfigProps(ctx: CodegenContext): List = listOf( + UseFipsProp, + UseDualStackProp, + ) + + override fun customizeEndpointResolution(ctx: ProtocolGenerator.GenerationContext): EndpointCustomization = object : EndpointCustomization { + override fun renderBindEndpointBuiltins( + ctx: ProtocolGenerator.GenerationContext, + rules: EndpointRuleSet, + writer: KotlinWriter, + ) { + val builtins = rules.parameters?.toList()?.filter(Parameter::isBuiltIn) ?: return + writer.write("#T(config, request)", bindAwsBuiltinsSymbol(ctx, builtins)) + } } } @@ -50,9 +84,8 @@ fun renderBindAwsBuiltins(ctx: ProtocolGenerator.GenerationContext, writer: Kotl ) { builtinParams.forEach { when (it.builtIn.get()) { - AwsBuiltins.REGION -> renderBasicConfigBinding(writer, it, AwsServiceConfigIntegration.RegionProp.propertyName) - AwsBuiltins.USE_FIPS -> renderBasicConfigBinding(writer, it, AwsServiceConfigIntegration.UseFipsProp.propertyName) - AwsBuiltins.USE_DUAL_STACK -> renderBasicConfigBinding(writer, it, AwsServiceConfigIntegration.UseDualStackProp.propertyName) + AwsBuiltins.USE_FIPS -> renderBasicConfigBinding(writer, it, BindAwsEndpointBuiltins.UseFipsProp.propertyName) + AwsBuiltins.USE_DUAL_STACK -> renderBasicConfigBinding(writer, it, BindAwsEndpointBuiltins.UseDualStackProp.propertyName) AwsBuiltins.S3_ACCELERATE -> renderBasicConfigBinding(writer, it, S3ClientConfigIntegration.EnableAccelerateProp.propertyName) AwsBuiltins.S3_FORCE_PATH_STYLE -> renderBasicConfigBinding(writer, it, S3ClientConfigIntegration.ForcePathStyleProp.propertyName) @@ -60,9 +93,6 @@ fun renderBindAwsBuiltins(ctx: ProtocolGenerator.GenerationContext, writer: Kotl AwsBuiltins.S3_USE_ARN_REGION -> renderBasicConfigBinding(writer, it, S3ClientConfigIntegration.UseArnRegionProp.propertyName) AwsBuiltins.S3_CONTROL_USE_ARN_REGION -> renderBasicConfigBinding(writer, it, S3ControlClientConfigIntegration.UseArnRegionProp.propertyName) - AwsBuiltins.SDK_ENDPOINT -> - writer.write("#L = config.#L?.toString()", it.defaultName(), AwsServiceConfigIntegration.EndpointUrlProp.propertyName) - // as a newer SDK we do NOT support these values, they are always false AwsBuiltins.S3_USE_GLOBAL_ENDPOINT, AwsBuiltins.STS_USE_GLOBAL_ENDPOINT -> writer.write("#L = false", it.defaultName()) diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/endpoints/PartitionsGenerator.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/PartitionsGenerator.kt similarity index 98% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/endpoints/PartitionsGenerator.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/PartitionsGenerator.kt index 8f6232e8338..b70fe275d72 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/endpoints/PartitionsGenerator.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/endpoints/PartitionsGenerator.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.endpoints +package aws.sdk.kotlin.codegen.endpoints import aws.sdk.kotlin.codegen.AwsRuntimeTypes import software.amazon.smithy.codegen.core.Symbol diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/middleware/AwsSpanInterceptorMiddleware.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/middleware/AwsSpanInterceptorMiddleware.kt similarity index 95% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/middleware/AwsSpanInterceptorMiddleware.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/middleware/AwsSpanInterceptorMiddleware.kt index bb2b7bcabfd..191a983cc7c 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/middleware/AwsSpanInterceptorMiddleware.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/middleware/AwsSpanInterceptorMiddleware.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.middleware +package aws.sdk.kotlin.codegen.middleware import aws.sdk.kotlin.codegen.AwsKotlinDependency import software.amazon.smithy.kotlin.codegen.core.KotlinWriter diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/middleware/RecursionDetectionMiddleware.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/middleware/RecursionDetectionMiddleware.kt similarity index 95% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/middleware/RecursionDetectionMiddleware.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/middleware/RecursionDetectionMiddleware.kt index da203ff67ee..a1a9e369c92 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/middleware/RecursionDetectionMiddleware.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/middleware/RecursionDetectionMiddleware.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.middleware +package aws.sdk.kotlin.codegen.middleware import aws.sdk.kotlin.codegen.AwsKotlinDependency import software.amazon.smithy.kotlin.codegen.core.KotlinWriter diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/middleware/UserAgentMiddleware.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/middleware/UserAgentMiddleware.kt similarity index 97% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/middleware/UserAgentMiddleware.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/middleware/UserAgentMiddleware.kt index 0cd1a9fd03a..472c268c388 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/middleware/UserAgentMiddleware.kt +++ b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/middleware/UserAgentMiddleware.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.middleware +package aws.sdk.kotlin.codegen.middleware import aws.sdk.kotlin.codegen.AwsKotlinDependency import software.amazon.smithy.kotlin.codegen.core.KotlinWriter diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/Presignable.kt b/codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/Presignable.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/Presignable.kt rename to codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/model/traits/Presignable.kt diff --git a/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration b/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration new file mode 100644 index 00000000000..9c1bcbd6748 --- /dev/null +++ b/codegen/aws-sdk-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration @@ -0,0 +1,38 @@ +aws.sdk.kotlin.codegen.AddUserAgentMetadataIntegration +aws.sdk.kotlin.codegen.AwsServiceConfigIntegration +aws.sdk.kotlin.codegen.GradleGenerator +aws.sdk.kotlin.codegen.AwsRetryHeaderIntegration +aws.sdk.kotlin.codegen.customization.ReplaceServiceExceptionBase +aws.sdk.kotlin.codegen.customization.DefaultMiddleware +aws.sdk.kotlin.codegen.customization.AccountIdEndpointBuiltinCustomization +aws.sdk.kotlin.codegen.customization.PresignableModelIntegration +aws.sdk.kotlin.codegen.customization.BackfillOptionalAuth +aws.sdk.kotlin.codegen.endpoints.BindAwsEndpointBuiltins +aws.sdk.kotlin.codegen.endpoints.AddAwsEndpointFunctions +aws.sdk.kotlin.codegen.PresignerGenerator +aws.sdk.kotlin.codegen.customization.flexiblechecksums.FlexibleChecksumsRequest +aws.sdk.kotlin.codegen.customization.flexiblechecksums.FlexibleChecksumsResponse +aws.sdk.kotlin.codegen.customization.AddAwsSpanAttributes +aws.sdk.kotlin.codegen.customization.s3.S3OperationErrorHandler +aws.sdk.kotlin.codegen.customization.s3.S3SigningConfig +aws.sdk.kotlin.codegen.customization.s3.S3ErrorMetadataIntegration +aws.sdk.kotlin.codegen.customization.s3.ClientConfigIntegration +aws.sdk.kotlin.codegen.customization.s3.ContinueIntegration +aws.sdk.kotlin.codegen.customization.s3.GetObjectResponseLengthValidationIntegration +aws.sdk.kotlin.codegen.customization.s3.HttpPathFilter +aws.sdk.kotlin.codegen.customization.s3.TruncatablePaginationIntegration +aws.sdk.kotlin.codegen.customization.s3.HostPrefixRequestRouteFilter +aws.sdk.kotlin.codegen.customization.s3.UnwrappedXmlOutputIntegration +aws.sdk.kotlin.codegen.customization.s3control.HostPrefixFilter +aws.sdk.kotlin.codegen.customization.s3control.ClientConfigIntegration +aws.sdk.kotlin.codegen.customization.s3.S3ErrorWith200StatusIntegration +aws.sdk.kotlin.codegen.customization.apigateway.ApiGatewayAddAcceptHeader +aws.sdk.kotlin.codegen.customization.glacier.GlacierAddVersionHeader +aws.sdk.kotlin.codegen.customization.glacier.GlacierAccountIdDefault +aws.sdk.kotlin.codegen.customization.glacier.GlacierBodyChecksum +aws.sdk.kotlin.codegen.customization.polly.PollyPresigner +aws.sdk.kotlin.codegen.customization.machinelearning.MachineLearningEndpointCustomization +aws.sdk.kotlin.codegen.customization.route53.TrimResourcePrefix +aws.sdk.kotlin.codegen.customization.route53.ChangeResourceRecordSetsUnmarshallingIntegration +aws.sdk.kotlin.codegen.customization.ec2.EC2MakePrimitivesOptional +aws.sdk.kotlin.codegen.customization.RemoveDefaults diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/resources/aws/sdk/kotlin/codegen/endpoints.json b/codegen/aws-sdk-codegen/src/main/resources/aws/sdk/kotlin/codegen/endpoints.json similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/resources/aws/sdk/kotlin/codegen/endpoints.json rename to codegen/aws-sdk-codegen/src/main/resources/aws/sdk/kotlin/codegen/endpoints.json diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/resources/aws/sdk/kotlin/codegen/partitions.json b/codegen/aws-sdk-codegen/src/main/resources/aws/sdk/kotlin/codegen/partitions.json similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/resources/aws/sdk/kotlin/codegen/partitions.json rename to codegen/aws-sdk-codegen/src/main/resources/aws/sdk/kotlin/codegen/partitions.json diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/resources/aws/sdk/kotlin/codegen/sdk-default-configuration.json b/codegen/aws-sdk-codegen/src/main/resources/aws/sdk/kotlin/codegen/sdk-default-configuration.json similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/main/resources/aws/sdk/kotlin/codegen/sdk-default-configuration.json rename to codegen/aws-sdk-codegen/src/main/resources/aws/sdk/kotlin/codegen/sdk-default-configuration.json diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AddUserAgentMetadataIntegrationTest.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AddUserAgentMetadataIntegrationTest.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AddUserAgentMetadataIntegrationTest.kt rename to codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AddUserAgentMetadataIntegrationTest.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegrationTest.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegrationTest.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegrationTest.kt rename to codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/AwsServiceConfigIntegrationTest.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/EndpointUrlConfigNamesTest.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/EndpointUrlConfigNamesTest.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/EndpointUrlConfigNamesTest.kt rename to codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/EndpointUrlConfigNamesTest.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/PresignerGeneratorTest.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/PresignerGeneratorTest.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/PresignerGeneratorTest.kt rename to codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/PresignerGeneratorTest.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriterTest.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriterTest.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriterTest.kt rename to codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriterTest.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/PresignableModelIntegrationTest.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/PresignableModelIntegrationTest.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/PresignableModelIntegrationTest.kt rename to codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/PresignableModelIntegrationTest.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/RemoveDefaultsTest.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/RemoveDefaultsTest.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/RemoveDefaultsTest.kt rename to codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/RemoveDefaultsTest.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/ec2/EC2MakePrimitivesOptionalTest.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/ec2/EC2MakePrimitivesOptionalTest.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/ec2/EC2MakePrimitivesOptionalTest.kt rename to codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/ec2/EC2MakePrimitivesOptionalTest.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegrationTest.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegrationTest.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegrationTest.kt rename to codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegrationTest.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/s3/ContinueIntegrationTest.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/s3/ContinueIntegrationTest.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/s3/ContinueIntegrationTest.kt rename to codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/s3/ContinueIntegrationTest.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/s3/GetObjectResponseLengthValidationIntegrationTest.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/s3/GetObjectResponseLengthValidationIntegrationTest.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/s3/GetObjectResponseLengthValidationIntegrationTest.kt rename to codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/s3/GetObjectResponseLengthValidationIntegrationTest.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnwrappedXmlOutputIntegrationTest.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnwrappedXmlOutputIntegrationTest.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnwrappedXmlOutputIntegrationTest.kt rename to codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/customization/s3/UnwrappedXmlOutputIntegrationTest.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/testutil/ModelUtil.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/testutil/ModelUtil.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/testutil/ModelUtil.kt rename to codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/testutil/ModelUtil.kt diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/testutil/StringExt.kt b/codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/testutil/StringExt.kt similarity index 100% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/testutil/StringExt.kt rename to codegen/aws-sdk-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/testutil/StringExt.kt diff --git a/codegen/sdk/build.gradle.kts b/codegen/sdk/build.gradle.kts index e508a9e7a0c..cde8eb1d452 100644 --- a/codegen/sdk/build.gradle.kts +++ b/codegen/sdk/build.gradle.kts @@ -172,7 +172,7 @@ fun transformsForService(service: AwsService): List? { fun removeDeprecatedShapesTransform(removeDeprecatedShapesUntil: String): String = """ { - "name": "AwsSdkKotlinRemoveDeprecatedShapes", + "name": "awsSmithyKotlinRemoveDeprecatedShapes", "args": { "until": "$removeDeprecatedShapesUntil" } diff --git a/codegen/smithy-aws-kotlin-codegen/build.gradle.kts b/codegen/smithy-aws-kotlin-codegen/build.gradle.kts index 72d61caa8c6..a4b32102efa 100644 --- a/codegen/smithy-aws-kotlin-codegen/build.gradle.kts +++ b/codegen/smithy-aws-kotlin-codegen/build.gradle.kts @@ -2,11 +2,9 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -import aws.sdk.kotlin.gradle.dsl.configurePublishing plugins { kotlin("jvm") jacoco - `maven-publish` } val sdkVersion: String by project @@ -36,25 +34,10 @@ dependencies { testImplementation(libs.kotlinx.serialization.json) } -val generateSdkRuntimeVersion by tasks.registering { - // generate the version of the runtime to use as a resource. - // this keeps us from having to manually change version numbers in multiple places - val resourcesDir = "$buildDir/resources/main/aws/sdk/kotlin/codegen" - val versionFile = file("$resourcesDir/sdk-version.txt") - val gradlePropertiesFile = rootProject.file("gradle.properties") - inputs.file(gradlePropertiesFile) - outputs.file(versionFile) - sourceSets.main.get().output.dir(resourcesDir) - doLast { - versionFile.writeText("$version") - } -} - val jvmTargetVersion = JavaVersion.VERSION_17.toString() tasks.compileKotlin { kotlinOptions.jvmTarget = jvmTargetVersion - dependsOn(generateSdkRuntimeVersion) } tasks.compileTestKotlin { @@ -110,14 +93,3 @@ val sourcesJar by tasks.creating(Jar::class) { archiveClassifier.set("sources") from(sourceSets.getByName("main").allSource) } - -publishing { - publications { - create("codegen") { - from(components["java"]) - artifact(sourcesJar) - } - } -} - -configurePublishing("aws-sdk-kotlin") diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsEndpointDelegator.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsEndpointDelegator.kt deleted file mode 100644 index 367e8cde5f1..00000000000 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/AwsEndpointDelegator.kt +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package aws.sdk.kotlin.codegen - -import aws.sdk.kotlin.codegen.protocols.endpoints.* -import software.amazon.smithy.codegen.core.CodegenException -import software.amazon.smithy.kotlin.codegen.core.useFileWriter -import software.amazon.smithy.kotlin.codegen.model.buildSymbol -import software.amazon.smithy.kotlin.codegen.rendering.endpoints.* -import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator -import software.amazon.smithy.model.node.Node -import software.amazon.smithy.rulesengine.language.EndpointRuleSet -import software.amazon.smithy.rulesengine.traits.EndpointTestCase -import java.io.File - -internal const val PARTITIONS_JSON_ENV_VAR = "PARTITIONS_FILE" -internal const val PARTITIONS_JSON_SYS_PROP = "aws.partitions_file" -private const val PARTITIONS_RESOURCE = "aws/sdk/kotlin/codegen/partitions.json" - -class AwsEndpointDelegator : EndpointDelegator { - - private fun getPartitionsJson(): String = - System.getProperty(PARTITIONS_JSON_SYS_PROP)?.let { File(it).readText() } - ?: System.getenv(PARTITIONS_JSON_ENV_VAR)?.let { File(it).readText() } - ?: javaClass.classLoader.getResource(PARTITIONS_RESOURCE)?.readText() - ?: throw CodegenException("could not load partitions.json resource") - - override fun generateEndpointProvider(ctx: ProtocolGenerator.GenerationContext, rules: EndpointRuleSet?) { - val partitionsData = getPartitionsJson() - val partitions = Node.parse(partitionsData).expectObjectNode() - val partitionsSymbol = PartitionsGenerator.getSymbol(ctx.settings) - - ctx.delegator.useFileWriter(partitionsSymbol) { - PartitionsGenerator(it, partitions).render() - } - - val paramsSymbol = EndpointParametersGenerator.getSymbol(ctx.settings) - val providerSymbol = EndpointProviderGenerator.getSymbol(ctx.settings) - val defaultProviderSymbol = DefaultEndpointProviderGenerator.getSymbol(ctx.settings) - - ctx.delegator.useFileWriter(providerSymbol) { - EndpointProviderGenerator(it, ctx.settings, providerSymbol, paramsSymbol).render() - } - - val endpointFunctions = buildMap { - putAll(awsEndpointFunctions) - put( - "aws.partition", - buildSymbol { - name = "partition" - namespace = PartitionsGenerator.getSymbol(ctx.settings).namespace - }, - ) - } - - if (rules != null) { - ctx.delegator.useFileWriter(defaultProviderSymbol) { - DefaultEndpointProviderGenerator(it, rules, defaultProviderSymbol, providerSymbol, paramsSymbol, ctx.settings, endpointFunctions, awsEndpointPropertyRenderers).render() - } - } - } - - override fun generateEndpointResolverAdapter(ctx: ProtocolGenerator.GenerationContext) { - ctx.delegator.useFileWriter(EndpointResolverAdapterGenerator.getSymbol(ctx.settings)) { - EndpointResolverAdapterGenerator(ctx, it).render() - } - } - - override fun generateEndpointProviderTests( - ctx: ProtocolGenerator.GenerationContext, - tests: List, - rules: EndpointRuleSet, - ) { - val paramsSymbol = EndpointParametersGenerator.getSymbol(ctx.settings) - val defaultProviderSymbol = DefaultEndpointProviderGenerator.getSymbol(ctx.settings) - val testSymbol = DefaultEndpointProviderTestGenerator.getSymbol(ctx.settings) - - ctx.delegator.useTestFileWriter("${testSymbol.name}.kt", testSymbol.namespace) { - DefaultEndpointProviderTestGenerator( - it, - rules, - tests, - defaultProviderSymbol, - paramsSymbol, - awsEndpointPropertyRenderers, - ).render() - } - } -} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegration.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegration.kt deleted file mode 100644 index 37e96b93943..00000000000 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/route53/ChangeResourceRecordSetsUnmarshallingIntegration.kt +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.codegen.customization.route53 - -import aws.sdk.kotlin.codegen.protocols.core.AwsHttpBindingProtocolGenerator -import aws.sdk.kotlin.codegen.sdkId -import software.amazon.smithy.kotlin.codegen.KotlinSettings -import software.amazon.smithy.kotlin.codegen.core.withBlock -import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration -import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding -import software.amazon.smithy.kotlin.codegen.model.expectShape -import software.amazon.smithy.model.Model -import software.amazon.smithy.model.shapes.ServiceShape - -class ChangeResourceRecordSetsUnmarshallingIntegration : KotlinIntegration { - override val sectionWriters: List = listOf( - SectionWriterBinding(AwsHttpBindingProtocolGenerator.ProtocolErrorDeserialization) { writer, _ -> - writer.withBlock("payload?.let {", "}\n") { - withBlock("aws.sdk.kotlin.services.route53.internal.parseRestXmlInvalidChangeBatchResponse(payload)?.let {", "}") { - write("setAseErrorMetadata(it.exception, wrappedResponse, it.errorDetails)") - write("throw it.exception") - } - } - }, - ) - - override fun enabledForService(model: Model, settings: KotlinSettings) = - model.expectShape(settings.service).sdkId.equals("route 53", ignoreCase = true) -} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpBindingProtocolGenerator.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpBindingProtocolGenerator.kt deleted file mode 100644 index 7f6c1a7f753..00000000000 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpBindingProtocolGenerator.kt +++ /dev/null @@ -1,186 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.codegen.protocols.core - -import aws.sdk.kotlin.codegen.AwsEndpointDelegator -import aws.sdk.kotlin.codegen.AwsKotlinDependency -import aws.sdk.kotlin.codegen.protocols.eventstream.EventStreamParserGenerator -import aws.sdk.kotlin.codegen.protocols.eventstream.EventStreamSerializerGenerator -import aws.sdk.kotlin.codegen.protocols.middleware.AwsSpanInterceptorMiddleware -import aws.sdk.kotlin.codegen.protocols.middleware.RecursionDetectionMiddleware -import aws.sdk.kotlin.codegen.protocols.middleware.UserAgentMiddleware -import aws.sdk.kotlin.codegen.protocols.protocoltest.AwsHttpProtocolUnitTestErrorGenerator -import aws.sdk.kotlin.codegen.protocols.protocoltest.AwsHttpProtocolUnitTestRequestGenerator -import aws.sdk.kotlin.codegen.protocols.protocoltest.AwsHttpProtocolUnitTestResponseGenerator -import software.amazon.smithy.aws.traits.protocols.AwsQueryCompatibleTrait -import software.amazon.smithy.codegen.core.Symbol -import software.amazon.smithy.kotlin.codegen.core.* -import software.amazon.smithy.kotlin.codegen.integration.SectionId -import software.amazon.smithy.kotlin.codegen.lang.KotlinTypes -import software.amazon.smithy.kotlin.codegen.model.buildSymbol -import software.amazon.smithy.kotlin.codegen.model.hasTrait -import software.amazon.smithy.kotlin.codegen.model.namespace -import software.amazon.smithy.kotlin.codegen.rendering.ExceptionBaseClassGenerator -import software.amazon.smithy.kotlin.codegen.rendering.endpoints.EndpointDelegator -import software.amazon.smithy.kotlin.codegen.rendering.protocol.* -import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.model.shapes.ShapeId - -/** - * Base class for all AWS HTTP protocol generators - */ -abstract class AwsHttpBindingProtocolGenerator : HttpBindingProtocolGenerator() { - - override val exceptionBaseClassSymbol: Symbol = buildSymbol { - name = "AwsServiceException" - namespace(AwsKotlinDependency.AWS_CORE) - } - - override fun getHttpProtocolClientGenerator(ctx: ProtocolGenerator.GenerationContext): HttpProtocolClientGenerator { - val middleware = getHttpMiddleware(ctx) - return AwsHttpProtocolClientGenerator(ctx, middleware, getProtocolHttpBindingResolver(ctx.model, ctx.service)) - } - - override fun getDefaultHttpMiddleware(ctx: ProtocolGenerator.GenerationContext): List { - val middleware = super.getDefaultHttpMiddleware(ctx).toMutableList() - middleware.add(UserAgentMiddleware()) - middleware.add(RecursionDetectionMiddleware()) - middleware.add(AwsSpanInterceptorMiddleware()) - return middleware - } - - override fun generateProtocolUnitTests(ctx: ProtocolGenerator.GenerationContext) { - val ignoredTests = TestMemberDelta( - setOf( - // FIXME - compression not yet supported, see https://github.com/awslabs/smithy-kotlin/issues/955 - "SDKAppliedContentEncoding_awsJson1_0", - "SDKAppliedContentEncoding_awsJson1_1", - "SDKAppliedContentEncoding_awsQuery", - "SDKAppliedContentEncoding_ec2Query", - "SDKAppliedContentEncoding_restJson1", - "SDKAppliedContentEncoding_restXml", - "SDKAppendedGzipAfterProvidedEncoding_restJson1", - "SDKAppendedGzipAfterProvidedEncoding_restXml", - "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsJson1_0", - "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsJson1_1", - "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsQuery", - "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_ec2Query", - ), - ) - - // The following can be used to generate only a specific test by name. - // val targetedTest = TestMemberDelta(setOf("RestJsonComplexErrorWithNoMessage"), TestContainmentMode.RUN_TESTS) - - val requestTestBuilder = AwsHttpProtocolUnitTestRequestGenerator.Builder() - val responseTestBuilder = AwsHttpProtocolUnitTestResponseGenerator.Builder() - val errorTestBuilder = AwsHttpProtocolUnitTestErrorGenerator.Builder() - - HttpProtocolTestGenerator( - ctx, - requestTestBuilder, - responseTestBuilder, - errorTestBuilder, - ignoredTests, - ).generateProtocolTests() - } - - /** - * Get the error "code" that uniquely identifies the AWS error. - */ - protected open fun getErrorCode(ctx: ProtocolGenerator.GenerationContext, errShapeId: ShapeId): String = errShapeId.name - - /** - * Render the code to parse the `ErrorDetails` from the HTTP response. - */ - abstract fun renderDeserializeErrorDetails(ctx: ProtocolGenerator.GenerationContext, op: OperationShape, writer: KotlinWriter) - - override fun eventStreamRequestHandler(ctx: ProtocolGenerator.GenerationContext, op: OperationShape): Symbol { - val resolver = getProtocolHttpBindingResolver(ctx.model, ctx.service) - val contentType = resolver.determineRequestContentType(op) ?: error("event streams must set a content-type") - val eventStreamSerializerGenerator = EventStreamSerializerGenerator(structuredDataSerializer(ctx), contentType) - return eventStreamSerializerGenerator.requestHandler(ctx, op) - } - - override fun eventStreamResponseHandler(ctx: ProtocolGenerator.GenerationContext, op: OperationShape): Symbol { - val eventStreamParserGenerator = EventStreamParserGenerator(ctx, structuredDataParser(ctx)) - return eventStreamParserGenerator.responseHandler(ctx, op) - } - - override fun operationErrorHandler(ctx: ProtocolGenerator.GenerationContext, op: OperationShape): Symbol = - op.errorHandler(ctx.settings) { writer -> - writer.withBlock( - "private suspend fun ${op.errorHandlerName()}(context: #T, call: #T): #Q {", - "}", - RuntimeTypes.Core.ExecutionContext, - RuntimeTypes.Http.HttpCall, - KotlinTypes.Nothing, - ) { - renderThrowOperationError(ctx, op, writer) - } - } - - object ProtocolErrorDeserialization : SectionId - - protected open fun renderThrowOperationError( - ctx: ProtocolGenerator.GenerationContext, - op: OperationShape, - writer: KotlinWriter, - ) { - val exceptionBaseSymbol = ExceptionBaseClassGenerator.baseExceptionSymbol(ctx.settings) - writer.write("val payload = call.response.body.#T()", RuntimeTypes.Http.readAll) - .write("val wrappedResponse = call.response.#T(payload)", RuntimeTypes.AwsProtocolCore.withPayload) - .write("val wrappedCall = call.copy(response = wrappedResponse)") - .write("") - .declareSection(ProtocolErrorDeserialization) - .write("val errorDetails = try {") - .indent() - .call { - renderDeserializeErrorDetails(ctx, op, writer) - } - .dedent() - .withBlock("} catch (ex: Exception) {", "}") { - withBlock("""throw #T("Failed to parse response as '${ctx.protocol.name}' error", ex).also {""", "}", exceptionBaseSymbol) { - write("#T(it, wrappedCall.response, null)", RuntimeTypes.AwsProtocolCore.setAseErrorMetadata) - } - } - .write("") - - if (ctx.service.hasTrait()) { - writer.write("var queryErrorDetails: #T? = null", RuntimeTypes.AwsProtocolCore.AwsQueryCompatibleErrorDetails) - writer.withBlock("call.response.headers[#T]?.let {", "}", RuntimeTypes.AwsProtocolCore.XAmznQueryErrorHeader) { - openBlock("queryErrorDetails = try {") - write("#T.parse(it)", RuntimeTypes.AwsProtocolCore.AwsQueryCompatibleErrorDetails) - closeAndOpenBlock("} catch (ex: Exception) {") - withBlock("""throw #T("Failed to parse awsQuery-compatible error", ex).also {""", "}", exceptionBaseSymbol) { - write("#T(it, wrappedResponse, errorDetails)", RuntimeTypes.AwsProtocolCore.setAseErrorMetadata) - } - closeBlock("}") - } - writer.write("") - } - - writer.withBlock("val ex = when(errorDetails.code) {", "}") { - op.errors.forEach { err -> - val errSymbol = ctx.symbolProvider.toSymbol(ctx.model.expectShape(err)) - val errDeserializerSymbol = buildSymbol { - name = "${errSymbol.name}Deserializer" - namespace = ctx.settings.pkg.serde - } - writer.write("#S -> #T().deserialize(context, wrappedCall)", getErrorCode(ctx, err), errDeserializerSymbol) - } - write("else -> #T(errorDetails.message)", exceptionBaseSymbol) - } - - writer.write("") - writer.write("#T(ex, wrappedResponse, errorDetails)", RuntimeTypes.AwsProtocolCore.setAseErrorMetadata) - if (ctx.service.hasTrait()) { - writer.write("queryErrorDetails?.let { #T(ex, it) }", RuntimeTypes.AwsProtocolCore.setAwsQueryCompatibleErrorMetadata) - } - - writer.write("throw ex") - } - - override fun endpointDelegator(ctx: ProtocolGenerator.GenerationContext): EndpointDelegator = AwsEndpointDelegator() -} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpProtocolClientGenerator.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpProtocolClientGenerator.kt deleted file mode 100644 index dcc45d7f0b0..00000000000 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpProtocolClientGenerator.kt +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package aws.sdk.kotlin.codegen.protocols.core - -import aws.sdk.kotlin.codegen.AwsRuntimeTypes.Core.Client.AwsClientOption -import software.amazon.smithy.codegen.core.Symbol -import software.amazon.smithy.kotlin.codegen.core.* -import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes.Auth.Signing.AwsSigningCommon.AwsSigningAttributes -import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes.SmithyClient.SdkClientOption -import software.amazon.smithy.kotlin.codegen.integration.SectionId -import software.amazon.smithy.kotlin.codegen.integration.SectionKey -import software.amazon.smithy.kotlin.codegen.integration.SectionWriter -import software.amazon.smithy.kotlin.codegen.model.hasIdempotentTokenMember -import software.amazon.smithy.kotlin.codegen.model.knowledge.AwsSignatureVersion4 -import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpBindingResolver -import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpProtocolClientGenerator -import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator -import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolMiddleware -import software.amazon.smithy.kotlin.codegen.utils.dq -import software.amazon.smithy.model.knowledge.OperationIndex -import software.amazon.smithy.model.knowledge.ServiceIndex -import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.model.traits.HttpBearerAuthTrait - -/** - * Override for generating concrete (AWS) HTTP service clients - */ -open class AwsHttpProtocolClientGenerator( - ctx: ProtocolGenerator.GenerationContext, - middlewares: List, - httpBindingResolver: HttpBindingResolver, -) : HttpProtocolClientGenerator(ctx, middlewares, httpBindingResolver) { - object MergeServiceDefaults : SectionId { - val GenerationContext: SectionKey = SectionKey("GenerationContext") - } - - override fun render(writer: KotlinWriter) { - writer.write("\n\n") - writer.write( - "#L const val ServiceApiVersion: String = #S", - ctx.settings.api.visibility, - ctx.service.version, - ) - writer.write("\n\n") - // set AWS specific span attributes for an operation - // https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/instrumentation/aws-sdk/ - val addAwsSpanAttrWriter = SectionWriter { w, _ -> - w.withBlock("attributes = #T {", "}", RuntimeTypes.Core.Collections.attributesOf) { - write("#S to #S", "rpc.system", "aws-api") - } - } - writer.registerSectionWriter(OperationTelemetryBuilder, addAwsSpanAttrWriter) - super.render(writer) - } - - override fun renderInit(writer: KotlinWriter) { - writer.withBlock("init {", "}") { - write("managedResources.#T(config.httpClient)", RuntimeTypes.Core.IO.addIfManaged) - - if (AwsSignatureVersion4.isSupportedAuthentication(ctx.model, ctx.settings.getService(ctx.model))) { - write("managedResources.#T(config.credentialsProvider)", RuntimeTypes.Core.IO.addIfManaged) - } - - val serviceIndex = ServiceIndex.of(ctx.model) - val hasBearerTokenAuth = serviceIndex - .getAuthSchemes(ctx.settings.service) - .containsKey(HttpBearerAuthTrait.ID) - if (hasBearerTokenAuth) { - write("managedResources.#T(config.bearerTokenProvider)", RuntimeTypes.Core.IO.addIfManaged) - } - } - } - - override fun renderOperationSetup(writer: KotlinWriter, opIndex: OperationIndex, op: OperationShape) { - super.renderOperationSetup(writer, opIndex, op) - - // override the default retry policy - writer.write("op.execution.retryPolicy = config.retryPolicy") - - writer.write("mergeServiceDefaults(op.context)") - } - - override fun renderAdditionalMethods(writer: KotlinWriter) { - renderMergeServiceDefaults(writer) - } - - /** - * render a utility function to populate an operation's ExecutionContext with defaults from service config, environment, etc - */ - private fun renderMergeServiceDefaults(writer: KotlinWriter) { - // FIXME - we likely need a way to let customizations modify/override this - // FIXME - we also need a way to tie in config properties added via integrations that need to influence the context - writer.dokka("merge the defaults configured for the service into the execution context before firing off a request") - writer.withBlock( - "private fun mergeServiceDefaults(ctx: #T) {", - "}", - RuntimeTypes.Core.ExecutionContext, - ) { - putIfAbsent(AwsClientOption, "Region", nullable = true) - putIfAbsent(SdkClientOption, "ClientName") - putIfAbsent(SdkClientOption, "LogMode") - // fill in auth/signing attributes - if (AwsSignatureVersion4.isSupportedAuthentication(ctx.model, ctx.service)) { - // default signing context (most of this has been moved to auth schemes but some things like event streams still depend on this) - val signingServiceName = AwsSignatureVersion4.signingServiceName(ctx.service) - putIfAbsent(AwsSigningAttributes, "SigningService", signingServiceName.dq()) - putIfAbsent(AwsSigningAttributes, "SigningRegion", "config.region", nullable = true) - putIfAbsent(AwsSigningAttributes, "CredentialsProvider") - } - - if (ctx.service.hasIdempotentTokenMember(ctx.model)) { - putIfAbsent(SdkClientOption, "IdempotencyTokenProvider", nullable = true) - } - - writer.declareSection(MergeServiceDefaults) - } - } -} - -internal fun KotlinWriter.putIfAbsent( - attributesSymbol: Symbol, - name: String, - literalValue: String? = null, - nullable: Boolean = false, -) { - val putSymbol = if (nullable) RuntimeTypes.Core.Collections.putIfAbsentNotNull else RuntimeTypes.Core.Collections.putIfAbsent - val actualValue = literalValue ?: "config.${name.replaceFirstChar(Char::lowercaseChar)}" - write("ctx.#T(#T.#L, #L)", putSymbol, attributesSymbol, name, actualValue) -} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/endpoints/DefaultEndpointProviderExt.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/endpoints/DefaultEndpointProviderExt.kt deleted file mode 100644 index 17352b1bd15..00000000000 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/endpoints/DefaultEndpointProviderExt.kt +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.codegen.protocols.endpoints - -import aws.sdk.kotlin.codegen.AwsRuntimeTypes -import software.amazon.smithy.codegen.core.Symbol -import software.amazon.smithy.kotlin.codegen.core.KotlinWriter -import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes -import software.amazon.smithy.kotlin.codegen.core.withBlock -import software.amazon.smithy.kotlin.codegen.rendering.endpoints.ExpressionRenderer -import software.amazon.smithy.kotlin.codegen.utils.getOrNull -import software.amazon.smithy.model.node.Node -import software.amazon.smithy.model.node.ObjectNode -import software.amazon.smithy.rulesengine.language.syntax.expressions.Expression -import java.util.* - -val awsEndpointFunctions = mapOf( - "aws.parseArn" to AwsRuntimeTypes.Endpoint.Functions.parseArn, - "aws.isVirtualHostableS3Bucket" to AwsRuntimeTypes.Endpoint.Functions.isVirtualHostableS3Bucket, -) - -val awsEndpointPropertyRenderers = mapOf( - "authSchemes" to ::renderAuthSchemes, -) - -private fun String.toAuthOptionFactoryFn(): Symbol? = - when (this) { - "sigv4" -> RuntimeTypes.Auth.HttpAuthAws.sigV4 - "sigv4a" -> RuntimeTypes.Auth.HttpAuthAws.sigV4A - else -> null - } - -private fun renderAuthSchemes(writer: KotlinWriter, authSchemes: Expression, expressionRenderer: ExpressionRenderer) { - writer.writeInline("#T to ", RuntimeTypes.SmithyClient.Endpoints.SigningContextAttributeKey) - writer.withBlock("listOf(", ")") { - authSchemes.toNode().expectArrayNode().forEach { - val scheme = it.expectObjectNode() - val schemeName = scheme.expectStringMember("name").value - val authFactoryFn = schemeName.toAuthOptionFactoryFn() ?: return@forEach - - withBlock("#T(", "),", authFactoryFn) { - // we delegate back to the expression visitor for each of these fields because it's possible to - // encounter template strings throughout - - writeInline("serviceName = ") - renderOrElse(expressionRenderer, scheme.getStringMember("signingName"), "null") - - writeInline("disableDoubleUriEncode = ") - renderOrElse(expressionRenderer, scheme.getBooleanMember("disableDoubleEncoding"), "false") - - when (schemeName) { - "sigv4" -> renderSigV4Fields(writer, scheme, expressionRenderer) - "sigv4a" -> renderSigV4AFields(writer, scheme, expressionRenderer) - } - } - } - } -} - -private fun KotlinWriter.renderOrElse( - expressionRenderer: ExpressionRenderer, - optionalNode: Optional, - whenNullValue: String, -) { - val nullableNode = optionalNode.getOrNull() - when (nullableNode) { - null -> writeInline(whenNullValue) - else -> expressionRenderer.renderExpression(Expression.fromNode(nullableNode)) - } - write(",") -} - -private fun renderSigV4Fields(writer: KotlinWriter, scheme: ObjectNode, expressionRenderer: ExpressionRenderer) { - writer.writeInline("signingRegion = ") - writer.renderOrElse(expressionRenderer, scheme.getStringMember("signingRegion"), "null") -} - -private fun renderSigV4AFields(writer: KotlinWriter, scheme: ObjectNode, expressionRenderer: ExpressionRenderer) { - writer.writeInline("signingRegionSet = ") - expressionRenderer.renderExpression(Expression.fromNode(scheme.expectArrayMember("signingRegionSet"))) - writer.write(",") -} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/middleware/MutateHeadersMiddleware.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/middleware/MutateHeadersMiddleware.kt deleted file mode 100644 index 7217e069b88..00000000000 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/middleware/MutateHeadersMiddleware.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package aws.sdk.kotlin.codegen.protocols.middleware - -import software.amazon.smithy.kotlin.codegen.core.KotlinWriter -import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes -import software.amazon.smithy.kotlin.codegen.core.withBlock -import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator -import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolMiddleware -import software.amazon.smithy.model.shapes.OperationShape - -/** - * General purpose middleware that allows mutation of headers - */ -class MutateHeadersMiddleware( - val extraHeaders: Map = emptyMap(), - val overrideHeaders: Map = emptyMap(), - val addMissingHeaders: Map = emptyMap(), -) : ProtocolMiddleware { - override val name: String = "MutateHeaders" - override val order: Byte = 10 - override fun render(ctx: ProtocolGenerator.GenerationContext, op: OperationShape, writer: KotlinWriter) { - writer.addImport(RuntimeTypes.HttpClient.Middleware.MutateHeadersMiddleware) - .withBlock("op.install(", ")") { - withBlock("#T().apply {", "}", RuntimeTypes.HttpClient.Middleware.MutateHeadersMiddleware) { - overrideHeaders.forEach { - writer.write("set(#S, #S)", it.key, it.value) - } - extraHeaders.forEach { - writer.write("append(#S, #S)", it.key, it.value) - } - addMissingHeaders.forEach { - writer.write("setIfMissing(#S, #S)", it.key, it.value) - } - } - } - } -} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/protocoltest/AwsHttpProtocolUnitTestRequestGenerator.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/protocoltest/AwsHttpProtocolUnitTestRequestGenerator.kt deleted file mode 100644 index b14251a8e23..00000000000 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/protocoltest/AwsHttpProtocolUnitTestRequestGenerator.kt +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package aws.sdk.kotlin.codegen.protocols.protocoltest - -import aws.sdk.kotlin.codegen.AwsRuntimeTypes -import software.amazon.smithy.kotlin.codegen.core.KotlinWriter -import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes -import software.amazon.smithy.kotlin.codegen.model.hasTrait -import software.amazon.smithy.kotlin.codegen.model.knowledge.AwsSignatureVersion4 -import software.amazon.smithy.kotlin.codegen.rendering.endpoints.EndpointProviderGenerator -import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpProtocolUnitTestGenerator -import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpProtocolUnitTestRequestGenerator -import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator -import software.amazon.smithy.kotlin.codegen.utils.getOrNull -import software.amazon.smithy.model.Model -import software.amazon.smithy.model.shapes.OperationShape -import software.amazon.smithy.model.shapes.ServiceShape -import software.amazon.smithy.protocoltests.traits.HttpMessageTestCase -import software.amazon.smithy.protocoltests.traits.HttpRequestTestCase -import software.amazon.smithy.rulesengine.traits.EndpointRuleSetTrait - -/** - * Override request unit tests to configure AWS specific behaviors - */ -class AwsHttpProtocolUnitTestRequestGenerator(builder: Builder) : - HttpProtocolUnitTestRequestGenerator(builder) { - override fun renderConfigureServiceClient(test: HttpRequestTestCase) { - super.renderConfigureServiceClient(test) - renderConfigureAwsServiceClient(ctx, writer, model, serviceShape, operation, test.host.getOrNull() ?: "hostname") - } - - open class Builder : HttpProtocolUnitTestRequestGenerator.Builder() { - override fun build(): HttpProtocolUnitTestGenerator = - AwsHttpProtocolUnitTestRequestGenerator(this) - } -} - -internal fun HttpProtocolUnitTestGenerator.renderConfigureAwsServiceClient( - ctx: ProtocolGenerator.GenerationContext, - writer: KotlinWriter, - model: Model, - serviceShape: ServiceShape, - operation: OperationShape, - hostname: String = "hostname", -) { - if (AwsSignatureVersion4.hasSigV4AuthScheme(model, serviceShape, operation)) { - writer.addImport(AwsRuntimeTypes.Config.Credentials.StaticCredentialsProvider) - writer.addImport(RuntimeTypes.Auth.Credentials.AwsCredentials.Credentials) - writer.write("val credentials = Credentials(#S, #S)", "AKID", "SECRET") - writer.write("credentialsProvider = StaticCredentialsProvider(credentials)") - } - - // specify a default region - writer.write("region = \"us-east-1\"") - - // if the model doesn't have endpoint rules we have to fill it in with a default - if (!serviceShape.hasTrait()) { - writer.write( - "endpointProvider = #T { #T(#S) }", - EndpointProviderGenerator.getSymbol(ctx.settings), - RuntimeTypes.SmithyClient.Endpoints.Endpoint, - "https://$hostname", - ) - } -} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/protocoltest/AwsHttpProtocolUnitTestResponseGenerator.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/protocoltest/AwsHttpProtocolUnitTestResponseGenerator.kt deleted file mode 100644 index 2c2a0224e63..00000000000 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/protocoltest/AwsHttpProtocolUnitTestResponseGenerator.kt +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package aws.sdk.kotlin.codegen.protocols.protocoltest - -import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpProtocolUnitTestErrorGenerator -import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpProtocolUnitTestGenerator -import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpProtocolUnitTestResponseGenerator -import software.amazon.smithy.protocoltests.traits.HttpResponseTestCase - -/** - * Override response unit tests to configure AWS specific behaviors - */ -open class AwsHttpProtocolUnitTestResponseGenerator(builder: Builder) : HttpProtocolUnitTestResponseGenerator(builder) { - override fun renderConfigureServiceClient(test: HttpResponseTestCase) { - super.renderConfigureServiceClient(test) - renderConfigureAwsServiceClient(ctx, writer, model, serviceShape, operation) - } - - open class Builder : HttpProtocolUnitTestResponseGenerator.Builder() { - override fun build(): HttpProtocolUnitTestGenerator = - AwsHttpProtocolUnitTestResponseGenerator(this) - } -} - -/** - * Override error unit tests to configure AWS specific behaviors - */ -class AwsHttpProtocolUnitTestErrorGenerator(builder: Builder) : HttpProtocolUnitTestErrorGenerator(builder) { - - override fun renderConfigureServiceClient(test: HttpResponseTestCase) { - super.renderConfigureServiceClient(test) - renderConfigureAwsServiceClient(ctx, writer, model, serviceShape, operation) - } - - class Builder : HttpProtocolUnitTestErrorGenerator.Builder() { - override fun build(): HttpProtocolUnitTestGenerator = - AwsHttpProtocolUnitTestErrorGenerator(this) - } -} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/transforms/IncludeOperations.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/transforms/IncludeOperations.kt deleted file mode 100644 index 6d2b8079ea9..00000000000 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/transforms/IncludeOperations.kt +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package aws.sdk.kotlin.codegen.transforms - -import software.amazon.smithy.build.TransformContext -import software.amazon.smithy.build.transforms.ConfigurableProjectionTransformer -import software.amazon.smithy.model.Model -import software.amazon.smithy.model.shapes.OperationShape - -/** - * A smithy build [transform](https://awslabs.github.io/smithy/1.0/guides/building-models/build-config.html#transforms) - * that filters out operations not included in the `operations` list of shape IDs - */ -class IncludeOperations : ConfigurableProjectionTransformer() { - - class Config { - var operations: Set = emptySet() - } - - override fun getName(): String = "awsSdkKotlinIncludeOperations" - override fun getConfigType(): Class = Config::class.java - - override fun transformWithConfig(context: TransformContext, config: Config): Model { - check(config.operations.isNotEmpty()) { "no operations provided to IncludeOperations transform!" } - return context.transformer.filterShapes(context.model) { shape -> - when (shape) { - is OperationShape -> shape.id.toString() in config.operations - else -> true - } - } - } -} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/transforms/RemoveDeprecatedShapes.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/transforms/RemoveDeprecatedShapes.kt deleted file mode 100644 index 8f92560323c..00000000000 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/transforms/RemoveDeprecatedShapes.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.codegen.transforms - -import software.amazon.smithy.build.TransformContext -import software.amazon.smithy.build.transforms.ConfigurableProjectionTransformer -import software.amazon.smithy.kotlin.codegen.model.getTrait -import software.amazon.smithy.kotlin.codegen.utils.getOrNull -import software.amazon.smithy.model.Model -import software.amazon.smithy.model.shapes.Shape -import software.amazon.smithy.model.traits.DeprecatedTrait -import java.time.DateTimeException -import java.time.LocalDate -import java.time.format.DateTimeFormatter -import java.util.function.Predicate - -// A date formatter used to parse Smithy @deprecated trait's `since` field -private val DEPRECATED_SINCE_DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd") - -class RemoveDeprecatedShapes : ConfigurableProjectionTransformer() { - class Config { - var until: String = "1970-01-01" // yyyy-MM-dd - } - - override fun getName(): String = "AwsSdkKotlinRemoveDeprecatedShapes" - - override fun getConfigType(): Class = Config::class.java - - /** - * Filter out shapes which have a [DeprecatedTrait] with a `since` property _date_ set, up to [Config.until]. - * NOTE: Smithy supports modeling `since` as a version _or_ date, this transformer only considers those modeled as a date. - */ - override fun transformWithConfig(context: TransformContext, config: Config): Model { - val until = requireNotNull(config.until.toLocalDate()) { "Failed to parse configured `until` date ${config.until}" } - println("Removing deprecated shapes using the configured `until` date $until") - - return context.transformer.removeShapesIf(context.model, shouldRemoveDeprecatedShape(until)) - } -} - -internal fun shouldRemoveDeprecatedShape(removeDeprecatedShapesUntil: LocalDate) = Predicate { shape -> - val since = shape.getTrait()?.since?.getOrNull() ?: return@Predicate false - - val deprecatedDate = since.toLocalDate() ?: return@Predicate false.also { - println("Failed to parse `since` field $since as a date, skipping removal of deprecated shape $shape") - } - - deprecatedDate < removeDeprecatedShapesUntil -} - -/** - * Parses a string of yyyy-MM-dd format to [LocalDate], returning `null` if parsing fails. - */ -internal fun String.toLocalDate(): LocalDate? = try { LocalDate.parse(this, DEPRECATED_SINCE_DATE_FORMATTER) } catch (e: DateTimeException) { null } diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SdkProtocolGeneratorSupplier.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/SdkProtocolGeneratorSupplier.kt similarity index 59% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SdkProtocolGeneratorSupplier.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/SdkProtocolGeneratorSupplier.kt index 818a93e0430..69ca17292c6 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/SdkProtocolGeneratorSupplier.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/SdkProtocolGeneratorSupplier.kt @@ -2,16 +2,11 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen +package software.amazon.smithy.kotlin.codegen.aws -import aws.sdk.kotlin.codegen.customization.s3.isS3 -import aws.sdk.kotlin.codegen.protocols.* -import software.amazon.smithy.kotlin.codegen.KotlinSettings +import software.amazon.smithy.kotlin.codegen.aws.protocols.* import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration -import software.amazon.smithy.kotlin.codegen.model.expectShape import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator -import software.amazon.smithy.model.Model -import software.amazon.smithy.model.shapes.ServiceShape /** * Integration that registers protocol generators this package provides @@ -25,12 +20,6 @@ class SdkProtocolGeneratorSupplier : KotlinIntegration { */ override val order: Byte = -10 - override fun enabledForService(model: Model, settings: KotlinSettings): Boolean { - // S3 gets it's own customized protocol generator - val service = model.expectShape(settings.service) - return !service.isS3 - } - override val protocolGenerators: List = listOf( AwsJson1_0(), diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/customization/RegionSupport.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/customization/RegionSupport.kt new file mode 100644 index 00000000000..1aeef428abd --- /dev/null +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/customization/RegionSupport.kt @@ -0,0 +1,109 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package software.amazon.smithy.kotlin.codegen.aws.customization + +import software.amazon.smithy.aws.traits.ServiceTrait +import software.amazon.smithy.kotlin.codegen.KotlinSettings +import software.amazon.smithy.kotlin.codegen.core.CodegenContext +import software.amazon.smithy.kotlin.codegen.core.KotlinWriter +import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes +import software.amazon.smithy.kotlin.codegen.core.getContextValue +import software.amazon.smithy.kotlin.codegen.integration.AppendingSectionWriter +import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding +import software.amazon.smithy.kotlin.codegen.lang.KotlinTypes +import software.amazon.smithy.kotlin.codegen.model.* +import software.amazon.smithy.kotlin.codegen.model.knowledge.AwsSignatureVersion4 +import software.amazon.smithy.kotlin.codegen.rendering.endpoints.EndpointCustomization +import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpProtocolClientGenerator +import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpProtocolUnitTestRequestGenerator +import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator +import software.amazon.smithy.kotlin.codegen.rendering.protocol.putIfAbsent +import software.amazon.smithy.kotlin.codegen.rendering.util.ConfigProperty +import software.amazon.smithy.model.Model +import software.amazon.smithy.model.shapes.ServiceShape +import software.amazon.smithy.rulesengine.language.EndpointRuleSet +import software.amazon.smithy.rulesengine.language.syntax.parameters.Parameter + +/** + * Registers support for the concept of region on the service client config, endpoint builtins, etc. + * + * Region is enabled IFF sigv4(a) is enabled or an AWS SDK service is targeted + */ +class RegionSupport : KotlinIntegration { + companion object { + const val BUILTIN_NAME = "AWS::Region" + + val RegionProp: ConfigProperty = ConfigProperty { + name = "region" + symbol = KotlinTypes.String.toBuilder().nullable().build() + documentation = """ + The region to sign with and make requests to. + """.trimIndent() + } + } + + // Allow other integrations to customize the service config props, later integrations take precedence. + // This is used by AWS SDK codegen to customize the base class and documentation for this property + override val order: Byte = -50 + + override fun enabledForService(model: Model, settings: KotlinSettings): Boolean { + val service = model.expectShape(settings.service) + val supportsSigv4 = AwsSignatureVersion4.isSupportedAuthentication(model, service) + val hasRegionBuiltin = service.getEndpointRules()?.parameters?.find { it.isBuiltIn && it.builtIn.get() == BUILTIN_NAME } != null + val isAwsSdk = service.hasTrait() + return supportsSigv4 || hasRegionBuiltin || isAwsSdk + } + + override fun additionalServiceConfigProps(ctx: CodegenContext): List = listOf(RegionProp) + + override fun customizeEndpointResolution(ctx: ProtocolGenerator.GenerationContext): EndpointCustomization = + object : EndpointCustomization { + override fun renderBindEndpointBuiltins( + ctx: ProtocolGenerator.GenerationContext, + rules: EndpointRuleSet, + writer: KotlinWriter, + ) { + val builtins = rules.parameters?.toList()?.filter(Parameter::isBuiltIn) ?: return + builtins.forEach { + when (it.builtIn.get()) { + BUILTIN_NAME -> writer.write("#L = config.#L", it.defaultName(), RegionProp.propertyName) + } + } + } + } + override val sectionWriters: List + get() = listOf( + SectionWriterBinding(HttpProtocolUnitTestRequestGenerator.ConfigureServiceClient, renderHttpProtocolRequestTestConfigureServiceClient), + SectionWriterBinding(HttpProtocolClientGenerator.MergeServiceDefaults, renderRegionOperationContextDefault), + ) + + // sets a default region for protocol tests + private val renderHttpProtocolRequestTestConfigureServiceClient = AppendingSectionWriter { writer -> + // specify a default region + writer.write("region = #S", "us-east-1") + } + + // sets (initial) region/signing region in the execution context + private val renderRegionOperationContextDefault = AppendingSectionWriter { writer -> + val ctx = writer.getContextValue(HttpProtocolClientGenerator.MergeServiceDefaults.GenerationContext) + val isAwsSdk = ctx.service.hasTrait() + + if (isAwsSdk) { + val awsClientOption = buildSymbol { + name = "AwsClientOption" + namespace = "aws.sdk.kotlin.runtime.client" + } + writer.putIfAbsent(awsClientOption, "Region", nullable = true) + } + + writer.putIfAbsent( + RuntimeTypes.Auth.Signing.AwsSigningCommon.AwsSigningAttributes, + "SigningRegion", + "config.region", + nullable = true, + ) + } +} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/ClockSkew.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/middleware/ClockSkew.kt similarity index 94% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/ClockSkew.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/middleware/ClockSkew.kt index 863ee5e75d5..ae71c8f5b36 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/ClockSkew.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/middleware/ClockSkew.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.customization +package software.amazon.smithy.kotlin.codegen.aws.middleware import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes import software.amazon.smithy.kotlin.codegen.integration.AppendingSectionWriter diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/AwsJson1_0.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/AwsJson1_0.kt similarity index 76% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/AwsJson1_0.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/AwsJson1_0.kt index 028d1cfa773..c43d68b2730 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/AwsJson1_0.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/AwsJson1_0.kt @@ -2,14 +2,14 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols +package software.amazon.smithy.kotlin.codegen.aws.protocols -import aws.sdk.kotlin.codegen.protocols.core.AwsHttpBindingProtocolGenerator -import aws.sdk.kotlin.codegen.protocols.json.AwsJsonHttpBindingResolver -import aws.sdk.kotlin.codegen.protocols.json.AwsJsonProtocolMiddleware -import aws.sdk.kotlin.codegen.protocols.json.AwsJsonProtocolParserGenerator -import aws.sdk.kotlin.codegen.protocols.json.JsonHttpBindingProtocolGenerator import software.amazon.smithy.aws.traits.protocols.AwsJson1_0Trait +import software.amazon.smithy.kotlin.codegen.aws.protocols.core.AwsHttpBindingProtocolGenerator +import software.amazon.smithy.kotlin.codegen.aws.protocols.json.AwsJsonHttpBindingResolver +import software.amazon.smithy.kotlin.codegen.aws.protocols.json.AwsJsonProtocolMiddleware +import software.amazon.smithy.kotlin.codegen.aws.protocols.json.AwsJsonProtocolParserGenerator +import software.amazon.smithy.kotlin.codegen.aws.protocols.json.JsonHttpBindingProtocolGenerator import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpBindingResolver import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolMiddleware diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/AwsJson1_1.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/AwsJson1_1.kt similarity index 76% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/AwsJson1_1.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/AwsJson1_1.kt index 1b92f14b3b0..f112298eded 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/AwsJson1_1.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/AwsJson1_1.kt @@ -3,14 +3,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols +package software.amazon.smithy.kotlin.codegen.aws.protocols -import aws.sdk.kotlin.codegen.protocols.core.AwsHttpBindingProtocolGenerator -import aws.sdk.kotlin.codegen.protocols.json.AwsJsonHttpBindingResolver -import aws.sdk.kotlin.codegen.protocols.json.AwsJsonProtocolMiddleware -import aws.sdk.kotlin.codegen.protocols.json.AwsJsonProtocolParserGenerator -import aws.sdk.kotlin.codegen.protocols.json.JsonHttpBindingProtocolGenerator import software.amazon.smithy.aws.traits.protocols.AwsJson1_1Trait +import software.amazon.smithy.kotlin.codegen.aws.protocols.core.AwsHttpBindingProtocolGenerator +import software.amazon.smithy.kotlin.codegen.aws.protocols.json.AwsJsonHttpBindingResolver +import software.amazon.smithy.kotlin.codegen.aws.protocols.json.AwsJsonProtocolMiddleware +import software.amazon.smithy.kotlin.codegen.aws.protocols.json.AwsJsonProtocolParserGenerator +import software.amazon.smithy.kotlin.codegen.aws.protocols.json.JsonHttpBindingProtocolGenerator import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpBindingResolver import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolMiddleware diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/AwsQuery.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/AwsQuery.kt similarity index 93% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/AwsQuery.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/AwsQuery.kt index a88741286ce..5aed86cb8c2 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/AwsQuery.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/AwsQuery.kt @@ -3,14 +3,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols +package software.amazon.smithy.kotlin.codegen.aws.protocols -import aws.sdk.kotlin.codegen.protocols.core.AbstractQueryFormUrlSerializerGenerator -import aws.sdk.kotlin.codegen.protocols.core.AwsHttpBindingProtocolGenerator -import aws.sdk.kotlin.codegen.protocols.core.QueryHttpBindingProtocolGenerator -import aws.sdk.kotlin.codegen.protocols.formurl.QuerySerdeFormUrlDescriptorGenerator import software.amazon.smithy.aws.traits.protocols.AwsQueryErrorTrait import software.amazon.smithy.aws.traits.protocols.AwsQueryTrait +import software.amazon.smithy.kotlin.codegen.aws.protocols.core.AbstractQueryFormUrlSerializerGenerator +import software.amazon.smithy.kotlin.codegen.aws.protocols.core.AwsHttpBindingProtocolGenerator +import software.amazon.smithy.kotlin.codegen.aws.protocols.core.QueryHttpBindingProtocolGenerator +import software.amazon.smithy.kotlin.codegen.aws.protocols.formurl.QuerySerdeFormUrlDescriptorGenerator import software.amazon.smithy.kotlin.codegen.core.* import software.amazon.smithy.kotlin.codegen.model.* import software.amazon.smithy.kotlin.codegen.model.traits.OperationOutput diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/Ec2Query.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/Ec2Query.kt similarity index 93% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/Ec2Query.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/Ec2Query.kt index 210b4c2eaeb..3db60123682 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/Ec2Query.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/Ec2Query.kt @@ -2,13 +2,13 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols +package software.amazon.smithy.kotlin.codegen.aws.protocols -import aws.sdk.kotlin.codegen.protocols.core.AbstractQueryFormUrlSerializerGenerator -import aws.sdk.kotlin.codegen.protocols.core.QueryHttpBindingProtocolGenerator -import aws.sdk.kotlin.codegen.protocols.formurl.QuerySerdeFormUrlDescriptorGenerator import software.amazon.smithy.aws.traits.protocols.Ec2QueryNameTrait import software.amazon.smithy.aws.traits.protocols.Ec2QueryTrait +import software.amazon.smithy.kotlin.codegen.aws.protocols.core.AbstractQueryFormUrlSerializerGenerator +import software.amazon.smithy.kotlin.codegen.aws.protocols.core.QueryHttpBindingProtocolGenerator +import software.amazon.smithy.kotlin.codegen.aws.protocols.formurl.QuerySerdeFormUrlDescriptorGenerator import software.amazon.smithy.kotlin.codegen.core.KotlinWriter import software.amazon.smithy.kotlin.codegen.core.RenderingContext import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/RestJson1.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/RestJson1.kt similarity index 90% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/RestJson1.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/RestJson1.kt index b00d159678b..1a64f47653a 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/RestJson1.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/RestJson1.kt @@ -2,12 +2,12 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols +package software.amazon.smithy.kotlin.codegen.aws.protocols -import aws.sdk.kotlin.codegen.protocols.core.AwsHttpBindingProtocolGenerator -import aws.sdk.kotlin.codegen.protocols.json.AwsJsonProtocolParserGenerator -import aws.sdk.kotlin.codegen.protocols.json.JsonHttpBindingProtocolGenerator import software.amazon.smithy.aws.traits.protocols.RestJson1Trait +import software.amazon.smithy.kotlin.codegen.aws.protocols.core.AwsHttpBindingProtocolGenerator +import software.amazon.smithy.kotlin.codegen.aws.protocols.json.AwsJsonProtocolParserGenerator +import software.amazon.smithy.kotlin.codegen.aws.protocols.json.JsonHttpBindingProtocolGenerator import software.amazon.smithy.kotlin.codegen.core.KotlinWriter import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes import software.amazon.smithy.kotlin.codegen.core.defaultName diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/RestXml.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/RestXml.kt similarity index 97% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/RestXml.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/RestXml.kt index d16f7890511..158fc9c0262 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/RestXml.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/RestXml.kt @@ -3,12 +3,12 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols +package software.amazon.smithy.kotlin.codegen.aws.protocols -import aws.sdk.kotlin.codegen.protocols.core.AwsHttpBindingProtocolGenerator -import aws.sdk.kotlin.codegen.protocols.xml.RestXmlSerdeDescriptorGenerator import software.amazon.smithy.aws.traits.protocols.RestXmlTrait import software.amazon.smithy.codegen.core.Symbol +import software.amazon.smithy.kotlin.codegen.aws.protocols.core.AwsHttpBindingProtocolGenerator +import software.amazon.smithy.kotlin.codegen.aws.protocols.xml.RestXmlSerdeDescriptorGenerator import software.amazon.smithy.kotlin.codegen.core.KotlinWriter import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes import software.amazon.smithy.kotlin.codegen.core.withBlock diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/AwsHttpBindingProtocolGenerator.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/AwsHttpBindingProtocolGenerator.kt new file mode 100644 index 00000000000..4ba2b8e56a4 --- /dev/null +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/AwsHttpBindingProtocolGenerator.kt @@ -0,0 +1,179 @@ +/* + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0 + */ +package software.amazon.smithy.kotlin.codegen.aws.protocols.core + +import software.amazon.smithy.aws.traits.protocols.AwsQueryCompatibleTrait +import software.amazon.smithy.codegen.core.Symbol +import software.amazon.smithy.kotlin.codegen.aws.protocols.eventstream.EventStreamParserGenerator +import software.amazon.smithy.kotlin.codegen.aws.protocols.eventstream.EventStreamSerializerGenerator +import software.amazon.smithy.kotlin.codegen.core.* +import software.amazon.smithy.kotlin.codegen.integration.SectionId +import software.amazon.smithy.kotlin.codegen.integration.SectionKey +import software.amazon.smithy.kotlin.codegen.lang.KotlinTypes +import software.amazon.smithy.kotlin.codegen.model.buildSymbol +import software.amazon.smithy.kotlin.codegen.model.hasTrait +import software.amazon.smithy.kotlin.codegen.rendering.ExceptionBaseClassGenerator +import software.amazon.smithy.kotlin.codegen.rendering.protocol.* +import software.amazon.smithy.model.shapes.OperationShape +import software.amazon.smithy.model.shapes.ShapeId + +/** + * Base class for all AWS HTTP protocol generators + */ +abstract class AwsHttpBindingProtocolGenerator : HttpBindingProtocolGenerator() { + + object Sections { + object ProtocolErrorDeserialization : SectionId { + val Operation = SectionKey("Operation") + } + + object RenderThrowOperationError : SectionId { + val Context = SectionKey("Context") + val Operation = SectionKey("Operation") + } + } + + override fun generateProtocolUnitTests(ctx: ProtocolGenerator.GenerationContext) { + val ignoredTests = TestMemberDelta( + setOf( + // FIXME - compression not yet supported, see https://github.com/awslabs/smithy-kotlin/issues/955 + "SDKAppliedContentEncoding_awsJson1_0", + "SDKAppliedContentEncoding_awsJson1_1", + "SDKAppliedContentEncoding_awsQuery", + "SDKAppliedContentEncoding_ec2Query", + "SDKAppliedContentEncoding_restJson1", + "SDKAppliedContentEncoding_restXml", + "SDKAppendedGzipAfterProvidedEncoding_restJson1", + "SDKAppendedGzipAfterProvidedEncoding_restXml", + "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsJson1_0", + "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsJson1_1", + "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_awsQuery", + "SDKAppendsGzipAndIgnoresHttpProvidedEncoding_ec2Query", + ), + ) + + // The following can be used to generate only a specific test by name. + // val targetedTest = TestMemberDelta(setOf("RestJsonComplexErrorWithNoMessage"), TestContainmentMode.RUN_TESTS) + + val requestTestBuilder = HttpProtocolUnitTestRequestGenerator.Builder() + val responseTestBuilder = HttpProtocolUnitTestResponseGenerator.Builder() + val errorTestBuilder = HttpProtocolUnitTestErrorGenerator.Builder() + + HttpProtocolTestGenerator( + ctx, + requestTestBuilder, + responseTestBuilder, + errorTestBuilder, + ignoredTests, + ).generateProtocolTests() + } + + /** + * Get the error "code" that uniquely identifies the AWS error. + */ + protected open fun getErrorCode(ctx: ProtocolGenerator.GenerationContext, errShapeId: ShapeId): String = errShapeId.name + + /** + * Render the code to parse the `ErrorDetails` from the HTTP response. + */ + abstract fun renderDeserializeErrorDetails(ctx: ProtocolGenerator.GenerationContext, op: OperationShape, writer: KotlinWriter) + + override fun eventStreamRequestHandler(ctx: ProtocolGenerator.GenerationContext, op: OperationShape): Symbol { + val resolver = getProtocolHttpBindingResolver(ctx.model, ctx.service) + val contentType = resolver.determineRequestContentType(op) ?: error("event streams must set a content-type") + val eventStreamSerializerGenerator = EventStreamSerializerGenerator(structuredDataSerializer(ctx), contentType) + return eventStreamSerializerGenerator.requestHandler(ctx, op) + } + + override fun eventStreamResponseHandler(ctx: ProtocolGenerator.GenerationContext, op: OperationShape): Symbol { + val eventStreamParserGenerator = EventStreamParserGenerator(ctx, structuredDataParser(ctx)) + return eventStreamParserGenerator.responseHandler(ctx, op) + } + + override fun operationErrorHandler(ctx: ProtocolGenerator.GenerationContext, op: OperationShape): Symbol = + op.errorHandler(ctx.settings) { writer -> + writer.withBlock( + "private suspend fun ${op.errorHandlerName()}(context: #T, call: #T): #Q {", + "}", + RuntimeTypes.Core.ExecutionContext, + RuntimeTypes.Http.HttpCall, + KotlinTypes.Nothing, + ) { + renderThrowOperationError(ctx, op, writer) + } + } + + private fun renderThrowOperationError( + ctx: ProtocolGenerator.GenerationContext, + op: OperationShape, + writer: KotlinWriter, + ) { + writer.declareSection( + Sections.RenderThrowOperationError, + mapOf( + Sections.RenderThrowOperationError.Context to ctx, + Sections.RenderThrowOperationError.Operation to op, + ), + ) { + val exceptionBaseSymbol = ExceptionBaseClassGenerator.baseExceptionSymbol(ctx.settings) + writer.write("val payload = call.response.body.#T()", RuntimeTypes.Http.readAll) + .write("val wrappedResponse = call.response.#T(payload)", RuntimeTypes.AwsProtocolCore.withPayload) + .write("val wrappedCall = call.copy(response = wrappedResponse)") + .write("") + .declareSection( + Sections.ProtocolErrorDeserialization, + mapOf( + Sections.ProtocolErrorDeserialization.Operation to op, + ), + ) + .write("val errorDetails = try {") + .indent() + .call { + renderDeserializeErrorDetails(ctx, op, writer) + } + .dedent() + .withBlock("} catch (ex: Exception) {", "}") { + withBlock("""throw #T("Failed to parse response as '${ctx.protocol.name}' error", ex).also {""", "}", exceptionBaseSymbol) { + write("#T(it, wrappedCall.response, null)", RuntimeTypes.AwsProtocolCore.setAseErrorMetadata) + } + } + .write("") + + if (ctx.service.hasTrait()) { + writer.write("var queryErrorDetails: #T? = null", RuntimeTypes.AwsProtocolCore.AwsQueryCompatibleErrorDetails) + writer.withBlock("call.response.headers[#T]?.let {", "}", RuntimeTypes.AwsProtocolCore.XAmznQueryErrorHeader) { + openBlock("queryErrorDetails = try {") + write("#T.parse(it)", RuntimeTypes.AwsProtocolCore.AwsQueryCompatibleErrorDetails) + closeAndOpenBlock("} catch (ex: Exception) {") + withBlock("""throw #T("Failed to parse awsQuery-compatible error", ex).also {""", "}", exceptionBaseSymbol) { + write("#T(it, wrappedResponse, errorDetails)", RuntimeTypes.AwsProtocolCore.setAseErrorMetadata) + } + closeBlock("}") + } + writer.write("") + } + + writer.withBlock("val ex = when(errorDetails.code) {", "}") { + op.errors.forEach { err -> + val errSymbol = ctx.symbolProvider.toSymbol(ctx.model.expectShape(err)) + val errDeserializerSymbol = buildSymbol { + name = "${errSymbol.name}Deserializer" + namespace = ctx.settings.pkg.serde + } + writer.write("#S -> #T().deserialize(context, wrappedCall)", getErrorCode(ctx, err), errDeserializerSymbol) + } + write("else -> #T(errorDetails.message)", exceptionBaseSymbol) + } + + writer.write("") + writer.write("#T(ex, wrappedResponse, errorDetails)", RuntimeTypes.AwsProtocolCore.setAseErrorMetadata) + if (ctx.service.hasTrait()) { + writer.write("queryErrorDetails?.let { #T(ex, it) }", RuntimeTypes.AwsProtocolCore.setAwsQueryCompatibleErrorMetadata) + } + + writer.write("throw ex") + } + } +} diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/core/QueryHttpBindingProtocolGenerator.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/QueryHttpBindingProtocolGenerator.kt similarity index 98% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/core/QueryHttpBindingProtocolGenerator.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/QueryHttpBindingProtocolGenerator.kt index 7afec237622..c79bc20bc15 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/core/QueryHttpBindingProtocolGenerator.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/QueryHttpBindingProtocolGenerator.kt @@ -2,9 +2,8 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.core +package software.amazon.smithy.kotlin.codegen.aws.protocols.core -import aws.sdk.kotlin.codegen.protocols.middleware.MutateHeadersMiddleware import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.kotlin.codegen.core.KotlinWriter import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes @@ -13,6 +12,7 @@ import software.amazon.smithy.kotlin.codegen.model.expectShape import software.amazon.smithy.kotlin.codegen.model.knowledge.SerdeIndex import software.amazon.smithy.kotlin.codegen.model.targetOrSelf import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpBindingResolver +import software.amazon.smithy.kotlin.codegen.rendering.protocol.MutateHeadersMiddleware import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolMiddleware import software.amazon.smithy.kotlin.codegen.rendering.serde.* diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/core/StaticHttpBindingResolver.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/StaticHttpBindingResolver.kt similarity index 98% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/core/StaticHttpBindingResolver.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/StaticHttpBindingResolver.kt index ffdcc9ea432..f549d0ed4c7 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/core/StaticHttpBindingResolver.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/StaticHttpBindingResolver.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.core +package software.amazon.smithy.kotlin.codegen.aws.protocols.core import software.amazon.smithy.kotlin.codegen.model.expectTrait import software.amazon.smithy.kotlin.codegen.model.hasTrait diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/eventstream/EventStreamParserGenerator.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/eventstream/EventStreamParserGenerator.kt similarity index 98% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/eventstream/EventStreamParserGenerator.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/eventstream/EventStreamParserGenerator.kt index a06943bc5d5..92845b590a8 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/eventstream/EventStreamParserGenerator.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/eventstream/EventStreamParserGenerator.kt @@ -3,9 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.eventstream +package software.amazon.smithy.kotlin.codegen.aws.protocols.eventstream -import aws.sdk.kotlin.codegen.AwsRuntimeTypes import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.kotlin.codegen.core.* @@ -118,7 +117,7 @@ class EventStreamParserGenerator( // this is a service exception still, just un-modeled write("is #T.Error -> throw #T(\"error processing event stream: errorCode=\${mt.errorCode}; message=\${mt.message}\")", messageTypeSymbol, baseExceptionSymbol) // this is a client exception because we failed to parse it - write("is #T.SdkUnknown -> throw #T(\"unrecognized event stream message `:message-type`: \${mt.messageType}\")", messageTypeSymbol, AwsRuntimeTypes.Core.ClientException) + write("is #T.SdkUnknown -> throw #T(\"unrecognized event stream message `:message-type`: \${mt.messageType}\")", messageTypeSymbol, RuntimeTypes.Core.ClientException) } } .dedent() @@ -218,7 +217,7 @@ class EventStreamParserGenerator( .closeAndOpenBlock("} else {") .write( "#T(#T(firstMessage), frames)", - AwsRuntimeTypes.Core.mergeSequential, + RuntimeTypes.Core.Utils.mergeSequential, RuntimeTypes.KotlinxCoroutines.Flow.flowOf, ) .closeBlock("}") diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/eventstream/EventStreamSerializerGenerator.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/eventstream/EventStreamSerializerGenerator.kt similarity index 98% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/eventstream/EventStreamSerializerGenerator.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/eventstream/EventStreamSerializerGenerator.kt index 8bc7d569fc5..6fb3c803fa3 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/eventstream/EventStreamSerializerGenerator.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/eventstream/EventStreamSerializerGenerator.kt @@ -3,9 +3,8 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.eventstream +package software.amazon.smithy.kotlin.codegen.aws.protocols.eventstream -import aws.sdk.kotlin.codegen.AwsRuntimeTypes import software.amazon.smithy.codegen.core.CodegenException import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.kotlin.codegen.core.* @@ -94,7 +93,7 @@ class EventStreamSerializerGenerator( writer.withBlock( "val messages = #T(#T(initialRequest), stream.#T(::#T))", "", - AwsRuntimeTypes.Core.mergeSequential, + RuntimeTypes.Core.Utils.mergeSequential, RuntimeTypes.KotlinxCoroutines.Flow.flowOf, RuntimeTypes.KotlinxCoroutines.Flow.map, encodeFn, diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/formurl/QuerySerdeFormUrlDescriptorGenerator.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/formurl/QuerySerdeFormUrlDescriptorGenerator.kt similarity index 96% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/formurl/QuerySerdeFormUrlDescriptorGenerator.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/formurl/QuerySerdeFormUrlDescriptorGenerator.kt index ad6bc5d1f9e..994b242aa49 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/formurl/QuerySerdeFormUrlDescriptorGenerator.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/formurl/QuerySerdeFormUrlDescriptorGenerator.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.formurl +package software.amazon.smithy.kotlin.codegen.aws.protocols.formurl import software.amazon.smithy.kotlin.codegen.core.RenderingContext import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonHttpBindingResolver.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonHttpBindingResolver.kt similarity index 84% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonHttpBindingResolver.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonHttpBindingResolver.kt index f0daafd8522..eba5e590788 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonHttpBindingResolver.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonHttpBindingResolver.kt @@ -3,9 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.json +package software.amazon.smithy.kotlin.codegen.aws.protocols.json -import aws.sdk.kotlin.codegen.protocols.core.StaticHttpBindingResolver +import software.amazon.smithy.kotlin.codegen.aws.protocols.core.StaticHttpBindingResolver import software.amazon.smithy.model.Model import software.amazon.smithy.model.pattern.UriPattern import software.amazon.smithy.model.shapes.ServiceShape diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonProtocolMiddleware.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonProtocolMiddleware.kt similarity index 94% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonProtocolMiddleware.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonProtocolMiddleware.kt index 9f339b8bf5d..e9ecfb37db9 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonProtocolMiddleware.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonProtocolMiddleware.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.json +package software.amazon.smithy.kotlin.codegen.aws.protocols.json import software.amazon.smithy.kotlin.codegen.core.KotlinWriter import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonProtocolParserGenerator.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonProtocolParserGenerator.kt similarity index 95% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonProtocolParserGenerator.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonProtocolParserGenerator.kt index 58807e7eda4..e98d29acf1e 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonProtocolParserGenerator.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonProtocolParserGenerator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.json +package software.amazon.smithy.kotlin.codegen.aws.protocols.json import software.amazon.smithy.kotlin.codegen.core.KotlinWriter import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonProtocolSerdeDescriptorGenerator.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonProtocolSerdeDescriptorGenerator.kt similarity index 96% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonProtocolSerdeDescriptorGenerator.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonProtocolSerdeDescriptorGenerator.kt index 6e635459793..a6471e992f2 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonProtocolSerdeDescriptorGenerator.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonProtocolSerdeDescriptorGenerator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.json +package software.amazon.smithy.kotlin.codegen.aws.protocols.json import software.amazon.smithy.kotlin.codegen.core.RenderingContext import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/json/JsonHttpBindingProtocolGenerator.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/JsonHttpBindingProtocolGenerator.kt similarity index 91% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/json/JsonHttpBindingProtocolGenerator.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/JsonHttpBindingProtocolGenerator.kt index eb08d6bdc7c..7e82faae3d8 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/json/JsonHttpBindingProtocolGenerator.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/JsonHttpBindingProtocolGenerator.kt @@ -3,9 +3,9 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.json +package software.amazon.smithy.kotlin.codegen.aws.protocols.json -import aws.sdk.kotlin.codegen.protocols.core.AwsHttpBindingProtocolGenerator +import software.amazon.smithy.kotlin.codegen.aws.protocols.core.AwsHttpBindingProtocolGenerator import software.amazon.smithy.kotlin.codegen.core.KotlinWriter import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes import software.amazon.smithy.kotlin.codegen.rendering.protocol.ProtocolGenerator diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/xml/RestXmlSerdeDescriptorGenerator.kt b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/xml/RestXmlSerdeDescriptorGenerator.kt similarity index 96% rename from codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/xml/RestXmlSerdeDescriptorGenerator.kt rename to codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/xml/RestXmlSerdeDescriptorGenerator.kt index ca5ff14127d..e71d2db2765 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/protocols/xml/RestXmlSerdeDescriptorGenerator.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/xml/RestXmlSerdeDescriptorGenerator.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.xml +package software.amazon.smithy.kotlin.codegen.aws.protocols.xml import software.amazon.smithy.kotlin.codegen.core.RenderingContext import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.ProjectionTransformer b/codegen/smithy-aws-kotlin-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.ProjectionTransformer deleted file mode 100644 index b9efe926aef..00000000000 --- a/codegen/smithy-aws-kotlin-codegen/src/main/resources/META-INF/services/software.amazon.smithy.build.ProjectionTransformer +++ /dev/null @@ -1,2 +0,0 @@ -aws.sdk.kotlin.codegen.transforms.IncludeOperations -aws.sdk.kotlin.codegen.transforms.RemoveDeprecatedShapes \ No newline at end of file diff --git a/codegen/smithy-aws-kotlin-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration b/codegen/smithy-aws-kotlin-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration index 2f9ea8324c4..07cdaabee7e 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration +++ b/codegen/smithy-aws-kotlin-codegen/src/main/resources/META-INF/services/software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration @@ -1,36 +1,3 @@ -aws.sdk.kotlin.codegen.SdkProtocolGeneratorSupplier -aws.sdk.kotlin.codegen.AddUserAgentMetadataIntegration -aws.sdk.kotlin.codegen.AwsServiceConfigIntegration -aws.sdk.kotlin.codegen.customization.s3.S3GeneratorSupplier -aws.sdk.kotlin.codegen.GradleGenerator -aws.sdk.kotlin.codegen.AwsRetryHeaderIntegration -aws.sdk.kotlin.codegen.customization.ClockSkew -aws.sdk.kotlin.codegen.customization.AccountIdEndpointBuiltinCustomization -aws.sdk.kotlin.codegen.customization.PresignableModelIntegration -aws.sdk.kotlin.codegen.customization.BackfillOptionalAuth -aws.sdk.kotlin.codegen.protocols.endpoints.BindAwsEndpointBuiltins -aws.sdk.kotlin.codegen.PresignerGenerator -aws.sdk.kotlin.codegen.customization.flexiblechecksums.FlexibleChecksumsRequest -aws.sdk.kotlin.codegen.customization.flexiblechecksums.FlexibleChecksumsResponse -aws.sdk.kotlin.codegen.customization.s3.S3SigningConfig -aws.sdk.kotlin.codegen.customization.s3.S3ErrorMetadataIntegration -aws.sdk.kotlin.codegen.customization.s3.ClientConfigIntegration -aws.sdk.kotlin.codegen.customization.s3.ContinueIntegration -aws.sdk.kotlin.codegen.customization.s3.GetObjectResponseLengthValidationIntegration -aws.sdk.kotlin.codegen.customization.s3.HttpPathFilter -aws.sdk.kotlin.codegen.customization.s3.TruncatablePaginationIntegration -aws.sdk.kotlin.codegen.customization.s3.HostPrefixRequestRouteFilter -aws.sdk.kotlin.codegen.customization.s3.UnwrappedXmlOutputIntegration -aws.sdk.kotlin.codegen.customization.s3control.HostPrefixFilter -aws.sdk.kotlin.codegen.customization.s3control.ClientConfigIntegration -aws.sdk.kotlin.codegen.customization.s3.S3ErrorWith200StatusIntegration -aws.sdk.kotlin.codegen.customization.apigateway.ApiGatewayAddAcceptHeader -aws.sdk.kotlin.codegen.customization.glacier.GlacierAddVersionHeader -aws.sdk.kotlin.codegen.customization.glacier.GlacierAccountIdDefault -aws.sdk.kotlin.codegen.customization.glacier.GlacierBodyChecksum -aws.sdk.kotlin.codegen.customization.polly.PollyPresigner -aws.sdk.kotlin.codegen.customization.machinelearning.MachineLearningEndpointCustomization -aws.sdk.kotlin.codegen.customization.route53.TrimResourcePrefix -aws.sdk.kotlin.codegen.customization.route53.ChangeResourceRecordSetsUnmarshallingIntegration -aws.sdk.kotlin.codegen.customization.ec2.EC2MakePrimitivesOptional -aws.sdk.kotlin.codegen.customization.RemoveDefaults +software.amazon.smithy.kotlin.codegen.aws.SdkProtocolGeneratorSupplier +software.amazon.smithy.kotlin.codegen.aws.customization.RegionSupport +software.amazon.smithy.kotlin.codegen.aws.middleware.ClockSkew diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpProtocolClientGeneratorTest.kt b/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpProtocolClientGeneratorTest.kt deleted file mode 100644 index 896ff228779..00000000000 --- a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpProtocolClientGeneratorTest.kt +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ - -package aws.sdk.kotlin.codegen.protocols.core -import software.amazon.smithy.kotlin.codegen.core.KotlinWriter -import software.amazon.smithy.kotlin.codegen.rendering.protocol.HttpTraitResolver -import software.amazon.smithy.kotlin.codegen.test.newTestContext -import software.amazon.smithy.kotlin.codegen.test.shouldContainOnlyOnceWithDiff -import software.amazon.smithy.kotlin.codegen.test.toSmithyModel -import kotlin.test.Test - -class AwsHttpProtocolClientGeneratorTest { - @Test - fun testRetryPolicyIsOverridden() { - val model = """ - namespace com.test - - use aws.protocols#awsJson1_1 - use aws.api#service - - @service(sdkId: "Test", endpointPrefix: "test.service") - @awsJson1_1 - service Example { - version: "1.0.0", - operations: [GetFoo] - } - - @http(method: "GET", uri: "/foo") - operation GetFoo {} - """.toSmithyModel() - - val testCtx = model.newTestContext(serviceName = "Example") - val writer = KotlinWriter("com.test") - - val generator = AwsHttpProtocolClientGenerator( - ctx = testCtx.generationCtx, - middlewares = emptyList(), - httpBindingResolver = HttpTraitResolver(testCtx.generationCtx, "application/json"), - ) - - generator.render(writer) - val contents = writer.toString() - val expected = """ - op.execution.retryPolicy = config.retryPolicy - """ - contents.shouldContainOnlyOnceWithDiff(expected) - } -} diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/transforms/RemoveDeprecatedShapesTest.kt b/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/transforms/RemoveDeprecatedShapesTest.kt deleted file mode 100644 index 12de8ab1876..00000000000 --- a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/transforms/RemoveDeprecatedShapesTest.kt +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. - * SPDX-License-Identifier: Apache-2.0 - */ -package aws.sdk.kotlin.codegen.transforms - -import software.amazon.smithy.model.shapes.FloatShape -import software.amazon.smithy.model.shapes.Shape -import software.amazon.smithy.model.shapes.ShapeId -import software.amazon.smithy.model.traits.DeprecatedTrait -import kotlin.test.Test -import kotlin.test.assertFalse -import kotlin.test.assertTrue - -class RemoveDeprecatedShapesTest { - private fun shapeDeprecatedSince(since: String?): Shape { - val deprecatedTrait = DeprecatedTrait.builder() - .since(since) - .build() - - return FloatShape.builder() - .addTrait(deprecatedTrait) - .id(ShapeId.from("aws.sdk.kotlin#testing")) - .build() - } - - @Test - fun testShouldBeRemoved() { - val shape = shapeDeprecatedSince("2022-01-01") - val removeDeprecatedShapesUntil = "2023-01-01".toLocalDate()!! - assertTrue(shouldRemoveDeprecatedShape(removeDeprecatedShapesUntil).test(shape)) - } - - @Test - fun testShouldNotBeRemoved() { - val shape = shapeDeprecatedSince("2024-01-01") - val removeDeprecatedShapesUntil = "2023-01-01".toLocalDate()!! - assertFalse(shouldRemoveDeprecatedShape(removeDeprecatedShapesUntil).test(shape)) - } - - @Test - fun testShouldNotBeRemovedIfDeprecatedSameDay() { - val shape = shapeDeprecatedSince("2023-01-01") - val removeDeprecatedShapesUntil = "2023-01-01".toLocalDate()!! - assertFalse(shouldRemoveDeprecatedShape(removeDeprecatedShapesUntil).test(shape)) - } - - @Test - fun testShouldNotBeRemovedIfMissingSinceField() { - val shape = shapeDeprecatedSince(null) - val removeDeprecatedShapesUntil = "2023-01-01".toLocalDate()!! - assertFalse(shouldRemoveDeprecatedShape(removeDeprecatedShapesUntil).test(shape)) - } -} diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpBindingProtocolGeneratorTest.kt b/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/AwsHttpBindingProtocolGeneratorTest.kt similarity index 98% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpBindingProtocolGeneratorTest.kt rename to codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/AwsHttpBindingProtocolGeneratorTest.kt index 3f4d36644ca..19a19638442 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/protocols/core/AwsHttpBindingProtocolGeneratorTest.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/core/AwsHttpBindingProtocolGeneratorTest.kt @@ -2,7 +2,7 @@ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.core +package software.amazon.smithy.kotlin.codegen.aws.protocols.core import software.amazon.smithy.codegen.core.Symbol import software.amazon.smithy.kotlin.codegen.core.KotlinWriter diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonHttpBindingResolverTest.kt b/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonHttpBindingResolverTest.kt similarity index 98% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonHttpBindingResolverTest.kt rename to codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonHttpBindingResolverTest.kt index cea57230a84..56036239744 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonHttpBindingResolverTest.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonHttpBindingResolverTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.json +package software.amazon.smithy.kotlin.codegen.aws.protocols.json import software.amazon.smithy.kotlin.codegen.model.expectShape import software.amazon.smithy.kotlin.codegen.test.newTestContext diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonProtocolSerdeDescriptorGeneratorTest.kt b/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonProtocolSerdeDescriptorGeneratorTest.kt similarity index 97% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonProtocolSerdeDescriptorGeneratorTest.kt rename to codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonProtocolSerdeDescriptorGeneratorTest.kt index 228d83d5b84..871f1d24811 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/protocols/json/AwsJsonProtocolSerdeDescriptorGeneratorTest.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/json/AwsJsonProtocolSerdeDescriptorGeneratorTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.json +package software.amazon.smithy.kotlin.codegen.aws.protocols.json import software.amazon.smithy.kotlin.codegen.test.* import software.amazon.smithy.model.shapes.ShapeId diff --git a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/protocols/xml/RestXmlSerdeDescriptorGeneratorTest.kt b/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/xml/RestXmlSerdeDescriptorGeneratorTest.kt similarity index 96% rename from codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/protocols/xml/RestXmlSerdeDescriptorGeneratorTest.kt rename to codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/xml/RestXmlSerdeDescriptorGeneratorTest.kt index 4ca2f538273..7da286c7a8b 100644 --- a/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/aws/sdk/kotlin/codegen/protocols/xml/RestXmlSerdeDescriptorGeneratorTest.kt +++ b/codegen/smithy-aws-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/aws/protocols/xml/RestXmlSerdeDescriptorGeneratorTest.kt @@ -3,7 +3,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -package aws.sdk.kotlin.codegen.protocols.xml +package software.amazon.smithy.kotlin.codegen.aws.protocols.xml import software.amazon.smithy.kotlin.codegen.test.* import software.amazon.smithy.model.shapes.ShapeId diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 07150edf76e..62be89ec553 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -7,8 +7,8 @@ coroutines-version = "1.7.3" atomicfu-version = "0.22.0" # smithy-kotlin codegen and runtime are versioned separately -smithy-kotlin-runtime-version = "1.0.3" -smithy-kotlin-codegen-version = "0.30.4" +smithy-kotlin-runtime-version = "1.0.4" +smithy-kotlin-codegen-version = "0.30.5" # codegen smithy-version = "1.41.1" diff --git a/gradle/sdk-plugins/src/main/kotlin/aws/sdk/kotlin/gradle/codegen/tasks/SmithyTasks.kt b/gradle/sdk-plugins/src/main/kotlin/aws/sdk/kotlin/gradle/codegen/tasks/SmithyTasks.kt index d7a1752838f..889595b2fec 100644 --- a/gradle/sdk-plugins/src/main/kotlin/aws/sdk/kotlin/gradle/codegen/tasks/SmithyTasks.kt +++ b/gradle/sdk-plugins/src/main/kotlin/aws/sdk/kotlin/gradle/codegen/tasks/SmithyTasks.kt @@ -103,8 +103,8 @@ private fun Project.createCodegenConfiguration(): Configuration { codegenConfig.extendsFrom(createSmithyCliConfiguration()) dependencies { - // depend on aws-kotlin code generation - codegenConfig(project(":codegen:smithy-aws-kotlin-codegen")) + // depend on AWS SDK Kotlin code generation + codegenConfig(project(":codegen:aws-sdk-codegen")) } return codegenConfig diff --git a/settings.gradle.kts b/settings.gradle.kts index 5bfee43b606..56e0ff1fd14 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -40,6 +40,7 @@ include(":dokka-aws") include(":bom") include(":codegen:sdk") include(":codegen:smithy-aws-kotlin-codegen") +include(":codegen:aws-sdk-codegen") include(":codegen:protocol-tests") include(":aws-runtime") include(":aws-runtime:aws-core")