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

AwsJson1.0 `@streaming` unique in payload (#2230)



* AwsJson1.0 `@streaming` unique in payload

Signed-off-by: default avatarDaniele Ahmed <ahmeddan@amazon.de>
parent 6d6d8d14
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -27,7 +27,6 @@ service PokemonService {
}

/// Capture Pokémons via event streams.
@http(uri: "/capture-pokemon-event/{region}", method: "POST")
operation CapturePokemon {
    input: CapturePokemonEventsInput,
    output: CapturePokemonEventsOutput,
@@ -36,17 +35,11 @@ operation CapturePokemon {

@input
structure CapturePokemonEventsInput {
    @httpPayload
    events: AttemptCapturingPokemonEvent,

    @httpLabel
    @required
    region: String,
}

@output
structure CapturePokemonEventsOutput {
    @httpPayload
    events: CapturePokemonEvents,
}

+18 −8
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@

package software.amazon.smithy.rust.codegen.core.smithy.protocols

import software.amazon.smithy.codegen.core.CodegenException
import software.amazon.smithy.model.Model
import software.amazon.smithy.model.pattern.UriPattern
import software.amazon.smithy.model.shapes.MemberShape
@@ -49,9 +50,17 @@ class AwsJsonHttpBindingResolver(
        .uri(UriPattern.parse("/"))
        .build()

    private fun bindings(shape: ToShapeId) =
        shape.let { model.expectShape(it.toShapeId()) }.members()
            .map {
    private fun bindings(shape: ToShapeId): List<HttpBindingDescriptor> {
        val members = shape.let { model.expectShape(it.toShapeId()) }.members()
        // TODO(https://github.com/awslabs/smithy-rs/issues/2237): support non-streaming members too
        if (members.size > 1 && members.any { it.isStreaming(model) }) {
            throw CodegenException(
                "We only support one payload member if that payload contains a streaming member." +
                    "Tracking issue to relax this constraint: https://github.com/awslabs/smithy-rs/issues/2237",
            )
        }

        return members.map {
            if (it.isStreaming(model)) {
                HttpBindingDescriptor(it, HttpLocation.PAYLOAD, "document")
            } else {
@@ -59,6 +68,7 @@ class AwsJsonHttpBindingResolver(
            }
        }
            .toList()
    }

    override fun httpTrait(operationShape: OperationShape): HttpTrait = httpTrait