All files / src/plugins/validation/swagger2/semantic-validators parameters.js

100% Statements 11/11
100% Branches 6/6
100% Functions 2/2
100% Lines 11/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28      29x 29x 29x   29x 35x   35x 5238x     5238x 114x 1x                 35x    
// Assertation 1:
// The items property for a parameter is required when its type is set to array
 
const isPlainObject = require('lodash/isPlainObject');
const { isParameterObject, walk } = require('../../../utils');
const MessageCarrier = require('../../../utils/messageCarrier');
 
module.exports.validate = function({ resolvedSpec }) {
  const messages = new MessageCarrier();
 
  walk(resolvedSpec, [], (obj, path) => {
    const isContentsOfParameterObject = isParameterObject(path, false); // 2nd arg is isOAS3
 
    // 1
    if (isContentsOfParameterObject) {
      if (obj.type === 'array' && !isPlainObject(obj.items)) {
        messages.addMessage(
          path,
          "Parameters with 'array' type require an 'items' property.",
          'error'
        );
      }
    }
  });
 
  return messages;
};