From 92ed89a2079e3962e6f8890af9587cf55dc39fc3 Mon Sep 17 00:00:00 2001 From: Chase Coalwell <782571+srchase@users.noreply.github.com> Date: Tue, 14 Mar 2023 08:25:05 -0600 Subject: [PATCH] Add EnumTrait validation test --- .../validation/malformed-enum.smithy | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/smithy-aws-protocol-tests/model/restJson1/validation/malformed-enum.smithy b/smithy-aws-protocol-tests/model/restJson1/validation/malformed-enum.smithy index c9843f51265..78567f53102 100644 --- a/smithy-aws-protocol-tests/model/restJson1/validation/malformed-enum.smithy +++ b/smithy-aws-protocol-tests/model/restJson1/validation/malformed-enum.smithy @@ -48,6 +48,40 @@ apply MalformedEnum @httpMalformedRequestTests([ value: ["ABC", "XYZ"] } }, + { + id: "RestJsonMalformedEnumTraitString", + documentation: """ + When a string member does not contain a valid enum value, + the response should be a 400 ValidationException. Internal-only + enum values are excluded from the response message.""", + protocol: restJson1, + request: { + method: "POST", + uri: "/MalformedEnum", + body: """ + { "stringWithEnumTrait" : $value:S }""", + headers: { + "content-type": "application/json" + } + }, + response: { + code: 400, + headers: { + "x-amzn-errortype": "ValidationException" + }, + body: { + mediaType: "application/json", + assertion: { + contents: """ + { "message" : "1 validation error detected. Value at '/stringWithEnumTrait' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", + "fieldList" : [{"message": "Value at '/stringWithEnumTrait' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", "path": "/stringWithEnumTrait"}]}""" + } + } + }, + testParameters: { + value: ["ABC", "XYZ"] + } + }, { id: "RestJsonMalformedEnumList", documentation: """ @@ -189,6 +223,8 @@ apply MalformedEnum @httpMalformedRequestTests([ structure MalformedEnumInput { string: EnumString, + stringWithEnumTrait: EnumTraitString, + list: EnumList, map: EnumMap, @@ -207,6 +243,13 @@ enum EnumString { JKL = "jkl" } +@enum([ + {value: "abc", name: "ABC", tags: ["external"]}, + {value: "def", name: "DEF"}, + {value: "ghi", name: "GHI", tags: ["internal"]}, +]) +string EnumTraitString + list EnumList { member: EnumString }