lambda-serverless-api
Advanced tools
Comparing version 1.9.2 to 1.10.0
@@ -92,2 +92,3 @@ const xor = require('lodash.xor'); | ||
wrap, | ||
loadYaml: yaml.load, | ||
generateSwagger: (existing = {}) => swagger(endpoints, existing), | ||
@@ -94,0 +95,0 @@ generateDifference, |
@@ -7,3 +7,3 @@ const fs = require("fs"); | ||
const loadRecursive = (dir, data) => { | ||
const loadRecursive = (dir, data, vars) => { | ||
Object.keys(data).forEach((key) => { | ||
@@ -13,16 +13,13 @@ let entry = get(data, key); | ||
// replace yaml variables with defaults | ||
entry = entry.replace(/\${[a-zA-Z0-9]+?:[a-zA-Z0-9]+?, ["']([a-zA-Z0-9]+?)["']}/g, "$1"); | ||
entry = entry.replace(/\${opt:([a-zA-Z0-9]+?)(?:, ["']([a-zA-Z0-9]+?)["'])?}/g, (_, k, v) => get(vars, k, v)); | ||
// load referenced yaml file | ||
const match = /^\${file\(([^(){}$]+?)\)(?::([a-zA-Z0-9.]+?))?}$/g.exec(entry); | ||
const match = /^\${file\((~?[a-zA-Z0-9._\-/]+?)\)(?::([a-zA-Z0-9.]+?))?}$/g.exec(entry); | ||
if (match) { | ||
const filePath = path.join(dir, match[1]); | ||
const loaded = yaml.safeLoad(fs.readFileSync(filePath, 'utf8')); | ||
entry = loadRecursive( | ||
path.dirname(filePath), | ||
get(loaded, match[2], loaded) | ||
); | ||
entry = loadRecursive(dir, get(loaded, match[2], loaded), vars); | ||
} | ||
} | ||
if (entry instanceof Object) { | ||
entry = loadRecursive(dir, entry); | ||
entry = loadRecursive(dir, entry, vars); | ||
} | ||
@@ -34,5 +31,6 @@ set(data, key, entry); | ||
module.exports.load = filePath => loadRecursive( | ||
module.exports.load = (filePath, vars = {}) => loadRecursive( | ||
path.dirname(filePath), | ||
yaml.safeLoad(fs.readFileSync(filePath, 'utf8')) | ||
yaml.safeLoad(fs.readFileSync(filePath, 'utf8')), | ||
vars | ||
); |
@@ -19,7 +19,7 @@ { | ||
"coveralls": "3.0.0", | ||
"lambda-tdd": "1.11.11", | ||
"lambda-tdd": "1.11.12", | ||
"js-gardener": "1.11.20", | ||
"semantic-release": "15.0.2" | ||
}, | ||
"version": "1.9.2", | ||
"version": "1.10.0", | ||
"scripts": { | ||
@@ -26,0 +26,0 @@ "test": "grunt gardener", |
@@ -80,1 +80,5 @@ [![Build Status](https://img.shields.io/travis/simlu/lambda-serverless-api/master.svg)](https://travis-ci.org/simlu/lambda-serverless-api) | ||
To monitor api errors and exceptions [lambda-rollbar](https://github.com/simlu/lambda-rollbar) can be enabled. Options are passed by putting them as `rollbar` into the constructor. | ||
## Loading serverless.yml | ||
Function `loadYaml` is exposed to load `serverless.yml` style files and resolve references and variables. This is handy to be used in `serverless.js` since the native loading currently has some issues. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18231
84
353