Skip to content

Commit e2e60a0

Browse files
authored
fix: supporte moving default lists for xml parser (#3087)
* 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.
1 parent 3dd8ab4 commit e2e60a0

File tree

7 files changed

+44
-4
lines changed

7 files changed

+44
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "bugfix",
3+
"category": "parser",
4+
"description": "Now we can disable inserting empty array in xml parser if the member doesn't exist in response."
5+
}

apis/metadata.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,8 @@
360360
},
361361
"s3control": {
362362
"name": "S3Control",
363-
"dualstackAvailable": true
363+
"dualstackAvailable": true,
364+
"xmlNoDefaultLists": true
364365
},
365366
"servicecatalog": {
366367
"name": "ServiceCatalog",

lib/model/api.js

+7
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var Operation = require('./operation');
33
var Shape = require('./shape');
44
var Paginator = require('./paginator');
55
var ResourceWaiter = require('./resource_waiter');
6+
var metadata = require('../../apis/metadata.json');
67

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

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

20+
var serviceIdentifier = options.serviceIdentifier;
21+
delete options.serviceIdentifier;
22+
1923
property(this, 'isApi', true, false);
2024
property(this, 'apiVersion', api.metadata.apiVersion);
2125
property(this, 'endpointPrefix', api.metadata.endpointPrefix);
@@ -30,6 +34,9 @@ function Api(api, options) {
3034
property(this, 'abbreviation', api.metadata.serviceAbbreviation);
3135
property(this, 'fullName', api.metadata.serviceFullName);
3236
property(this, 'serviceId', api.metadata.serviceId);
37+
if (serviceIdentifier) {
38+
property(this, 'xmlNoDefaultLists', metadata[serviceIdentifier].xmlNoDefaultLists, false);
39+
}
3340

3441
memoizedProperty(this, 'className', function() {
3542
var name = api.metadata.serviceAbbreviation || api.metadata.serviceFullName;

lib/service.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,9 @@ AWS.util.update(AWS.Service, {
751751
if (api.isApi) {
752752
svc.prototype.api = api;
753753
} else {
754-
svc.prototype.api = new Api(api);
754+
svc.prototype.api = new Api(api, {
755+
serviceIdentifier: superclass.serviceIdentifier
756+
});
755757
}
756758
}
757759

lib/xml/browser_parser.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,10 @@ function parseStructure(xml, shape) {
108108
getElementByTagName(xml, memberShape.name);
109109
if (xmlChild) {
110110
data[memberName] = parseXml(xmlChild, memberShape);
111-
} else if (!memberShape.flattened && memberShape.type === 'list') {
111+
} else if (
112+
!memberShape.flattened &&
113+
memberShape.type === 'list' &&
114+
!shape.api.xmlNoDefaultLists) {
112115
data[memberName] = memberShape.defaultValue;
113116
}
114117
}

lib/xml/node_parser.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function parseStructure(xml, shape) {
7070
} else if (memberShape.isXmlAttribute &&
7171
xml.$ && Object.prototype.hasOwnProperty.call(xml.$, xmlName)) {
7272
data[memberName] = parseScalar(xml.$[xmlName], memberShape);
73-
} else if (memberShape.type === 'list') {
73+
} else if (memberShape.type === 'list' && !shape.api.xmlNoDefaultLists) {
7474
data[memberName] = memberShape.defaultValue;
7575
}
7676
});

test/xml/parser.spec.js

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)