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 error struct with default impl #3190

Merged
merged 5 commits into from
Nov 14, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
# author = "rcoh"

[[smithy-rs]]
message = """
Fix rendering of @error structs when fields have default values
"""
references = ["smithy-rs#3182"]
meta = { "breaking" = false, "tada" = false, "bug" = true, "target" = "client"}
author = "codypenta"

[[aws-sdk-rust]]
message = "Change `ByteStream::into_async_read` to return `AsyncBufRead`"
references = ["smithy-rs#3164"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import software.amazon.smithy.rust.codegen.core.smithy.RuntimeType
import software.amazon.smithy.rust.codegen.core.smithy.RustSymbolProvider
import software.amazon.smithy.rust.codegen.core.smithy.customize.writeCustomizations
import software.amazon.smithy.rust.codegen.core.smithy.generators.setterName
import software.amazon.smithy.rust.codegen.core.smithy.isOptional
import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpBindingDescriptor
import software.amazon.smithy.rust.codegen.core.smithy.protocols.HttpLocation
import software.amazon.smithy.rust.codegen.core.smithy.protocols.Protocol
Expand Down Expand Up @@ -163,7 +164,8 @@ class ProtocolParserGenerator(
val errorMessageMember = errorShape.errorMessageMember()
// If the message member is optional and wasn't set, we set a generic error message.
if (errorMessageMember != null) {
if (errorMessageMember.isOptional) {
val symbol = symbolProvider.toSymbol(errorMessageMember)
if (symbol.isOptional()) {
rust(
"""
if tmp.message.is_none() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/

package software.amazon.smithy.rust.codegen.client.smithy.generators.protocol

import org.junit.jupiter.api.Test
import software.amazon.smithy.rust.codegen.client.testutil.clientIntegrationTest
import software.amazon.smithy.rust.codegen.core.testutil.asSmithyModel

class ProtocolParserGeneratorTest {
private val model = """
${'$'}version: "2.0"
namespace test

use aws.protocols#restJson1

@restJson1
service TestService {
version: "2019-12-16",
operations: [SomeOperation]
errors: [SomeTopLevelError]
}

@http(uri: "/SomeOperation", method: "POST")
operation SomeOperation {
input: SomeOperationInputOutput,
output: SomeOperationInputOutput,
errors: [SomeOperationError]
}

structure SomeOperationInputOutput {
payload: String,
a: String,
b: Integer
}

@error("server")
structure SomeTopLevelError {
@required
requestId: String

@required
message: String

code: String = "400"

context: String
}

@error("client")
structure SomeOperationError {
@required
requestId: String

@required
message: String

code: String = "400"

context: String
}
"""
.asSmithyModel()

@Test
fun `generate an complex error structure that compiles`() {
clientIntegrationTest(model) { _, _ -> }
}
}
Loading