-
Notifications
You must be signed in to change notification settings - Fork 419
/
properties.js
771 lines (670 loc) · 23.3 KB
/
properties.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
const Hoek = require('@hapi/hoek');
const Definitions = require('../lib/definitions');
const Utilities = require('../lib/utilities');
const internals = {};
/**
* constructor for properties
*
* @param {Object} settings
* @param {Object} definitionCollection
* @param {Object} altDefinitionCollection
* @param {Array} definitionCache
*/
exports =
module.exports =
internals.properties =
function (settings, definitionCollection, altDefinitionCollection, definitionCache) {
this.settings = settings;
this.definitionCollection = definitionCollection;
this.altDefinitionCollection = altDefinitionCollection;
// definitionCache has to be an array of two WeakMaps
this.definitionCache = definitionCache;
this.definitions = new Definitions(settings);
// swagger type can be 'string', 'number', 'integer', 'boolean', 'array' or 'file'
this.simpleTypePropertyMap = {
boolean: { type: 'boolean' },
binary: { type: 'string', format: 'binary' },
date: { type: 'string', format: 'date' },
number: { type: 'number' },
string: { type: 'string' }
};
this.complexTypePropertyMap = {
any: { type: 'string' },
array: { type: 'array' },
func: { type: 'string' },
object: { type: 'object' },
alternatives: { type: 'alternatives' }
};
// merge
this.propertyMap = Hoek.applyToDefaults(this.simpleTypePropertyMap, this.complexTypePropertyMap);
//this.allowedProps = ['$ref','format','title','description','default','multipleOf','maximum','exclusiveMaximum','minimum','exclusiveMinimum','maxLength','minLength','pattern','maxItems','minItems','uniqueItems','maxProperties','minProperties','required','enum','type','items','allOf','properties','additionalProperties','discriminator','readOnly','xml','externalDocs','example'];
// add none swagger property needed to flag touched state of required property
//this.allowedProps.push('optional');
};
/**
* parse Joi validators object into a swagger property
*
* @param {string} name
* @param {Object} joiObj
* @param {string} parent
* @param {string} parameterType
* @param {Boolean} useDefinitions
* @param {Boolean} isAlt
* @return {Object}
*/
internals.properties.prototype.parseProperty = function (name, joiObj, parent, parameterType, useDefinitions, isAlt) {
let property = { type: 'void' };
// if wrong format or forbidden - return undefined
if (!Utilities.isJoi(joiObj)) {
return undefined;
}
if (Hoek.reach(joiObj, '_flags.presence') === 'forbidden') {
return undefined;
}
if (Utilities.getJoiMetaProperty(joiObj, 'swaggerHidden') === true) {
return undefined;
}
// default the use of definitions to true
if (useDefinitions === undefined || useDefinitions === null) {
useDefinitions = true;
}
// get name from joi label if its not a path
if (!name && parameterType !== 'path') {
const joiLabel = Utilities.getJoiLabel(joiObj);
if (joiLabel) {
name = joiLabel;
}
}
// add correct type and format by mapping
let joiType = joiObj.type.toLowerCase();
// for Joi extension, use the any type
if (!(joiType in this.propertyMap)) {
joiType = 'any';
}
const map = this.propertyMap[joiType];
property.type = map.type;
if (map.format) {
property.format = map.format;
}
// this must be done even if the caching returns something
this.setRequiredAndOptionalOnParent(name, parent, joiObj);
// Joi object caching - speeds up parsing
let joiCache;
if (useDefinitions && Array.isArray(this.definitionCache) && property.type === 'object') {
// select WeakMap for current definition collection
joiCache = isAlt === true ? this.definitionCache[1] : this.definitionCache[0];
if (joiCache.has(joiObj)) {
return joiCache.get(joiObj);
}
}
property = this.parsePropertyMetadata(property, name, parent, joiObj);
// add enum
const describe = joiObj.describe();
const allowDropdown = !property['x-meta'] || !property['x-meta'].disableDropdown;
if (allowDropdown && Array.isArray(describe.allow) && describe.allow.length) {
if (
describe.allow[0] &&
typeof describe.allow[0] === 'object' &&
describe.allow[0].override === true &&
Object.keys(describe.allow[0]).length === 1
) {
describe.allow.shift();
}
// filter out empty values and arrays
const enums = describe.allow.filter((item) => {
return item !== '' && item !== null;
});
if (enums.length > 0) {
property.enum = enums;
}
if (this.settings.OAS === 'v3.0' && describe.allow.some((item) => item === null)) {
property.nullable = true;
}
}
// add number properties
if (property.type === 'string') {
property = this.parseString(property, joiObj);
if (useDefinitions === true && property.enum) {
const refName = this.definitions.append(name, property, this.getDefinitionCollection(isAlt), this.settings);
property = {
$ref: this.getDefinitionRef(isAlt) + refName
};
}
}
// add number properties
if (property.type === 'number') {
property = this.parseNumber(property, joiObj);
}
// add date properties
if (property.type === 'string' && property.format === 'date') {
property = this.parseDate(property, joiObj);
}
// add object child properties
if (property.type === 'object') {
if (Utilities.hasJoiChildren(joiObj) || Utilities.hasJoiDescription(joiObj)) {
property = this.parseObject(property, joiObj, name, parameterType, useDefinitions, isAlt);
if (useDefinitions === true) {
const refName = this.definitions.append(name, property, this.getDefinitionCollection(isAlt), this.settings);
property = {
$ref: this.getDefinitionRef(isAlt) + refName
};
}
} else if (joiObj.$_terms.patterns) {
const objectPattern = joiObj.$_terms.patterns[0];
let patternName = 'string';
if (objectPattern.schema) {
patternName =
objectPattern.schema.$_terms.examples && objectPattern.schema.$_terms.examples[0]
? objectPattern.schema.$_terms.examples[0]
: objectPattern.schema.type;
}
property.properties = {
[patternName]: this.parseProperty(
patternName,
objectPattern.rule,
property,
parameterType,
useDefinitions,
isAlt
)
};
} else {
// default empty object
property.properties = {};
if (useDefinitions === true) {
const objectSchema = { type: 'object', properties: {} };
const refName = this.definitions.append(name, objectSchema, this.getDefinitionCollection(isAlt), this.settings);
property = {
$ref: this.getDefinitionRef(isAlt) + refName
};
}
}
const allowUnknown = joiObj._flags.allowUnknown;
if (allowUnknown !== undefined && !allowUnknown) {
property.additionalProperties = false;
}
}
// add array properties
if (property.type === 'array') {
property = this.parseArray(property, joiObj, name, parameterType, useDefinitions, isAlt);
if (useDefinitions === true) {
const refName = this.definitions.append(name, property, this.getDefinitionCollection(isAlt), this.settings);
property = {
$ref: this.getDefinitionRef(isAlt) + refName
};
}
}
// add alternatives properties
if (property.type === 'alternatives') {
property = this.parseAlternatives(property, joiObj, name, parameterType, useDefinitions);
}
// convert property to file upload, if indicated by meta property
if (Utilities.getJoiMetaProperty(joiObj, 'swaggerType') === 'file') {
property.type = 'file';
property.in = 'formData';
}
property = Utilities.deleteEmptyProperties(property);
if (joiCache && property.$ref) {
joiCache.set(joiObj, property);
}
return property;
};
/**
* set required and optional properties on parent if they do not exist yet
*
* @param {string} name
* @param {string} parent
* @param {Object} joiObj
* @returns {void}
*/
internals.properties.prototype.setRequiredAndOptionalOnParent = function (name, parent, joiObj) {
// nothing needs to be done if the parent or the property doesn't exist
if (!parent || !name) {
return;
}
const describe = joiObj.describe();
if (Hoek.reach(joiObj, '_flags.presence')) {
if (parent.required === undefined) {
parent.required = [];
}
if (this.settings.OAS === 'v2' && parent.optional === undefined) {
parent.optional = [];
}
if (Hoek.reach(joiObj, '_flags.presence') === 'required') {
if (!parent.required.includes(name)) {
parent.required.push(name);
}
}
if (this.settings.OAS === 'v2' && Hoek.reach(joiObj, '_flags.presence') === 'optional') {
if (!parent.optional.includes(name)) {
parent.optional.push(name);
}
}
}
// interdependencies are not yet supported https://github.com/OAI/OpenAPI-Specification/issues/256
if (describe.whens && describe.whens.length > 0) {
describe.whens.forEach((test) => {
if (Hoek.reach(test, 'then.flags.presence') === 'required') {
if (parent.required === undefined) {
parent.required = [];
}
if (!parent.required.includes(name)) {
parent.required.push(name);
}
}
});
}
};
/**
* parse property metadata
*
* @param {Object} property
* @param {Object} joiObj
* @return {Object}
*/
internals.properties.prototype.parsePropertyMetadata = function (property, name, parent, joiObj) {
const describe = joiObj.describe();
// add common properties
property.description = Hoek.reach(joiObj, '_flags.description');
property.notes = Hoek.reach(joiObj, '$_terms.notes');
property.tags = Hoek.reach(joiObj, '$_terms.tags');
property.title = Utilities.getJoiMetaProperty(joiObj, 'title');
// add extended properties not part of openAPI spec
if (this.settings.xProperties === true) {
internals.convertRules(property, describe.rules, ['unit'], 'x-format');
const exampleObj = Hoek.reach(joiObj, '$_terms.examples.0');
/* $lab:coverage:off$ */
// exampleObj.value != null will coerce undefined and null
// eslint-disable-next-line no-eq-null
property.example = exampleObj && exampleObj.value != null ? exampleObj.value : exampleObj;
/* $lab:coverage:on$ */
const xMeta = Hoek.reach(joiObj, '$_terms.metas.0');
if (xMeta) {
const meta = Hoek.clone(xMeta);
delete meta.swaggerLabel;
if (Object.keys(meta).length) {
if ('xml' in meta) {
property.xml = meta.xml;
delete meta.xml;
}
property['x-meta'] = meta;
}
}
}
this.setRequiredAndOptionalOnParent(name, parent, joiObj);
let propertyDefault = Hoek.reach(joiObj, '_flags.default');
// allow for function calls
if (Utilities.isFunction(propertyDefault)) {
propertyDefault = propertyDefault();
}
if (property.type === 'array' && Array.isArray(propertyDefault) && propertyDefault.length === 0) {
// Default should not be set for empty arrays
} else {
property.default = propertyDefault;
}
return property;
};
/**
* parse string property
*
* @param {Object} property
* @param {Object} joiObj
* @return {Object}
*/
internals.properties.prototype.parseString = function (property, joiObj) {
const describe = joiObj.describe();
if (describe.type !== 'date') {
property.minLength = internals.getArgByName(describe.rules, 'min', 'limit');
property.maxLength = internals.getArgByName(describe.rules, 'max', 'limit');
}
// add regex
joiObj._rules.forEach((test) => {
if (Utilities.isObject(test.args) && test.args.regex) {
if (Utilities.isRegex(test.args.regex)) {
// get the regex source (as opposed to regex.toString()) so
// we exclude the surrounding '/' delimeters as well as any
// trailing flags (g, i, m)
property.pattern = test.args.regex.source;
} else {
property.pattern = test.args.regex;
}
}
});
// add extended properties not part of openAPI spec
if (this.settings.xProperties === true) {
internals.convertRules(property, describe.rules, ['insensitive', 'length'], 'x-constraint');
internals.convertRules(
property,
describe.rules,
['creditCard', 'alphanum', 'token', 'email', 'ip', 'uri', 'guid', 'hex', 'hostname', 'isoDate'],
'x-format'
);
internals.convertRules(property, describe.rules, ['case', 'trim'], 'x-convert');
}
return property;
};
/**
* parse number property
*
* @param {Object} property
* @param {Object} joiObj
* @return {Object}
*/
internals.properties.prototype.parseNumber = function (property, joiObj) {
const describe = joiObj.describe();
property.minimum = internals.getArgByName(describe.rules, 'min');
property.maximum = internals.getArgByName(describe.rules, 'max');
if (internals.hasPropertyByName(describe.rules, 'integer')) {
property.type = 'integer';
}
if (Array.isArray(describe.metas)) {
const meta = describe.metas.find((meta) => {
return typeof meta.format === 'string';
});
if (meta) {
property.format = meta.format;
}
}
// add extended properties not part of openAPI spec
if (this.settings.xProperties === true) {
internals.convertRules(
property,
describe.rules,
['greater', 'less', 'precision', 'multiple', 'sign'],
'x-constraint'
);
}
return property;
};
/**
* parse date property - adds additional schema info based on Joi date formats
*
* @param {Object} input
* @param {Object} joiObj
* @return {Object}
*/
internals.properties.prototype.parseDate = function (input, joiObj) {
const dateFormat = Hoek.reach(joiObj, '_flags.format');
const property = Hoek.clone(input);
if (['timestamp', 'javascript'].includes(dateFormat)) {
// Seems like the exact name of the format differs for different versions of Joi
// Javascript is what is set by Joi.date().timestamp()
property.type = 'integer';
delete property.format;
} else if (dateFormat === 'iso') {
// Joi.date().iso()
property.type = 'string';
property.format = 'date-time';
}
return property;
};
/**
* parse object property
*
* @param {Object} property
* @param {Object} joiObj
* @param {string} name
* @param {Boolean} useDefinitions
* @param {Boolean} isAlt
* @return {Object}
*/
internals.properties.prototype.parseObject = function (property, joiObj, name, parameterType, useDefinitions, isAlt) {
property.properties = {};
joiObj._ids._byKey.forEach((obj) => {
const keyName = obj.id;
let itemName = obj.id;
const joiChildObj = obj.schema;
// get name form label if set
if (Utilities.getJoiLabel(joiChildObj)) {
itemName = Utilities.getJoiLabel(joiChildObj);
}
//name, joiObj, parent, parameterType, useDefinitions, isAlt
const parsedProperty = this.parseProperty(itemName, joiChildObj, property, parameterType, useDefinitions, isAlt);
if (parsedProperty) {
delete parsedProperty.name;
property.properties[keyName] = parsedProperty;
}
// switch references if naming has changed
if (keyName !== itemName) {
property.required = Utilities.replaceValue(property.required, itemName, keyName);
if (this.settings.OAS === 'v2') {
property.optional = Utilities.replaceValue(property.optional, itemName, keyName);
}
}
});
return property;
};
/**
* parse array property
*
* @param {Object} property
* @param {Object} joiObj
* @param {string} name
* @param {string} parameterType,
* @param {Boolean} useDefinitions
* @param {Boolean} isAlt
* @return {Object}
*/
internals.properties.prototype.parseArray = function (property, joiObj, name, parameterType, useDefinitions, isAlt) {
const describe = joiObj.describe();
property.minItems = internals.getArgByName(describe.rules, 'min');
property.maxItems = internals.getArgByName(describe.rules, 'max');
// add extended properties not part of openAPI spec
if (this.settings.xProperties === true) {
internals.convertRules(property, describe.rules, ['length', 'unique'], 'x-constraint');
if (describe.flags && describe.flags.sparse) {
internals.addToPropertyObject(property, 'x-constraint', 'sparse', true);
}
if (describe.flags && describe.flags.single) {
internals.addToPropertyObject(property, 'x-constraint', 'single', true);
}
}
// default the items with type:string
property.items = {
type: 'string'
};
// set swaggers collectionFormat to one that works with hapi
if ((parameterType === 'query' || parameterType === 'formData') && this.settings.OAS === 'v2') {
property.collectionFormat = 'multi';
}
// swagger appears to only support one array item type at a time, so grab the first one
const arrayItemTypes = joiObj.$_terms.items;
const arrayItem = Utilities.first(arrayItemTypes);
if (arrayItem) {
// get name of item if it has one
let itemName;
if (Utilities.getJoiLabel(arrayItem)) {
itemName = Utilities.getJoiLabel(arrayItem);
}
//name, joiObj, parent, parameterType, useDefinitions, isAlt
const arrayItemProperty = this.parseProperty(itemName, arrayItem, property, parameterType, useDefinitions, isAlt);
if (this.simpleTypePropertyMap[arrayItem.type.toLowerCase()]) {
// map simple types directly
property.items = {};
for (const key in arrayItemProperty) {
property.items[key] = arrayItemProperty[key];
}
} else {
property.items = arrayItemProperty;
}
}
property.name = name;
return property;
};
/**
* parse alternatives property
*
* @param {Object} property
* @param {Object} joiObj
* @param {string} name
* @param {string} parameterType
* @param {Boolean} useDefinitions
* @return {Object}
*/
internals.properties.prototype.parseAlternatives = function (property, joiObj, name, parameterType, useDefinitions) {
const buildAlternativesArray = (schemas) => {
return schemas
.map((schema) => {
const childMetaName = Utilities.getJoiMetaProperty(schema, 'swaggerLabel');
const altName = childMetaName || Utilities.getJoiLabel(schema) || name;
//name, joiObj, parent, parameterType, useDefinitions, isAlt
return this.parseProperty(altName, schema, property, parameterType, useDefinitions, true);
})
.filter((obj) => obj);
};
// convert .try() alternatives structures
if (Hoek.reach(joiObj, '$_terms.matches.0.schema')) {
if (this.settings.OAS === 'v2') {
// add first into definitionCollection
const child = joiObj.$_terms.matches[0].schema;
const childName = Utilities.getJoiLabel(joiObj);
//name, joiObj, parent, parameterType, useDefinitions, isAlt
property = this.parseProperty(childName, child, property, parameterType, useDefinitions, false);
// create the alternatives without appending to the definitionCollection
// if (property && this.settings.xProperties === true) {
if (this.settings.xProperties === true) {
const altArray = buildAlternativesArray(joiObj.$_terms.matches.map((obj) => obj.schema));
property['x-alternatives'] = Hoek.clone(altArray);
}
} else {
property.anyOf = buildAlternativesArray(joiObj.$_terms.matches.map((obj) => obj.schema));
delete property.type;
}
}
// convert .when() alternatives structures
else {
if (this.settings.OAS === 'v2') {
// add first into definitionCollection
const child = joiObj.$_terms.matches[0].then;
const childMetaName = Utilities.getJoiMetaProperty(child, 'swaggerLabel');
const childName = childMetaName || Utilities.getJoiLabel(child) || name;
//name, joiObj, parent, parameterType, useDefinitions, isAlt
property = this.parseProperty(childName, child, property, parameterType, useDefinitions, false);
// create the alternatives without appending to the definitionCollection
if (property && this.settings.xProperties === true) {
const altArray = buildAlternativesArray(
joiObj.$_terms.matches.reduce((res, obj) => {
obj.then && res.push(obj.then);
obj.otherwise && res.push(obj.otherwise);
return res;
}, [])
);
property['x-alternatives'] = Hoek.clone(altArray);
}
} else {
property.anyOf = buildAlternativesArray(
joiObj.$_terms.matches.reduce((res, obj) => {
obj.then && res.push(obj.then);
obj.otherwise && res.push(obj.otherwise);
return res;
}, [])
);
delete property.type;
}
}
return property;
};
/**
* selects the correct definition collection
*
* @param {Boolean} isAlt
* @return {Object}
*/
internals.properties.prototype.getDefinitionCollection = function (isAlt) {
return isAlt === true ? this.altDefinitionCollection : this.definitionCollection;
};
/**
* selects the correct definition reference
*
* @param {Boolean} isAlt
* @return {string}
*/
internals.properties.prototype.getDefinitionRef = function (isAlt) {
if (isAlt === true) {
return '#/x-alt-definitions/';
}
if (this.settings.OAS === 'v2') {
return '#/definitions/';
}
return '#/components/schemas/';
};
/**
* coverts rules into property objects
*
* @param {Object} property
* @param {Array} rules
* @param {Array} ruleNames
* @param {string} groupName
*/
internals.convertRules = function (property, rules, ruleNames, groupName) {
ruleNames.forEach((ruleName) => {
internals.appendToPropertyObject(property, rules, groupName, ruleName);
});
};
/**
* appends a name item to object on a property
*
* @param {Object} property
* @param {Array} rules
* @param {string} groupName
* @param {string} ruleName
*/
internals.appendToPropertyObject = function (property, rules, groupName, ruleName) {
if (internals.hasPropertyByName(rules, ruleName)) {
let value = internals.getArgByName(rules, ruleName);
if (Utilities.isObject(value) && Utilities.hasProperties(value) === false) {
value = undefined;
}
internals.addToPropertyObject(property, groupName, ruleName, value);
}
};
/**
* add a name item to object on a property
*
* @param {Object} property
* @param {string} groupName
* @param {string} ruleName
* @param {string} value
*/
internals.addToPropertyObject = function (property, groupName, ruleName, value) {
if (!property[groupName]) {
property[groupName] = {};
}
property[groupName][ruleName] = value !== undefined ? value : true;
};
/**
* return the value of an item in array of object by name - structure [ { name: 'value', arg: 'value' } ]
*
* @param {Array} array
* @param {string} name
* @return {String || Undefined}
*/
internals.getArgByName = function (array, name, key = undefined) {
if (Array.isArray(array)) {
let i = array.length;
while (i--) {
if (array[i].name === name) {
if (array[i].args) {
if (key) {
return array[i].args[key];
}
// If not specified, return first
return Object.values(array[i].args)[0];
}
// TODO check why we return true if we must return a string or undefined
return true;
}
}
}
return undefined;
};
/**
* return existence of an item in array of - structure [ { name: 'value' } ]
*
* @param {Array} array
* @param {string} name
* @return {Boolean}
*/
internals.hasPropertyByName = function (array, name) {
return Array.isArray(array) && array.some((obj) => obj.name === name);
};