How to use the json-schema-faker/lib function in json-schema-faker

To help you get started, we’ve selected a few json-schema-faker examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github julienvincent / modelizr / src / mock.js View on Github external
/**
                 * Determine if a model with the same PK is in the cache. Use it if it is.
                 */
                const shouldSetSchema = (model._isUnion && schemaAttribute)
                const _key = _model.model().getKey()
                id = model._isUnion ? (opts.idType === INCREMENT ? _.size(cache[_key]) + 1 : gen()) : id
                if (cache[_key] && cache[_key][id]) {
                    return mergeNested({
                        ...cache[_key][id],
                        ...(shouldSetSchema ? {
                            [schemaAttribute]: _model._definedAttribute
                        } : {})
                    })
                }

                let mocked = _.set(jsf(_model), primary, id)
                if (shouldSetSchema) mocked = _.set(mocked, schemaAttribute, _model._definedAttribute)

                cache[_key] = {...cache[_key], [id]: mocked}

                if (opts.generateFromParams) {
                    _.forEach(_model.params, (param, key) => {
                        _model.properties = _.mapValues(_model.properties, (prop, _key) => {
                            if (_key == key && _key !== primary) {
                                if (prop._isModel || prop._isUnion) {
                                    return {
                                        ...prop,
                                        params: {
                                            ...prop.params,
                                            [prop.primaryKey]: param
                                        }
                                    }