@har-sdk/openapi-sampler
Version:
[](https://codeclimate.com/github/NeuraLegion/har-sdk/maintainability) [ {
this.traverse = traverse;
}
sample(schema, spec, options) {
const res = {};
if (schema && typeof schema.properties === 'object') {
const requiredKeys = Array.isArray(schema.required)
? schema.required
: [];
const requiredKeyDict = requiredKeys.reduce((dict, key) => {
dict[key] = true;
return dict;
}, {});
Object.keys(schema.properties).forEach((propertyName) => {
// skip before traverse that could be costly
if ((options === null || options === void 0 ? void 0 : options.skipNonRequired) &&
// eslint-disable-next-line no-prototype-builtins
!requiredKeyDict.hasOwnProperty(propertyName)) {
return;
}
const sample = this.traverse.traverse(schema.properties[propertyName], options, spec);
if ((options === null || options === void 0 ? void 0 : options.skipReadOnly) && sample.readOnly) {
return;
}
if ((options === null || options === void 0 ? void 0 : options.skipWriteOnly) && sample.writeOnly) {
return;
}
res[propertyName] = sample.value;
});
}
if (schema && typeof schema.additionalProperties === 'object') {
res.property1 = this.traverse.traverse(schema.additionalProperties, options, spec).value;
res.property2 = this.traverse.traverse(schema.additionalProperties, options, spec).value;
}
return res;
}
}
//# sourceMappingURL=ObjectSampler.js.map