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

chore: Update to Smithy 1.49.0 #1515

Merged
merged 3 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package software.amazon.smithy.aws.swift.codegen.middleware

import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.model.node.Node
import software.amazon.smithy.model.shapes.MemberShape
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.rulesengine.language.EndpointRuleSet
Expand Down Expand Up @@ -115,15 +116,7 @@ class OperationEndpointResolverMiddleware(
): String? {
return when {
staticContextParam != null -> {
return when (param.type) {
ParameterType.STRING -> {
"\"${staticContextParam.value}\""
}

ParameterType.BOOLEAN -> {
staticContextParam.value.toString()
}
}
swiftParam(param.type, staticContextParam.value)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored this logic to a private method just below.

}
contextParam != null -> {
return "input.${contextParam.memberName.toLowerCamelCase()}"
Expand Down Expand Up @@ -171,9 +164,12 @@ class OperationEndpointResolverMiddleware(
}

private val Parameter.defaultValueLiteral: String
get() {
return when (type) {
ParameterType.BOOLEAN -> default.get().toString()
ParameterType.STRING -> "\"${default.get()}\""
}
get() = swiftParam(type, default.get().toNode())

private fun swiftParam(parameterType: ParameterType, node: Node): String {
return when (parameterType) {
ParameterType.STRING -> "\"${node}\""
ParameterType.BOOLEAN -> node.toString()
ParameterType.STRING_ARRAY -> "[${node.expectArrayNode().map { "\"$it\"" }.joinToString(", ")}]"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ fun ParameterType.toShapeType(): ShapeType? {
return when (this) {
ParameterType.STRING -> ShapeType.STRING
ParameterType.BOOLEAN -> ShapeType.BOOLEAN
else -> null
ParameterType.STRING_ARRAY -> ShapeType.LIST
Copy link
Contributor Author

@jbelkins jbelkins May 21, 2024

Choose a reason for hiding this comment

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

Added STRING_ARRAY case and eliminated the else so this fails to compile when the next new ParameterType case is added.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AWSDeprecatedShapeRemover : SwiftIntegration {
Predicate<Shape> {
val since = it.getTrait<DeprecatedTrait>()?.since?.orElse(null) ?: 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 $it")
println("Could not parse `since` field \"$since\" as a date, skipping removal of deprecated shape $it")
Copy link
Contributor Author

@jbelkins jbelkins May 21, 2024

Choose a reason for hiding this comment

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

Changed this language because use of the word "failed" makes it difficult to search logs for test failures.

}
return@Predicate deprecatedDate < REMOVE_BEFORE_DATE.toLocalDate()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class EC2QueryProtocolGenerator : AWSHTTPBindingProtocolGenerator(EC2QueryCustom
override val testsToIgnore = setOf(
"SDKAppliedContentEncoding_ec2Query",
"SDKAppendsGzipAndIgnoresHttpProvidedEncoding_ec2Query",
"Ec2EmptyQueryLists",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will fix this test in a separate ticket.
#1514

)
override val tagsToIgnore = setOf("defaults")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,38 +80,41 @@ class EndpointParamsGeneratorTests {
endpointParamsGenerator.render(writer)
val contents = writer.toString()
val expected = """
public struct EndpointParams {
public let boolBar: Swift.Bool?
public let boolBaz: Swift.String?
public let boolFoo: Swift.Bool
public let endpoint: Swift.String?
public let region: Swift.String
public let stringBar: Swift.String?
public let stringBaz: Swift.String?
public let stringFoo: Swift.String?

public init(
boolBar: Swift.Bool? = nil,
boolBaz: Swift.String? = nil,
boolFoo: Swift.Bool,
endpoint: Swift.String? = nil,
region: Swift.String,
stringBar: Swift.String? = nil,
stringBaz: Swift.String? = nil,
stringFoo: Swift.String? = nil
)
{
self.boolBar = boolBar
self.boolBaz = boolBaz
self.boolFoo = boolFoo
self.endpoint = endpoint
self.region = region
self.stringBar = stringBar
self.stringBaz = stringBaz
self.stringFoo = stringFoo
}
}
""".trimIndent()
public struct EndpointParams {
public let boolBar: Swift.Bool?
public let boolBaz: Swift.String?
public let boolFoo: Swift.Bool
public let endpoint: Swift.String?
public let region: Swift.String
public let stringArrayBar: Swift.Array<Swift.String>?
public let stringBar: Swift.String?
public let stringBaz: Swift.String?
public let stringFoo: Swift.String?

public init(
boolBar: Swift.Bool? = nil,
boolBaz: Swift.String? = nil,
boolFoo: Swift.Bool,
endpoint: Swift.String? = nil,
region: Swift.String,
stringArrayBar: Swift.Array<Swift.String>? = nil,
stringBar: Swift.String? = nil,
stringBaz: Swift.String? = nil,
stringFoo: Swift.String? = nil
)
{
self.boolBar = boolBar
self.boolBaz = boolBaz
self.boolFoo = boolFoo
self.endpoint = endpoint
self.region = region
self.stringArrayBar = stringArrayBar
self.stringBar = stringBar
self.stringBaz = stringBaz
self.stringFoo = stringFoo
}
}
"""
contents.shouldContainOnlyOnce(expected)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class OperationEndpointResolverMiddlewareTests {
guard let region = config.region else {
throw SdkError<GetThingOutputError>.client(ClientError.unknownError(("Missing required parameter: region")))
}
let endpointParams = EndpointParams(boolBar: true, boolBaz: input.fuzz, boolFoo: config.boolFoo, endpoint: config.endpoint, region: region, stringBar: "some value", stringBaz: input.buzz, stringFoo: config.stringFoo)
let endpointParams = EndpointParams(boolBar: true, boolBaz: input.fuzz, boolFoo: config.boolFoo, endpoint: config.endpoint, region: region, stringArrayBar: ["five", "six", "seven"], stringBar: "some value", stringBaz: input.buzz, stringFoo: config.stringFoo)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a test that code-generates a static param typed to stringArray.

operationStack.buildStep.intercept(position: .before, middleware: EndpointResolverMiddleware<GetThingOutput>(endpointResolver: config.endpointResolver, endpointParams: endpointParams))
"""
contents.shouldContainOnlyOnce(expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use smithy.rules#endpointRuleSet

@clientContextParams(
stringFoo: {type: "string", documentation: "a client string parameter"},
boolFoo: {type: "boolean", documentation: "a client boolean parameter"}
boolFoo: {type: "boolean", documentation: "a client boolean parameter"},
)
@service(
sdkId: "Json Protocol",
Expand All @@ -33,6 +33,7 @@ apply ExampleService @endpointRuleSet({
boolFoo: {type: "boolean", required: true},
boolBar: {type: "boolean"},
boolBaz: {type: "string"},
stringArrayBar: {type: "stringArray"},
region: {type: "string", builtIn: "AWS::Region", required: true},
},
rules: []
Expand All @@ -42,6 +43,7 @@ apply ExampleService @endpointRuleSet({
@staticContextParams(
stringBar: {value: "some value"},
boolBar: {value: true}
stringArrayBar: {value: ["five", "six", "seven"]}
)
@http(method: "POST", uri: "/endpointtest/getthing")
operation GetThing {
Expand All @@ -53,8 +55,8 @@ structure GetThingInput {
fizz: String,

@contextParam(name: "stringBaz")
buzz: String,
buzz: String

@contextParam(name: "boolBaz")
fuzz: String,
fuzz: String
}
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kotlin.code.style=official
org.gradle.jvmargs=-Xmx4096M

# codegen
smithyVersion=1.47.0
smithyVersion=1.49.0
smithyGradleVersion=0.6.0

smithySwiftVersion = 0.1.0
Expand Down
Loading