Upgrade to Smithy 1.6.1 (#235)

This commit is contained in:
Russell Cohen 2021-03-03 14:08:03 -05:00 committed by GitHub
parent 970f69bf06
commit 638b2a90de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 26 additions and 10 deletions

View File

@ -10,7 +10,6 @@ import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.model.traits.EndpointTrait
import software.amazon.smithy.rust.codegen.rustlang.Derives
import software.amazon.smithy.rust.codegen.rustlang.RustWriter
import software.amazon.smithy.rust.codegen.rustlang.documentShape
@ -51,9 +50,9 @@ abstract class HttpProtocolGenerator(
private val symbolProvider = protocolConfig.symbolProvider
private val model = protocolConfig.model
fun renderOperation(operationWriter: RustWriter, inputWriter: RustWriter, operationShape: OperationShape, customizations: List<OperationCustomization>) {
if (operationShape.hasTrait(EndpointTrait::class.java)) {
/* if (operationShape.hasTrait(EndpointTrait::class.java)) {
TODO("https://github.com/awslabs/smithy-rs/issues/197")
}
} */
val inputShape = operationShape.inputShape(model)
val inputSymbol = symbolProvider.toSymbol(inputShape)
val builderGenerator = OperationInputBuilderGenerator(model, symbolProvider, operationShape, protocolConfig.moduleName, customizations)

View File

@ -10,6 +10,7 @@ import software.amazon.smithy.model.knowledge.OperationIndex
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.StructureShape
import software.amazon.smithy.model.traits.ErrorTrait
import software.amazon.smithy.protocoltests.traits.AppliesTo
import software.amazon.smithy.protocoltests.traits.HttpMessageTestCase
import software.amazon.smithy.protocoltests.traits.HttpRequestTestCase
import software.amazon.smithy.protocoltests.traits.HttpRequestTestsTrait
@ -66,9 +67,9 @@ class HttpProtocolTestGenerator(
fun render() {
val requestTests = operationShape.getTrait(HttpRequestTestsTrait::class.java)
.orNull()?.testCases.orEmpty().map { TestCase.RequestTest(it) }
.orNull()?.getTestCasesFor(AppliesTo.CLIENT).orEmpty().map { TestCase.RequestTest(it) }
val responseTests = operationShape.getTrait(HttpResponseTestsTrait::class.java)
.orNull()?.testCases.orEmpty().map { TestCase.ResponseTest(it, outputShape) }
.orNull()?.getTestCasesFor(AppliesTo.CLIENT).orEmpty().map { TestCase.ResponseTest(it, outputShape) }
val errorTests = operationIndex.getErrors(operationShape).flatMap { error ->
val testCases = error.getTrait(HttpResponseTestsTrait::class.java).orNull()?.testCases.orEmpty()
@ -159,6 +160,9 @@ class HttpProtocolTestGenerator(
assert_eq!(http_request.uri().path(), ${uri.dq()});
"""
)
resolvedHost.orNull()?.also { host ->
rust("""assert_eq!(http_request.uri().host().expect("host should be set"), ${host.dq()});""")
}
}
checkQueryParams(this, httpRequestTestCase.queryParams)
checkForbidQueryParams(this, httpRequestTestCase.forbidQueryParams)
@ -167,7 +171,10 @@ class HttpProtocolTestGenerator(
checkForbidHeaders(this, httpRequestTestCase.forbidHeaders)
checkRequiredHeaders(this, httpRequestTestCase.requireHeaders)
if (protocolSupport.requestBodySerialization) {
checkBody(this, httpRequestTestCase.body.orElse(""), httpRequestTestCase.bodyMediaType.orElse(null))
// "If no request body is defined, then no assertions are made about the body of the message."
httpRequestTestCase.body.orNull()?.let { body ->
checkBody(this, body, httpRequestTestCase.bodyMediaType.orNull())
}
}
// Explicitly warn if the test case defined parameters that we aren't doing anything with
@ -362,7 +369,17 @@ class HttpProtocolTestGenerator(
),
// Document deserialization:
FailingTest(AwsJson11, "PutAndGetInlineDocumentsInput", Action.Response)
FailingTest(AwsJson11, "PutAndGetInlineDocumentsInput", Action.Response),
// Endpoint trait https://github.com/awslabs/smithy-rs/issues/197
// This will also require running operations through the endpoint middleware (or moving endpoint middleware
// into operation construction
FailingTest(JsonRpc10, "AwsJson10EndpointTrait", Action.Request),
FailingTest(JsonRpc10, "AwsJson10EndpointTraitWithHostLabel", Action.Request),
FailingTest(AwsJson11, "AwsJson11EndpointTrait", Action.Request),
FailingTest(AwsJson11, "AwsJson11EndpointTraitWithHostLabel", Action.Request),
FailingTest(RestJson, "RestJsonEndpointTrait", Action.Request),
FailingTest(RestJson, "RestJsonEndpointTraitWithHostLabel", Action.Request)
)
private val RunOnly: Set<String>? = null

View File

@ -181,7 +181,7 @@ class BasicAwsJsonGenerator(
override fun toBodyImpl(implBlockWriter: RustWriter, inputShape: StructureShape, inputBody: StructureShape?) {
if (inputBody == null) {
bodyBuilderFun(implBlockWriter) {
write("vec![]")
write("\"{}\".to_string().into()")
}
return
}

View File

@ -6,7 +6,7 @@
kotlin.code.style=official
# codegen
smithyVersion=1.5.0
smithyVersion=1.6.1
# kotlin
kotlinVersion=1.4.21

View File

@ -30,7 +30,7 @@ pub enum ProtocolTestFailure {
MissingHeader { expected: String },
#[error("Header `{forbidden}` was forbidden but found: `{found}`")]
ForbiddenHeader { forbidden: String, found: String },
#[error("body did not match. Hint:\n{hint}")]
#[error("body did not match. Hint:\n{hint}. Expected:\n `{expected}`\n Actual: \n`{found}")]
BodyDidNotMatch {
expected: String,
found: String,