Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate the schema to require defaults #254

Open
theRemix opened this issue May 17, 2018 · 4 comments · Fixed by A-312/node-blueconfig#1
Open

Validate the schema to require defaults #254

theRemix opened this issue May 17, 2018 · 4 comments · Fixed by A-312/node-blueconfig#1

Comments

@theRemix
Copy link

Default values are required for every config key.
If a default value is not set, convict does not throw a validation error.

If there are any missing default keys, config.validate() should throw a validation error.

@jonpacker
Copy link

jonpacker commented Nov 22, 2018

This just bit us, when doing config.get('value'), the configuration object was returned { doc: 'Some documentation', format: '*', env: 'TEST_VALUE' }. This stopped happening when we set default.

@molomby
Copy link

molomby commented Feb 5, 2019

On 4.4.1, when I have no default configured for a value, eg..

var convict = require("convict")

var config = convict({
  something: {
    format: (val) => { /* noop */ },
    env: "SOMETHING"
  }
});

config.validate({ allowed: 'strict' });

The error I get is..

Error: something.format: should be of type Function: value was {}

Which is neither correct (format is a function..?) or at all helpful.

@A-312
Copy link
Contributor

A-312 commented Jan 6, 2020

var convict = require("convict")

var config = convict({
  something: {
    format: (val) => { /* noop */ },
    env: "SOMETHING"
  }
});

config.validate({ allowed: 'strict' });

Convict understands :

{
  "something": {
    "format": {
      "format": "function"
    },
    "env": {
      "default": "SOMETHING",
      "format": "string"
    }
  }
}

@A-312
Copy link
Contributor

A-312 commented Jan 6, 2020

Default values are required for every config key.
If a default value is not set, convict does not throw a validation error.

We can't do that because :

node-convict/lib/convict.js

Lines 241 to 245 in d263763

} else if (typeof node !== 'object' || Array.isArray(node) ||
node === null || Object.keys(node).length == 0) {
// Normalize shorthand "value" config properties
node = { default: node };
}

Or we should disable the magic normalizer when we use the strict mode.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants