Loading codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointTestGenerator.kt +10 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.util.PANIC import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.orNull Loading Loading @@ -73,7 +74,8 @@ internal class EndpointTestGenerator( ) } testCase.expect.error.ifPresent { error -> val expectedError = escape("expected error: $error [${testCase.documentation.orNull() ?: "no docs"}]") val expectedError = escape("expected error: $error [${testCase.documentation.orNull() ?: "no docs"}]") rustTemplate( """ let error = endpoint.expect_err(${expectedError.dq()}); Loading Loading @@ -116,6 +118,7 @@ internal class EndpointTestGenerator( }.join(","), ) } is Value.Integer -> rust(value.expectInteger().toString()) is Value.Record -> rustBlock("") { Loading @@ -123,7 +126,11 @@ internal class EndpointTestGenerator( "let mut out = #{HashMap}::<String, #{Document}>::new();", *codegenScope, ) value.forEach { identifier, v -> // TODO(https://github.com/awslabs/smithy/pull/1555): remove when this is released val keys = mutableListOf<Identifier>() value.forEach { id, _ -> keys.add(id) } keys.sortedBy { it.name.value }.forEach { identifier -> val v = value.get(identifier) rust( "out.insert(${identifier.toString().dq()}.to_string(), #W.into());", // When writing into the hashmap, it always needs to be an owned type Loading @@ -132,6 +139,7 @@ internal class EndpointTestGenerator( } rustTemplate("out") } else -> PANIC("unexpected type: $value") } } } Loading codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/rulesgen/LiteralGenerator.kt +1 −1 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ class LiteralGenerator(private val ownership: Ownership, private val context: Co "let mut out = #{HashMap}::<String, #{Document}>::new();", *codegenScope, ) members.forEach { (identifier, literal) -> members.keys.sortedBy { it.toString() }.map { k -> k to members[k]!! }.forEach { (identifier, literal) -> rust( "out.insert(${identifier.toString().dq()}.to_string(), #W.into());", // When writing into the hashmap, it always needs to be an owned type Loading codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/endpoint/EndpointsDecoratorTest.kt +17 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,15 @@ class EndpointsDecoratorTest { ], "type": "endpoint", "endpoint": { "url": "https://www.{Region}.example.com" "url": "https://www.{Region}.example.com", "properties": { "first-properties": { "z-first": "zazz", "y-second": "bar", "x-third": "baz" }, "second-properties": [1,2,3] } } }], "parameters": { Loading Loading @@ -73,6 +81,14 @@ class EndpointsDecoratorTest { "expect": { "endpoint": { "url": "https://failingtest.com" "properties": { "first-properties": { "a-first": "zazz", "b-second": "bar", "c-third": "baz" }, "second-properties": [1,2,3] } } } } Loading Loading
codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/generators/EndpointTestGenerator.kt +10 −2 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate import software.amazon.smithy.rust.codegen.core.rustlang.writable import software.amazon.smithy.rust.codegen.core.smithy.RuntimeConfig import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType import software.amazon.smithy.rust.codegen.core.util.PANIC import software.amazon.smithy.rust.codegen.core.util.dq import software.amazon.smithy.rust.codegen.core.util.orNull Loading Loading @@ -73,7 +74,8 @@ internal class EndpointTestGenerator( ) } testCase.expect.error.ifPresent { error -> val expectedError = escape("expected error: $error [${testCase.documentation.orNull() ?: "no docs"}]") val expectedError = escape("expected error: $error [${testCase.documentation.orNull() ?: "no docs"}]") rustTemplate( """ let error = endpoint.expect_err(${expectedError.dq()}); Loading Loading @@ -116,6 +118,7 @@ internal class EndpointTestGenerator( }.join(","), ) } is Value.Integer -> rust(value.expectInteger().toString()) is Value.Record -> rustBlock("") { Loading @@ -123,7 +126,11 @@ internal class EndpointTestGenerator( "let mut out = #{HashMap}::<String, #{Document}>::new();", *codegenScope, ) value.forEach { identifier, v -> // TODO(https://github.com/awslabs/smithy/pull/1555): remove when this is released val keys = mutableListOf<Identifier>() value.forEach { id, _ -> keys.add(id) } keys.sortedBy { it.name.value }.forEach { identifier -> val v = value.get(identifier) rust( "out.insert(${identifier.toString().dq()}.to_string(), #W.into());", // When writing into the hashmap, it always needs to be an owned type Loading @@ -132,6 +139,7 @@ internal class EndpointTestGenerator( } rustTemplate("out") } else -> PANIC("unexpected type: $value") } } } Loading
codegen-client/src/main/kotlin/software/amazon/smithy/rust/codegen/client/smithy/endpoint/rulesgen/LiteralGenerator.kt +1 −1 Original line number Diff line number Diff line Loading @@ -49,7 +49,7 @@ class LiteralGenerator(private val ownership: Ownership, private val context: Co "let mut out = #{HashMap}::<String, #{Document}>::new();", *codegenScope, ) members.forEach { (identifier, literal) -> members.keys.sortedBy { it.toString() }.map { k -> k to members[k]!! }.forEach { (identifier, literal) -> rust( "out.insert(${identifier.toString().dq()}.to_string(), #W.into());", // When writing into the hashmap, it always needs to be an owned type Loading
codegen-client/src/test/kotlin/software/amazon/smithy/rust/codegen/client/endpoint/EndpointsDecoratorTest.kt +17 −1 Original line number Diff line number Diff line Loading @@ -42,7 +42,15 @@ class EndpointsDecoratorTest { ], "type": "endpoint", "endpoint": { "url": "https://www.{Region}.example.com" "url": "https://www.{Region}.example.com", "properties": { "first-properties": { "z-first": "zazz", "y-second": "bar", "x-third": "baz" }, "second-properties": [1,2,3] } } }], "parameters": { Loading Loading @@ -73,6 +81,14 @@ class EndpointsDecoratorTest { "expect": { "endpoint": { "url": "https://failingtest.com" "properties": { "first-properties": { "a-first": "zazz", "b-second": "bar", "c-third": "baz" }, "second-properties": [1,2,3] } } } } Loading