How to use the json-schema-faker.resolve 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 khalidx / resource-x / src / index.ts View on Github external
// validate and dereference the specification
    specification = await swagger.validate(specification) as OpenAPIV2.Document
    specification['x-amazon-apigateway-request-validators'] = {
      validateBodyAndParameters: {
        validateRequestBody: true,
        validateRequestParameters: true
      }
    }
    specification['x-amazon-apigateway-request-validator'] = 'validateBodyAndParameters'
    for (let pathKey of Object.keys(specification.paths)) {
      for (let operationKey of Object.keys(specification.paths[pathKey])) {
        let responses = specification.paths[pathKey][operationKey].responses
        let status = Object.keys(responses)[0]
        let schema = responses[status].schema
        let mockData: any
        if (schema) mockData = await jsf.resolve(schema)
        specification.paths[pathKey][operationKey]['x-amazon-apigateway-integration'] = {
          type: 'mock',
          requestTemplates: {
            'application/json': '{\"statusCode\": 200}'
          },
          responses: {
            default: (operationKey === 'options') ? {
              statusCode: '200',
              responseParameters: {
                'method.response.header.Access-Control-Allow-Headers': "'Content-Type,X-Amz-Date,Authorization,X-Api-Key'",
                'method.response.header.Access-Control-Allow-Methods': "'*'",
                'method.response.header.Access-Control-Allow-Origin': "'*'"
              },
              responseTemplates: {
                'application/json': '{}'
              }
github swisspush / apikana / src / generate-sample.js View on Github external
function generateFakeData(file, typeName) {
            var json = require(file.path);

            jsf.option({failOnInvalidTypes: true, fileOnInvalidFormat: true, fillProperties:true});

            jsf.resolve(json, file.base).then(sample => {
                sample['$schema'] = slash(path.relative(path.join(source, 'samples'), file.path));
                var data = JSON.stringify(sample, undefined, 2);
                str(data).pipe(vinylSource('generated-'+typeName+'.json')).pipe(gulp.dest('samples', {cwd: source}));
            }, err => console.error(err));
        };
github json-schema-faker / json-schema-server / lib / server.js View on Github external
      .then(refs => jsf.resolve(content, refs, this.params.directory))
      .then(sample => {
github cytle / faker-ts / lib / faker.ts View on Github external
export const getMock = (schema: any) => jsf.resolve(schema);
export const fakerGenerate = (schema: Definition) => jsf.generate(schema, []);
github itsthatguy / rivet / src / index.ts View on Github external
export const generate = (schemaPath: string | {}): Promise => {
  const schema = getSchema(schemaPath);
  return jsf.resolve(schema);
};
github MoonMail / MoonMail / lists-microservice / scripts / deploy-docs.js View on Github external
return Promise.map(definitionEntries, ([key, schema]) => {
    const s = Object.assign({}, schema, { definitions });
    return jsf.resolve(s).then(sample => ({ [key]: sample }));
  })
    .then(samples => samples.reduce((total, el) => Object.assign(total, el), {}))
github ritz078 / transform / workers / json-schema-to-rust-serde.js View on Github external
new Promise(resolve => {
      jsf.resolve(JSON.parse(code)).then(_json => {
        resolve(
          transform(_json, {
            lang: "rust-serde",
            rustCase
          })
        );
      });
    })
);
github technocreatives / openapi-mock-eller / src / index.js View on Github external
async [mockName](req, res) {
      if (data.validateRequest && !data.validateRequest(req.body)) {
        return res.json({
          error: {
            message: "Request failed to validate",
            meta: data.validateRequest.errors
          }
        })
      }
  
      if (responseSchema == null) {
        return res.json({})
      }
      
      const fakedResponse = await jsf.resolve(responseSchema)
  
      return res.json(fakedResponse)
    }
  }