Skip to content

Commit

Permalink
Updated operation output rules descriptions to be structures.
Browse files Browse the repository at this point in the history
Previously output rules started at the structure members.
  • Loading branch information
trevorrowe committed Feb 19, 2013
1 parent f9f8fe9 commit c6a85e9
Show file tree
Hide file tree
Showing 8 changed files with 213 additions and 140 deletions.
9 changes: 6 additions & 3 deletions lib/service_interface/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,11 @@ AWS.ServiceInterface.Query = {
var rules = operation.output || {};

if (req.client.api.resultWrapped) {
var tmp = {};
tmp[wrapperKey] = {type: 'structure', members: rules};
var tmp = {
type: 'structure',
members: {}
}
tmp.members[wrapperKey] = rules
rules = tmp;
}

Expand All @@ -90,7 +93,7 @@ AWS.ServiceInterface.Query = {
}
}

AWS.util.each(operation.output || {}, function (memberName, memberRules) {
AWS.util.each((operation.output || {}).members || {}, function (memberName, memberRules) {
if (memberRules.wrapper && data[memberName]) {
AWS.util.update(data, data[memberName]);
delete data[memberName];
Expand Down
2 changes: 1 addition & 1 deletion lib/service_interface/rest.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ AWS.ServiceInterface.Rest = {
var data = {};
var r = resp.httpResponse;
var operation = req.client.api.operations[req.operation];
var rules = operation.output || {};
var rules = (operation.output || {}).members || {};

// normalize headers names to lower-cased keys for matching
var headers = {};
Expand Down
4 changes: 2 additions & 2 deletions lib/service_interface/rest_xml.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ AWS.ServiceInterface.RestXml = {
var req = resp.request;
var httpResponse = resp.httpResponse;
var operation = req.client.api.operations[req.operation];
var rules = operation.output || {};
var rules = (operation.output || {}).members || {};

if (operation.output_payload) {
var payload = httpResponse.body;
Expand All @@ -60,7 +60,7 @@ AWS.ServiceInterface.RestXml = {
}
resp.data[operation.output_payload] = payload;
} else if (httpResponse.body.length > 0) {
var parser = new AWS.XML.Parser(rules);
var parser = new AWS.XML.Parser(operation.output || {});
AWS.util.update(resp.data, parser.parse(httpResponse.body.toString()));
}

Expand Down
2 changes: 1 addition & 1 deletion lib/xml/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var xml2js = require('xml2js');
AWS.XML.Parser = inherit({

constructor: function XMLParser(rules) {
this.rules = rules;
this.rules = (rules || {}).members || {};
},

// options passed to xml2js parser
Expand Down
16 changes: 9 additions & 7 deletions test/unit/service_interface/query.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ describe 'AWS.ServiceInterface.Query', ->
Input:
members: {}
output:
Data:
type: 'structure'
members:
Name:
type: 'string'
Count:
type: 'float'
type: 'structure'
members:
Data:
type: 'structure'
members:
Name:
type: 'string'
Count:
type: 'float'

client = new MockQueryClient({region:'region'})
request = new AWS.Request(client, 'operationName')
Expand Down
66 changes: 40 additions & 26 deletions test/unit/service_interface/rest.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -156,40 +156,48 @@ describe 'AWS.ServiceInterface.Rest', ->
it 'extracts header values', ->
extractData ->
operation.output =
ContentType:
type: 'string'
location: 'header'
name: 'content-type'
type: 'structure'
members:
ContentType:
type: 'string'
location: 'header'
name: 'content-type'
response.httpResponse.headers['content-type'] = 'text/plain'
expect(response.data.ContentType).toEqual('text/plain')

it 'extracts headers when the rule name is camel-cased', ->
extractData ->
operation.output =
ContentType:
type: 'string'
location: 'header'
name: 'Content-Type'
type: 'structure'
members:
ContentType:
type: 'string'
location: 'header'
name: 'Content-Type'
response.httpResponse.headers['content-type'] = 'text/plain'
expect(response.data.ContentType).toEqual('text/plain')

it 'extracts headers when the header name is camel-cased', ->
extractData ->
operation.output =
ContentType:
type: 'string'
location: 'header'
name: 'content-type'
type: 'structure'
members:
ContentType:
type: 'string'
location: 'header'
name: 'content-type'
response.httpResponse.headers['Content-Type'] = 'text/plain'
expect(response.data.ContentType).toEqual('text/plain')

it 'extracts map types from header', ->
extractData ->
operation.output =
Metadata:
type: 'map'
location: 'header'
name: 'x-amz-meta-'
type: 'structure'
members:
Metadata:
type: 'map'
location: 'header'
name: 'x-amz-meta-'
response.httpResponse.headers['X-AMZ-META-FOO'] = 'foo'
response.httpResponse.headers['x-amz-meta-bar'] = 'bar'
expect(response.data.Metadata.FOO).toEqual('foo')
Expand All @@ -198,27 +206,33 @@ describe 'AWS.ServiceInterface.Rest', ->
it 'adds empty map if no matching headers are found', ->
extractData ->
operation.output =
Metadata:
type: 'map'
location: 'header'
name: 'x-amz-meta-'
type: 'structure'
members:
Metadata:
type: 'map'
location: 'header'
name: 'x-amz-meta-'
expect(response.data.Metadata).toEqual({})

describe 'status code', ->
it 'extracts the http status when instructed to', ->
extractData ->
operation.output =
Result:
type: 'integer'
location: 'status'
type: 'structure'
members:
Result:
type: 'integer'
location: 'status'
response.httpResponse.statusCode = 200
expect(response.data.Result).toEqual(200)

it 'casts string status codes to integers', ->
extractData ->
operation.output =
Result:
type: 'integer'
location: 'status'
type: 'structure'
members:
Result:
type: 'integer'
location: 'status'
response.httpResponse.statusCode = '202'
expect(response.data.Result).toEqual(202)
36 changes: 26 additions & 10 deletions test/unit/service_interface/rest_xml.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,14 @@ describe 'AWS.ServiceInterface.RestXml', ->
svc.extractData(response)

it 'parses the xml body', ->
operation.output = {Foo:{},Bar:{type:'list',members:{name:'Item'}}}
operation.output =
type: 'structure'
members:
Foo: {}
Bar:
type: 'list'
members:
name: 'Item'
extractData """
<xml>
<Foo>foo</Foo>
Expand All @@ -255,14 +262,21 @@ describe 'AWS.ServiceInterface.RestXml', ->

it 'sets payload element to a Buffer object when it streams', ->
operation.output_payload = 'Body'
operation.output = {Body:{streaming:true}}
operation.output =
type: 'structure'
members:
Body:
streaming: true
extractData 'Buffer data'
expect(response.data.Body instanceof Buffer).toBeTruthy()
expect(response.data.Body.toString()).toEqual('Buffer data')

it 'sets payload element to String when it does not stream', ->
operation.output_payload = 'Body'
operation.output = {Body:{}}
operation.output =
type: 'structure'
members:
Body: {}
extractData 'Buffer data'
expect(typeof response.data.Body).toEqual('string')
expect(response.data.Body).toEqual('Buffer data')
Expand All @@ -271,13 +285,15 @@ describe 'AWS.ServiceInterface.RestXml', ->
response.httpResponse.headers['x-amz-foo'] = 'foo'
response.httpResponse.headers['x-amz-bar'] = 'bar'
operation.output =
Foo:
location: 'header'
name: 'x-amz-foo'
Bar:
location: 'header'
name: 'x-amz-bar'
Baz: {}
type: 'structure'
members:
Foo:
location: 'header'
name: 'x-amz-foo'
Bar:
location: 'header'
name: 'x-amz-bar'
Baz: {}
operation.output_payload = 'Baz'
extractData 'Buffer data'
expect(response.data.Foo).toEqual('foo')
Expand Down
Loading

0 comments on commit c6a85e9

Please sign in to comment.