Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: generate internal-only clients with internal visibility #1045

Merged
merged 10 commits into from
Sep 19, 2023
5 changes: 5 additions & 0 deletions .changes/1371764e-c78a-4127-935c-407d11574af7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "1371764e-c78a-4127-935c-407d11574af7",
"type": "misc",
"description": "Generate internal-only clients with `internal` visibility"
}
1,486 changes: 0 additions & 1,486 deletions aws-runtime/aws-config/api/aws-config.api

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion aws-runtime/aws-config/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,11 @@ codegen {
generateDefaultBuildFiles = false
generateFullProject = false
}
apiSettings {
visibility = "internal"
}
}

// TODO - could we add a trait such that we change visibility to `internal` or a build setting...?
transforms = listOf(
"""
{
Expand Down Expand Up @@ -149,6 +151,9 @@ codegen {
generateDefaultBuildFiles = false
generateFullProject = false
}
apiSettings {
visibility = "internal"
}
}

transforms = listOf(
Expand Down Expand Up @@ -181,6 +186,9 @@ codegen {
generateDefaultBuildFiles = false
generateFullProject = false
}
apiSettings {
visibility = "internal"
}
}

transforms = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AwsEndpointDelegator : EndpointDelegator {
val defaultProviderSymbol = DefaultEndpointProviderGenerator.getSymbol(ctx.settings)

ctx.delegator.useFileWriter(providerSymbol) {
EndpointProviderGenerator(it, providerSymbol, paramsSymbol).render()
EndpointProviderGenerator(it, ctx.settings, providerSymbol, paramsSymbol).render()
}

val endpointFunctions = buildMap {
Expand All @@ -58,7 +58,7 @@ class AwsEndpointDelegator : EndpointDelegator {
}
if (rules != null) {
ctx.delegator.useFileWriter(defaultProviderSymbol) {
DefaultEndpointProviderGenerator(it, rules, defaultProviderSymbol, providerSymbol, paramsSymbol, endpointFunctions, awsEndpointPropertyRenderers).render()
DefaultEndpointProviderGenerator(it, rules, defaultProviderSymbol, providerSymbol, paramsSymbol, ctx.settings, endpointFunctions, awsEndpointPropertyRenderers).render()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,11 @@ open class AwsHttpProtocolClientGenerator(

override fun render(writer: KotlinWriter) {
writer.write("\n\n")
writer.write("public const val ServiceApiVersion: String = #S", ctx.service.version)
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/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ import software.amazon.smithy.model.node.ObjectNode
import software.amazon.smithy.model.node.ToNode
import java.util.*

class SmithyKotlinApiSettings : ToNode {
var visibility: String? = null
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: It's a string here in configuration, but becomes a Visibility enum once it's actually parsed from the Node object


override fun toNode(): Node {
val builder = ObjectNode.objectNodeBuilder()
builder.withNullableMember("visibility", visibility)
return builder.build()
}
}

class SmithyKotlinBuildSettings : ToNode {
var generateFullProject: Boolean? = null
var generateDefaultBuildFiles: Boolean? = null
Expand All @@ -24,6 +34,7 @@ class SmithyKotlinBuildSettings : ToNode {

val optInArrNode = optInAnnotations?.map { Node.from(it) }?.let { ArrayNode.fromNodes(it) }
builder.withOptionalMember("optInAnnotations", Optional.ofNullable(optInArrNode))

return builder.build()
}
}
Expand All @@ -43,6 +54,12 @@ class SmithyKotlinPluginSettings : SmithyBuildPlugin {
buildSettings!!.apply(configure)
}

internal var apiSettings: SmithyKotlinApiSettings? = null
fun apiSettings(configure: SmithyKotlinApiSettings.() -> Unit) {
if (apiSettings == null) apiSettings = SmithyKotlinApiSettings()
apiSettings!!.apply(configure)
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
Expand Down Expand Up @@ -79,6 +96,7 @@ class SmithyKotlinPluginSettings : SmithyBuildPlugin {
}
.withNullableMember("sdkId", sdkId)
.withNullableMember("build", buildSettings)
.withNullableMember("api", apiSettings)

return obj.build()
}
Expand Down