From 244009d6a9aa8f58f5485bb35416feb2db0a0ac0 Mon Sep 17 00:00:00 2001 From: Daniele Ahmed Date: Thu, 26 May 2022 11:15:54 +0000 Subject: [PATCH 1/7] Add tests for httpResponseCode These tests ensure that * @required and @httpResponseCode are correctly handled * @http's code is used in place of @httpResponseCode when the latter is not used They were not handled correctly in https://github.com/awslabs/smithy-rs/issues/1229. Signed-off-by: Daniele Ahmed --- .../model/restJson1/http-response-code.smithy | 56 ++++++++++++++++++- 1 file changed, 55 insertions(+), 1 deletion(-) diff --git a/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy b/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy index c167ea5f0d1..7c2f5c3250a 100644 --- a/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy @@ -19,6 +19,34 @@ structure HttpResponseCodeOutput { Status: Integer } +@http(method: "GET", uri: "/responseCodeRequired", code: 200) +operation ResponseCodeRequired { + input: ResponseCodeRequiredInput, + output: ResponseCodeRequiredOutput, +} + +@input +structure ResponseCodeRequiredInput {} + +@output +structure ResponseCodeRequiredOutput { + @required + @httpResponseCode + responseCode: Integer, +} + +@http(method: "GET", uri: "/responseCodeHttpFallback", code: 418) +operation ResponseCodeHttpFallback { + input: ResponseCodeHttpFallbackInput, + output: ResponseCodeHttpFallbackOutput, +} + +@input +structure ResponseCodeHttpFallbackInput {} + +@output +structure ResponseCodeHttpFallbackOutput {} + apply HttpResponseCode @httpResponseTests([ { id: "RestJsonHttpResponseCode", @@ -71,5 +99,31 @@ apply HttpResponseCode @httpResponseTests([ Status: 201, }, appliesTo: "client" - }, + } +]) + +apply ResponseCodeRequired @httpResponseTests([ + { + id: "RestJsonHttpResponseCodeRequired", + documentation: """ + This test ensures that servers handle @httpResponseCode being @required.""", + protocol: restJson1, + code: 201, + body: "", + params: {"responseCode": 201} + appliesTo: "server" + } +]) + +apply ResponseCodeHttpFallback @httpResponseTests([ + { + id: "RestJsonHttpResponseCodeNotSetFallsBackToHttpCode", + documentation: """ + This test ensures that servers fall back to the code set + by @http if @httpResponseCode is not set.""", + protocol: restJson1, + code: 418, + body: "", + appliesTo: "server" + } ]) From 414b521e6f62beae2cdb3982e439ec650713e652 Mon Sep 17 00:00:00 2001 From: Daniele Ahmed Date: Thu, 26 May 2022 11:21:15 +0000 Subject: [PATCH 2/7] simplify Signed-off-by: Daniele Ahmed --- .../model/restJson1/http-response-code.smithy | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy b/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy index 7c2f5c3250a..5af6af2d40e 100644 --- a/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy @@ -21,13 +21,9 @@ structure HttpResponseCodeOutput { @http(method: "GET", uri: "/responseCodeRequired", code: 200) operation ResponseCodeRequired { - input: ResponseCodeRequiredInput, output: ResponseCodeRequiredOutput, } -@input -structure ResponseCodeRequiredInput {} - @output structure ResponseCodeRequiredOutput { @required @@ -37,15 +33,13 @@ structure ResponseCodeRequiredOutput { @http(method: "GET", uri: "/responseCodeHttpFallback", code: 418) operation ResponseCodeHttpFallback { - input: ResponseCodeHttpFallbackInput, - output: ResponseCodeHttpFallbackOutput, + input: ResponseCodeHttpFallbackInputOutput, + output: ResponseCodeHttpFallbackInputOutput, } @input -structure ResponseCodeHttpFallbackInput {} - @output -structure ResponseCodeHttpFallbackOutput {} +structure ResponseCodeHttpFallbackInputOutput {} apply HttpResponseCode @httpResponseTests([ { @@ -99,7 +93,7 @@ apply HttpResponseCode @httpResponseTests([ Status: 201, }, appliesTo: "client" - } + }, ]) apply ResponseCodeRequired @httpResponseTests([ From 410aa70420042cb81abe241e9029b9c363fb67ff Mon Sep 17 00:00:00 2001 From: Daniele Ahmed Date: Thu, 26 May 2022 15:00:27 +0000 Subject: [PATCH 3/7] address comment Signed-off-by: Daniele Ahmed --- .../model/restJson1/http-response-code.smithy | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy b/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy index 5af6af2d40e..c3063b4d1df 100644 --- a/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy @@ -104,7 +104,9 @@ apply ResponseCodeRequired @httpResponseTests([ protocol: restJson1, code: 201, body: "", - params: {"responseCode": 201} + params: { + responseCode: 201, + }, appliesTo: "server" } ]) From 2e2c90d177e4eaf519f77c4ddc0c3290a6619078 Mon Sep 17 00:00:00 2001 From: Daniele Ahmed Date: Thu, 26 May 2022 15:07:07 +0000 Subject: [PATCH 4/7] remove @input @output Signed-off-by: Daniele Ahmed --- .../model/restJson1/http-response-code.smithy | 2 -- 1 file changed, 2 deletions(-) diff --git a/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy b/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy index c3063b4d1df..913acab6e28 100644 --- a/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy @@ -37,8 +37,6 @@ operation ResponseCodeHttpFallback { output: ResponseCodeHttpFallbackInputOutput, } -@input -@output structure ResponseCodeHttpFallbackInputOutput {} apply HttpResponseCode @httpResponseTests([ From 4c7ee41a11218a3ceb0140ca351ae0d343e36ea9 Mon Sep 17 00:00:00 2001 From: Daniele Ahmed Date: Thu, 26 May 2022 15:11:33 +0000 Subject: [PATCH 5/7] change response code Signed-off-by: Daniele Ahmed --- .../model/restJson1/http-response-code.smithy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy b/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy index 913acab6e28..c132afaaeee 100644 --- a/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy @@ -31,7 +31,7 @@ structure ResponseCodeRequiredOutput { responseCode: Integer, } -@http(method: "GET", uri: "/responseCodeHttpFallback", code: 418) +@http(method: "GET", uri: "/responseCodeHttpFallback", code: 201) operation ResponseCodeHttpFallback { input: ResponseCodeHttpFallbackInputOutput, output: ResponseCodeHttpFallbackInputOutput, @@ -116,7 +116,7 @@ apply ResponseCodeHttpFallback @httpResponseTests([ This test ensures that servers fall back to the code set by @http if @httpResponseCode is not set.""", protocol: restJson1, - code: 418, + code: 201, body: "", appliesTo: "server" } From 77db0bf0e5ebe483ab7cc9daafa0b6106e9221dc Mon Sep 17 00:00:00 2001 From: Daniele Ahmed Date: Thu, 9 Jun 2022 14:22:36 +0000 Subject: [PATCH 6/7] address comments Signed-off-by: Daniele Ahmed --- .../model/restJson1/http-response-code.smithy | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy b/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy index c132afaaeee..5eb6a4af073 100644 --- a/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy @@ -101,7 +101,8 @@ apply ResponseCodeRequired @httpResponseTests([ This test ensures that servers handle @httpResponseCode being @required.""", protocol: restJson1, code: 201, - body: "", + body: "{}", + bodyMediaType: "application/json", params: { responseCode: 201, }, @@ -117,7 +118,8 @@ apply ResponseCodeHttpFallback @httpResponseTests([ by @http if @httpResponseCode is not set.""", protocol: restJson1, code: 201, - body: "", + body: "{}", + bodyMediaType: "application/json", appliesTo: "server" } ]) From 341a0cd2078bd6901c5a097a2e15b4e1d794194a Mon Sep 17 00:00:00 2001 From: 82marbag <69267416+82marbag@users.noreply.github.com> Date: Wed, 15 Jun 2022 15:18:48 +0000 Subject: [PATCH 7/7] address comment Signed-off-by: Daniele Ahmed --- .../model/restJson1/http-response-code.smithy | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy b/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy index 5eb6a4af073..79554c34c43 100644 --- a/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/http-response-code.smithy @@ -101,6 +101,9 @@ apply ResponseCodeRequired @httpResponseTests([ This test ensures that servers handle @httpResponseCode being @required.""", protocol: restJson1, code: 201, + headers: { + "Content-Type": "application/json" + }, body: "{}", bodyMediaType: "application/json", params: { @@ -118,6 +121,9 @@ apply ResponseCodeHttpFallback @httpResponseTests([ by @http if @httpResponseCode is not set.""", protocol: restJson1, code: 201, + headers: { + "Content-Type": "application/json" + }, body: "{}", bodyMediaType: "application/json", appliesTo: "server"