Unverified Commit 79a0e72f authored by 82marbag's avatar 82marbag Committed by GitHub
Browse files

Add injection hook for structures from a ServiceShape (#3147)

Analogous to https://github.com/awslabs/smithy-rs/pull/3001

, for
`ServiceShape`s


----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._

Signed-off-by: default avatarDaniele Ahmed <ahmeddan@amazon.de>
parent cc2b9474
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -624,6 +624,9 @@ open class ServerCodegenVisitor(

            ScopeMacroGenerator(codegenContext).render(this)
        }

        codegenDecorator.postprocessServiceGenerateAdditionalStructures(shape)
            .forEach { structureShape -> this.structureShape(structureShape) }
    }

    /**
@@ -649,7 +652,7 @@ open class ServerCodegenVisitor(
            protocolGenerator.renderOperation(this, shape)
        }

        codegenDecorator.postprocessGenerateAdditionalStructures(shape)
        codegenDecorator.postprocessOperationGenerateAdditionalStructures(shape)
            .forEach { structureShape -> this.structureShape(structureShape) }
    }

+15 −3
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ package software.amazon.smithy.rust.codegen.server.smithy.customize

import software.amazon.smithy.build.PluginContext
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.rust.codegen.core.smithy.customize.CombinedCoreCodegenDecorator
@@ -41,7 +42,15 @@ interface ServerCodegenDecorator : CoreCodegenDecorator<ServerCodegenContext, Se
     * making the resulting crate not compile (since it will contain more than one struct with the same name).
     * Therefore, ensure that all the structure shapes returned by this method are not in the service's closure.
     */
    fun postprocessGenerateAdditionalStructures(operationShape: OperationShape): List<StructureShape> = emptyList()
    fun postprocessOperationGenerateAdditionalStructures(operationShape: OperationShape): List<StructureShape> = emptyList()

    /**
     * For each service, this hook allows decorators to return a collection of structure shapes that will additionally be generated.
     * If a structure shape is in the service's closure, note that returning it here will cause for it to be generated more than once,
     * making the resulting crate not compile (since it will contain more than one struct with the same name).
     * Therefore, ensure that all the structure shapes returned by this method are not in the service's closure.
     */
    fun postprocessServiceGenerateAdditionalStructures(serviceShape: ServiceShape): List<StructureShape> = emptyList()

    /**
     * Configuration methods that should be injected into the `${serviceName}Config` struct to allow users to configure
@@ -81,8 +90,11 @@ class CombinedServerCodegenDecorator(decorators: List<ServerCodegenDecorator>) :
            decorator.postprocessValidationExceptionNotAttachedErrorMessage(accumulated)
        }

    override fun postprocessGenerateAdditionalStructures(operationShape: OperationShape): List<StructureShape> =
        orderedDecorators.flatMap { it.postprocessGenerateAdditionalStructures(operationShape) }
    override fun postprocessOperationGenerateAdditionalStructures(operationShape: OperationShape): List<StructureShape> =
        orderedDecorators.flatMap { it.postprocessOperationGenerateAdditionalStructures(operationShape) }

    override fun postprocessServiceGenerateAdditionalStructures(serviceShape: ServiceShape): List<StructureShape> =
        orderedDecorators.flatMap { it.postprocessServiceGenerateAdditionalStructures(serviceShape) }

    override fun configMethods(codegenContext: ServerCodegenContext): List<ConfigMethod> =
        orderedDecorators.flatMap { it.configMethods(codegenContext) }