Skip to content

Commit

Permalink
Fix consistent service naming and add test coverage (#2349)
Browse files Browse the repository at this point in the history
* Make service name casing consistent

* Add naming-obstacle-course-casing.smithy

* Add missing import

* Relax obstacle course even further

* Better TODO

* Add CHANGELOG.next.toml
  • Loading branch information
hlbarber authored Feb 13, 2023
1 parent f705bde commit 9ecd7f0
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,9 @@ message = "`aws_smithy_types::Error` has been renamed to `aws_smithy_types::erro
references = ["smithy-rs#76", "smithy-rs#2129"]
meta = { "breaking" = true, "tada" = false, "bug" = false }
author = "jdisanti"

[[smithy-rs]]
message = "Fix inconsistent casing in services re-export."
references = ["smithy-rs#2349"]
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "server" }
author = "hlbarber"
5 changes: 5 additions & 0 deletions codegen-client-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ val allCodegenTests = "../codegen-core/common-test-models".let { commonModels ->
""".trimIndent(),
imports = listOf("$commonModels/naming-obstacle-course-ops.smithy"),
),
CodegenTest(
"casing#ACRONYMInside_Service",
"naming_test_casing",
imports = listOf("$commonModels/naming-obstacle-course-casing.smithy"),
),
CodegenTest(
"naming_obs_structs#NamingObstacleCourseStructs",
"naming_test_structs",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
$version: "1.0"
namespace casing

use aws.protocols#awsJson1_1

// TODO(https://github.com/awslabs/smithy-rs/issues/2340): The commented part of the model breaks the generator in a
// miriad of ways. Any solution to the linked issue must address this.

/// Confounds model generation machinery with lots of problematic casing
@awsJson1_1
service ACRONYMInside_Service {
operations: [
DoNothing,
// ACRONYMInside_Op
// ACRONYM_InsideOp
]
}

operation DoNothing {}

// operation ACRONYMInside_Op {
// input: Input,
// output: Output,
// errors: [Error],
// }

// operation ACRONYM_InsideOp {
// input: Input,
// output: Output,
// errors: [Error],
// }

// structure Input {
// ACRONYMInside_Member: ACRONYMInside_Struct,
// ACRONYM_Inside_Member: ACRONYM_InsideStruct,
// ACRONYM_InsideMember: ACRONYMInsideStruct
// }

// structure Output {
// ACRONYMInside_Member: ACRONYMInside_Struct,
// ACRONYM_Inside_Member: ACRONYM_InsideStruct,
// ACRONYM_InsideMember: ACRONYMInsideStruct
// }

// @error("client")
// structure Error {
// ACRONYMInside_Member: ACRONYMInside_Struct,
// ACRONYM_Inside_Member: ACRONYM_InsideStruct,
// ACRONYM_InsideMember: ACRONYMInsideStruct
// }

// structure ACRONYMInside_Struct {
// ACRONYMInside_Member: ACRONYM_InsideStruct,
// ACRONYM_Inside_Member: Integer,
// }

// structure ACRONYM_InsideStruct {
// ACRONYMInside_Member: Integer,
// }

// structure ACRONYMInsideStruct {
// ACRONYMInside_Member: Integer,
// }
1 change: 1 addition & 0 deletions codegen-server-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencies {
val allCodegenTests = "../codegen-core/common-test-models".let { commonModels ->
listOf(
CodegenTest("crate#Config", "naming_test_ops", imports = listOf("$commonModels/naming-obstacle-course-ops.smithy")),
CodegenTest("casing#ACRONYMInside_Service", "naming_test_casing", imports = listOf("$commonModels/naming-obstacle-course-casing.smithy")),
CodegenTest(
"naming_obs_structs#NamingObstacleCourseStructs",
"naming_test_structs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import software.amazon.smithy.rust.codegen.core.rustlang.rust
import software.amazon.smithy.rust.codegen.core.rustlang.rustTemplate
import software.amazon.smithy.rust.codegen.core.smithy.RustCrate
import software.amazon.smithy.rust.codegen.core.smithy.generators.protocol.ProtocolSupport
import software.amazon.smithy.rust.codegen.core.util.toPascalCase
import software.amazon.smithy.rust.codegen.core.util.toSnakeCase
import software.amazon.smithy.rust.codegen.server.smithy.ServerCargoDependency
import software.amazon.smithy.rust.codegen.server.smithy.ServerCodegenContext
Expand All @@ -42,7 +43,7 @@ open class ServerServiceGenerator(
) {
private val index = TopDownIndex.of(codegenContext.model)
protected val operations = index.getContainedOperations(codegenContext.serviceShape).sortedBy { it.id }
private val serviceName = codegenContext.serviceShape.id.name.toString()
private val serviceName = codegenContext.serviceShape.id.name.toPascalCase()

fun documentation(writer: RustWriter) {
val operations = index.getContainedOperations(codegenContext.serviceShape).toSortedSet(compareBy { it.id })
Expand Down

0 comments on commit 9ecd7f0

Please sign in to comment.