UNPKG

unmock-core

Version:

[![npm](https://img.shields.io/npm/v/unmock-core.svg)][npmjs] [![CircleCI](https://circleci.com/gh/unmock/unmock-js.svg?style=svg)](https://circleci.com/gh/unmock/unmock-js) [![codecov](https://codecov.io/gh/unmock/unmock-js/branch/dev/graph/badge.svg)](h

64 lines 2.54 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const debug_1 = __importDefault(require("debug")); const lodash_1 = require("lodash"); const actors_1 = require("./actors"); const constants_1 = require("./constants"); const translators_1 = require("./translators"); const utils_1 = require("./utils"); const debugLog = debug_1.default("unmock:dsl"); class DSL { static translateDSLToOAS(state, schema) { let translated = {}; if (state.$size !== undefined) { utils_1.throwOnErrorIfStrict(() => { translated = Object.assign({}, translated, translators_1.translate$size(state, schema)); delete state.$size; }); } return translated; } static translateTopLevelToOAS(top, responses) { if (responses === undefined) { return responses; } if (top.$times !== undefined) { utils_1.throwOnErrorIfStrict(() => { const translated = translators_1.translate$times(top.$times); utils_1.injectUnmockProperty(responses, translated); }); } return responses; } static actTopLevelFromOAS(states) { const copy = {}; for (const code of Object.keys(states)) { copy[code] = {}; for (const mediaType of Object.keys(states[code])) { copy[code][mediaType] = lodash_1.cloneDeep(states[code][mediaType]); const schema = copy[code][mediaType]; if (schema.properties === undefined) { continue; } if (utils_1.hasUnmockProperty(schema, constants_1.SCHEMA_TIMES)) { actors_1.actOn$times(copy[code], states[code], mediaType); } if (Object.keys(schema.properties).length === 0) { debugLog(`schema.properties is now empty, removing 'properties' from copied response '${code}/${mediaType}'`); delete schema.properties; } } if (Object.keys(copy[code]).length === 0) { debugLog(`Entire response is empty, removing '${code}' from copied response`); delete copy[code]; } } return copy; } } DSL.STRICT_MODE = true; exports.DSL = DSL; //# sourceMappingURL=dsl.js.map