Skip to content

Commit

Permalink
chore: upgrade to smithy 1.13.0 (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
wooj2 authored Nov 1, 2021
1 parent 769bb62 commit f226295
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ kotlin.code.style=official
# config

# codegen
smithyVersion=1.12.0
smithyVersion=1.13.0
# kotlin
kotlinVersion=1.5.0
kotlin.native.ignoreDisabledTargets=true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ abstract class HttpBindingProtocolGenerator : ProtocolGenerator {
operationMiddleware.appendMiddleware(operation, ContentTypeMiddleware(ctx.model, ctx.symbolProvider, resolver.determineRequestContentType(operation)))
operationMiddleware.appendMiddleware(operation, OperationInputBodyMiddleware(ctx.model, ctx.symbolProvider))

operationMiddleware.appendMiddleware(operation, ContentLengthMiddleware())
operationMiddleware.appendMiddleware(operation, ContentLengthMiddleware(ctx.model))

operationMiddleware.appendMiddleware(operation, LoggingMiddleware())
operationMiddleware.appendMiddleware(operation, DeserializeMiddleware())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package software.amazon.smithy.swift.codegen.integration.middlewares

import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.swift.codegen.ClientRuntimeTypes
import software.amazon.smithy.swift.codegen.SwiftWriter
import software.amazon.smithy.swift.codegen.integration.middlewares.handlers.MiddlewareShapeUtils
import software.amazon.smithy.swift.codegen.middleware.MiddlewarePosition
import software.amazon.smithy.swift.codegen.middleware.MiddlewareRenderable
import software.amazon.smithy.swift.codegen.middleware.MiddlewareStep

class ContentLengthMiddleware : MiddlewareRenderable {
class ContentLengthMiddleware(val model: Model) : MiddlewareRenderable {

override val name = "ContentLengthMiddleware"

Expand All @@ -20,6 +22,9 @@ class ContentLengthMiddleware : MiddlewareRenderable {
op: OperationShape,
operationStackName: String
) {
writer.write("$operationStackName.${middlewareStep.stringValue()}.intercept(position: ${position.stringValue()}, middleware: \$N())", ClientRuntimeTypes.Middleware.ContentLengthMiddleware)
val hasHttpBody = MiddlewareShapeUtils.hasHttpBody(model, op)
if (hasHttpBody) {
writer.write("$operationStackName.${middlewareStep.stringValue()}.intercept(position: ${position.stringValue()}, middleware: \$N())", ClientRuntimeTypes.Middleware.ContentLengthMiddleware)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import software.amazon.smithy.swift.codegen.middleware.MiddlewareStep
class ContentTypeMiddleware(
val model: Model,
val symbolProvider: SymbolProvider,
val defaultContentType: String
val defaultContentType: String,
val shouldRender: Boolean = false
) : MiddlewareRenderable {

override val name = "ContentTypeMiddleware"
Expand All @@ -26,9 +27,12 @@ class ContentTypeMiddleware(
op: OperationShape,
operationStackName: String,
) {
val inputShapeName = MiddlewareShapeUtils.inputSymbol(symbolProvider, model, op).name
val outputShapeName = MiddlewareShapeUtils.outputSymbol(symbolProvider, model, op).name
val outputErrorName = MiddlewareShapeUtils.outputErrorSymbolName(op)
writer.write("$operationStackName.${middlewareStep.stringValue()}.intercept(position: ${position.stringValue()}, middleware: ContentTypeMiddleware<$inputShapeName, $outputShapeName, $outputErrorName>(contentType: \"${defaultContentType}\"))")
val hasHttpBody = MiddlewareShapeUtils.hasHttpBody(model, op)
if (hasHttpBody || shouldRender) {
val inputShapeName = MiddlewareShapeUtils.inputSymbol(symbolProvider, model, op).name
val outputShapeName = MiddlewareShapeUtils.outputSymbol(symbolProvider, model, op).name
val outputErrorName = MiddlewareShapeUtils.outputErrorSymbolName(op)
writer.write("$operationStackName.${middlewareStep.stringValue()}.intercept(position: ${position.stringValue()}, middleware: ContentTypeMiddleware<$inputShapeName, $outputShapeName, $outputErrorName>(contentType: \"${defaultContentType}\"))")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import software.amazon.smithy.codegen.core.SymbolProvider
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.swift.codegen.SwiftWriter
import software.amazon.smithy.swift.codegen.integration.isInHttpBody
import software.amazon.smithy.swift.codegen.integration.middlewares.handlers.MiddlewareShapeUtils
import software.amazon.smithy.swift.codegen.middleware.MiddlewarePosition
import software.amazon.smithy.swift.codegen.middleware.MiddlewareRenderable
Expand All @@ -27,9 +26,8 @@ class OperationInputBodyMiddleware(
op: OperationShape,
operationStackName: String,
) {
val inputShape = model.expectShape(op.input.get())
val inputShapeName = MiddlewareShapeUtils.inputSymbol(symbolProvider, model, op).name
val hasHttpBody = inputShape.members().filter { it.isInHttpBody() }.count() > 0
val hasHttpBody = MiddlewareShapeUtils.hasHttpBody(model, op)
if (hasHttpBody || shouldRender) {
writer.write("$operationStackName.${middlewareStep.stringValue()}.intercept(position: ${position.stringValue()}, middleware: ${inputShapeName}BodyMiddleware())")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ import software.amazon.smithy.codegen.core.SymbolProvider
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.knowledge.OperationIndex
import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.Shape
import software.amazon.smithy.swift.codegen.SwiftSettings
import software.amazon.smithy.swift.codegen.integration.isInHttpBody
import software.amazon.smithy.swift.codegen.model.capitalizedName

class MiddlewareShapeUtils {
companion object {
fun inputShape(model: Model, op: OperationShape): Shape {
return model.expectShape(op.input.get())
}
fun inputSymbol(symbolProvider: SymbolProvider, model: Model, op: OperationShape): Symbol {
val opIndex = OperationIndex.of(model)
return inputSymbol(symbolProvider, opIndex, op)
Expand All @@ -36,5 +41,10 @@ class MiddlewareShapeUtils {
fun rootNamespace(settings: SwiftSettings): String {
return settings.moduleName
}

fun hasHttpBody(model: Model, op: OperationShape): Boolean {
val inputShape = inputShape(model, op)
return inputShape.members().filter { it.isInHttpBody() }.count() > 0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ class HttpProtocolUnitTestRequestGeneratorTests {
}
operationStack.serializeStep.intercept(position: .after, middleware: EmptyInputAndEmptyOutputInputHeadersMiddleware())
operationStack.serializeStep.intercept(position: .after, middleware: EmptyInputAndEmptyOutputInputQueryItemMiddleware())
operationStack.serializeStep.intercept(position: .after, middleware: ContentTypeMiddleware<EmptyInputAndEmptyOutputInput, EmptyInputAndEmptyOutputOutputResponse, EmptyInputAndEmptyOutputOutputError>(contentType: "application/json"))
operationStack.finalizeStep.intercept(position: .before, middleware: ClientRuntime.ContentLengthMiddleware())
operationStack.deserializeStep.intercept(position: .after,
middleware: MockDeserializeMiddleware<EmptyInputAndEmptyOutputOutputResponse, EmptyInputAndEmptyOutputOutputError>(
id: "TestDeserializeMiddleware"){ context, actual in
Expand Down Expand Up @@ -499,8 +497,6 @@ class HttpProtocolUnitTestRequestGeneratorTests {
}
operationStack.serializeStep.intercept(position: .after, middleware: HttpPrefixHeadersInputHeadersMiddleware())
operationStack.serializeStep.intercept(position: .after, middleware: HttpPrefixHeadersInputQueryItemMiddleware())
operationStack.serializeStep.intercept(position: .after, middleware: ContentTypeMiddleware<HttpPrefixHeadersInput, HttpPrefixHeadersOutputResponse, HttpPrefixHeadersOutputError>(contentType: "application/json"))
operationStack.finalizeStep.intercept(position: .before, middleware: ClientRuntime.ContentLengthMiddleware())
operationStack.deserializeStep.intercept(position: .after,
middleware: MockDeserializeMiddleware<HttpPrefixHeadersOutputResponse, HttpPrefixHeadersOutputError>(
id: "TestDeserializeMiddleware"){ context, actual in
Expand Down

0 comments on commit f226295

Please sign in to comment.