Skip to content
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
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/CodegenTestCommon.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ val AllCargoCommands = listOf(Cargo.CHECK, Cargo.TEST, Cargo.CLIPPY, Cargo.DOCS)
*/
fun cargoCommands(properties: PropertyRetriever): List<Cargo> {
val cargoCommandsOverride = properties.get("cargoCommands")?.split(",")?.map { it.trim() }?.map {
when(it) {
when (it) {
"check" -> Cargo.CHECK
"test" -> Cargo.TEST
"docs" -> Cargo.DOCS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import software.amazon.smithy.rust.codegen.smithy.RustSymbolProvider
import software.amazon.smithy.rust.codegen.smithy.SymbolVisitorConfig
import software.amazon.smithy.rust.codegen.smithy.customize.RustCodegenDecorator
import software.amazon.smithy.rust.codegen.smithy.generators.BuilderGenerator
import software.amazon.smithy.rust.codegen.smithy.generators.CodegenTarget
import software.amazon.smithy.rust.codegen.smithy.generators.EnumGenerator
import software.amazon.smithy.rust.codegen.smithy.generators.StructureGenerator
import software.amazon.smithy.rust.codegen.smithy.generators.CodegenTarget
import software.amazon.smithy.rust.codegen.smithy.generators.UnionGenerator
import software.amazon.smithy.rust.codegen.smithy.generators.implBlock
import software.amazon.smithy.rust.codegen.smithy.generators.protocol.ProtocolGenerator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import software.amazon.smithy.rust.codegen.rustlang.RustModule
import software.amazon.smithy.rust.codegen.server.smithy.generators.protocol.ServerProtocolTestGenerator
import software.amazon.smithy.rust.codegen.smithy.CodegenContext
import software.amazon.smithy.rust.codegen.smithy.RustCrate
import software.amazon.smithy.rust.codegen.smithy.customize.RustCodegenDecorator
import software.amazon.smithy.rust.codegen.smithy.generators.protocol.ProtocolGenerator
import software.amazon.smithy.rust.codegen.smithy.generators.protocol.ProtocolSupport
import software.amazon.smithy.rust.codegen.smithy.protocols.HttpBindingResolver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

package software.amazon.smithy.rust.codegen.server.smithy.generators.http


import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.Shape
import software.amazon.smithy.rust.codegen.smithy.CodegenContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,21 +90,21 @@ class ServerProtocolTestGenerator(
abstract val protocol: ShapeId
abstract val testType: TestType

data class RequestTest(val testCase: HttpRequestTestCase): TestCase() {
data class RequestTest(val testCase: HttpRequestTestCase) : TestCase() {
override val id: String = testCase.id
override val documentation: String? = testCase.documentation.orNull()
override val protocol: ShapeId = testCase.protocol
override val testType: TestType = TestType.Request
}

data class ResponseTest(val testCase: HttpResponseTestCase, val targetShape: StructureShape): TestCase() {
data class ResponseTest(val testCase: HttpResponseTestCase, val targetShape: StructureShape) : TestCase() {
override val id: String = testCase.id
override val documentation: String? = testCase.documentation.orNull()
override val protocol: ShapeId = testCase.protocol
override val testType: TestType = TestType.Response
}

data class MalformedRequestTest(val testCase: HttpMalformedRequestTestCase): TestCase() {
data class MalformedRequestTest(val testCase: HttpMalformedRequestTestCase) : TestCase() {
override val id: String = testCase.id
override val documentation: String? = testCase.documentation.orNull()
override val protocol: ShapeId = testCase.protocol
Expand Down Expand Up @@ -239,7 +239,7 @@ class ServerProtocolTestGenerator(
rust("/* test case disabled for this protocol (not yet supported) */")
return
}
with (httpRequestTestCase) {
with(httpRequestTestCase) {
renderHttpRequest(uri, headers, body.orNull(), queryParams, host.orNull())
}
if (protocolSupport.requestBodyDeserialization) {
Expand Down Expand Up @@ -308,7 +308,7 @@ class ServerProtocolTestGenerator(
* with the given response.
*/
private fun RustWriter.renderHttpMalformedRequestTestCase(testCase: HttpMalformedRequestTestCase) {
with (testCase.request) {
with(testCase.request) {
// TODO(https://github.com/awslabs/smithy/issues/1102): `uri` should probably not be an `Optional`.
renderHttpRequest(uri.get(), headers, body.orNull(), queryParams, host.orNull())
}
Expand Down Expand Up @@ -348,18 +348,18 @@ class ServerProtocolTestGenerator(
rustTemplate(
"""
.body(${
if (body != null) {
// The `replace` is necessary to fix the malformed request test `RestJsonInvalidJsonBody`.
// https://github.com/awslabs/smithy/blob/887ae4f6d118e55937105583a07deb90d8fabe1c/smithy-aws-protocol-tests/model/restJson1/malformedRequests/malformed-request-body.smithy#L47
//
// Smithy is written in Java, which parses `\u000c` within a `String` as a single char given by the
// corresponding Unicode code point. That is the "form feed" 0x0c character. When printing it,
// it gets written as "\f", which is an invalid Rust escape sequence: https://static.rust-lang.org/doc/master/reference.html#literals
// So we need to write the corresponding Rust Unicode escape sequence to make the program compile.
"#{SmithyHttpServer}::body::Body::from(#{Bytes}::from_static(b${body.replace("\u000c", "\\u{000c}").dq()}))"
} else {
"#{SmithyHttpServer}::body::Body::empty()"
}
if (body != null) {
// The `replace` is necessary to fix the malformed request test `RestJsonInvalidJsonBody`.
// https://github.com/awslabs/smithy/blob/887ae4f6d118e55937105583a07deb90d8fabe1c/smithy-aws-protocol-tests/model/restJson1/malformedRequests/malformed-request-body.smithy#L47
//
// Smithy is written in Java, which parses `\u000c` within a `String` as a single char given by the
// corresponding Unicode code point. That is the "form feed" 0x0c character. When printing it,
// it gets written as "\f", which is an invalid Rust escape sequence: https://static.rust-lang.org/doc/master/reference.html#literals
// So we need to write the corresponding Rust Unicode escape sequence to make the program compile.
"#{SmithyHttpServer}::body::Body::from(#{Bytes}::from_static(b${body.replace("\u000c", "\\u{000c}").dq()}))"
} else {
"#{SmithyHttpServer}::body::Body::empty()"
}
}).unwrap();
""",
*codegenScope
Expand Down