Skip to content

Commit

Permalink
Merge branch 'LeoAnesi-feat/validation-add-support-for-class-validator'
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilmysliwiec committed Nov 17, 2020
2 parents 2f780d4 + 2b8bf8d commit 431b3c4
Show file tree
Hide file tree
Showing 6 changed files with 3,167 additions and 2,985 deletions.
6 changes: 5 additions & 1 deletion lib/config.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ export class ConfigModule {
...process.env,
};
}
if (options.validationSchema) {
if (options.validate) {
const validatedConfig = options.validate(config);
validatedEnvConfig = validatedConfig;
this.assignVariablesToProcess(validatedConfig);
} else if (options.validationSchema) {
const validationOptions = this.getSchemaValidationOptions(options);
const {
error,
Expand Down
11 changes: 10 additions & 1 deletion lib/interfaces/config-module-options.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,23 @@ export interface ConfigModuleOptions {
*/
encoding?: string;

/**
* Custom function to validate environment variables. It takes an object containing environment
* variables as input and outputs validated environment variables.
* If exception is thrown in the function it would prevent the application from bootstrapping.
* Also, environment variables can be edited through this function, changes
* will be reflected in the process.env object.
*/
validate?: (config: Record<string, any>) => Record<string, any>;

/**
* Environment variables validation schema (Joi).
*/
validationSchema?: any;

/**
* Schema validation options.
* See: https://hapi.dev/family/joi/?v=16.1.8#anyvalidatevalue-options
* See: https://joi.dev/api/?v=17.3.0#anyvalidatevalue-options
*/
validationOptions?: Record<string, any>;

Expand Down
Loading

0 comments on commit 431b3c4

Please sign in to comment.