smithy-lang / smithy-kotlin

Smithy code generator for Kotlin (in development)
Apache License 2.0
64 stars 26 forks source link

feat: add DSL markers to codegenned structure builders #1065

Closed ianbotsf closed 2 months ago

ianbotsf commented 2 months ago

Issue \

Resolves #428

Description of changes

Calls within nested DSL functions will resolve an implicit receiver from anywhere up the hierarchy, enabling bad calls like this one:

CreateBucketRequest {
    bucket = "foo"
    grantRead = "bar"
    createBucketConfiguration {
        grantRead = "baz" // Should be prohibited
    }
}

In the above example, setting grantRead from within createBucketConfiguration should be prohibited because grantRead is a member of CreateBucketRequest.Builder, not CreateBucketConfiguration.Builder.

This change introduces a new DSL marker annotation @SdkDsl which is applied to every codegenned structure builder. Code like the above example now fails to compile.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.