UNPKG

rivet

Version:

Suite of utilities for working with the Rivet consumer-driven API contacts testing model.

37 lines (36 loc) 1.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var path_1 = require("path"); var types = require("./types"); exports.types = types; var jsf = require("json-schema-faker"); var config_1 = require("./lib/config"); exports.Config = config_1.default; var getFilePath = function (schemaPath) { var regex = /^(.+)\//; var match = schemaPath.match(regex); var aliasKey = match && match[1] || ''; var relativePath = schemaPath.replace(regex, ''); var pathAlias = config_1.default.aliases[aliasKey] || config_1.default.contractsRoot; var absolutePath = path_1.resolve(config_1.default.appRoot, pathAlias, relativePath); return absolutePath; }; var getSchema = function (schemaPath) { var schema = (typeof schemaPath === 'string') ? exports.load(schemaPath) : schemaPath; return schema; }; exports.load = function (schemaPath) { var absolutePath = getFilePath(schemaPath); var schema = require(absolutePath); return schema; }; exports.generate = function (schemaPath) { var schema = getSchema(schemaPath); return jsf.resolve(schema); }; exports.generateSync = function (schemaPath) { var schema = getSchema(schemaPath); return jsf(schema); };