|
| 1 | +$version: "1.0" |
| 2 | + |
| 3 | +namespace aws.protocoltests.restjson.validation |
| 4 | + |
| 5 | +use aws.protocols#restJson1 |
| 6 | +use smithy.test#httpMalformedRequestTests |
| 7 | +use smithy.framework#ValidationException |
| 8 | + |
| 9 | +@http(uri: "/MalformedEnum", method: "POST") |
| 10 | +operation MalformedEnum { |
| 11 | + input: MalformedEnumInput, |
| 12 | + errors: [ValidationException] |
| 13 | +} |
| 14 | + |
| 15 | +apply MalformedEnum @httpMalformedRequestTests([ |
| 16 | + { |
| 17 | + id: "RestJsonMalformedEnumString", |
| 18 | + documentation: """ |
| 19 | + When a string member does not contain a valid enum value, |
| 20 | + the response should be a 400 ValidationException.""", |
| 21 | + protocol: restJson1, |
| 22 | + request: { |
| 23 | + method: "POST", |
| 24 | + uri: "/MalformedEnum", |
| 25 | + body: """ |
| 26 | + { "string" : $value:S }""", |
| 27 | + headers: { |
| 28 | + "content-type": "application/json" |
| 29 | + } |
| 30 | + }, |
| 31 | + response: { |
| 32 | + code: 400, |
| 33 | + headers: { |
| 34 | + "x-amzn-errortype": "ValidationException" |
| 35 | + }, |
| 36 | + body: { |
| 37 | + mediaType: "application/json", |
| 38 | + assertion: { |
| 39 | + contents: """ |
| 40 | + { "message" : "1 validation error detected. Value $value:L at '/string' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", |
| 41 | + "fieldList" : [{"message": "Value $value:L at '/string' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", "path": "/string"}]}""" |
| 42 | + } |
| 43 | + } |
| 44 | + }, |
| 45 | + testParameters: { |
| 46 | + value: ["ABC", "XYZ"] |
| 47 | + } |
| 48 | + }, |
| 49 | + { |
| 50 | + id: "RestJsonMalformedEnumList", |
| 51 | + documentation: """ |
| 52 | + When a list member value does not contain a valid enum value, |
| 53 | + the response should be a 400 ValidationException.""", |
| 54 | + protocol: restJson1, |
| 55 | + request: { |
| 56 | + method: "POST", |
| 57 | + uri: "/MalformedEnum", |
| 58 | + body: """ |
| 59 | + { "list" : [$value:S] }""", |
| 60 | + headers: { |
| 61 | + "content-type": "application/json" |
| 62 | + } |
| 63 | + }, |
| 64 | + response: { |
| 65 | + code: 400, |
| 66 | + headers: { |
| 67 | + "x-amzn-errortype": "ValidationException" |
| 68 | + }, |
| 69 | + body: { |
| 70 | + mediaType: "application/json", |
| 71 | + assertion: { |
| 72 | + contents: """ |
| 73 | + { "message" : "1 validation error detected. Value $value:L at '/list/0' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", |
| 74 | + "fieldList" : [{"message": "Value $value:L at '/list/0' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", "path": "/list/0"}]}""" |
| 75 | + } |
| 76 | + } |
| 77 | + }, |
| 78 | + testParameters: { |
| 79 | + value: ["ABC", "XYZ"] |
| 80 | + } |
| 81 | + }, |
| 82 | + { |
| 83 | + id: "RestJsonMalformedEnumMapKey", |
| 84 | + documentation: """ |
| 85 | + When a map member's key does not contain a valid enum value, |
| 86 | + the response should be a 400 ValidationException.""", |
| 87 | + protocol: restJson1, |
| 88 | + request: { |
| 89 | + method: "POST", |
| 90 | + uri: "/MalformedEnum", |
| 91 | + body: """ |
| 92 | + { "map" : { $value:S : "abc" } }""", |
| 93 | + headers: { |
| 94 | + "content-type": "application/json" |
| 95 | + } |
| 96 | + }, |
| 97 | + response: { |
| 98 | + code: 400, |
| 99 | + headers: { |
| 100 | + "x-amzn-errortype": "ValidationException" |
| 101 | + }, |
| 102 | + body: { |
| 103 | + mediaType: "application/json", |
| 104 | + assertion: { |
| 105 | + contents: """ |
| 106 | + { "message" : "1 validation error detected. Value $value:L at '/map' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", |
| 107 | + "fieldList" : [{"message": "Value $value:L at '/map' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", "path": "/map"}]}""" |
| 108 | + } |
| 109 | + } |
| 110 | + }, |
| 111 | + testParameters: { |
| 112 | + value: ["ABC", "XYZ"] |
| 113 | + } |
| 114 | + }, |
| 115 | + { |
| 116 | + id: "RestJsonMalformedEnumMapValue", |
| 117 | + documentation: """ |
| 118 | + When a map member's value does not contain a valid enum value, |
| 119 | + the response should be a 400 ValidationException.""", |
| 120 | + protocol: restJson1, |
| 121 | + request: { |
| 122 | + method: "POST", |
| 123 | + uri: "/MalformedEnum", |
| 124 | + body: """ |
| 125 | + { "map" : { "abc": $value:S } }""", |
| 126 | + headers: { |
| 127 | + "content-type": "application/json" |
| 128 | + } |
| 129 | + }, |
| 130 | + response: { |
| 131 | + code: 400, |
| 132 | + headers: { |
| 133 | + "x-amzn-errortype": "ValidationException" |
| 134 | + }, |
| 135 | + body: { |
| 136 | + mediaType: "application/json", |
| 137 | + assertion: { |
| 138 | + contents: """ |
| 139 | + { "message" : "1 validation error detected. Value $value:L at '/map/abc' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", |
| 140 | + "fieldList" : [{"message": "Value $value:L at '/map/abc' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", "path": "/map/abc"}]}""" |
| 141 | + } |
| 142 | + } |
| 143 | + }, |
| 144 | + testParameters: { |
| 145 | + value: ["ABC", "XYZ"] |
| 146 | + } |
| 147 | + }, |
| 148 | + { |
| 149 | + id: "RestJsonMalformedEnumUnion", |
| 150 | + documentation: """ |
| 151 | + When a union member's value does not contain a valid enum value, |
| 152 | + the response should be a 400 ValidationException.""", |
| 153 | + protocol: restJson1, |
| 154 | + request: { |
| 155 | + method: "POST", |
| 156 | + uri: "/MalformedEnum", |
| 157 | + body: """ |
| 158 | + { "union" : { "first": $value:S } }""", |
| 159 | + headers: { |
| 160 | + "content-type": "application/json" |
| 161 | + } |
| 162 | + }, |
| 163 | + response: { |
| 164 | + code: 400, |
| 165 | + headers: { |
| 166 | + "x-amzn-errortype": "ValidationException" |
| 167 | + }, |
| 168 | + body: { |
| 169 | + mediaType: "application/json", |
| 170 | + assertion: { |
| 171 | + contents: """ |
| 172 | + { "message" : "1 validation error detected. Value $value:L at '/union/first' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", |
| 173 | + "fieldList" : [{"message": "Value $value:L at '/union/first' failed to satisfy constraint: Member must satisfy enum value set: [abc, def]", "path": "/union/first"}]}""" |
| 174 | + } |
| 175 | + } |
| 176 | + }, |
| 177 | + testParameters: { |
| 178 | + value: ["ABC", "XYZ"] |
| 179 | + } |
| 180 | + }, |
| 181 | +]) |
| 182 | + |
| 183 | +structure MalformedEnumInput { |
| 184 | + string: EnumString, |
| 185 | + |
| 186 | + list: EnumList, |
| 187 | + |
| 188 | + map: EnumMap, |
| 189 | + |
| 190 | + union: EnumUnion |
| 191 | +} |
| 192 | + |
| 193 | +@enum([{value: "abc", name: "ABC"}, {value: "def", name: "DEF"}]) |
| 194 | +string EnumString |
| 195 | + |
| 196 | +list EnumList { |
| 197 | + member: EnumString |
| 198 | +} |
| 199 | + |
| 200 | +map EnumMap { |
| 201 | + key: EnumString, |
| 202 | + value: EnumString |
| 203 | +} |
| 204 | + |
| 205 | +union EnumUnion { |
| 206 | + first: EnumString, |
| 207 | + second: EnumString |
| 208 | +} |
0 commit comments