function propertyNamingConvention()

in functions/naming-convention.js [29:62]


function propertyNamingConvention(schema, options, path) {
  const errors = [];

  const { type, ...patternOpts } = options;
  const isType = isSchemaType(type);

  // Check property names
  for (const name of schema.properties ? Object.keys(schema.properties) : []) {
    if (isType(schema.properties[name]) && pattern(name, patternOpts)) {
      errors.push({
        message: `property "${name}" does not follow ${options.type} naming convention`,
        path: [...path, 'properties', name],
      });
    }
  }

  if (schema.items) {
    errors.push(
      ...propertyNamingConvention(schema.items, options, [...path, 'items']),
    );
  }

  for (const applicator of ['allOf', 'anyOf', 'oneOf']) {
    if (schema[applicator] && Array.isArray(schema[applicator])) {
      for (const [index, value] of schema[applicator].entries()) {
        errors.push(
          ...propertyNamingConvention(value, options, [...path, applicator, index]),
        );
      }
    }
  }

  return errors;
}