From 667c0ba3963162d2a2e6f75a6a563c0db2ae4d11 Mon Sep 17 00:00:00 2001 From: AllanZhengYP Date: Thu, 10 Feb 2022 22:44:06 +0000 Subject: [PATCH] disable validation for non-object values to document members --- .../bugfix-ParamValidator-72a79dfa.json | 5 +++++ lib/param_validator.js | 3 +-- test/param_validator.spec.js | 21 +++++++++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 .changes/next-release/bugfix-ParamValidator-72a79dfa.json diff --git a/.changes/next-release/bugfix-ParamValidator-72a79dfa.json b/.changes/next-release/bugfix-ParamValidator-72a79dfa.json new file mode 100644 index 0000000000..2e563660bd --- /dev/null +++ b/.changes/next-release/bugfix-ParamValidator-72a79dfa.json @@ -0,0 +1,5 @@ +{ + "type": "bugfix", + "category": "ParamValidator", + "description": "Fix the validation error when assign non-object values to member with document trait" +} \ No newline at end of file diff --git a/lib/param_validator.js b/lib/param_validator.js index 2875663e9f..99391ad6e5 100644 --- a/lib/param_validator.js +++ b/lib/param_validator.js @@ -51,10 +51,9 @@ AWS.ParamValidator = AWS.util.inherit({ }, validateStructure: function validateStructure(shape, params, context) { - this.validateType(params, context, ['object'], 'structure'); - if (shape.isDocument) return true; + this.validateType(params, context, ['object'], 'structure'); var paramName; for (var i = 0; shape.required && i < shape.required.length; i++) { paramName = shape.required[i]; diff --git a/test/param_validator.spec.js b/test/param_validator.spec.js index ad844842f9..9387032c02 100644 --- a/test/param_validator.spec.js +++ b/test/param_validator.spec.js @@ -226,6 +226,7 @@ }, hash3: { type: 'structure', + members: {}, document: true } } @@ -275,13 +276,21 @@ } }); }); - it('accepts document type members', function () { - return expectValid({ - hash1: { - hash3: {foo: 'foo', bar: ['bar']} - } + for (const documentMember of [ + 'string', + 1, + true, + { foo: 'foo', bar: ['bar'] }, + [1, 'array', false, { baz: 'baz' }] + ]) { + it('accepts document type member of ' + JSON.stringify(documentMember), function () { + return expectValid({ + hash1: { + hash3: documentMember + } + }); }); - }); + } return it('does not check inherited properties on parameters', function() { var cls, obj; cls = function() {