Skip to content

Commit

Permalink
Pascal case operation names
Browse files Browse the repository at this point in the history
And hence pascal case operation error struct names too, like we're
currently doing with operation input and output struct names.

Fixes #1826.
  • Loading branch information
david-perez committed Oct 7, 2022
1 parent e78da55 commit 9b6ae23
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()}"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit 9b6ae23

Please sign in to comment.