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

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

Open
david-perez opened this issue Oct 7, 2022 · 0 comments · May be fixed by #1827
Labels
bug Something isn't working

Comments

@david-perez
Copy link
Contributor

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?

@david-perez david-perez added the bug Something isn't working label Oct 7, 2022
david-perez added a commit that referenced this issue Oct 7, 2022
And hence pascal case operation error struct names too, like we're
currently doing with operation input and output struct names.

Fixes #1826.
This was referenced Oct 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant