Skip to content

Commit

Permalink
fix: supporte moving default lists for xml parser (#3087)
Browse files Browse the repository at this point in the history
* fix: supporte moving default lists for xml parser

Currently for all xml service, the parser inserts empty
array [] when a list member doesn't exist in xml string.
It was introduced long ago: eae5b32
This change introduce a new key in metadata called
xmlNoDefaultLists. If set to true, xml parser will not
try to insert default empty array if the member doesn't
exist. This key is only applicable to rest-xml, query
protocol services.
  • Loading branch information
AllanZhengYP authored Feb 3, 2020
1 parent 3dd8ab4 commit e2e60a0
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/next-release/bugfix-parser-5e14f8ef.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": "bugfix",
"category": "parser",
"description": "Now we can disable inserting empty array in xml parser if the member doesn't exist in response."
}
3 changes: 2 additions & 1 deletion apis/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,8 @@
},
"s3control": {
"name": "S3Control",
"dualstackAvailable": true
"dualstackAvailable": true,
"xmlNoDefaultLists": true
},
"servicecatalog": {
"name": "ServiceCatalog",
Expand Down
7 changes: 7 additions & 0 deletions lib/model/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var Operation = require('./operation');
var Shape = require('./shape');
var Paginator = require('./paginator');
var ResourceWaiter = require('./resource_waiter');
var metadata = require('../../apis/metadata.json');

var util = require('../util');
var property = util.property;
Expand All @@ -16,6 +17,9 @@ function Api(api, options) {

api.metadata = api.metadata || {};

var serviceIdentifier = options.serviceIdentifier;
delete options.serviceIdentifier;

property(this, 'isApi', true, false);
property(this, 'apiVersion', api.metadata.apiVersion);
property(this, 'endpointPrefix', api.metadata.endpointPrefix);
Expand All @@ -30,6 +34,9 @@ function Api(api, options) {
property(this, 'abbreviation', api.metadata.serviceAbbreviation);
property(this, 'fullName', api.metadata.serviceFullName);
property(this, 'serviceId', api.metadata.serviceId);
if (serviceIdentifier) {
property(this, 'xmlNoDefaultLists', metadata[serviceIdentifier].xmlNoDefaultLists, false);
}

memoizedProperty(this, 'className', function() {
var name = api.metadata.serviceAbbreviation || api.metadata.serviceFullName;
Expand Down
4 changes: 3 additions & 1 deletion lib/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,9 @@ AWS.util.update(AWS.Service, {
if (api.isApi) {
svc.prototype.api = api;
} else {
svc.prototype.api = new Api(api);
svc.prototype.api = new Api(api, {
serviceIdentifier: superclass.serviceIdentifier
});
}
}

Expand Down
5 changes: 4 additions & 1 deletion lib/xml/browser_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ function parseStructure(xml, shape) {
getElementByTagName(xml, memberShape.name);
if (xmlChild) {
data[memberName] = parseXml(xmlChild, memberShape);
} else if (!memberShape.flattened && memberShape.type === 'list') {
} else if (
!memberShape.flattened &&
memberShape.type === 'list' &&
!shape.api.xmlNoDefaultLists) {
data[memberName] = memberShape.defaultValue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/xml/node_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function parseStructure(xml, shape) {
} else if (memberShape.isXmlAttribute &&
xml.$ && Object.prototype.hasOwnProperty.call(xml.$, xmlName)) {
data[memberName] = parseScalar(xml.$[xmlName], memberShape);
} else if (memberShape.type === 'list') {
} else if (memberShape.type === 'list' && !shape.api.xmlNoDefaultLists) {
data[memberName] = memberShape.defaultValue;
}
});
Expand Down
22 changes: 22 additions & 0 deletions test/xml/parser.spec.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e2e60a0

Please sign in to comment.