mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
fix(Variables): Properly resolve vars if prototype in path
This commit is contained in:
parent
5057f9ab86
commit
496d3574c6
@ -308,7 +308,10 @@ class Variables {
|
||||
return BbPromise.all(populations).then((results) =>
|
||||
results.forEach((result) => {
|
||||
if (result.value !== result.populated) {
|
||||
_.set(target, result.path, result.populated);
|
||||
const pathArray = Array.isArray(result.path) ? result.path : result.path.split('.');
|
||||
let obj = target;
|
||||
for (const property of pathArray.slice(0, -1)) obj = obj[property];
|
||||
obj[_.last(pathArray)] = result.populated;
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
2
test/fixtures/variables/serverless.yml
vendored
2
test/fixtures/variables/serverless.yml
vendored
@ -17,3 +17,5 @@ custom:
|
||||
nestedVal:
|
||||
prop: resolvedNested
|
||||
nestedReference: ${self:custom.${self:custom.nestedRef}.prop}
|
||||
prototype:
|
||||
nestedInPrototype: ${file(config.json):foo}-in-prototype
|
||||
|
||||
@ -2816,6 +2816,10 @@ describe('test/unit/lib/classes/Variables.test.js', () => {
|
||||
expect(processedConfig.custom.nestedReference).to.equal('resolvedNested');
|
||||
});
|
||||
|
||||
it('should handle resolving variables when `prototype` is part of the path', async () => {
|
||||
expect(processedConfig.custom.prototype.nestedInPrototype).to.equal('bar-in-prototype');
|
||||
});
|
||||
|
||||
describe('variable resolving', () => {
|
||||
describe('when unresolvedVariablesNotificationMode is set to "error"', () => {
|
||||
it('should error for missing "environment variable" type variables', async () => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user