From 9b6ae23e9f1bcfb1cc2a87ebc1acccfb241db726 Mon Sep 17 00:00:00 2001 From: david-perez Date: Fri, 7 Oct 2022 15:34:31 +0200 Subject: [PATCH] Pascal case operation names And hence pascal case operation error struct names too, like we're currently doing with operation input and output struct names. Fixes #1826. --- .../naming-obstacle-course-ops.smithy | 6 +++++- .../smithy/rust/codegen/core/smithy/SymbolVisitor.kt | 10 ++-------- .../smithy/generators/http/HttpBindingGenerator.kt | 1 - .../core/smithy/transformers/OperationNormalizer.kt | 1 - .../smithy/generators/ServerOperationGenerator.kt | 2 +- 5 files changed, 8 insertions(+), 12 deletions(-) diff --git a/codegen-core/common-test-models/naming-obstacle-course-ops.smithy b/codegen-core/common-test-models/naming-obstacle-course-ops.smithy index 087d99b750..f54b27e76f 100644 --- a/codegen-core/common-test-models/naming-obstacle-course-ops.smithy +++ b/codegen-core/common-test-models/naming-obstacle-course-ops.smithy @@ -5,6 +5,7 @@ use smithy.test#httpRequestTests use smithy.test#httpResponseTests use aws.protocols#awsJson1_1 use aws.api#service +use smithy.framework#ValidationException /// Confounds model generation machinery with lots of problematic names @awsJson1_1 @@ -41,17 +42,20 @@ service Config { } ]) operation ReservedWordsAsMembers { - input: ReservedWords + input: ReservedWords, + errors: [ValidationException], } // tests that module names are properly escaped operation Match { input: ReservedWords + errors: [ValidationException], } // Should generate a PascalCased `RpcEchoInput` struct. operation RPCEcho { input: ReservedWords + errors: [ValidationException], } structure ReservedWords { diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt index 3b2024faed..90f400f163 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt @@ -284,16 +284,10 @@ open class SymbolVisitor( TODO("Not yet implemented: https://github.com/awslabs/smithy-rs/issues/312") } - override fun operationShape(shape: OperationShape): Symbol { - return symbolBuilder( - RustType.Opaque( - shape.contextName(serviceShape) - .replaceFirstChar { it.uppercase() }, - ), - ) + override fun operationShape(shape: OperationShape) = + symbolBuilder(RustType.Opaque(shape.contextName(serviceShape).toPascalCase())) .locatedIn(Operations) .build() - } override fun resourceShape(shape: ResourceShape?): Symbol { TODO("Not yet implemented: resources are not supported") diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt index e76ed60ac9..219e87dbe5 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/http/HttpBindingGenerator.kt @@ -404,7 +404,6 @@ class HttpBindingGenerator( /** * Generate a unique name for the deserializer function for a given [operationShape] and HTTP binding. */ - // Rename here technically not required, operations and members cannot be renamed. private fun fnName(operationShape: OperationShape, binding: HttpBindingDescriptor) = "${operationShape.id.getName(service).toSnakeCase()}_${binding.member.container.name.toSnakeCase()}_${binding.memberName.toSnakeCase()}" diff --git a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/OperationNormalizer.kt b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/OperationNormalizer.kt index 1a00d431ae..4c69c10202 100644 --- a/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/OperationNormalizer.kt +++ b/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/transformers/OperationNormalizer.kt @@ -32,7 +32,6 @@ import kotlin.streams.toList */ object OperationNormalizer { // Functions to construct synthetic shape IDs—Don't rely on these in external code. - // Rename safety: Operations cannot be renamed // In order to ensure that the fully qualified smithy id of a synthetic shape can never conflict with an existing shape, // the `synthetic` namespace is appended. private fun OperationShape.syntheticInputId() = diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt index b61b1baa45..e250911900 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt @@ -30,7 +30,7 @@ class ServerOperationGenerator( private val symbolProvider = codegenContext.symbolProvider private val model = codegenContext.model - private val operationName = symbolProvider.toSymbol(operation).name.toPascalCase() + private val operationName = symbolProvider.toSymbol(operation).name private val operationId = operation.id /** Returns `std::convert::Infallible` if the model provides no errors. */