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

Fix consistent service naming and add test coverage #2349

Merged
merged 7 commits into from
Feb 13, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I am not in love with the naming here :)

operations: [
DoNothing,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't need this operation if #2351 is merged

// 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")),
Copy link
Contributor

Choose a reason for hiding this comment

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

There's no harm in adding this to codegen-client too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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