From 2ec2ca21409727e4b03f1fa8e022dc69951aeb47 Mon Sep 17 00:00:00 2001 From: david-perez Date: Tue, 18 Jun 2024 12:53:10 +0200 Subject: [PATCH] Simplify `@httpPayload` on string shape protocol tests In #2314, I added an operation featuring an `@httpPayload`-bound shape to test `Content-Type` header checking, among other things. However, I failed to notice there is already a `http-string-payload.smithy` file in the test suite to test `@httpPayload`-bound string shapes. This PR merges and applies the tests I added in #2314 to the operation that already existed. --- .../model/restJson1/http-payload.smithy | 118 +----------------- .../restJson1/http-string-payload.smithy | 74 ++++++++++- .../model/restJson1/main.smithy | 1 - 3 files changed, 73 insertions(+), 120 deletions(-) diff --git a/smithy-aws-protocol-tests/model/restJson1/http-payload.smithy b/smithy-aws-protocol-tests/model/restJson1/http-payload.smithy index 14d1e19c7fd..57a89b19414 100644 --- a/smithy-aws-protocol-tests/model/restJson1/http-payload.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/http-payload.smithy @@ -1,4 +1,5 @@ // This file defines test cases that test HTTP payload bindings. +// Note that string payloads are tested in `http-string-payload.smithy`. // See: https://smithy.io/2.0/spec/http-bindings.html#httppayload-trait $version: "2.0" @@ -374,120 +375,3 @@ structure HttpPayloadWithUnionInputOutput { union UnionPayload { greeting: String } - -/// This example serializes a string shape in the payload. -/// -/// In this example, no JSON document is synthesized because the payload is -/// not a structure or a union type. -@http(uri: "/HttpPayloadTraitOnString", method: "POST") -operation HttpPayloadTraitOnString { - input: HttpPayloadTraitOnStringInputOutput, - output: HttpPayloadTraitOnStringInputOutput -} - -structure HttpPayloadTraitOnStringInputOutput { - @httpPayload - foo: String, -} - -apply HttpPayloadTraitOnString @httpRequestTests([ - { - id: "RestJsonHttpPayloadTraitOnString", - documentation: "Serializes a string in the HTTP payload", - protocol: restJson1, - method: "POST", - uri: "/HttpPayloadTraitOnString", - body: "Foo", - bodyMediaType: "text/plain", - headers: { - "Content-Type": "text/plain", - }, - requireHeaders: [ - "Content-Length" - ], - params: { - foo: "Foo", - } - }, -]) - -apply HttpPayloadTraitOnString @httpResponseTests([ - { - id: "RestJsonHttpPayloadTraitOnString", - documentation: "Serializes a string in the HTTP payload", - protocol: restJson1, - code: 200, - body: "Foo", - bodyMediaType: "text/plain", - headers: { - "Content-Type": "text/plain", - }, - params: { - foo: "Foo", - } - }, -]) - -apply HttpPayloadTraitOnString @httpMalformedRequestTests([ - { - id: "RestJsonHttpPayloadTraitOnStringNoContentType", - documentation: "Serializes a string in the HTTP payload without a content-type header", - protocol: restJson1, - request: { - method: "POST", - uri: "/HttpPayloadTraitOnString", - body: "Foo", - // We expect a `Content-Type` header but none was provided. - }, - response: { - code: 415, - headers: { - "x-amzn-errortype": "UnsupportedMediaTypeException" - } - }, - tags: [ "content-type" ] - }, - { - id: "RestJsonHttpPayloadTraitOnStringWrongContentType", - documentation: "Serializes a string in the HTTP payload without the expected content-type header", - protocol: restJson1, - request: { - method: "POST", - uri: "/HttpPayloadTraitOnString", - body: "Foo", - headers: { - // We expect `text/plain`. - "Content-Type": "application/json", - }, - }, - response: { - code: 415, - headers: { - "x-amzn-errortype": "UnsupportedMediaTypeException" - } - }, - tags: [ "content-type" ] - }, - { - id: "RestJsonHttpPayloadTraitOnStringUnsatisfiableAccept", - documentation: "Serializes a string in the HTTP payload with an unstatisfiable accept header", - protocol: restJson1, - request: { - method: "POST", - uri: "/HttpPayloadTraitOnString", - body: "Foo", - headers: { - "Content-Type": "text/plain", - // We can't satisfy this requirement; the server will return `text/plain`. - "Accept": "application/json", - }, - }, - response: { - code: 406, - headers: { - "x-amzn-errortype": "NotAcceptableException" - } - }, - tags: [ "accept" ] - }, -]) diff --git a/smithy-aws-protocol-tests/model/restJson1/http-string-payload.smithy b/smithy-aws-protocol-tests/model/restJson1/http-string-payload.smithy index 52cab5cc99f..3dcdf401b47 100644 --- a/smithy-aws-protocol-tests/model/restJson1/http-string-payload.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/http-string-payload.smithy @@ -4,6 +4,7 @@ namespace aws.protocoltests.restjson use smithy.test#httpRequestTests use smithy.test#httpResponseTests +use smithy.test#httpMalformedRequestTests @http(uri: "/EnumPayload", method: "POST") @httpRequestTests([ @@ -46,8 +47,14 @@ enum StringEnum { { id: "RestJsonStringPayloadRequest", uri: "/StringPayload", - headers: { "Content-Type": "text/plain" }, body: "rawstring", + bodyMediaType: "text/plain", + headers: { + "Content-Type": "text/plain", + }, + requireHeaders: [ + "Content-Length" + ], params: { payload: "rawstring" }, method: "POST", protocol: "aws.protocols#restJson1" @@ -58,11 +65,75 @@ enum StringEnum { id: "RestJsonStringPayloadResponse", headers: { "Content-Type": "text/plain" }, body: "rawstring", + bodyMediaType: "text/plain", params: { payload: "rawstring" }, protocol: "aws.protocols#restJson1", code: 200 } ]) +@httpMalformedRequestTests([ + { + id: "RestJsonStringPayloadNoContentType", + documentation: "Serializes a string in the HTTP payload without a content-type header", + protocol: "aws.protocols#restJson1", + request: { + method: "POST", + uri: "/StringPayload", + body: "rawstring", + // We expect a `Content-Type` header but none was provided. + }, + response: { + code: 415, + headers: { + "x-amzn-errortype": "UnsupportedMediaTypeException" + } + }, + tags: [ "content-type" ] + }, + { + id: "RestJsonStringPayloadWrongContentType", + documentation: "Serializes a string in the HTTP payload without the expected content-type header", + protocol: "aws.protocols#restJson1", + request: { + method: "POST", + uri: "/StringPayload", + body: "rawstring", + headers: { + // We expect `text/plain`. + "Content-Type": "application/json", + }, + }, + response: { + code: 415, + headers: { + "x-amzn-errortype": "UnsupportedMediaTypeException" + } + }, + tags: [ "content-type" ] + }, + { + id: "RestJsonStringPayloadUnsatisfiableAccept", + documentation: "Serializes a string in the HTTP payload with an unstatisfiable accept header", + protocol: "aws.protocols#restJson1", + request: { + method: "POST", + uri: "/StringPayload", + body: "rawstring", + headers: { + "Content-Type": "text/plain", + // We can't satisfy this requirement; the server will return `text/plain`. + "Accept": "application/json", + }, + }, + response: { + code: 406, + headers: { + "x-amzn-errortype": "NotAcceptableException" + } + }, + tags: [ "accept" ] + }, +]) operation HttpStringPayload { input: StringPayloadInput, output: StringPayloadInput @@ -72,4 +143,3 @@ structure StringPayloadInput { @httpPayload payload: String } - diff --git a/smithy-aws-protocol-tests/model/restJson1/main.smithy b/smithy-aws-protocol-tests/model/restJson1/main.smithy index ad29e0067b4..b5612d294a6 100644 --- a/smithy-aws-protocol-tests/model/restJson1/main.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/main.smithy @@ -62,7 +62,6 @@ service RestJson { HttpEnumPayload, HttpStringPayload, HttpPayloadWithUnion, - HttpPayloadTraitOnString, // @httpResponseCode tests HttpResponseCode,