Changing schema name causes `string` defaults to show up as undefined
anujdatar opened this issue · 2 comments
const Conf = require('conf');
const schema = {
foo: {
type: 'number',
maximum: 100,
minimum: 1,
default: 50
},
bar: {
type: 'string',
format: 'url',
default: 'https://www.google.com'
},
test: {
default: 'aaaaaaaaaaaaaaa'
}
};
const config = new Conf({schema});
console.log(config.get('foo')); // => 50
console.log(config.get('bar')); // => https://www.google.com
console.log(config.get('test')); // => aaaaaaaaaaaaaaa
This works fine, just changing even one character from the schema name causes all string defaults to be returned as undefined.
Something as simple as capitalizing the S in schema throws it off. Numbers seem to work fine. Same issue when you remove type definition from the schema, numbers work, strings don't.
const Conf = require('conf');
const Schema = {
foo: {
type: 'number',
maximum: 100,
minimum: 1,
default: 50
},
bar: {
type: 'string',
format: 'url',
default: 'https://www.google.com'
},
test: {
default: 'aaaaaaaaaaaaaaa'
}
};
const config = new Conf({Schema});
console.log(config.get('foo')); // => 50
console.log(config.get('bar')); // => undefined
console.log(config.get('test')); // => undefined
I am using Node v14.15.1
const config = new Conf({Schema});
is shorthand for:
const config = new Conf({Schema: Schema});
so the option name is no longer what's expected.
Right, what I meant was the name of the schema variable, not the option name.
I just used schema
and Schema
in the initial issue to say that even a slight change in the schema variable name causes string defaults to be returned as undefined. (Notice: one has a lowercase s
, and the other has an uppercase S
)
So, this works:
const schema = {...some_schema_object}
const config = new Conf({schema}) // works as expected
But, the following examples don't work:
const someRandomVariableName = {...some_schema_object}
const config = new Conf({someRandomVariableName}) // does not work
or
const confSchema = {...some_schema_object}
const config = new Conf({confSchema}) // does not work
or
const Schema = {...some_schema_object}
const config = new Conf({Schema}) // does not work