How to use json-schema-faker - 10 common examples

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 brabeji / swagger-graphql-schema / src / createFakerResolver.js View on Github external
return (root, args, context, info) => {
        const random = seedrandom(RANDOM_SEED);
        jsf.format('uuid', generateUUID(random));
        jsf.format('uniqueId', generateUUID(random));
        jsf.option({ random });
        const fake = jsf(operation.schema);
        // console.log(`CALLING API: ${operation.path}\n\n${JSON.stringify(fake, null, 2)}`);
        return fake;
    }
};
github brabeji / swagger-graphql-schema / src / createFakerResolver.js View on Github external
return (root, args, context, info) => {
        const random = seedrandom(RANDOM_SEED);
        jsf.format('uuid', generateUUID(random));
        jsf.format('uniqueId', generateUUID(random));
        jsf.option({ random });
        const fake = jsf(operation.schema);
        // console.log(`CALLING API: ${operation.path}\n\n${JSON.stringify(fake, null, 2)}`);
        return fake;
    }
};
github brabeji / swagger-graphql-schema / src / createFakerResolver.js View on Github external
return (root, args, context, info) => {
        const random = seedrandom(RANDOM_SEED);
        jsf.format('uuid', generateUUID(random));
        jsf.format('uniqueId', generateUUID(random));
        jsf.option({ random });
        const fake = jsf(operation.schema);
        // console.log(`CALLING API: ${operation.path}\n\n${JSON.stringify(fake, null, 2)}`);
        return fake;
    }
};
github brabeji / swagger-graphql-schema / src / createFakerResolver.js View on Github external
return (root, args, context, info) => {
        const random = seedrandom(RANDOM_SEED);
        jsf.format('uuid', generateUUID(random));
        jsf.format('uniqueId', generateUUID(random));
        jsf.option({ random });
        const fake = jsf(operation.schema);
        // console.log(`CALLING API: ${operation.path}\n\n${JSON.stringify(fake, null, 2)}`);
        return fake;
    }
};
github coryhouse / javascript-development-environment / buildScripts / generateMockData.js View on Github external
/* This script generates mock data for local development.
   This way you don't have to point to an actual API,
   but you can enjoy realistic, but randomized data,
   and rapid page loads due to local, static data.
 */

/* eslint-disable no-console */

import jsf from 'json-schema-faker';
import {schema} from './mockDataSchema';
import fs from 'fs';
import chalk from 'chalk';

const json = JSON.stringify(jsf(schema));

fs.writeFile("./src/api/db.json", json, function (err) {
  if (err) {
    return console.log(chalk.red(err));
  } else {
    console.log(chalk.green("Mock data generated."));
  }
});
github json-schema-faker / json-schema-server / lib / server.js View on Github external
configureJSF: function configureJSF() {
    // TODO: check only if diff/checksum changes on each request,
    // if changed just reload the entire module before faking anything
    try {
      this.log('Configuring json-schema-faker');

      if (this.params.formats) {
        jsf.format(require(this.params.formats));
      }

      jsf.extend('faker', () => require('faker'));
      jsf.extend('chance', () => new (require('chance'))());
    } catch (e) {
      return this.callback(e);
    }
  },
github openownership / data-standard / schema / tools / data-faker.js View on Github external
var jsonschema = 
    JSON.parse(
        require('fs').readFileSync(
            require('path').resolve(
                __dirname, 
                '../beneficial-ownership-statements.json'),
            'utf8'));

var schemapatches = 
    JSON.parse(require('fs').readFileSync(
        require('path').resolve(
            __dirname,
        'schemapatches.json'),
    'utf8'));

jsf.format('URI', function(gen, jsonschema) {
    return gen.randexp('^http://[A-Za-z0-9]+\\.com$');
});

jsf.option({
    alwaysFakeOptionals: true
});

var minBeneficialOwnershipStatements = 1;
var beneficialOwnershipStatement = jsonschema.definitions.BeneficialOwnershipStatement;
var statementGroups = jsonschema.properties.statementGroups;
var flat_arrays = ["qualificationStatements", "entityStatements",
                   "personStatements", "provenanceStatements"];

var applyCommonPatches = function(original, patched) {
    // add common definitions for faker formats
    // patch in company and natural person names
github technocreatives / openapi-mock-eller / src / index.js View on Github external
const express = require('express')
const router = require("express-promise-router")
const _ = require("lodash")
const fs = require("fs")
const jref = require("json-ref-lite")
const yaml = require("js-yaml")
const winston = require("winston")
const faker = require("faker")
const jsf = require("json-schema-faker")

jsf.format("byte", () => new Buffer(faker.lorem.sentence(12)).toString("base64"))

jsf.option({
  alwaysFakeOptionals: true
})

const ajv = require("ajv")({
  unknownFormats: "ignore"
})

const logger = winston.createLogger({
  level: 'info',
  format: winston.format.json(),
  transports: [
    // new winston.transports.File({ filename: 'error.log', level: 'error' }),
    // new winston.transports.File({ filename: 'combined.log' })
  ]
github unmock / unmock-js / packages / unmock-core / src / generator.ts View on Github external
statusCode: number;
  headerSchema?: any;
  bodySchema?: any;
}): ISerializedResponse => {
  jsf.extend("faker", () => require("faker"));
  jsf.option("optionalsProbability", runnerConfiguration.optionalsProbability);
  // When optionalsProbability is set to 100%, generate exactly 100% of all optionals.
  // otherwise, generate up to optionalsProbability% of optionals
  jsf.option(
    "fixedProbabilities",
    runnerConfiguration.optionalsProbability === 1,
  );
  // disables this temporarily as it messes with user-defined min items
  // jsf.option("minItems", runnerConfiguration.minItems);
  // jsf.option("minLength", runnerConfiguration.minItems);
  jsf.option("useDefaultValue", false);
  jsf.option("random", rng);
  const bodyAsJson = bodySchema ? jsf.generate(bodySchema) : undefined;
  const body = bodyAsJson ? JSON.stringify(bodyAsJson) : undefined;
  jsf.option("useDefaultValue", true);
  const resHeaders = headerSchema ? jsf.generate(headerSchema) : undefined;
  jsf.option("useDefaultValue", false);

  return {
    body,
    bodyAsJson,
    headers: resHeaders,
    statusCode,
  };
};
github unmock / unmock-js / packages / unmock-core / src / generator.ts View on Github external
jsf.extend("faker", () => require("faker"));
  jsf.option("optionalsProbability", runnerConfiguration.optionalsProbability);
  // When optionalsProbability is set to 100%, generate exactly 100% of all optionals.
  // otherwise, generate up to optionalsProbability% of optionals
  jsf.option(
    "fixedProbabilities",
    runnerConfiguration.optionalsProbability === 1,
  );
  // disables this temporarily as it messes with user-defined min items
  // jsf.option("minItems", runnerConfiguration.minItems);
  // jsf.option("minLength", runnerConfiguration.minItems);
  jsf.option("useDefaultValue", false);
  jsf.option("random", rng);
  const bodyAsJson = bodySchema ? jsf.generate(bodySchema) : undefined;
  const body = bodyAsJson ? JSON.stringify(bodyAsJson) : undefined;
  jsf.option("useDefaultValue", true);
  const resHeaders = headerSchema ? jsf.generate(headerSchema) : undefined;
  jsf.option("useDefaultValue", false);

  return {
    body,
    bodyAsJson,
    headers: resHeaders,
    statusCode,
  };
};