UNPKG

@har-sdk/openapi-sampler

Version:

[![Maintainability](https://api.codeclimate.com/v1/badges/4acaec95c82465cb2c3d/maintainability)](https://codeclimate.com/github/NeuraLegion/har-sdk/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/4acaec95c82465cb2c3d/test_coverage

39 lines 1.77 kB
export class ObjectSampler { constructor(traverse) { 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