diff --git a/.changes/next-release/feature-protocol-2b945450.json b/.changes/next-release/feature-protocol-2b945450.json new file mode 100644 index 0000000000..3e50b1e941 --- /dev/null +++ b/.changes/next-release/feature-protocol-2b945450.json @@ -0,0 +1,5 @@ +{ + "type": "feature", + "category": "protocol", + "description": "Update protocol tests" +} \ No newline at end of file diff --git a/test/fixtures/protocol/input/rest-json.json b/test/fixtures/protocol/input/rest-json.json index 293b4bfc30..d18b7b9043 100644 --- a/test/fixtures/protocol/input/rest-json.json +++ b/test/fixtures/protocol/input/rest-json.json @@ -1620,5 +1620,148 @@ } } ] + }, + { + "description": "Union trait", + "metadata": { + "protocol": "rest-json", + "apiVersion": "2014-01-01" + }, + "shapes": { + "InputShape": { + "type": "structure", + "members": { + "OneOf": {"shape": "MyUnion"} + } + }, + "MyUnion": { + "type": "structure", + "union": true, + "members": { + "a": {"shape": "StringType"}, + "b": {"shape": "StringType"}, + "c": {"shape": "Struct"}, + "d": {"shape": "Struct"}, + "e": {"shape": "ComplexList"} + } + }, + "StringType": { + "type": "string" + }, + "Struct": { + "type": "structure", + "members": { + "hello": {"shape": "StringType"} + } + }, + "ComplexList": { + "type": "list", + "member": {"shape": "Struct"} + } + }, + "cases": [ + { + "given": { + "input": { + "shape": "InputShape" + }, + "http": { + "method": "POST" + }, + "name": "OperationName" + }, + "params": { + "OneOf": {"a": "hi"} + }, + "serialized": { + "uri": "/", + "body": "{\"OneOf\": {\"a\": \"hi\"}}" + } + }, + { + "given": { + "input": { + "shape": "InputShape" + }, + "http": { + "method": "POST" + }, + "name": "OperationName" + }, + "params": { + "OneOf": {"b": "hi"} + }, + "serialized": { + "uri": "/", + "body": "{\"OneOf\": {\"b\": \"hi\"}}" + } + }, + { + "given": { + "input": { + "shape": "InputShape" + }, + "http": { + "method": "POST" + }, + "name": "OperationName" + }, + "params": { + "OneOf": { + "c": { + "hello": "hi" + } + } + }, + "serialized": { + "uri": "/", + "body": "{\"OneOf\": {\"c\": {\"hello\": \"hi\"}}}" + } + }, + { + "given": { + "input": { + "shape": "InputShape" + }, + "http": { + "method": "POST" + }, + "name": "OperationName" + }, + "params": { + "OneOf": { + "d": { + "hello": "hi" + } + } + }, + "serialized": { + "uri": "/", + "body": "{\"OneOf\": {\"d\": {\"hello\": \"hi\"}}}" + } + }, + { + "given": { + "input": { + "shape": "InputShape" + }, + "http": { + "method": "POST" + }, + "name": "OperationName" + }, + "params": { + "OneOf": { + "e": [ + {"hello": "hi"} + ] + } + }, + "serialized": { + "uri": "/", + "body": "{\"OneOf\": {\"e\": [{\"hello\": \"hi\"}]}}" + } + } + ] } ] diff --git a/test/fixtures/protocol/output/ec2.json b/test/fixtures/protocol/output/ec2.json index f2a25dc3e3..bbef7ef9d5 100644 --- a/test/fixtures/protocol/output/ec2.json +++ b/test/fixtures/protocol/output/ec2.json @@ -567,5 +567,92 @@ } } ] + }, + { + "description": "Modeled exceptions", + "metadata": { + "protocol": "ec2" + }, + "shapes": { + "ExceptionShape": { + "type": "structure", + "members": { + "Status": { + "shape": "StatusShape", + "location": "statusCode" + }, + "BodyMember": { + "shape": "StringType" + }, + "Message": { + "shape": "StringType" + } + } + }, + "OtherExceptionShape": { + "BodyMember": { + "shape": "StringType" + } + }, + "StatusShape": { + "type": "integer" + }, + "StringType": { + "type": "string" + } + }, + "cases": [ + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": { + "Status": 400, + "BodyMember": "mybody", + "Message": "mymessage" + }, + "errorCode": "ExceptionShape", + "errorMessage": "mymessage", + "response": { + "status_code": 400, + "headers": {}, + "body": "ExceptionShapemymessagemybody" + } + }, + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": {}, + "errorCode": "OtherExceptionShape", + "errorMessage": "mymessage", + "response": { + "status_code": 400, + "headers": {}, + "body": "OtherExceptionShapemymessagemybody" + } + }, + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": {}, + "errorCode": "UndefinedShape", + "response": { + "status_code": 400, + "headers": {}, + "body": "UndefinedShapemybody" + } + } + ] } ] diff --git a/test/fixtures/protocol/output/json.json b/test/fixtures/protocol/output/json.json index 9b70b80e48..521ec6acce 100644 --- a/test/fixtures/protocol/output/json.json +++ b/test/fixtures/protocol/output/json.json @@ -431,5 +431,151 @@ } } ] + }, + { + "description": "Modeled exceptions", + "metadata": { + "protocol": "json" + }, + "shapes": { + "ExceptionShape": { + "type": "structure", + "members": { + "Status": { + "shape": "StatusShape", + "location": "statusCode" + }, + "BodyMember": { + "shape": "StringType" + }, + "Code": { + "shape": "StringType" + }, + "Message": { + "shape": "StringType" + } + } + }, + "OtherExceptionShape": { + "BodyMember": { + "shape": "StringType" + } + }, + "StatusShape": { + "type": "integer" + }, + "StringType": { + "type": "string" + } + }, + "cases": [ + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": { + "Status": 400, + "BodyMember": "mybody", + "Code": "OtherExceptionShape", + "Message": "mymessage" + }, + "errorCode": "ExceptionShape", + "errorMessage": "mymessage", + "response": { + "status_code": 400, + "headers": {}, + "body": "{ \"__type\": \"ExceptionShape\", \"Code\": \"OtherExceptionShape\", \"BodyMember\": \"mybody\", \"Message\": \"mymessage\"}" + } + }, + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": {}, + "errorCode": "OtherExceptionShape", + "errorMessage": "mymessage", + "response": { + "status_code": 400, + "headers": {}, + "body": "{ \"__type\": \"OtherExceptionShape\", \"Code\": \"ExceptionShape\", \"BodyMember\": \"mybody\", \"Message\": \"mymessage\"}" + } + }, + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": {}, + "errorCode": "UndefinedShape", + "response": { + "status_code": 400, + "headers": { + "ImaHeader": "test", + "X-Foo": "abc" + }, + "body": "{ \"__type\": \"UndefinedShape\", \"Code\": \"ExceptionShape\", \"BodyMember\": \"mybody\"}" + } + } + ] + }, + { + "description": "Modeled exceptions with jsonVersion 1.0", + "metadata": { + "protocol": "json", + "jsonVersion": "1.0" + }, + "shapes": { + "ExceptionShape": { + "type": "structure", + "members": { + "Status": { + "shape": "StatusShape", + "location": "statusCode" + }, + "BodyMember": { + "shape": "StringType" + }, + "Message": { + "shape": "StringType" + } + } + }, + "StatusShape": { + "type": "integer" + }, + "StringType": { + "type": "string" + } + }, + "cases": [ + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": { + "Status": 400, + "BodyMember": "mybody", + "Message": "mymessage" + }, + "errorCode": "ExceptionShape", + "errorMessage": "mymessage", + "response": { + "status_code": 400, + "headers": {}, + "body": "{ \"__type\": \"FooPrefix#ExceptionShape\", \"BodyMember\": \"mybody\", \"Message\": \"mymessage\"}" + } + } + ] } ] diff --git a/test/fixtures/protocol/output/query.json b/test/fixtures/protocol/output/query.json index a2fd3a52ed..02963cf992 100644 --- a/test/fixtures/protocol/output/query.json +++ b/test/fixtures/protocol/output/query.json @@ -889,5 +889,92 @@ } } ] + }, + { + "description": "Modeled exceptions", + "metadata": { + "protocol": "query" + }, + "shapes": { + "ExceptionShape": { + "type": "structure", + "members": { + "Status": { + "shape": "StatusShape", + "location": "statusCode" + }, + "BodyMember": { + "shape": "StringType" + }, + "Message": { + "shape": "StringType" + } + } + }, + "OtherExceptionShape": { + "BodyMember": { + "shape": "StringType" + } + }, + "StatusShape": { + "type": "integer" + }, + "StringType": { + "type": "string" + } + }, + "cases": [ + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": { + "Status": 400, + "BodyMember": "mybody", + "Message": "mymessage" + }, + "errorCode": "ExceptionShape", + "errorMessage": "mymessage", + "response": { + "status_code": 400, + "headers": {}, + "body": "SomeTypeExceptionShapemymessagemybody" + } + }, + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": {}, + "errorCode": "OtherExceptionShape", + "errorMessage": "mymessage", + "response": { + "status_code": 400, + "headers": {}, + "body": "SomeTypeOtherExceptionShapemymessagemybody" + } + }, + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": {}, + "errorCode": "UndefinedShape", + "response": { + "status_code": 400, + "headers": {}, + "body": "SomeTypeUndefinedShapemybody" + } + } + ] } ] diff --git a/test/fixtures/protocol/output/rest-json.json b/test/fixtures/protocol/output/rest-json.json index 7f2badddaa..c98b641802 100644 --- a/test/fixtures/protocol/output/rest-json.json +++ b/test/fixtures/protocol/output/rest-json.json @@ -733,6 +733,34 @@ "headers": {}, "body": "{\"BodyListField\":[\"{\\\"Foo\\\":\\\"Bar\\\"}\"]}" } + }, + { + "given": { + "output": { + "shape": "OutputShape" + }, + "name": "OperationName" + }, + "result": { + "HeaderField": {"Foo":{}} + }, + "response": { + "status_code": 200, + "headers": {"X-Amz-Foo": "e30="} + } + }, + { + "given": { + "output": { + "shape": "OutputShape" + }, + "name": "OperationName" + }, + "result": {}, + "response": { + "status_code": 200, + "headers": {"X-Amz-Foo": ""} + } } ] }, @@ -815,5 +843,331 @@ } } ] + }, + { + "description": "Modeled exceptions", + "metadata": { + "protocol": "rest-json" + }, + "shapes": { + "ExceptionShape": { + "type": "structure", + "members": { + "ImaHeader": { + "shape": "HeaderShape" + }, + "ImaHeaderLocation": { + "shape": "HeaderShape", + "locationName": "X-Foo" + }, + "Status": { + "shape": "StatusShape", + "location": "statusCode" + }, + "BodyMember": { + "shape": "StringType" + }, + "Message": { + "shape": "StringType" + } + } + }, + "OtherExceptionShape": { + "BodyMember": { + "shape": "StringType" + } + }, + "HeaderShape": { + "type": "string", + "location": "header" + }, + "StatusShape": { + "type": "integer" + }, + "StringType": { + "type": "string" + } + }, + "cases": [ + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": { + "ImaHeader": "test", + "ImaHeaderLocation": "abc", + "Status": 400, + "BodyMember": "mybody", + "Message": "mymessage" + }, + "errorCode": "ExceptionShape", + "errorMessage": "mymessage", + "response": { + "status_code": 400, + "headers": { + "ImaHeader": "test", + "X-Foo": "abc", + "X-Amzn-Errortype": "ExceptionShape" + }, + "body": "{\"BodyMember\": \"mybody\", \"Message\": \"mymessage\"}" + } + }, + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": { + "ImaHeader": "test", + "ImaHeaderLocation": "abc", + "Status": 400, + "BodyMember": "mybody", + "Message": "mymessage" + }, + "errorCode": "ExceptionShape", + "errorMessage": "mymessage", + "response": { + "status_code": 400, + "headers": { + "ImaHeader": "test", + "X-Foo": "abc" + }, + "body": "{ \"code\": \"ExceptionShape\", \"BodyMember\": \"mybody\", \"Message\": \"mymessage\"}" + } + }, + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": { + "ImaHeader": "test", + "ImaHeaderLocation": "abc", + "Status": 400, + "BodyMember": "mybody", + "Message": "mymessage" + }, + "errorCode": "ExceptionShape", + "errorMessage": "mymessage", + "response": { + "status_code": 400, + "headers": { + "ImaHeader": "test", + "X-Foo": "abc", + "X-Amzn-Errortype": "ExceptionShape" + }, + "body": "{ \"code\": \"OtherExceptionShape\", \"BodyMember\": \"mybody\", \"Message\": \"mymessage\"}" + } + }, + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": {}, + "errorCode": "OtherExceptionShape", + "errorMessage": "mymessage", + "response": { + "status_code": 400, + "headers": { + "ImaHeader": "test", + "X-Foo": "abc", + "X-Amzn-Errortype": "OtherExceptionShape" + }, + "body": "{ \"BodyMember\": \"mybody\", \"Message\": \"mymessage\"}" + } + }, + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": {}, + "errorCode": "OtherExceptionShape", + "errorMessage": "mymessage", + "response": { + "status_code": 400, + "headers": { + "ImaHeader": "test", + "X-Foo": "abc" + }, + "body": "{ \"code\": \"OtherExceptionShape\", \"BodyMember\": \"mybody\", \"Message\": \"mymessage\"}" + } + }, + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": {}, + "errorCode": "UndefinedShape", + "response": { + "status_code": 400, + "headers": { + "ImaHeader": "test", + "X-Foo": "abc", + "X-Amzn-Errortype": "UndefinedShape" + }, + "body": "{ \"BodyMember\": \"mybody\"}" + } + }, + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": {}, + "errorCode": "UndefinedShape", + "response": { + "status_code": 400, + "headers": { + "ImaHeader": "test", + "X-Foo": "abc" + }, + "body": "{ \"code\": \"UndefinedShape\", \"BodyMember\": \"mybody\"}" + } + } + ] + }, + { + "description": "Unions", + "metadata": { + "protocol": "rest-json" + }, + "shapes": { + "OutputShape": { + "type": "structure", + "members": { + "OneOf": { + "shape": "MyUnion" + } + } + }, + "MyUnion": { + "type": "structure", + "union": true, + "members": { + "a": {"shape": "StringType"}, + "b": {"shape": "StringType"}, + "c": {"shape": "Struct"}, + "d": {"shape": "Struct"}, + "e": {"shape": "ComplexList"} + } + }, + "StringType": { + "type": "string" + }, + "Struct": { + "type": "structure", + "members": { + "hello": {"shape": "StringType"} + } + }, + "ComplexList": { + "type": "list", + "member": {"shape": "Struct"} + } + }, + "cases": [ + { + "given": { + "output": { + "shape": "OutputShape" + }, + "name": "OperationName" + }, + "result": { + "OneOf": {"a": "hi"} + }, + "response": { + "status_code": 200, + "headers": {}, + "body": "{\"OneOf\": {\"a\": \"hi\"}}" + } + }, + { + "given": { + "output": { + "shape": "OutputShape" + }, + "name": "OperationName" + }, + "result": { + "OneOf": {"b": "hi"} + }, + "response": { + "status_code": 200, + "headers": {}, + "body": "{\"OneOf\": {\"b\": \"hi\"}}" + } + }, + { + "given": { + "output": { + "shape": "OutputShape" + }, + "name": "OperationName" + }, + "result": { + "OneOf": {"c": {"hello": "hi"}} + }, + "response": { + "status_code": 200, + "headers": {}, + "body": "{\"OneOf\": {\"c\": {\"hello\": \"hi\"}}}" + } + }, + { + "given": { + "output": { + "shape": "OutputShape" + }, + "name": "OperationName" + }, + "result": { + "OneOf": {"d": {"hello": "hi"}} + }, + "response": { + "status_code": 200, + "headers": {}, + "body": "{\"OneOf\": {\"d\": {\"hello\": \"hi\"}}}" + } + }, + { + "given": { + "output": { + "shape": "OutputShape" + }, + "name": "OperationName" + }, + "result": { + "OneOf": { + "e": [ + {"hello": "hi"} + ] + } + }, + "response": { + "status_code": 200, + "headers": {}, + "body": "{\"OneOf\": {\"e\": [{\"hello\": \"hi\"}]}}" + } + } + ] } ] diff --git a/test/fixtures/protocol/output/rest-xml.json b/test/fixtures/protocol/output/rest-xml.json index 0260b915ca..385a30e6ae 100644 --- a/test/fixtures/protocol/output/rest-xml.json +++ b/test/fixtures/protocol/output/rest-xml.json @@ -968,5 +968,117 @@ } } ] + }, + { + "description": "Modeled exceptions", + "metadata": { + "protocol": "rest-xml" + }, + "shapes": { + "ExceptionShape": { + "type": "structure", + "members": { + "ImaHeader": { + "shape": "HeaderShape" + }, + "ImaHeaderLocation": { + "shape": "HeaderShape", + "locationName": "X-Foo" + }, + "Status": { + "shape": "StatusShape", + "location": "statusCode" + }, + "BodyMember": { + "shape": "StringType" + }, + "Message": { + "shape": "StringType" + } + } + }, + "OtherExceptionShape": { + "BodyMember": { + "shape": "StringType" + } + }, + "HeaderShape": { + "type": "string", + "location": "header" + }, + "StatusShape": { + "type": "integer" + }, + "StringType": { + "type": "string" + } + }, + "cases": [ + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": { + "ImaHeader": "test", + "ImaHeaderLocation": "abc", + "Status": 400, + "BodyMember": "mybody", + "Message": "mymessage" + }, + "errorCode": "ExceptionShape", + "errorMessage": "mymessage", + "response": { + "status_code": 400, + "headers": { + "ImaHeader": "test", + "X-Foo": "abc", + "X-Amzn-Requestid": "foo-id" + }, + "body": "SomeTypeExceptionShapemymessagemybody" + } + }, + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": {}, + "errorCode": "OtherExceptionShape", + "errorMessage": "mymessage", + "response": { + "status_code": 400, + "headers": { + "ImaHeader": "test", + "X-Foo": "abc", + "X-Amzn-Requestid": "foo-id" + }, + "body": "SomeTypeOtherExceptionShapemymessagemybody" + } + }, + { + "given": { + "errors": [ + {"shape": "ExceptionShape"} + ], + "name": "OperationName" + }, + "error": {}, + "errorCode": "UndefinedShape", + "response": { + "status_code": 400, + "headers": { + "ImaHeader": "test", + "X-Foo": "abc", + "X-Amzn-Requestid": "foo-id" + }, + "body": "SomeTypeUndefinedShapemybody" + } + } + ] } ] diff --git a/test/protocol/protocol.spec.js b/test/protocol/protocol.spec.js index abfe281a10..77b088e8f8 100644 --- a/test/protocol/protocol.spec.js +++ b/test/protocol/protocol.spec.js @@ -125,9 +125,11 @@ expectedData = formatData(_case.result, svc.api.operations[_case.op].output); resultData = formatData(req.response.data, svc.api.operations[_case.op].output); results = []; - for (k in expectedData) { - v = expectedData[k]; - results.push(expect(resultData[k]).to.eql(v)); + if (resultData) { + for (k in expectedData) { + v = expectedData[k]; + results.push(expect(resultData[k]).to.eql(v)); + } } return results; };