[JavaScript] Do not parse null and undefined as type. (#4933)

* [JavaScript] Do not parse null and undefined as type.

* update pet store example for #4932
This commit is contained in:
Zhanwei Wang
2017-03-06 15:01:19 +08:00
committed by wing328
parent 5d327e66a1
commit 10950db2dd
2 changed files with 8 additions and 2 deletions

View File

@@ -452,9 +452,12 @@
* or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
* return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
* all properties on <code>data<code> will be converted to this type.
* @returns An instance of the specified type.
* @returns An instance of the specified type or null or undefined if data is null or undefined.
*/
{{/emitJSDoc}} exports.convertToType = function(data, type) {
if (data === null || data === undefined)
return data
switch (type) {
case 'Boolean':
return Boolean(data);

View File

@@ -442,9 +442,12 @@
* or the constructor function for a complex type. Pass an array containing the type name to return an array of that type. To
* return an object, pass an object with one property whose name is the key type and whose value is the corresponding value type:
* all properties on <code>data<code> will be converted to this type.
* @returns An instance of the specified type.
* @returns An instance of the specified type or null or undefined if data is null or undefined.
*/
exports.convertToType = function(data, type) {
if (data === null || data === undefined)
return data
switch (type) {
case 'Boolean':
return Boolean(data);