From 6466fe77c65b8a17b219f0b0a60c767915205f95 Mon Sep 17 00:00:00 2001 From: Hayden Baker Date: Fri, 12 Jul 2024 13:19:56 -0700 Subject: [PATCH] Add restJson1 protocol test for content-type and POST operation with no input (#2342) --- .../model/restJson1/http-content-type.smithy | 95 ++++++++++++++++--- .../model/restJson1/main.smithy | 6 +- 2 files changed, 88 insertions(+), 13 deletions(-) diff --git a/smithy-aws-protocol-tests/model/restJson1/http-content-type.smithy b/smithy-aws-protocol-tests/model/restJson1/http-content-type.smithy index acf23b8d3dc..3930bbeb5b4 100644 --- a/smithy-aws-protocol-tests/model/restJson1/http-content-type.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/http-content-type.smithy @@ -228,7 +228,7 @@ structure TestPayloadBlobInputOutput { data: Blob } -/// This example operation serializes a request without an HTTP body. +/// This example GET operation serializes a request without a modeled HTTP body. /// /// These tests are to ensure we do not attach a body or related headers /// (Content-Length, Content-Type) to operations that semantically @@ -236,14 +236,14 @@ structure TestPayloadBlobInputOutput { /// @readonly @http(uri: "/no_payload", method: "GET") -operation TestNoPayload { +operation TestGetNoPayload { input: TestNoPayloadInputOutput, output: TestNoPayloadInputOutput } -apply TestNoPayload @httpRequestTests([ +apply TestGetNoPayload @httpRequestTests([ { - id: "RestJsonHttpWithNoModeledBody", + id: "RestJsonHttpGetWithNoModeledBody", documentation: "Serializes a GET request with no modeled body", protocol: restJson1, method: "GET", @@ -257,9 +257,9 @@ apply TestNoPayload @httpRequestTests([ } ]) -apply TestNoPayload @httpRequestTests([ +apply TestGetNoPayload @httpRequestTests([ { - id: "RestJsonHttpWithHeaderMemberNoModeledBody", + id: "RestJsonHttpGetWithHeaderMemberNoModeledBody", documentation: "Serializes a GET request with header member but no modeled body", protocol: restJson1, method: "GET", @@ -278,12 +278,59 @@ apply TestNoPayload @httpRequestTests([ } ]) +/// This example POST operation serializes a request without a modeled HTTP body. +/// +/// These tests are to ensure we do not attach a body or related headers +/// (Content-Type) to a POST operation with no modeled payload. +/// +@readonly +@http(uri: "/no_payload", method: "POST") +operation TestPostNoPayload { + input: TestNoPayloadInputOutput, + output: TestNoPayloadInputOutput +} + +apply TestPostNoPayload @httpRequestTests([ + { + id: "RestJsonHttpPostWithNoModeledBody", + documentation: "Serializes a POST request with no modeled body", + protocol: restJson1, + method: "POST", + uri: "/no_payload", + body: "", + forbidHeaders: [ + "Content-Type" + ], + params: {} + } +]) + +apply TestPostNoPayload @httpRequestTests([ + { + id: "RestJsonHttpWithPostHeaderMemberNoModeledBody", + documentation: "Serializes a POST request with header member but no modeled body", + protocol: restJson1, + method: "POST", + uri: "/no_payload", + body: "", + headers: { + "X-Amz-Test-Id": "t-12345" + }, + forbidHeaders: [ + "Content-Type" + ], + params: { + testId: "t-12345" + } + } +]) + structure TestNoPayloadInputOutput { @httpHeader("X-Amz-Test-Id") testId: String, } -/// This example operation has no input and serializes a request without an HTTP body. +/// This example GET operation has no input and serializes a request without a HTTP body. /// /// These tests are to ensure we do not attach a body or related headers /// (Content-Length, Content-Type) to operations that semantically @@ -291,20 +338,46 @@ structure TestNoPayloadInputOutput { /// @readonly @http(uri: "/no_input_no_payload", method: "GET") -operation TestNoInputNoPayload { +operation TestGetNoInputNoPayload { output: TestNoPayloadInputOutput } -apply TestNoInputNoPayload @httpRequestTests([ +apply TestGetNoInputNoPayload @httpRequestTests([ { - id: "RestJsonHttpWithNoInput", + id: "RestJsonHttpGetWithNoInput", documentation: "Serializes a GET request for an operation with no input, and therefore no modeled body", protocol: restJson1, method: "GET", uri: "/no_input_no_payload", body: "", forbidHeaders: [ - "Content-Length", + "Content-Type", + "Content-Length" + ], + params: {} + } +]) + +/// This example POST operation has no input and serializes a request without a HTTP body. +/// +/// These tests are to ensure we do not attach a body or related headers +/// (Content-Type) to a POST operation with no modeled input. +/// +@readonly +@http(uri: "/no_input_no_payload", method: "POST") +operation TestPostNoInputNoPayload { + output: TestNoPayloadInputOutput +} + +apply TestPostNoInputNoPayload @httpRequestTests([ + { + id: "RestJsonHttpPostWithNoInput", + documentation: "Serializes a POST request for an operation with no input, and therefore no modeled body", + protocol: restJson1, + method: "POST", + uri: "/no_input_no_payload", + body: "", + forbidHeaders: [ "Content-Type" ], params: {} diff --git a/smithy-aws-protocol-tests/model/restJson1/main.smithy b/smithy-aws-protocol-tests/model/restJson1/main.smithy index b5612d294a6..e37c1cf55ba 100644 --- a/smithy-aws-protocol-tests/model/restJson1/main.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/main.smithy @@ -144,8 +144,10 @@ service RestJson { TestBodyStructure, TestPayloadStructure, TestPayloadBlob, - TestNoPayload, - TestNoInputNoPayload, + TestGetNoPayload + TestPostNoPayload, + TestGetNoInputNoPayload, + TestPostNoInputNoPayload, // client-only timestamp parsing tests DatetimeOffsets,