Skip to content

Operation input and output struct names are pascal cased, but operation error struct names are not #1826

Open
@david-perez

Description

@david-perez

As of writing, this diff atop e78da55:

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 087d99b75..f54b27e76 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 {

makes codegen-server-test:build -P modules="naming_test_ops" -P cargoCommands="test" yield:

error[E0412]: cannot find type `RpcEchoError` in module `crate::error`
   --> naming_test_ops/rust-server-codegen/src/operation_shape.rs:130:32
    |
130 |     type Error = crate::error::RpcEchoError;
    |                                ^^^^^^^^^^^^ help: an enum with a similar name exists: `RPCEchoError`
    |
   ::: naming_test_ops/rust-server-codegen/src/error.rs:326:1
    |
326 | pub enum RPCEchoError {
    | --------------------- similarly named enum `RPCEchoError` defined here

This is due to the fact that the operation error struct name is generated as:

https://github.com/awslabs/smithy-rs/blob/e78da5598a2d94d23fd18e30492a20ce3603f844/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/generators/error/CombinedErrorGenerator.kt#L74

So it's not pascal cased; RPCEchoError is generated. However, ServerOperationGenerator pascal cases the operation name here:

https://github.com/awslabs/smithy-rs/blob/e78da5598a2d94d23fd18e30492a20ce3603f844/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServerOperationGenerator.kt#L33-L33

Note that we do pascal case operation inputs and outputs, since these are regular Structure shapes, and so SymbolVisitor pascal cases them here:

https://github.com/awslabs/smithy-rs/blob/e78da5598a2d94d23fd18e30492a20ce3603f844/codegen-core/src/main/kotlin/software/amazon/smithy/rust/codegen/core/smithy/SymbolVisitor.kt#L310

My preference to fix this bug would be to just pascal case operation names; that's a breaking change for the clients, since it uses the operation names as-is in operation.rs. I'm assuming we don't rename operation names for a reason?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions