All files / lib/joi-to-json-schema/types array.ts

95.65% Statements 22/23
85.71% Branches 12/14
100% Functions 3/3
95.45% Lines 21/22

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 29 30 31 32 33 34 35 36 37 381x 8x 8x 8x   1x 1x   1x 1x   1x 1x   1x 1x     8x 8x 2x       8x 3x 5x       8x 3x       8x    
export const array = (convert, schema, joi, transformer) => {
  schema.type = "array";
  joi._rules.forEach(test => {
    switch (test.name) {
      case "unique":
        schema.uniqueItems = true;
        break;
      case "length":
        schema.minItems = schema.maxItems = test.args.limit;
        break;
      case "min":
        schema.minItems = test.args.limit;
        break;
      case "max":
        schema.maxItems = test.args.limit;
        break;
    }
  });
  Eif (joi.$_terms) {
    if (joi.$_terms.ordered.length) {
      schema.ordered = joi.$_terms.ordered.map(item => convert(item, transformer));
    }
 
    let list;
    if (joi.$_terms._inclusions.length) {
      list = joi.$_terms._inclusions;
    } else Iif (joi.$_terms._requireds.length) {
      list = joi.$_terms._requireds;
    }
 
    if (list) {
      schema.items = convert(list[0], transformer);
    }
  }
 
  return schema;
};