How to use the json-schema-faker.format 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 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 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 EricHenry / swagger-data-gen / lib / jsfConfig.js View on Github external
'use strict';

var jsf = require('json-schema-faker');
var generators = require('./generators/generators.js');

jsf.format('date', generators.fullDate);
jsf.format('byte', generators.byte);
jsf.format('binary', generators.binary);
jsf.format('password', generators.password);

module.exports = jsf;
github EricHenry / swagger-data-gen / lib / jsfConfig.js View on Github external
'use strict';

var jsf = require('json-schema-faker');
var generators = require('./generators/generators.js');

jsf.format('date', generators.fullDate);
jsf.format('byte', generators.byte);
jsf.format('binary', generators.binary);
jsf.format('password', generators.password);

module.exports = jsf;
github json-schema-faker / grunt-jsonschema-faker / tasks / jsonschema_faker.js View on Github external
_.each(externalFormats, function(formatFunction, formatName){
        jsf.format(formatName, formatFunction());
    });
github EricHenry / swagger-data-gen / lib / jsfConfig.js View on Github external
'use strict';

var jsf = require('json-schema-faker');
var generators = require('./generators/generators.js');

jsf.format('date', generators.fullDate);
jsf.format('byte', generators.byte);
jsf.format('binary', generators.binary);
jsf.format('password', generators.password);

module.exports = jsf;
github EricHenry / swagger-data-gen / lib / jsfConfig.js View on Github external
'use strict';

var jsf = require('json-schema-faker');
var generators = require('./generators/generators.js');

jsf.format('date', generators.fullDate);
jsf.format('byte', generators.byte);
jsf.format('binary', generators.binary);
jsf.format('password', generators.password);

module.exports = jsf;