From 487ec3762b346e2b8056bf2dfe714ed79bd7ef72 Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Thu, 11 Apr 2024 18:13:19 +0000 Subject: [PATCH 1/2] feat: add DSL markers to codegenned structure builders --- .changes/19208b1c-8c36-452b-a6e3-e0bef345776a.json | 8 ++++++++ .../amazon/smithy/kotlin/codegen/core/RuntimeTypes.kt | 1 + .../smithy/kotlin/codegen/rendering/StructureGenerator.kt | 1 + .../kotlin/codegen/rendering/StructureGeneratorTest.kt | 1 + runtime/runtime-core/api/runtime-core.api | 3 +++ .../common/src/aws/smithy/kotlin/runtime/Annotations.kt | 6 ++++++ 6 files changed, 20 insertions(+) create mode 100644 .changes/19208b1c-8c36-452b-a6e3-e0bef345776a.json diff --git a/.changes/19208b1c-8c36-452b-a6e3-e0bef345776a.json b/.changes/19208b1c-8c36-452b-a6e3-e0bef345776a.json new file mode 100644 index 000000000..5c82c3976 --- /dev/null +++ b/.changes/19208b1c-8c36-452b-a6e3-e0bef345776a.json @@ -0,0 +1,8 @@ +{ + "id": "19208b1c-8c36-452b-a6e3-e0bef345776a", + "type": "feature", + "description": "Add new @SdkDsl DSL marker to all generated structure builders, clarifying DSL scopes when building complex types", + "issues": [ + "awslabs/smithy-kotlin#428" + ] +} \ No newline at end of file diff --git a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/core/RuntimeTypes.kt b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/core/RuntimeTypes.kt index 62eb4d455..80d992e2c 100644 --- a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/core/RuntimeTypes.kt +++ b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/core/RuntimeTypes.kt @@ -98,6 +98,7 @@ object RuntimeTypes { val fromEpochMilliseconds = symbol("fromEpochMilliseconds", "time") val TimestampFormat = symbol("TimestampFormat", "time") val ClientException = symbol("ClientException") + val SdkDsl = symbol("SdkDsl") object Collections : RuntimeTypePackage(KotlinDependency.CORE, "collections") { val Attributes = symbol("Attributes") diff --git a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/StructureGenerator.kt b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/StructureGenerator.kt index 15c4a416b..dd366ddbb 100644 --- a/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/StructureGenerator.kt +++ b/codegen/smithy-kotlin-codegen/src/main/kotlin/software/amazon/smithy/kotlin/codegen/rendering/StructureGenerator.kt @@ -223,6 +223,7 @@ class StructureGenerator( private fun renderBuilder() { writer.write("") + .write("@#T", RuntimeTypes.Core.SdkDsl) .withBlock("public class Builder {", "}") { for (member in sortedMembers) { val (memberName, memberSymbol) = memberNameSymbolIndex[member]!! diff --git a/codegen/smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/rendering/StructureGeneratorTest.kt b/codegen/smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/rendering/StructureGeneratorTest.kt index e12a6686a..33b7f3ad4 100644 --- a/codegen/smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/rendering/StructureGeneratorTest.kt +++ b/codegen/smithy-kotlin-codegen/src/test/kotlin/software/amazon/smithy/kotlin/codegen/rendering/StructureGeneratorTest.kt @@ -184,6 +184,7 @@ class StructureGeneratorTest { @Test fun `it renders a builder impl`() { val expected = """ + @SdkDsl public class Builder { /** * This *is* documentation about the member. diff --git a/runtime/runtime-core/api/runtime-core.api b/runtime/runtime-core/api/runtime-core.api index c9a68703f..01b1c46db 100644 --- a/runtime/runtime-core/api/runtime-core.api +++ b/runtime/runtime-core/api/runtime-core.api @@ -36,6 +36,9 @@ public class aws/smithy/kotlin/runtime/SdkBaseException : java/lang/RuntimeExcep public fun getSdkErrorMetadata ()Laws/smithy/kotlin/runtime/ErrorMetadata; } +public abstract interface annotation class aws/smithy/kotlin/runtime/SdkDsl : java/lang/annotation/Annotation { +} + public class aws/smithy/kotlin/runtime/ServiceErrorMetadata : aws/smithy/kotlin/runtime/ErrorMetadata { public static final field Companion Laws/smithy/kotlin/runtime/ServiceErrorMetadata$Companion; public fun ()V diff --git a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/Annotations.kt b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/Annotations.kt index d004442b8..ee3ab01e2 100644 --- a/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/Annotations.kt +++ b/runtime/runtime-core/common/src/aws/smithy/kotlin/runtime/Annotations.kt @@ -52,3 +52,9 @@ public annotation class InternalApi AnnotationTarget.CONSTRUCTOR, ) public annotation class ExperimentalApi + +/** + * Signifies that a type is considered part of an SDK DSL for the purposes of scope control + */ +@DslMarker +public annotation class SdkDsl From 67a4ff64cae9112f391eb7ecd0a20b6a85e39620 Mon Sep 17 00:00:00 2001 From: Ian Botsford <83236726+ianbotsf@users.noreply.github.com> Date: Thu, 11 Apr 2024 19:56:22 +0000 Subject: [PATCH 2/2] update changelog entry to point to breaking change announcement --- .changes/19208b1c-8c36-452b-a6e3-e0bef345776a.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changes/19208b1c-8c36-452b-a6e3-e0bef345776a.json b/.changes/19208b1c-8c36-452b-a6e3-e0bef345776a.json index 5c82c3976..2b83dfc8a 100644 --- a/.changes/19208b1c-8c36-452b-a6e3-e0bef345776a.json +++ b/.changes/19208b1c-8c36-452b-a6e3-e0bef345776a.json @@ -1,8 +1,8 @@ { "id": "19208b1c-8c36-452b-a6e3-e0bef345776a", "type": "feature", - "description": "Add new @SdkDsl DSL marker to all generated structure builders, clarifying DSL scopes when building complex types", + "description": "⚠️ **IMPORTANT**: Add new @SdkDsl DSL marker to all generated structure builders, clarifying DSL scopes when building complex types. See the [**Scope control applied to DSL builders** breaking change announcement](https://github.com/awslabs/aws-sdk-kotlin/discussions/1280) for more details.", "issues": [ "awslabs/smithy-kotlin#428" ] -} \ No newline at end of file +}